Added console command handling to botcmd.py and used that to save messages on quit
This commit is contained in:
parent
f87b690f8b
commit
d5c994fb81
|
@ -0,0 +1 @@
|
|||
msgs.txt
|
28
botcmd.py
28
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()
|
||||
|
|
BIN
botcmd.pyc
BIN
botcmd.pyc
Binary file not shown.
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue