Add #chan override prefix
This commit is contained in:
parent
d98bfd7b47
commit
47a8418785
89
botcmd.py
89
botcmd.py
|
@ -383,13 +383,26 @@ def parse((line, irc)):
|
||||||
return
|
return
|
||||||
|
|
||||||
if line[1]=='PRIVMSG':
|
if line[1]=='PRIVMSG':
|
||||||
|
reply = chan
|
||||||
|
|
||||||
cmdline = [line[3][1:]] + line[4:]
|
cmdline = [line[3][1:]] + line[4:]
|
||||||
while '' in cmdline:
|
while '' in cmdline:
|
||||||
cmdline.remove('')
|
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'):
|
if matchcmd(cmdline, '#echo'):
|
||||||
text = parsecmd(cmdline, '{text}')
|
text = parsecmd(cmdline, '{text}')
|
||||||
irc.msg(chan, zwsp+text)
|
irc.msg(reply, zwsp+text)
|
||||||
elif matchcmd(cmdline, '#op'):
|
elif matchcmd(cmdline, '#op'):
|
||||||
args = parsecmd(cmdline, '{args}')
|
args = parsecmd(cmdline, '{args}')
|
||||||
chmode(irc, chan, nick, '+o', args.split(' '))
|
chmode(irc, chan, nick, '+o', args.split(' '))
|
||||||
|
@ -413,11 +426,11 @@ def parse((line, irc)):
|
||||||
if isauthorized(irc, chan, nick):
|
if isauthorized(irc, chan, nick):
|
||||||
irc.send('KICK %s %s :%s'%(chan, kicknick, kickreason))
|
irc.send('KICK %s %s :%s'%(chan, kicknick, kickreason))
|
||||||
else:
|
else:
|
||||||
irc.msg(chan, 'Usage #kick nick reason')
|
irc.msg(reply, 'Usage #kick nick reason')
|
||||||
elif matchcmd(cmdline, '#src'):
|
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':
|
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'):
|
elif matchcmd(cmdline, '#msg'):
|
||||||
if matchcmd(cmdline, '#msg', 'nick {message}'):
|
if matchcmd(cmdline, '#msg', 'nick {message}'):
|
||||||
msgnick, message = parsecmd(cmdline, 'nick {message}')
|
msgnick, message = parsecmd(cmdline, 'nick {message}')
|
||||||
|
@ -427,7 +440,7 @@ def parse((line, irc)):
|
||||||
msgs[msgnick].append((nick, message))
|
msgs[msgnick].append((nick, message))
|
||||||
msgslock.release()
|
msgslock.release()
|
||||||
else:
|
else:
|
||||||
irc.msg(chan, 'Usage: #msg nick message')
|
irc.msg(reply, 'Usage: #msg nick message')
|
||||||
elif matchcmd(cmdline, '#trusted?'):
|
elif matchcmd(cmdline, '#trusted?'):
|
||||||
if matchcmd(cmdline, '#trusted?', '[nick]'):
|
if matchcmd(cmdline, '#trusted?', '[nick]'):
|
||||||
trustnick = parsecmd(cmdline, '[nick]')
|
trustnick = parsecmd(cmdline, '[nick]')
|
||||||
|
@ -436,13 +449,13 @@ def parse((line, irc)):
|
||||||
account = getaccount(irc, trustnick)
|
account = getaccount(irc, trustnick)
|
||||||
if account:
|
if account:
|
||||||
if istrusted(chan, account):
|
if istrusted(chan, account):
|
||||||
irc.msg(chan, '%s is trusted' % trustnick)
|
irc.msg(reply, '%s is trusted' % trustnick)
|
||||||
else:
|
else:
|
||||||
irc.msg(chan, '%s is not trusted' % trustnick)
|
irc.msg(reply, '%s is not trusted' % trustnick)
|
||||||
else:
|
else:
|
||||||
irc.msg(chan, 'Failed to get account for %s' % trustnick)
|
irc.msg(reply, 'Failed to get account for %s' % trustnick)
|
||||||
else:
|
else:
|
||||||
irc.msg(chan, 'Usage: #trusted? [nick]')
|
irc.msg(reply, 'Usage: #trusted? [nick]')
|
||||||
elif matchcmd(cmdline, '#trust'):
|
elif matchcmd(cmdline, '#trust'):
|
||||||
if matchcmd(cmdline, '#trust', 'nick'):
|
if matchcmd(cmdline, '#trust', 'nick'):
|
||||||
trustnick = parsecmd(cmdline, 'nick')
|
trustnick = parsecmd(cmdline, 'nick')
|
||||||
|
@ -451,9 +464,9 @@ def parse((line, irc)):
|
||||||
if account:
|
if account:
|
||||||
addtrusted(chan, account)
|
addtrusted(chan, account)
|
||||||
else:
|
else:
|
||||||
irc.msg(chan, 'Failed to get account for %s' % trustnick)
|
irc.msg(reply, 'Failed to get account for %s' % trustnick)
|
||||||
else:
|
else:
|
||||||
irc.msg(chan, 'Usage #trust nick')
|
irc.msg(reply, 'Usage #trust nick')
|
||||||
elif matchcmd(cmdline, '#untrust'):
|
elif matchcmd(cmdline, '#untrust'):
|
||||||
if matchcmd(cmdline, '#untrust', 'nick'):
|
if matchcmd(cmdline, '#untrust', 'nick'):
|
||||||
untrustnick = parsecmd(cmdline, 'nick')
|
untrustnick = parsecmd(cmdline, 'nick')
|
||||||
|
@ -465,9 +478,9 @@ def parse((line, irc)):
|
||||||
rmtrusted(chan, untrustnick)
|
rmtrusted(chan, untrustnick)
|
||||||
godslock.release()
|
godslock.release()
|
||||||
else:
|
else:
|
||||||
irc.msg(chan, 'Failed to get account for %s' % untrustnick)
|
irc.msg(reply, 'Failed to get account for %s' % untrustnick)
|
||||||
else:
|
else:
|
||||||
irc.msg(chan, 'Usage #untrust nick')
|
irc.msg(reply, 'Usage #untrust nick')
|
||||||
elif matchcmd(cmdline, '#ls-trusted'):
|
elif matchcmd(cmdline, '#ls-trusted'):
|
||||||
trustedlock.acquire()
|
trustedlock.acquire()
|
||||||
if chan in trusted:
|
if chan in trusted:
|
||||||
|
@ -479,40 +492,40 @@ def parse((line, irc)):
|
||||||
if isauthorized(irc, chan, nick):
|
if isauthorized(irc, chan, nick):
|
||||||
irc.send('INVITE %s %s' % (invitenick, chan))
|
irc.send('INVITE %s %s' % (invitenick, chan))
|
||||||
else:
|
else:
|
||||||
irc.msg(chan, 'Usage #invite nick')
|
irc.msg(reply, 'Usage #invite nick')
|
||||||
elif matchcmd(cmdline, '#help'):
|
elif matchcmd(cmdline, '#help'):
|
||||||
if matchcmd(cmdline, '#help', '[command]'):
|
if matchcmd(cmdline, '#help', '[command]'):
|
||||||
command = parsecmd(cmdline, '[command]')
|
command = parsecmd(cmdline, '[command]')
|
||||||
helptext = help(command)
|
helptext = help(command)
|
||||||
if helptext:
|
if helptext:
|
||||||
irc.msg(chan, zwsp+helptext)
|
irc.msg(reply, zwsp+helptext)
|
||||||
elif matchcmd(cmdline, '#esoteric') and chan=='#esoteric':
|
elif matchcmd(cmdline, '#esoteric') and chan == '#esoteric':
|
||||||
irc.msg(chan, 'Nothing here')
|
irc.msg(reply, 'Nothing here')
|
||||||
elif cmdline[0] in [irc.nick, irc.nick+',', irc.nick+':']:
|
elif cmdline[0] in [irc.nick, irc.nick+',', irc.nick+':']:
|
||||||
question = parsecmd(cmdline, '{question}')
|
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]):
|
elif die_expr.match(cmdline[0]):
|
||||||
die=cmdline[0][1:].split('d')
|
die = cmdline[0][1:].split('d')
|
||||||
times=int(die[0]) if die[0] else 1
|
times = int(die[0]) if die[0] else 1
|
||||||
die='%' if die[1]=='%' else int(die[1])
|
die = '%' if die[1] == '%' else int(die[1])
|
||||||
if die=='%':
|
if die == '%':
|
||||||
if times!=1:
|
if times != 1:
|
||||||
irc.msg(chan, 'Not supported')
|
irc.msg(reply, 'Not supported')
|
||||||
else:
|
else:
|
||||||
irc.msg(chan, '%s%s' % (random.randint(0,9), random.randint(0,9)))
|
irc.msg(reply, '%s%s' % (random.randint(0,9), random.randint(0,9)))
|
||||||
elif die<2:
|
elif die < 2:
|
||||||
irc.msg(chan, 'This die is not available in your space-time region.')
|
irc.msg(reply, 'This die is not available in your space-time region.')
|
||||||
elif times<1:
|
elif times < 1:
|
||||||
irc.msg(chan, 'What exactly do you want me to do?')
|
irc.msg(reply, 'What exactly do you want me to do?')
|
||||||
elif times>128:
|
elif times > 128:
|
||||||
irc.msg(chan, 'Sorry, I don\'t have that many. Can I borrow yours?')
|
irc.msg(reply, 'Sorry, I don\'t have that many. Can I borrow yours?')
|
||||||
else:
|
else:
|
||||||
rolls=[random.randint(1, die) for i in xrange(times)]
|
rolls = [random.randint(1, die) for i in xrange(times)]
|
||||||
result=reduce((lambda x,y:x+y), rolls)
|
result = reduce((lambda x, y: x + y), rolls)
|
||||||
if times>1:
|
if times > 1:
|
||||||
irc.msg(chan, '%s (%s)' % (str(result), ', '.join([str(i) for i in rolls])))
|
irc.msg(reply, '%s (%s)' % (str(result), ', '.join([str(i) for i in rolls])))
|
||||||
else:
|
else:
|
||||||
irc.msg(chan, str(result))
|
irc.msg(reply, str(result))
|
||||||
elif line[1] == '330': # WHOIS: is logged in as
|
elif line[1] == '330': # WHOIS: is logged in as
|
||||||
whoisnick = line[3]
|
whoisnick = line[3]
|
||||||
account = line[4]
|
account = line[4]
|
||||||
|
@ -560,6 +573,7 @@ def usage(cmd, message = True):
|
||||||
'#untrust': 'nick',
|
'#untrust': 'nick',
|
||||||
'#ls-trusted': '',
|
'#ls-trusted': '',
|
||||||
'#invite': 'nick',
|
'#invite': 'nick',
|
||||||
|
'#chan': 'channel command',
|
||||||
'#help': '[command]'}
|
'#help': '[command]'}
|
||||||
|
|
||||||
if cmd in usage:
|
if cmd in usage:
|
||||||
|
@ -584,10 +598,11 @@ def help(cmd):
|
||||||
'#untrust': 'remove nick from trusted list',
|
'#untrust': 'remove nick from trusted list',
|
||||||
'#ls-trusted': 'list nicks that are trusted. use only in a query',
|
'#ls-trusted': 'list nicks that are trusted. use only in a query',
|
||||||
'#invite': 'invites nick to channel',
|
'#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'}
|
'#help': 'give short info of command or list commands'}
|
||||||
|
|
||||||
if cmd=='':
|
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':
|
elif cmd=='me':
|
||||||
return 'I shall.'
|
return 'I shall.'
|
||||||
elif cmd in helptext:
|
elif cmd in helptext:
|
||||||
|
|
Loading…
Reference in New Issue