Rewrote auth system, added #kick and arguments to #deop

This commit is contained in:
Juhani Haverinen 2013-07-08 19:57:42 +03:00
parent 395770d9ae
commit c25af3b204
2 changed files with 42 additions and 11 deletions

View File

@ -1,17 +1,19 @@
import eliza import eliza
import threading import threading
concmd=['/q'] concmd=['/q','/debg']
doctor=eliza.eliza() doctor=eliza.eliza()
opnicks=['nortti','nortti_','shikhin','shikhin_','shikhin__','sortiecat','martinFTW','graphitemaster','XgF','sprocklem'] trusted=['nortti','nortti_','shikhin','shikhin_','shikhin__','sortiecat','martinFTW','graphitemaster','XgF','sprocklem']
opchans=['#osdev-offtopic'] opchans=['#osdev-offtopic']
oprights={} oprights={}
for i in opnicks: for i in trusted:
oprights[i]=opchans oprights[i]=opchans
autoops={} autoops={}
msgs={} msgs={}
msglock=threading.Lock() msglock=threading.Lock()
authcmds={}
authcmdlock=threading.Lock()
msglock.acquire() msglock.acquire()
f=open('msgs.txt','r') f=open('msgs.txt','r')
@ -25,7 +27,14 @@ for line in f:
f.close() f.close()
msglock.release() msglock.release()
def addauthcmd(nick,cmd):
authcmdlock.acquire()
if nick not in trusted:
return
if nick not in authcmds:
authcmds[nick]=[]
authcmds[nick].append(cmd)
authcmdlock.release()
def parse((line,irc)): def parse((line,irc)):
line=line.split(' ') line=line.split(' ')
nick=line[0].split('!')[0][1:] nick=line[0].split('!')[0][1:]
@ -35,12 +44,26 @@ def parse((line,irc)):
irc.send('PRIVMSG %s :%s'%(chan,' '.join(line[4:]))) irc.send('PRIVMSG %s :%s'%(chan,' '.join(line[4:])))
elif line[3]==':#op': elif line[3]==':#op':
if len(line)==4: if len(line)==4:
addauthcmd(nick,'MODE %s +o %s'%(chan,nick))
irc.send('PRIVMSG NickServ :ACC '+nick) irc.send('PRIVMSG NickServ :ACC '+nick)
else: else:
for name in line[4:]: for name in line[4:]:
irc.send('PRIVMSG NickServ :ACC '+name) addauthcmd(nick,'MODE %s +o %s'%(chan,name))
irc.send('PRIVMSG NickServ :ACC '+nick)
elif line[3]==':#deop': elif line[3]==':#deop':
irc.send('MODE %s -o %s'%(chan,nick)) if len(line)==4:
addauthcmd(nick,'MODE %s -o %s'%(chan,nick))
irc.send('PRIVMSG NickServ :ACC '+nick)
else:
for name in line[4:]:
addauthcmd(nick,'MODE %s -o %s'%(chan,name))
irc.send('PRIVMSG NickServ :ACC '+nick)
elif line[3]==':#kick':
if len(line)>4:
addauthcmd(nick,'KICK %s %s :%s'%(chan,line[4],' '.join(line[5:])))
irc.send('PRIVMSG NickServ :ACC '+nick)
else:
irc.send('PRIVMSG %s :Usage #kick nick reason'%chan)
elif line[3]==':#src': elif line[3]==':#src':
irc.send('PRIVMSG %s :https://github.com/JuEeHa/oonbotti2'%chan) irc.send('PRIVMSG %s :https://github.com/JuEeHa/oonbotti2'%chan)
elif line[3]==':#msg': elif line[3]==':#msg':
@ -65,11 +88,17 @@ def parse((line,irc)):
elif line[3][1:] in ('oonbotti:', 'oonbotti', 'oonbotti,', 'oonbotti2', 'oonbotti2:', 'oonbotti2,'): elif line[3][1:] in ('oonbotti:', 'oonbotti', 'oonbotti,', 'oonbotti2', 'oonbotti2:', 'oonbotti2,'):
irc.send('PRIVMSG %s :%s: %s'%(chan,nick,doctor.respond(' '.join(line[4:])))) irc.send('PRIVMSG %s :%s: %s'%(chan,nick,doctor.respond(' '.join(line[4:]))))
elif line[1]=='NOTICE' and line[0].split('!')[0]==':NickServ' and line[4]=='ACC': 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: authcmdlock.acquire()
for opchan in oprights[line[3][1:]]: if line[3][1:] in trusted and line[3][1:] in authcmds and line[5]=='3':
irc.send('MODE %s +o %s'%(opchan,line[3][1:])) for i in authcmds.pop(line[3][1:]):
irc.send(i)
else:
authcmds.pop(line[3][1:])
authcmdlock.release()
elif line[1]=='JOIN' and nick in autoops and chan in autoops[nick]: elif line[1]=='JOIN' and nick in autoops and chan in autoops[nick]:
irc.send('PRIVMSG NickServ :ACC '+nick) irc.send('PRIVMSG NickServ :ACC '+nick)
elif line[1]=='482':
irc.send('PRIVMSG %s :Not op'%line[3])
msglock.acquire() msglock.acquire()
if (line[1]=='PRIVMSG' or line[1]=='JOIN') and nick in msgs: if (line[1]=='PRIVMSG' or line[1]=='JOIN') and nick in msgs:
@ -88,13 +117,15 @@ def execcmd(cmdline):
def help(cmd): def help(cmd):
if cmd=='': if cmd=='':
return '#echo #op #deop #src #msg #readmsg #help' return '#echo #op #deop #kick #src #msg #readmsg #help'
elif cmd=='#echo': elif cmd=='#echo':
return '#echo text echo text back' return '#echo text echo text back'
elif cmd=='#op': elif cmd=='#op':
return '#op [nick] give nick or yourself op rights in case nick/you is/are trusted by oonbotti2 and identified with NickServ' return '#op [nick] give nick or yourself op rights in case nick/you is/are trusted by oonbotti2 and identified with NickServ'
elif cmd=='#deop': elif cmd=='#deop':
return '#deop remove your oprights (added due to irrarional demand by shikhin and sortiecat)' return '#deop [nick] remove your/nick\'s op rights (added due to irrational demand by shikhin and sortiecat, nick support added for same reason)'
elif cmd=='#kick':
return '#kick nick reason kicks nick with specified reason'
elif cmd=='#src': elif cmd=='#src':
return '#src paste a link to oonbotti2\'s git repo' return '#src paste a link to oonbotti2\'s git repo'
elif cmd=='#msg': elif cmd=='#msg':

Binary file not shown.