forked from CloudBotIRC/CloudBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request CloudBotIRC#224 from linuxdaemon/gonzobot+mock
Add mock command
- Loading branch information
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from cloudbot import hook | ||
|
||
|
||
def get_latest_line(conn, chan, nick): | ||
for name, _, msg in reversed(conn.history[chan.casefold()]): | ||
if nick.casefold() == name.casefold(): | ||
return msg | ||
|
||
return None | ||
|
||
|
||
@hook.command | ||
def mock(text, chan, conn, message): | ||
"""<nick> - turn <user>'s last message in to aLtErNaTiNg cApS""" | ||
nick = text.strip() | ||
line = get_latest_line(conn, chan, nick) | ||
if line is None: | ||
return "Nothing found in recent history for {}".format(nick) | ||
|
||
if line.startswith("\x01ACTION"): | ||
fmt = "* {nick} {msg}" | ||
line = line[8:].strip(' \x01') | ||
else: | ||
fmt = "<{nick}> {msg}" | ||
|
||
# Return the message in aLtErNaTiNg cApS | ||
line = "".join(c.upper() if i & 1 else c.lower() for i, c in enumerate(line)) | ||
message(fmt.format(nick=nick, msg=line)) |