Permalink
Browse files

Merge pull request #2 from mnn2104/master

remember and forget work
  • Loading branch information...
2 parents fcb156c + d1edda1 commit 385054e80d820469ea64c464b875118152bc4c46 @magoni committed Mar 5, 2012
Showing with 28 additions and 1 deletion.
  1. +2 −1 .gitignore
  2. +26 −0 dongbot.py
View
@@ -1,2 +1,3 @@
*~
-\#*\#
+\#*\#
+.DS_Store
View
@@ -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,
@@ -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))
@@ -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.