Added console command handling to botcmd.py and used that to save messages on quit

This commit is contained in:
Juhani Haverinen 2013-07-07 15:43:33 +03:00
parent f87b690f8b
commit d5c994fb81
4 changed files with 30 additions and 3 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
msgs.txt

View File

@ -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()

Binary file not shown.

View File

@ -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):