Skip to content

Commit

Permalink
Merge pull request CloudBotIRC#224 from linuxdaemon/gonzobot+mock
Browse files Browse the repository at this point in the history
Add mock command
  • Loading branch information
edwardslabs authored Nov 21, 2017
2 parents 93de966 + 21c49cb commit 7475dc7
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions plugins/mock.py
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))

0 comments on commit 7475dc7

Please sign in to comment.