2013-06-29 22:18:56 +00:00
|
|
|
import eliza
|
2013-07-06 21:21:27 +00:00
|
|
|
import threading
|
2013-06-29 22:18:56 +00:00
|
|
|
|
2013-07-07 12:43:33 +00:00
|
|
|
concmd=['/q']
|
|
|
|
|
2013-06-29 22:18:56 +00:00
|
|
|
doctor=eliza.eliza()
|
2013-07-06 19:10:46 +00:00
|
|
|
opnicks=['nortti','nortti_','shikhin','shikhin_','shikhin__','sortiecat','martinFTW','graphitemaster','XgF','sprocklem']
|
2013-06-29 22:01:33 +00:00
|
|
|
opchans=['#osdev-offtopic']
|
|
|
|
oprights={}
|
|
|
|
for i in opnicks:
|
|
|
|
oprights[i]=opchans
|
2013-07-06 19:10:46 +00:00
|
|
|
autoops={}
|
|
|
|
msgs={}
|
2013-07-06 21:21:27 +00:00
|
|
|
msglock=threading.Lock()
|
2013-06-29 22:01:33 +00:00
|
|
|
|
2013-07-07 12:43:33 +00:00
|
|
|
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()
|
|
|
|
|
|
|
|
|
2013-06-29 22:01:33 +00:00
|
|
|
def parse((line,irc)):
|
|
|
|
line=line.split(' ')
|
2013-07-06 19:10:46 +00:00
|
|
|
nick=line[0].split('!')[0][1:]
|
|
|
|
chan=line[2] if line[2][0]=='#' else nick
|
2013-06-29 22:18:56 +00:00
|
|
|
if line[1]=='PRIVMSG':
|
|
|
|
if line[3]==':#echo':
|
2013-07-06 19:10:46 +00:00
|
|
|
irc.send('PRIVMSG %s :%s'%(chan,' '.join(line[4:])))
|
2013-06-29 22:18:56 +00:00
|
|
|
elif line[3]==':#op':
|
2013-07-06 19:10:46 +00:00
|
|
|
if len(line)==4:
|
|
|
|
irc.send('PRIVMSG NickServ :ACC '+nick)
|
|
|
|
else:
|
|
|
|
for name in line[4:]:
|
|
|
|
irc.send('PRIVMSG NickServ :ACC '+name)
|
2013-06-29 22:18:56 +00:00
|
|
|
elif line[3]==':#src':
|
2013-07-06 19:10:46 +00:00
|
|
|
irc.send('PRIVMSG %s :https://github.com/JuEeHa/oonbotti2'%chan)
|
|
|
|
elif line[3]==':#msg':
|
|
|
|
if len(line)>5:
|
2013-07-06 21:21:27 +00:00
|
|
|
msglock.acquire()
|
2013-07-06 19:10:46 +00:00
|
|
|
if line[4] not in msgs:
|
|
|
|
msgs[line[4]]=[]
|
|
|
|
msgs[line[4]].append((nick,' '.join(line[5:])))
|
2013-07-06 21:21:27 +00:00
|
|
|
msglock.release()
|
2013-07-06 19:10:46 +00:00
|
|
|
else:
|
|
|
|
irc.send('PRIVMSG %s :Usage: #msg nick message'%chan)
|
|
|
|
elif line[3]==':#readmsg':
|
2013-07-06 21:21:27 +00:00
|
|
|
msglock.acquire()
|
2013-07-06 19:10:46 +00:00
|
|
|
if nick in msgs:
|
|
|
|
for sender,msg in msgs.pop(nick):
|
|
|
|
irc.send('PRIVMSG %s :<%s> %s'%(chan,sender,msg))
|
|
|
|
else:
|
|
|
|
irc.send('PRIVMSG %s :You have no unread messages'%chan)
|
2013-07-06 21:21:27 +00:00
|
|
|
msglock.release()
|
2013-06-30 11:42:14 +00:00
|
|
|
elif line[3]==':#help':
|
2013-07-06 19:10:46 +00:00
|
|
|
irc.send('PRIVMSG %s :#echo #op #src #msg #readmsg #help'%chan)
|
2013-06-29 22:18:56 +00:00
|
|
|
elif line[3][1:] in ('oonbotti:', 'oonbotti', 'oonbotti,', 'oonbotti2', 'oonbotti2:', 'oonbotti2,'):
|
2013-07-06 19:10:46 +00:00
|
|
|
irc.send('PRIVMSG %s :%s: %s'%(chan,nick,doctor.respond(' '.join(line[4:]))))
|
2013-06-29 22:01:33 +00:00
|
|
|
elif line[1]=='NOTICE' and line[0].split('!')[0]==':NickServ' and line[4]=='ACC':
|
|
|
|
if line[3][1:] in oprights and int(line[5])==3:
|
2013-07-06 19:10:46 +00:00
|
|
|
for opchan in oprights[line[3][1:]]:
|
|
|
|
irc.send('MODE %s +o %s'%(opchan,line[3][1:]))
|
|
|
|
elif line[1]=='JOIN' and nick in autoops and chan in autoops[nick]:
|
|
|
|
irc.send('PRIVMSG NickServ :ACC '+nick)
|
|
|
|
|
2013-07-06 21:21:27 +00:00
|
|
|
msglock.acquire()
|
2013-07-06 19:10:46 +00:00
|
|
|
if (line[1]=='PRIVMSG' or line[1]=='JOIN') and nick in msgs:
|
2013-07-07 12:43:33 +00:00
|
|
|
irc.send('PRIVMSG %s :%s: You have unread messages, read them with #readmsg'%(chan,nick))
|
2013-07-06 21:21:27 +00:00
|
|
|
msglock.release()
|
2013-07-07 12:43:33 +00:00
|
|
|
|
|
|
|
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()
|