diff --git a/botcmd.py b/botcmd.py index e7e95ae..cf091a3 100644 --- a/botcmd.py +++ b/botcmd.py @@ -383,13 +383,26 @@ def parse((line, irc)): return if line[1]=='PRIVMSG': + reply = chan + cmdline = [line[3][1:]] + line[4:] while '' in cmdline: cmdline.remove('') + # #chan: channel override prefix + if matchcmd(cmdline, '#chan'): + if matchcmd(cmdline, '#chan', 'channel {command}'): + newchan, newcmdline = parsecmd(cmdline, 'channel {command}') + newcmdline = newcmdline.split(' ') + if isauthorized(irc, newchan, nick): + chan = newchan + cmdline = newcmdline + else: + irc.msg(chan, 'Usage #chan channel command') + if matchcmd(cmdline, '#echo'): text = parsecmd(cmdline, '{text}') - irc.msg(chan, zwsp+text) + irc.msg(reply, zwsp+text) elif matchcmd(cmdline, '#op'): args = parsecmd(cmdline, '{args}') chmode(irc, chan, nick, '+o', args.split(' ')) @@ -413,11 +426,11 @@ def parse((line, irc)): if isauthorized(irc, chan, nick): irc.send('KICK %s %s :%s'%(chan, kicknick, kickreason)) else: - irc.msg(chan, 'Usage #kick nick reason') + irc.msg(reply, 'Usage #kick nick reason') elif matchcmd(cmdline, '#src'): - irc.msg(chan, 'https://github.com/JuEeHa/oonbotti2') + irc.msg(reply, 'https://github.com/JuEeHa/oonbotti2') elif matchcmd(cmdline, '#prefix') and chan == '#osdev-offtopic': - irc.msg(chan, 'gopher://smar.fi:7070/0/hash-prefix') + irc.msg(reply, 'gopher://smar.fi:7070/0/hash-prefix') elif matchcmd(cmdline, '#msg'): if matchcmd(cmdline, '#msg', 'nick {message}'): msgnick, message = parsecmd(cmdline, 'nick {message}') @@ -427,7 +440,7 @@ def parse((line, irc)): msgs[msgnick].append((nick, message)) msgslock.release() else: - irc.msg(chan, 'Usage: #msg nick message') + irc.msg(reply, 'Usage: #msg nick message') elif matchcmd(cmdline, '#trusted?'): if matchcmd(cmdline, '#trusted?', '[nick]'): trustnick = parsecmd(cmdline, '[nick]') @@ -436,13 +449,13 @@ def parse((line, irc)): account = getaccount(irc, trustnick) if account: if istrusted(chan, account): - irc.msg(chan, '%s is trusted' % trustnick) + irc.msg(reply, '%s is trusted' % trustnick) else: - irc.msg(chan, '%s is not trusted' % trustnick) + irc.msg(reply, '%s is not trusted' % trustnick) else: - irc.msg(chan, 'Failed to get account for %s' % trustnick) + irc.msg(reply, 'Failed to get account for %s' % trustnick) else: - irc.msg(chan, 'Usage: #trusted? [nick]') + irc.msg(reply, 'Usage: #trusted? [nick]') elif matchcmd(cmdline, '#trust'): if matchcmd(cmdline, '#trust', 'nick'): trustnick = parsecmd(cmdline, 'nick') @@ -451,9 +464,9 @@ def parse((line, irc)): if account: addtrusted(chan, account) else: - irc.msg(chan, 'Failed to get account for %s' % trustnick) + irc.msg(reply, 'Failed to get account for %s' % trustnick) else: - irc.msg(chan, 'Usage #trust nick') + irc.msg(reply, 'Usage #trust nick') elif matchcmd(cmdline, '#untrust'): if matchcmd(cmdline, '#untrust', 'nick'): untrustnick = parsecmd(cmdline, 'nick') @@ -465,9 +478,9 @@ def parse((line, irc)): rmtrusted(chan, untrustnick) godslock.release() else: - irc.msg(chan, 'Failed to get account for %s' % untrustnick) + irc.msg(reply, 'Failed to get account for %s' % untrustnick) else: - irc.msg(chan, 'Usage #untrust nick') + irc.msg(reply, 'Usage #untrust nick') elif matchcmd(cmdline, '#ls-trusted'): trustedlock.acquire() if chan in trusted: @@ -479,40 +492,40 @@ def parse((line, irc)): if isauthorized(irc, chan, nick): irc.send('INVITE %s %s' % (invitenick, chan)) else: - irc.msg(chan, 'Usage #invite nick') + irc.msg(reply, 'Usage #invite nick') elif matchcmd(cmdline, '#help'): if matchcmd(cmdline, '#help', '[command]'): command = parsecmd(cmdline, '[command]') helptext = help(command) if helptext: - irc.msg(chan, zwsp+helptext) - elif matchcmd(cmdline, '#esoteric') and chan=='#esoteric': - irc.msg(chan, 'Nothing here') + irc.msg(reply, zwsp+helptext) + elif matchcmd(cmdline, '#esoteric') and chan == '#esoteric': + irc.msg(reply, 'Nothing here') elif cmdline[0] in [irc.nick, irc.nick+',', irc.nick+':']: question = parsecmd(cmdline, '{question}') - irc.msg(chan, '%s: %s' % (nick, doctor.respond(question))) + irc.msg(reply, '%s: %s' % (nick, doctor.respond(question))) elif die_expr.match(cmdline[0]): - die=cmdline[0][1:].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.msg(chan, 'Not supported') + die = cmdline[0][1:].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.msg(reply, 'Not supported') else: - irc.msg(chan, '%s%s' % (random.randint(0,9), random.randint(0,9))) - elif die<2: - irc.msg(chan, 'This die is not available in your space-time region.') - elif times<1: - irc.msg(chan, 'What exactly do you want me to do?') - elif times>128: - irc.msg(chan, 'Sorry, I don\'t have that many. Can I borrow yours?') + irc.msg(reply, '%s%s' % (random.randint(0,9), random.randint(0,9))) + elif die < 2: + irc.msg(reply, 'This die is not available in your space-time region.') + elif times < 1: + irc.msg(reply, 'What exactly do you want me to do?') + elif times > 128: + irc.msg(reply, '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.msg(chan, '%s (%s)' % (str(result), ', '.join([str(i) for i in rolls]))) + rolls = [random.randint(1, die) for i in xrange(times)] + result = reduce((lambda x, y: x + y), rolls) + if times > 1: + irc.msg(reply, '%s (%s)' % (str(result), ', '.join([str(i) for i in rolls]))) else: - irc.msg(chan, str(result)) + irc.msg(reply, str(result)) elif line[1] == '330': # WHOIS: is logged in as whoisnick = line[3] account = line[4] @@ -560,6 +573,7 @@ def usage(cmd, message = True): '#untrust': 'nick', '#ls-trusted': '', '#invite': 'nick', + '#chan': 'channel command', '#help': '[command]'} if cmd in usage: @@ -584,10 +598,11 @@ def help(cmd): '#untrust': 'remove nick from trusted list', '#ls-trusted': 'list nicks that are trusted. use only in a query', '#invite': 'invites nick to channel', + '#chan': 'Runs the command as if it was sent on the specified channel. Requires user to be trusted', '#help': 'give short info of command or list commands'} if cmd=='': - return '#echo #op #deop #voice #devoice #kick #src #msg #trusted? #trust #untrust #ls-trusted #invite #help' + return '#echo #op #deop #voice #devoice #kick #src #msg #trusted? #trust #untrust #ls-trusted #invite #chan #help' elif cmd=='me': return 'I shall.' elif cmd in helptext: