diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a5414f3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +msgs.txt diff --git a/botcmd.py b/botcmd.py index b1c158c..95cae81 100644 --- a/botcmd.py +++ b/botcmd.py @@ -1,6 +1,8 @@ import eliza import threading +concmd=['/q'] + doctor=eliza.eliza() opnicks=['nortti','nortti_','shikhin','shikhin_','shikhin__','sortiecat','martinFTW','graphitemaster','XgF','sprocklem'] opchans=['#osdev-offtopic'] @@ -11,6 +13,19 @@ autoops={} msgs={} msglock=threading.Lock() +msglock.acquire() +f=open('msgs.txt','r') +for line in f: + while len(line)>0 and line[-1]=='\n': line=line[:-1] + if len(line)>0: + receiver,sender,msg=line.split('\t') + if receiver not in msgs: + msgs[receiver]=[] + msgs[receiver].append((sender,msg)) +f.close() +msglock.release() + + def parse((line,irc)): line=line.split(' ') nick=line[0].split('!')[0][1:] @@ -33,7 +48,6 @@ def parse((line,irc)): msgs[line[4]]=[] msgs[line[4]].append((nick,' '.join(line[5:]))) msglock.release() - irc.send('PRIVMSG %s :Sent'%chan) else: irc.send('PRIVMSG %s :Usage: #msg nick message'%chan) elif line[3]==':#readmsg': @@ -57,5 +71,15 @@ def parse((line,irc)): msglock.acquire() if (line[1]=='PRIVMSG' or line[1]=='JOIN') and nick in msgs: - irc.send('PRIVMSG %s :You have unread messages, read them with #readmsg'%chan) + irc.send('PRIVMSG %s :%s: You have unread messages, read them with #readmsg'%(chan,nick)) msglock.release() + +def execcmd(cmdline): + if cmdline[0]=='/q': + msglock.acquire() + f=open('msgs.txt','w') + for receiver in msgs: + for sender, msg in msgs[receiver]: + f.write('%s\t%s\t%s\n'%(receiver,sender,msg)) + f.close() + msglock.release() diff --git a/botcmd.pyc b/botcmd.pyc index 2a9d332..45ca5cb 100644 Binary files a/botcmd.pyc and b/botcmd.pyc differ diff --git a/ircbot.py b/ircbot.py index 199fadd..8c70f18 100644 --- a/ircbot.py +++ b/ircbot.py @@ -89,6 +89,8 @@ class Keyhandler(threading.Thread): while True: line=raw_input() c=line.split(' ') + if c[0] in botcmd.concmd: + botcmd.execcmd(c) if c[0]=='/j' and len(c)==2: self.outc.send('JOIN '+c[1]) elif c[0]=='/m' and len(c)>2: @@ -96,7 +98,7 @@ class Keyhandler(threading.Thread): elif c[0]=='/q' and len(c)==1: self.outc.send('QUIT') break - elif c[0][0]=='/': + elif c[0][0]=='/' and c[0] not in botcmd.concmd: self.outc.send(c[0][1:].upper()+' '+' '.join(c[1:])) class Loghandler(threading.Thread):