Skip to content

Commit

Permalink
Merge pull request #2 from mnn2104/master
Browse files Browse the repository at this point in the history
remember and forget work
  • Loading branch information
magoni committed Mar 5, 2012
2 parents fcb156c + d1edda1 commit 385054e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*~
\#*\#
\#*\#
.DS_Store
26 changes: 26 additions & 0 deletions dongbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

IRC_PORT = 6667
SERVER = 'esm41.com'
REMEMBER_OBJ = re.compile(r"remember:(.*)->(.*)")
FORGET_OBJ = re.compile(r"forget:(.*)")
CHAN_MESSAGE = re.compile(r"PRIVMSG #(\w+) :(.*)")
remembered = {}

class IRCBot:
def __init__(self,
Expand Down Expand Up @@ -52,9 +56,30 @@ def start(self):

def handle(self, message):
print message
chan_message = CHAN_MESSAGE.search(message)
if message.startswith('PING :'):
server = message[len('PING'):]
self.s.send('PONG%s\r\n' % (server,))
elif chan_message:
#this should end up being refactored at some point in time
channel = chan_message.groups()[0]
msg = chan_message.groups()[1]
rem_object = REMEMBER_OBJ.search(msg)
for_object = FORGET_OBJ.search(msg)
if rem_object:
groups = rem_object.groups()
remembered[groups[0].strip()] = groups[1].strip()
self.send_action("#" + channel, "remembered \"%s\"" %
(groups[0].strip(),))
elif for_object:
groups = for_object.groups()
remembered.pop(groups[0].strip())
self.send_action("#" + channel, "forgot \"%s\"" %
(groups[0].strip(),))
else:
for key in remembered:
if msg.find(key) != -1:
self.send_message("#" + channel, remembered[key])

def send_message(self, channel, message):
self.s.send('PRIVMSG %s :%s\r\n' % (channel, message))
Expand All @@ -67,5 +92,6 @@ def irc_quit(self, message):
self.s.close()

if "__main__" == __name__:

bot = IRCBot("pydongbot", 'lol', SERVER, ['#dongtest'])
bot.start()

0 comments on commit 385054e

Please sign in to comment.