Take advantage of new irc-object

This commit is contained in:
Juhani Haverinen 2015-01-24 14:21:06 +02:00
parent 90f88aedc4
commit 64c7f8165b
1 changed files with 34 additions and 34 deletions

View File

@ -105,19 +105,19 @@ def chmode(irc,chan,nick,mode,args):
else:
for name in args:
addauthcmd(nick,'MODE %s %s %s'%(chan,mode,name))
irc.send('PRIVMSG NickServ :ACC '+nick)
irc.msg('NickServ', 'ACC '+nick)
def parse((line,irc)):
line=line.split(' ')
nick=line[0].split('!')[0][1:]
chan=line[2] if line[2][0]=='#' else nick
chan=line[2] if line[2][0]=='#' else nick
if nick in blacklist:
return
if line[1]=='PRIVMSG':
if line[3]==':#echo':
irc.send('PRIVMSG %s :\xe2\x80\x8b%s'%(chan,' '.join(line[4:])))
irc.msg(chan, '\xe2\x80\x8b'+' '.join(line[4:]))
elif line[3]==':#op':
chmode(irc,chan,nick,'+o',line[4:])
elif line[3]==':#deop':
@ -128,19 +128,19 @@ def parse((line,irc)):
chmode(irc,chan,nick,'-v',line[4:])
elif line[3]==':#kick':
if len(line)>4:
if line[4].lower()=='oonbotti2':
if line[4].lower()==irc.nick:
irc.send('KICK %s %s :Fuck you'%(chan,nick))
elif random.randint(0,9)==0 and len(line)==5:
irc.send('KICK %s %s :Bam'%(chan,nick))
else:
addauthcmd(nick,'KICK %s %s :%s'%(chan,line[4],' '.join(line[5:])))
irc.send('PRIVMSG NickServ :ACC '+nick)
irc.msg('NickServ', 'ACC '+nick)
else:
irc.send('PRIVMSG %s :Usage #kick nick reason'%chan)
irc.msg(chan, 'Usage #kick nick reason')
elif line[3]==':#src':
irc.send('PRIVMSG %s :https://github.com/JuEeHa/oonbotti2'%chan)
irc.msg(chan, 'https://github.com/JuEeHa/oonbotti2')
elif line[3]==':#prefix' and chan=='#osdev-offtopic':
irc.send('PRIVMSG %s :gopher://smar.fi:7070/0/hash-prefix'%chan)
irc.msg(chan, 'gopher://smar.fi:7070/0/hash-prefix')
elif line[3]==':#msg':
if len(line)>5:
msglock.acquire()
@ -149,65 +149,65 @@ def parse((line,irc)):
msgs[line[4]].append((nick,' '.join(line[5:])))
msglock.release()
else:
irc.send('PRIVMSG %s :Usage: #msg nick message'%chan)
irc.msg(chan, 'Usage: #msg nick message')
elif line[3]==':#trusted?':
addauthcmd(nick,'PRIVMSG %s :%s: You are trusted'%(chan,nick))
irc.send('PRIVMSG NickServ :ACC '+nick)
irc.msg('NickServ', 'ACC '+nick)
elif line[3]==':#trust':
if len(line)==5:
addauthfunc(nick,(lambda :addtrusted(line[4])))
irc.send('PRIVMSG NickServ :ACC '+nick)
irc.msg('NickServ', 'ACC '+nick)
else:
irc.send('PRIVMSG %s :Usage #trust nick'%chan)
irc.msg(chan, 'Usage #trust nick')
elif line[3]==':#untrust':
if len(line)==5:
godslock.acquire()
if line[4] not in gods:
addauthfunc(nick,(lambda :rmtrusted(line[4])))
irc.send('PRIVMSG NickServ :ACC '+nick)
irc.msg('NickServ', 'ACC '+nick)
godslock.release()
else:
irc.send('PRIVMSG %s :Usage #trust nick'%chan)
irc.msg(chan, 'Usage #untrust nick')
elif line[3]==':#ls-trusted':
trustedlock.acquire()
irc.send('PRIVMSG %s :%s'%(nick,', '.join(trusted)))
irc.msg(nick, ', '.join(trusted))
trustedlock.release()
elif line[3]==':#invite':
if len(line)==5:
addauthcmd(nick, 'INVITE %s %s'%(line[4], chan))
irc.send('PRIVMSG NickServ :ACC '+nick)
irc.msg('NickServ', 'ACC '+nick)
else:
irc.send('PRIVMSG %s :Usage #invite nick'%chan)
irc.msg(chan, 'Usage #invite nick')
elif line[3]==':#help':
helptext=help(' '.join(line[4:]))
if helptext:
irc.send('PRIVMSG %s : %s'%(chan,helptext))
irc.msg(chan, helptext)
elif line[3]==':#esoteric' and chan=='#esoteric':
irc.send('PRIVMSG %s :Nothing here'%chan)
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.msg(chan, 'Nothing here')
elif line[3][1:] in [irc.nick, irc.nick+',', irc.nick+':']:
irc.msg(chan, '%s: %s' % (nick, doctor.respond(' '.join(line[4:]))))
elif die_expr.match(line[3][1:]):
die=line[3][2:].split('d')
times=int(die[0]) if die[0] else 1
die='%' if die[1]=='%' else int(die[1])
if die=='%':
if times!=1:
irc.send('PRIVMSG %s :Not supported'%chan)
irc.msg(chan, 'Not supported')
else:
irc.send('PRIVMSG %s :%s%s'%(chan, random.randint(0,9), random.randint(0,9)))
irc.msg(chan, '%s%s' % (random.randint(0,9), random.randint(0,9)))
elif die<2:
irc.send('PRIVMSG %s :This die is not available in your space-time region.'%chan)
irc.msg(chan, 'This die is not available in your space-time region.')
elif times<1:
irc.send('PRIVMSG %s :What exactly do you want me to do?'%chan)
irc.msg(chan, 'What exactly do you want me to do?')
elif times>128:
irc.send('PRIVMSG %s :Sorry, I don\'t have that many. Can I borrow yours?'%chan)
irc.msg(chan, 'Sorry, I don\'t have that many. Can I borrow yours?')
else:
rolls=[random.randint(1, die) for i in xrange(times)]
result=reduce((lambda x,y:x+y), rolls)
if times>1:
irc.send('PRIVMSG %s :%s (%s)'%(chan, str(result), ', '.join([str(i) for i in rolls])))
irc.msg(chan, '%s (%s)' % (str(result), ', '.join([str(i) for i in rolls])))
else:
irc.send('PRIVMSG %s :%s'%(chan, str(result)))
irc.msg(chan, str(result))
elif line[1]=='NOTICE' and line[0].split('!')[0]==':NickServ' and line[4]=='ACC':
authfunclock.acquire()
authcmdlock.acquire()
@ -229,15 +229,15 @@ def parse((line,irc)):
if line[3][1:] in authfuncs:
authfuncs.pop(line[3][1:])
if line[5]=='0':
irc.send('PRIVMSG %s :Register account with NickServ'%line[3][1:])
irc.msg(line[3][1:], 'Register account with NickServ')
elif line[5]=='1':
irc.send('PRIVMSG %s :Identify with NickServ'%line[3][1:])
irc.msg(line[3][1:], 'PRIVMSG %s :Identify with NickServ')
else:
irc.send('PRIVMSG %s :WTF, NickServ returned %s'%(line[3][1:],line[5]))
irc.msg(line[3][1:], 'WTF, NickServ returned %s'+line[5])
authcmdlock.release()
authfunclock.release()
elif line[1]=='482':
irc.send('PRIVMSG %s :Not op'%line[3])
irc.msg(line[3], 'Not op')
#elif line[1]=='332' or line[1]=='TOPIC':
# if line[1]=='332':
# ch=line[3]
@ -250,7 +250,7 @@ def parse((line,irc)):
msglock.acquire()
if (line[1]=='PRIVMSG' or line[1]=='JOIN') and nick in msgs:
for sender,msg in msgs.pop(nick):
irc.send('PRIVMSG %s :<%s> %s'%(nick,sender,msg))
irc.msg(nick, '<%s> %s' % (sender, msg))
msglock.release()
def execcmd(cmdline):
@ -290,7 +290,7 @@ def help(cmd):
elif cmd=='#msg':
return '#msg nick message send a message to nick'
elif cmd=='#trusted?':
return '#trusted? tell you if you are trusted by oonbotti'
return '#trusted? tell you if you are trusted by oonbotti2'
elif cmd=='#trust':
return '#trust nick add nick to trusted list'
elif cmd=='#untrust':