mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-01 01:09:22 +01:00
plugins: use irc.reply(...) instead of irc.msg(irc.called_by, ...) whereever possible
This commit is contained in:
parent
e942b411f1
commit
17a2dcd21f
@ -120,7 +120,7 @@ def identify(irc, source, args):
|
|||||||
|
|
||||||
Logs in to PyLink using the configured administrator account."""
|
Logs in to PyLink using the configured administrator account."""
|
||||||
if utils.isChannel(irc.called_by):
|
if utils.isChannel(irc.called_by):
|
||||||
irc.msg(irc.called_by, 'Error: This command must be sent in private. '
|
irc.reply('Error: This command must be sent in private. '
|
||||||
'(Would you really type a password inside a channel?)')
|
'(Would you really type a password inside a channel?)')
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
@ -163,10 +163,10 @@ def load(irc, source, args):
|
|||||||
try:
|
try:
|
||||||
name = args[0]
|
name = args[0]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
irc.msg(irc.called_by, "Error: Not enough arguments. Needs 1: plugin name.")
|
irc.reply("Error: Not enough arguments. Needs 1: plugin name.")
|
||||||
return
|
return
|
||||||
if name in world.plugins:
|
if name in world.plugins:
|
||||||
irc.msg(irc.called_by, "Error: %r is already loaded." % name)
|
irc.reply("Error: %r is already loaded." % name)
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
world.plugins[name] = pl = utils.loadModuleFromFolder(name, world.plugins_folder)
|
world.plugins[name] = pl = utils.loadModuleFromFolder(name, world.plugins_folder)
|
||||||
@ -180,7 +180,7 @@ def load(irc, source, args):
|
|||||||
if hasattr(pl, 'main'):
|
if hasattr(pl, 'main'):
|
||||||
log.debug('Calling main() function of plugin %r', pl)
|
log.debug('Calling main() function of plugin %r', pl)
|
||||||
pl.main(irc)
|
pl.main(irc)
|
||||||
irc.msg(irc.called_by, "Loaded plugin %r." % name)
|
irc.reply("Loaded plugin %r." % name)
|
||||||
utils.add_cmd(load)
|
utils.add_cmd(load)
|
||||||
|
|
||||||
def unload(irc, source, args):
|
def unload(irc, source, args):
|
||||||
@ -191,7 +191,7 @@ def unload(irc, source, args):
|
|||||||
try:
|
try:
|
||||||
name = args[0]
|
name = args[0]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
irc.msg(irc.called_by, "Error: Not enough arguments. Needs 1: plugin name.")
|
irc.reply("Error: Not enough arguments. Needs 1: plugin name.")
|
||||||
return
|
return
|
||||||
if name in world.plugins:
|
if name in world.plugins:
|
||||||
pl = world.plugins[name]
|
pl = world.plugins[name]
|
||||||
@ -240,10 +240,10 @@ def unload(irc, source, args):
|
|||||||
# Garbage collect.
|
# Garbage collect.
|
||||||
gc.collect()
|
gc.collect()
|
||||||
|
|
||||||
irc.msg(irc.called_by, "Unloaded plugin %r." % name)
|
irc.reply("Unloaded plugin %r." % name)
|
||||||
return True # We succeeded, make it clear (this status is used by reload() below)
|
return True # We succeeded, make it clear (this status is used by reload() below)
|
||||||
else:
|
else:
|
||||||
irc.msg(irc.called_by, "Unknown plugin %r." % name)
|
irc.reply("Unknown plugin %r." % name)
|
||||||
utils.add_cmd(unload)
|
utils.add_cmd(unload)
|
||||||
|
|
||||||
@utils.add_cmd
|
@utils.add_cmd
|
||||||
@ -254,7 +254,7 @@ def reload(irc, source, args):
|
|||||||
try:
|
try:
|
||||||
name = args[0]
|
name = args[0]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
irc.msg(irc.called_by, "Error: Not enough arguments. Needs 1: plugin name.")
|
irc.reply("Error: Not enough arguments. Needs 1: plugin name.")
|
||||||
return
|
return
|
||||||
if unload(irc, source, args):
|
if unload(irc, source, args):
|
||||||
load(irc, source, args)
|
load(irc, source, args)
|
||||||
|
@ -20,7 +20,7 @@ def spawnclient(irc, source, args):
|
|||||||
try:
|
try:
|
||||||
nick, ident, host = args[:3]
|
nick, ident, host = args[:3]
|
||||||
except ValueError:
|
except ValueError:
|
||||||
irc.msg(irc.called_by, "Error: Not enough arguments. Needs 3: nick, user, host.")
|
irc.reply("Error: Not enough arguments. Needs 3: nick, user, host.")
|
||||||
return
|
return
|
||||||
irc.proto.spawnClient(nick, ident, host, manipulatable=True)
|
irc.proto.spawnClient(nick, ident, host, manipulatable=True)
|
||||||
|
|
||||||
@ -33,15 +33,15 @@ def quit(irc, source, args):
|
|||||||
try:
|
try:
|
||||||
nick = args[0]
|
nick = args[0]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
irc.msg(irc.called_by, "Error: Not enough arguments. Needs 1-2: nick, reason (optional).")
|
irc.reply("Error: Not enough arguments. Needs 1-2: nick, reason (optional).")
|
||||||
return
|
return
|
||||||
if irc.pseudoclient.uid == utils.nickToUid(irc, nick):
|
if irc.pseudoclient.uid == utils.nickToUid(irc, nick):
|
||||||
irc.msg(irc.called_by, "Error: Cannot quit the main PyLink PseudoClient!")
|
irc.reply("Error: Cannot quit the main PyLink PseudoClient!")
|
||||||
return
|
return
|
||||||
u = utils.nickToUid(irc, nick)
|
u = utils.nickToUid(irc, nick)
|
||||||
quitmsg = ' '.join(args[1:]) or 'Client Quit'
|
quitmsg = ' '.join(args[1:]) or 'Client Quit'
|
||||||
if not utils.isManipulatableClient(irc, u):
|
if not utils.isManipulatableClient(irc, u):
|
||||||
irc.msg(irc.called_by, "Error: Cannot force quit a protected PyLink services client.")
|
irc.reply("Error: Cannot force quit a protected PyLink services client.")
|
||||||
return
|
return
|
||||||
irc.proto.quitClient(u, quitmsg)
|
irc.proto.quitClient(u, quitmsg)
|
||||||
irc.callHooks([u, 'PYLINK_BOTSPLUGIN_QUIT', {'text': quitmsg, 'parse_as': 'QUIT'}])
|
irc.callHooks([u, 'PYLINK_BOTSPLUGIN_QUIT', {'text': quitmsg, 'parse_as': 'QUIT'}])
|
||||||
@ -57,15 +57,15 @@ def joinclient(irc, source, args):
|
|||||||
if not clist:
|
if not clist:
|
||||||
raise IndexError
|
raise IndexError
|
||||||
except IndexError:
|
except IndexError:
|
||||||
irc.msg(irc.called_by, "Error: Not enough arguments. Needs 2: nick, comma separated list of channels.")
|
irc.reply("Error: Not enough arguments. Needs 2: nick, comma separated list of channels.")
|
||||||
return
|
return
|
||||||
u = utils.nickToUid(irc, nick)
|
u = utils.nickToUid(irc, nick)
|
||||||
if not utils.isManipulatableClient(irc, u):
|
if not utils.isManipulatableClient(irc, u):
|
||||||
irc.msg(irc.called_by, "Error: Cannot force join a protected PyLink services client.")
|
irc.reply("Error: Cannot force join a protected PyLink services client.")
|
||||||
return
|
return
|
||||||
for channel in clist:
|
for channel in clist:
|
||||||
if not utils.isChannel(channel):
|
if not utils.isChannel(channel):
|
||||||
irc.msg(irc.called_by, "Error: Invalid channel name %r." % channel)
|
irc.reply("Error: Invalid channel name %r." % channel)
|
||||||
return
|
return
|
||||||
irc.proto.joinClient(u, channel)
|
irc.proto.joinClient(u, channel)
|
||||||
irc.callHooks([u, 'PYLINK_BOTSPLUGIN_JOIN', {'channel': channel, 'users': [u],
|
irc.callHooks([u, 'PYLINK_BOTSPLUGIN_JOIN', {'channel': channel, 'users': [u],
|
||||||
@ -83,16 +83,16 @@ def nick(irc, source, args):
|
|||||||
nick = args[0]
|
nick = args[0]
|
||||||
newnick = args[1]
|
newnick = args[1]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
irc.msg(irc.called_by, "Error: Not enough arguments. Needs 2: nick, newnick.")
|
irc.reply("Error: Not enough arguments. Needs 2: nick, newnick.")
|
||||||
return
|
return
|
||||||
u = utils.nickToUid(irc, nick)
|
u = utils.nickToUid(irc, nick)
|
||||||
if newnick in ('0', u):
|
if newnick in ('0', u):
|
||||||
newnick = u
|
newnick = u
|
||||||
elif not utils.isNick(newnick):
|
elif not utils.isNick(newnick):
|
||||||
irc.msg(irc.called_by, 'Error: Invalid nickname %r.' % newnick)
|
irc.reply('Error: Invalid nickname %r.' % newnick)
|
||||||
return
|
return
|
||||||
elif not utils.isManipulatableClient(irc, u):
|
elif not utils.isManipulatableClient(irc, u):
|
||||||
irc.msg(irc.called_by, "Error: Cannot force nick changes for a protected PyLink services client.")
|
irc.reply("Error: Cannot force nick changes for a protected PyLink services client.")
|
||||||
return
|
return
|
||||||
irc.proto.nickClient(u, newnick)
|
irc.proto.nickClient(u, newnick)
|
||||||
irc.callHooks([u, 'PYLINK_BOTSPLUGIN_NICK', {'newnick': newnick, 'oldnick': nick, 'parse_as': 'NICK'}])
|
irc.callHooks([u, 'PYLINK_BOTSPLUGIN_NICK', {'newnick': newnick, 'oldnick': nick, 'parse_as': 'NICK'}])
|
||||||
@ -108,15 +108,15 @@ def part(irc, source, args):
|
|||||||
clist = args[1].split(',')
|
clist = args[1].split(',')
|
||||||
reason = ' '.join(args[2:])
|
reason = ' '.join(args[2:])
|
||||||
except IndexError:
|
except IndexError:
|
||||||
irc.msg(irc.called_by, "Error: Not enough arguments. Needs 2: nick, comma separated list of channels.")
|
irc.reply("Error: Not enough arguments. Needs 2: nick, comma separated list of channels.")
|
||||||
return
|
return
|
||||||
u = utils.nickToUid(irc, nick)
|
u = utils.nickToUid(irc, nick)
|
||||||
if not utils.isManipulatableClient(irc, u):
|
if not utils.isManipulatableClient(irc, u):
|
||||||
irc.msg(irc.called_by, "Error: Cannot force part a protected PyLink services client.")
|
irc.reply("Error: Cannot force part a protected PyLink services client.")
|
||||||
return
|
return
|
||||||
for channel in clist:
|
for channel in clist:
|
||||||
if not utils.isChannel(channel):
|
if not utils.isChannel(channel):
|
||||||
irc.msg(irc.called_by, "Error: Invalid channel name %r." % channel)
|
irc.reply("Error: Invalid channel name %r." % channel)
|
||||||
return
|
return
|
||||||
irc.proto.partClient(u, channel, reason)
|
irc.proto.partClient(u, channel, reason)
|
||||||
irc.callHooks([u, 'PYLINK_BOTSPLUGIN_PART', {'channels': clist, 'text': reason, 'parse_as': 'PART'}])
|
irc.callHooks([u, 'PYLINK_BOTSPLUGIN_PART', {'channels': clist, 'text': reason, 'parse_as': 'PART'}])
|
||||||
@ -133,12 +133,12 @@ def kick(irc, source, args):
|
|||||||
target = args[2]
|
target = args[2]
|
||||||
reason = ' '.join(args[3:])
|
reason = ' '.join(args[3:])
|
||||||
except IndexError:
|
except IndexError:
|
||||||
irc.msg(irc.called_by, "Error: Not enough arguments. Needs 3-4: source nick, channel, target, reason (optional).")
|
irc.reply("Error: Not enough arguments. Needs 3-4: source nick, channel, target, reason (optional).")
|
||||||
return
|
return
|
||||||
u = utils.nickToUid(irc, nick) or nick
|
u = utils.nickToUid(irc, nick) or nick
|
||||||
targetu = utils.nickToUid(irc, target)
|
targetu = utils.nickToUid(irc, target)
|
||||||
if not utils.isChannel(channel):
|
if not utils.isChannel(channel):
|
||||||
irc.msg(irc.called_by, "Error: Invalid channel name %r." % channel)
|
irc.reply("Error: Invalid channel name %r." % channel)
|
||||||
return
|
return
|
||||||
if utils.isInternalServer(irc, u):
|
if utils.isInternalServer(irc, u):
|
||||||
irc.proto.kickServer(u, channel, targetu, reason)
|
irc.proto.kickServer(u, channel, targetu, reason)
|
||||||
@ -155,20 +155,20 @@ def mode(irc, source, args):
|
|||||||
try:
|
try:
|
||||||
modesource, target, modes = args[0], args[1], args[2:]
|
modesource, target, modes = args[0], args[1], args[2:]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
irc.msg(irc.called_by, 'Error: Not enough arguments. Needs 3: source nick, target, modes to set.')
|
irc.reply('Error: Not enough arguments. Needs 3: source nick, target, modes to set.')
|
||||||
return
|
return
|
||||||
target = utils.nickToUid(irc, target) or target
|
target = utils.nickToUid(irc, target) or target
|
||||||
extclient = target in irc.users and not utils.isInternalClient(irc, target)
|
extclient = target in irc.users and not utils.isInternalClient(irc, target)
|
||||||
parsedmodes = utils.parseModes(irc, target, modes)
|
parsedmodes = utils.parseModes(irc, target, modes)
|
||||||
ischannel = target in irc.channels
|
ischannel = target in irc.channels
|
||||||
if not (target in irc.users or ischannel):
|
if not (target in irc.users or ischannel):
|
||||||
irc.msg(irc.called_by, "Error: Invalid channel or nick %r." % target)
|
irc.reply("Error: Invalid channel or nick %r." % target)
|
||||||
return
|
return
|
||||||
elif not parsedmodes:
|
elif not parsedmodes:
|
||||||
irc.msg(irc.called_by, "Error: No valid modes were given.")
|
irc.reply("Error: No valid modes were given.")
|
||||||
return
|
return
|
||||||
elif not (ischannel or utils.isManipulatableClient(irc, target)):
|
elif not (ischannel or utils.isManipulatableClient(irc, target)):
|
||||||
irc.msg(irc.called_by, "Error: Can only set modes on channels or non-protected PyLink clients.")
|
irc.reply("Error: Can only set modes on channels or non-protected PyLink clients.")
|
||||||
return
|
return
|
||||||
if utils.isInternalServer(irc, modesource):
|
if utils.isInternalServer(irc, modesource):
|
||||||
# Setting modes from a server.
|
# Setting modes from a server.
|
||||||
@ -189,21 +189,21 @@ def msg(irc, source, args):
|
|||||||
try:
|
try:
|
||||||
msgsource, target, text = args[0], args[1], ' '.join(args[2:])
|
msgsource, target, text = args[0], args[1], ' '.join(args[2:])
|
||||||
except IndexError:
|
except IndexError:
|
||||||
irc.msg(irc.called_by, 'Error: Not enough arguments. Needs 3: source nick, target, text.')
|
irc.reply('Error: Not enough arguments. Needs 3: source nick, target, text.')
|
||||||
return
|
return
|
||||||
sourceuid = utils.nickToUid(irc, msgsource)
|
sourceuid = utils.nickToUid(irc, msgsource)
|
||||||
if not sourceuid:
|
if not sourceuid:
|
||||||
irc.msg(irc.called_by, 'Error: Unknown user %r.' % msgsource)
|
irc.reply('Error: Unknown user %r.' % msgsource)
|
||||||
return
|
return
|
||||||
if not utils.isChannel(target):
|
if not utils.isChannel(target):
|
||||||
real_target = utils.nickToUid(irc, target)
|
real_target = utils.nickToUid(irc, target)
|
||||||
if real_target is None:
|
if real_target is None:
|
||||||
irc.msg(irc.called_by, 'Error: Unknown user %r.' % target)
|
irc.reply('Error: Unknown user %r.' % target)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
real_target = target
|
real_target = target
|
||||||
if not text:
|
if not text:
|
||||||
irc.msg(irc.called_by, 'Error: No text given.')
|
irc.reply('Error: No text given.')
|
||||||
return
|
return
|
||||||
irc.proto.messageClient(sourceuid, real_target, text)
|
irc.proto.messageClient(sourceuid, real_target, text)
|
||||||
irc.callHooks([sourceuid, 'PYLINK_BOTSPLUGIN_MSG', {'target': real_target, 'text': text, 'parse_as': 'PRIVMSG'}])
|
irc.callHooks([sourceuid, 'PYLINK_BOTSPLUGIN_MSG', {'target': real_target, 'text': text, 'parse_as': 'PRIVMSG'}])
|
||||||
|
@ -17,10 +17,10 @@ def status(irc, source, args):
|
|||||||
Returns your current PyLink login status."""
|
Returns your current PyLink login status."""
|
||||||
identified = irc.users[source].identified
|
identified = irc.users[source].identified
|
||||||
if identified:
|
if identified:
|
||||||
irc.msg(irc.called_by, 'You are identified as \x02%s\x02.' % identified)
|
irc.reply('You are identified as \x02%s\x02.' % identified)
|
||||||
else:
|
else:
|
||||||
irc.msg(irc.called_by, 'You are not identified as anyone.')
|
irc.reply('You are not identified as anyone.')
|
||||||
irc.msg(irc.called_by, 'Operator access: \x02%s\x02' % bool(utils.isOper(irc, source)))
|
irc.reply('Operator access: \x02%s\x02' % bool(utils.isOper(irc, source)))
|
||||||
|
|
||||||
def listcommands(irc, source, args):
|
def listcommands(irc, source, args):
|
||||||
"""takes no arguments.
|
"""takes no arguments.
|
||||||
@ -32,8 +32,8 @@ def listcommands(irc, source, args):
|
|||||||
nfuncs = len(world.commands[cmd])
|
nfuncs = len(world.commands[cmd])
|
||||||
if nfuncs > 1:
|
if nfuncs > 1:
|
||||||
cmds[idx] = '%s(x%s)' % (cmd, nfuncs)
|
cmds[idx] = '%s(x%s)' % (cmd, nfuncs)
|
||||||
irc.msg(irc.called_by, 'Available commands include: %s' % ', '.join(cmds))
|
irc.reply('Available commands include: %s' % ', '.join(cmds))
|
||||||
irc.msg(irc.called_by, 'To see help on a specific command, type \x02help <command>\x02.')
|
irc.reply('To see help on a specific command, type \x02help <command>\x02.')
|
||||||
utils.add_cmd(listcommands, 'list')
|
utils.add_cmd(listcommands, 'list')
|
||||||
|
|
||||||
@utils.add_cmd
|
@utils.add_cmd
|
||||||
@ -52,7 +52,7 @@ def help(irc, source, args):
|
|||||||
else:
|
else:
|
||||||
funcs = world.commands[command]
|
funcs = world.commands[command]
|
||||||
if len(funcs) > 1:
|
if len(funcs) > 1:
|
||||||
irc.msg(irc.called_by, 'The following \x02%s\x02 plugins bind to the \x02%s\x02 command: %s'
|
irc.reply('The following \x02%s\x02 plugins bind to the \x02%s\x02 command: %s'
|
||||||
% (len(funcs), command, ', '.join([func.__module__ for func in funcs])))
|
% (len(funcs), command, ', '.join([func.__module__ for func in funcs])))
|
||||||
for func in funcs:
|
for func in funcs:
|
||||||
doc = func.__doc__
|
doc = func.__doc__
|
||||||
@ -63,7 +63,7 @@ def help(irc, source, args):
|
|||||||
# arguments the command takes.
|
# arguments the command takes.
|
||||||
lines[0] = '\x02%s %s\x02 (plugin: %r)' % (command, lines[0], mod)
|
lines[0] = '\x02%s %s\x02 (plugin: %r)' % (command, lines[0], mod)
|
||||||
for line in lines:
|
for line in lines:
|
||||||
irc.msg(irc.called_by, line.strip())
|
irc.reply(line.strip())
|
||||||
else:
|
else:
|
||||||
irc.msg(source, "Error: Command %r (from plugin %r) "
|
irc.msg(source, "Error: Command %r (from plugin %r) "
|
||||||
"doesn't offer any help." % (command, mod))
|
"doesn't offer any help." % (command, mod))
|
||||||
@ -77,14 +77,14 @@ def showuser(irc, source, args):
|
|||||||
try:
|
try:
|
||||||
target = args[0]
|
target = args[0]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
irc.msg(irc.called_by, "Error: Not enough arguments. Needs 1: nick.")
|
irc.reply("Error: Not enough arguments. Needs 1: nick.")
|
||||||
return
|
return
|
||||||
u = utils.nickToUid(irc, target) or target
|
u = utils.nickToUid(irc, target) or target
|
||||||
# Only show private info if the person is calling 'showuser' on themselves,
|
# Only show private info if the person is calling 'showuser' on themselves,
|
||||||
# or is an oper.
|
# or is an oper.
|
||||||
verbose = utils.isOper(irc, source) or u == source
|
verbose = utils.isOper(irc, source) or u == source
|
||||||
if u not in irc.users:
|
if u not in irc.users:
|
||||||
irc.msg(irc.called_by, 'Error: Unknown user %r.' % target)
|
irc.reply('Error: Unknown user %r.' % target)
|
||||||
return
|
return
|
||||||
|
|
||||||
f = lambda s: irc.msg(source, s)
|
f = lambda s: irc.msg(source, s)
|
||||||
@ -112,10 +112,10 @@ def showchan(irc, source, args):
|
|||||||
try:
|
try:
|
||||||
channel = utils.toLower(irc, args[0])
|
channel = utils.toLower(irc, args[0])
|
||||||
except IndexError:
|
except IndexError:
|
||||||
irc.msg(irc.called_by, "Error: Not enough arguments. Needs 1: channel.")
|
irc.reply("Error: Not enough arguments. Needs 1: channel.")
|
||||||
return
|
return
|
||||||
if channel not in irc.channels:
|
if channel not in irc.channels:
|
||||||
irc.msg(irc.called_by, 'Error: Unknown channel %r.' % channel)
|
irc.reply('Error: Unknown channel %r.' % channel)
|
||||||
return
|
return
|
||||||
|
|
||||||
f = lambda s: irc.msg(source, s)
|
f = lambda s: irc.msg(source, s)
|
||||||
@ -155,15 +155,15 @@ def version(irc, source, args):
|
|||||||
"""takes no arguments.
|
"""takes no arguments.
|
||||||
|
|
||||||
Returns the version of the currently running PyLink instance."""
|
Returns the version of the currently running PyLink instance."""
|
||||||
irc.msg(irc.called_by, "PyLink version \x02%s\x02, released under the Mozilla Public License version 2.0." % world.version)
|
irc.reply("PyLink version \x02%s\x02, released under the Mozilla Public License version 2.0." % world.version)
|
||||||
irc.msg(irc.called_by, "The source of this program is available at \x02%s\x02." % world.source)
|
irc.reply("The source of this program is available at \x02%s\x02." % world.source)
|
||||||
|
|
||||||
@utils.add_cmd
|
@utils.add_cmd
|
||||||
def echo(irc, source, args):
|
def echo(irc, source, args):
|
||||||
"""<text>
|
"""<text>
|
||||||
|
|
||||||
Echoes the text given."""
|
Echoes the text given."""
|
||||||
irc.msg(irc.called_by, ' '.join(args))
|
irc.reply(' '.join(args))
|
||||||
|
|
||||||
@utils.add_cmd
|
@utils.add_cmd
|
||||||
def rehash(irc, source, args):
|
def rehash(irc, source, args):
|
||||||
@ -178,7 +178,7 @@ def rehash(irc, source, args):
|
|||||||
new_conf = conf.validateConf(conf.loadConf(fname))
|
new_conf = conf.validateConf(conf.loadConf(fname))
|
||||||
except Exception as e: # Something went wrong, abort.
|
except Exception as e: # Something went wrong, abort.
|
||||||
log.exception("Error REHASH'ing config: ")
|
log.exception("Error REHASH'ing config: ")
|
||||||
irc.msg(irc.called_by, "Error loading configuration file: %s: %s", type(e).__name__, e)
|
irc.reply("Error loading configuration file: %s: %s", type(e).__name__, e)
|
||||||
return
|
return
|
||||||
conf.conf = new_conf
|
conf.conf = new_conf
|
||||||
for network, ircobj in world.networkobjects.copy().items():
|
for network, ircobj in world.networkobjects.copy().items():
|
||||||
@ -198,4 +198,4 @@ def rehash(irc, source, args):
|
|||||||
if network not in world.networkobjects:
|
if network not in world.networkobjects:
|
||||||
proto = utils.getProtoModule(sdata['protocol'])
|
proto = utils.getProtoModule(sdata['protocol'])
|
||||||
world.networkobjects[network] = classes.Irc(network, proto, new_conf)
|
world.networkobjects[network] = classes.Irc(network, proto, new_conf)
|
||||||
irc.msg(irc.called_by, "Done.")
|
irc.reply("Done.")
|
||||||
|
@ -17,7 +17,7 @@ def _exec(irc, source, args):
|
|||||||
utils.checkAuthenticated(irc, source, allowOper=False)
|
utils.checkAuthenticated(irc, source, allowOper=False)
|
||||||
args = ' '.join(args)
|
args = ' '.join(args)
|
||||||
if not args.strip():
|
if not args.strip():
|
||||||
irc.msg(irc.called_by, 'No code entered!')
|
irc.reply('No code entered!')
|
||||||
return
|
return
|
||||||
log.info('(%s) Executing %r for %s', irc.name, args, utils.getHostmask(irc, source))
|
log.info('(%s) Executing %r for %s', irc.name, args, utils.getHostmask(irc, source))
|
||||||
exec(args, globals(), locals())
|
exec(args, globals(), locals())
|
||||||
@ -31,8 +31,8 @@ def _eval(irc, source, args):
|
|||||||
utils.checkAuthenticated(irc, source, allowOper=False)
|
utils.checkAuthenticated(irc, source, allowOper=False)
|
||||||
args = ' '.join(args)
|
args = ' '.join(args)
|
||||||
if not args.strip():
|
if not args.strip():
|
||||||
irc.msg(irc.called_by, 'No code entered!')
|
irc.reply('No code entered!')
|
||||||
return
|
return
|
||||||
log.info('(%s) Evaluating %r for %s', irc.name, args, utils.getHostmask(irc, source))
|
log.info('(%s) Evaluating %r for %s', irc.name, args, utils.getHostmask(irc, source))
|
||||||
irc.msg(irc.called_by, eval(args))
|
irc.reply(eval(args))
|
||||||
utils.add_cmd(_eval, 'eval')
|
utils.add_cmd(_eval, 'eval')
|
||||||
|
@ -22,12 +22,12 @@ def disconnect(irc, source, args):
|
|||||||
netname = args[0]
|
netname = args[0]
|
||||||
network = world.networkobjects[netname]
|
network = world.networkobjects[netname]
|
||||||
except IndexError: # No argument given.
|
except IndexError: # No argument given.
|
||||||
irc.msg(irc.called_by, 'Error: Not enough arguments (needs 1: network name (case sensitive)).')
|
irc.reply('Error: Not enough arguments (needs 1: network name (case sensitive)).')
|
||||||
return
|
return
|
||||||
except KeyError: # Unknown network.
|
except KeyError: # Unknown network.
|
||||||
irc.msg(irc.called_by, 'Error: No such network "%s" (case sensitive).' % netname)
|
irc.reply('Error: No such network "%s" (case sensitive).' % netname)
|
||||||
return
|
return
|
||||||
irc.msg(irc.called_by, "Done.")
|
irc.reply("Done.")
|
||||||
# Abort the connection! Simple as that.
|
# Abort the connection! Simple as that.
|
||||||
network.aborted.set()
|
network.aborted.set()
|
||||||
|
|
||||||
@ -41,18 +41,18 @@ def connect(irc, source, args):
|
|||||||
netname = args[0]
|
netname = args[0]
|
||||||
network = world.networkobjects[netname]
|
network = world.networkobjects[netname]
|
||||||
except IndexError: # No argument given.
|
except IndexError: # No argument given.
|
||||||
irc.msg(irc.called_by, 'Error: Not enough arguments (needs 1: network name (case sensitive)).')
|
irc.reply('Error: Not enough arguments (needs 1: network name (case sensitive)).')
|
||||||
return
|
return
|
||||||
except KeyError: # Unknown network.
|
except KeyError: # Unknown network.
|
||||||
irc.msg(irc.called_by, 'Error: No such network "%s" (case sensitive).' % netname)
|
irc.reply('Error: No such network "%s" (case sensitive).' % netname)
|
||||||
return
|
return
|
||||||
if network.connection_thread.is_alive():
|
if network.connection_thread.is_alive():
|
||||||
irc.msg(irc.called_by, 'Error: Network "%s" seems to be already connected.' % netname)
|
irc.reply('Error: Network "%s" seems to be already connected.' % netname)
|
||||||
else: # Reconnect the network!
|
else: # Reconnect the network!
|
||||||
network.initVars()
|
network.initVars()
|
||||||
network.connection_thread = threading.Thread(target=network.connect)
|
network.connection_thread = threading.Thread(target=network.connect)
|
||||||
network.connection_thread.start()
|
network.connection_thread.start()
|
||||||
irc.msg(irc.called_by, "Done.")
|
irc.reply("Done.")
|
||||||
|
|
||||||
@utils.add_cmd
|
@utils.add_cmd
|
||||||
def autoconnect(irc, source, args):
|
def autoconnect(irc, source, args):
|
||||||
@ -66,13 +66,13 @@ def autoconnect(irc, source, args):
|
|||||||
seconds = float(args[1])
|
seconds = float(args[1])
|
||||||
network = world.networkobjects[netname]
|
network = world.networkobjects[netname]
|
||||||
except IndexError: # Arguments not given.
|
except IndexError: # Arguments not given.
|
||||||
irc.msg(irc.called_by, 'Error: Not enough arguments (needs 2: network name (case sensitive), autoconnect time (in seconds)).')
|
irc.reply('Error: Not enough arguments (needs 2: network name (case sensitive), autoconnect time (in seconds)).')
|
||||||
return
|
return
|
||||||
except KeyError: # Unknown network.
|
except KeyError: # Unknown network.
|
||||||
irc.msg(irc.called_by, 'Error: No such network "%s" (case sensitive).' % netname)
|
irc.reply('Error: No such network "%s" (case sensitive).' % netname)
|
||||||
return
|
return
|
||||||
except ValueError:
|
except ValueError:
|
||||||
irc.msg(irc.called_by, 'Error: Invalid argument "%s" for <seconds>.' % seconds)
|
irc.reply('Error: Invalid argument "%s" for <seconds>.' % seconds)
|
||||||
return
|
return
|
||||||
network.serverdata['autoconnect'] = seconds
|
network.serverdata['autoconnect'] = seconds
|
||||||
irc.msg(irc.called_by, "Done.")
|
irc.reply("Done.")
|
||||||
|
@ -1074,22 +1074,22 @@ def create(irc, source, args):
|
|||||||
try:
|
try:
|
||||||
channel = utils.toLower(irc, args[0])
|
channel = utils.toLower(irc, args[0])
|
||||||
except IndexError:
|
except IndexError:
|
||||||
irc.msg(irc.called_by, "Error: Not enough arguments. Needs 1: channel.")
|
irc.reply("Error: Not enough arguments. Needs 1: channel.")
|
||||||
return
|
return
|
||||||
if not utils.isChannel(channel):
|
if not utils.isChannel(channel):
|
||||||
irc.msg(irc.called_by, 'Error: Invalid channel %r.' % channel)
|
irc.reply('Error: Invalid channel %r.' % channel)
|
||||||
return
|
return
|
||||||
if source not in irc.channels[channel].users:
|
if source not in irc.channels[channel].users:
|
||||||
irc.msg(irc.called_by, 'Error: You must be in %r to complete this operation.' % channel)
|
irc.reply('Error: You must be in %r to complete this operation.' % channel)
|
||||||
return
|
return
|
||||||
utils.checkAuthenticated(irc, source)
|
utils.checkAuthenticated(irc, source)
|
||||||
localentry = getRelay((irc.name, channel))
|
localentry = getRelay((irc.name, channel))
|
||||||
if localentry:
|
if localentry:
|
||||||
irc.msg(irc.called_by, 'Error: Channel %r is already part of a relay.' % channel)
|
irc.reply('Error: Channel %r is already part of a relay.' % channel)
|
||||||
return
|
return
|
||||||
db[(irc.name, channel)] = {'claim': [irc.name], 'links': set(), 'blocked_nets': set()}
|
db[(irc.name, channel)] = {'claim': [irc.name], 'links': set(), 'blocked_nets': set()}
|
||||||
initializeChannel(irc, channel)
|
initializeChannel(irc, channel)
|
||||||
irc.msg(irc.called_by, 'Done.')
|
irc.reply('Done.')
|
||||||
|
|
||||||
@utils.add_cmd
|
@utils.add_cmd
|
||||||
def destroy(irc, source, args):
|
def destroy(irc, source, args):
|
||||||
@ -1099,10 +1099,10 @@ def destroy(irc, source, args):
|
|||||||
try:
|
try:
|
||||||
channel = utils.toLower(irc, args[0])
|
channel = utils.toLower(irc, args[0])
|
||||||
except IndexError:
|
except IndexError:
|
||||||
irc.msg(irc.called_by, "Error: Not enough arguments. Needs 1: channel.")
|
irc.reply("Error: Not enough arguments. Needs 1: channel.")
|
||||||
return
|
return
|
||||||
if not utils.isChannel(channel):
|
if not utils.isChannel(channel):
|
||||||
irc.msg(irc.called_by, 'Error: Invalid channel %r.' % channel)
|
irc.reply('Error: Invalid channel %r.' % channel)
|
||||||
return
|
return
|
||||||
utils.checkAuthenticated(irc, source)
|
utils.checkAuthenticated(irc, source)
|
||||||
|
|
||||||
@ -1112,9 +1112,9 @@ def destroy(irc, source, args):
|
|||||||
removeChannel(world.networkobjects.get(link[0]), link[1])
|
removeChannel(world.networkobjects.get(link[0]), link[1])
|
||||||
removeChannel(irc, channel)
|
removeChannel(irc, channel)
|
||||||
del db[entry]
|
del db[entry]
|
||||||
irc.msg(irc.called_by, 'Done.')
|
irc.reply('Done.')
|
||||||
else:
|
else:
|
||||||
irc.msg(irc.called_by, 'Error: No such relay %r exists.' % channel)
|
irc.reply('Error: No such relay %r exists.' % channel)
|
||||||
return
|
return
|
||||||
|
|
||||||
@utils.add_cmd
|
@utils.add_cmd
|
||||||
@ -1127,7 +1127,7 @@ def link(irc, source, args):
|
|||||||
channel = utils.toLower(irc, args[1])
|
channel = utils.toLower(irc, args[1])
|
||||||
remotenet = args[0].lower()
|
remotenet = args[0].lower()
|
||||||
except IndexError:
|
except IndexError:
|
||||||
irc.msg(irc.called_by, "Error: Not enough arguments. Needs 2-3: remote netname, channel, local channel name (optional).")
|
irc.reply("Error: Not enough arguments. Needs 2-3: remote netname, channel, local channel name (optional).")
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
localchan = utils.toLower(irc, args[2])
|
localchan = utils.toLower(irc, args[2])
|
||||||
@ -1135,37 +1135,37 @@ def link(irc, source, args):
|
|||||||
localchan = channel
|
localchan = channel
|
||||||
for c in (channel, localchan):
|
for c in (channel, localchan):
|
||||||
if not utils.isChannel(c):
|
if not utils.isChannel(c):
|
||||||
irc.msg(irc.called_by, 'Error: Invalid channel %r.' % c)
|
irc.reply('Error: Invalid channel %r.' % c)
|
||||||
return
|
return
|
||||||
if source not in irc.channels[localchan].users:
|
if source not in irc.channels[localchan].users:
|
||||||
irc.msg(irc.called_by, 'Error: You must be in %r to complete this operation.' % localchan)
|
irc.reply('Error: You must be in %r to complete this operation.' % localchan)
|
||||||
return
|
return
|
||||||
utils.checkAuthenticated(irc, source)
|
utils.checkAuthenticated(irc, source)
|
||||||
if remotenet not in world.networkobjects:
|
if remotenet not in world.networkobjects:
|
||||||
irc.msg(irc.called_by, 'Error: No network named %r exists.' % remotenet)
|
irc.reply('Error: No network named %r exists.' % remotenet)
|
||||||
return
|
return
|
||||||
localentry = getRelay((irc.name, localchan))
|
localentry = getRelay((irc.name, localchan))
|
||||||
if localentry:
|
if localentry:
|
||||||
irc.msg(irc.called_by, 'Error: Channel %r is already part of a relay.' % localchan)
|
irc.reply('Error: Channel %r is already part of a relay.' % localchan)
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
entry = db[(remotenet, channel)]
|
entry = db[(remotenet, channel)]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
irc.msg(irc.called_by, 'Error: No such relay %r exists.' % channel)
|
irc.reply('Error: No such relay %r exists.' % channel)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
if irc.name in entry['blocked_nets']:
|
if irc.name in entry['blocked_nets']:
|
||||||
irc.msg(irc.called_by, 'Error: Access denied (network is banned from linking to this channel).')
|
irc.reply('Error: Access denied (network is banned from linking to this channel).')
|
||||||
return
|
return
|
||||||
for link in entry['links']:
|
for link in entry['links']:
|
||||||
if link[0] == irc.name:
|
if link[0] == irc.name:
|
||||||
irc.msg(irc.called_by, "Error: Remote channel '%s%s' is already"
|
irc.reply("Error: Remote channel '%s%s' is already"
|
||||||
" linked here as %r." % (remotenet,
|
" linked here as %r." % (remotenet,
|
||||||
channel, link[1]))
|
channel, link[1]))
|
||||||
return
|
return
|
||||||
entry['links'].add((irc.name, localchan))
|
entry['links'].add((irc.name, localchan))
|
||||||
initializeChannel(irc, localchan)
|
initializeChannel(irc, localchan)
|
||||||
irc.msg(irc.called_by, 'Done.')
|
irc.reply('Done.')
|
||||||
|
|
||||||
@utils.add_cmd
|
@utils.add_cmd
|
||||||
def delink(irc, source, args):
|
def delink(irc, source, args):
|
||||||
@ -1176,7 +1176,7 @@ def delink(irc, source, args):
|
|||||||
try:
|
try:
|
||||||
channel = utils.toLower(irc, args[0])
|
channel = utils.toLower(irc, args[0])
|
||||||
except IndexError:
|
except IndexError:
|
||||||
irc.msg(irc.called_by, "Error: Not enough arguments. Needs 1-2: channel, remote netname (optional).")
|
irc.reply("Error: Not enough arguments. Needs 1-2: channel, remote netname (optional).")
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
remotenet = args[1].lower()
|
remotenet = args[1].lower()
|
||||||
@ -1184,13 +1184,13 @@ def delink(irc, source, args):
|
|||||||
remotenet = None
|
remotenet = None
|
||||||
utils.checkAuthenticated(irc, source)
|
utils.checkAuthenticated(irc, source)
|
||||||
if not utils.isChannel(channel):
|
if not utils.isChannel(channel):
|
||||||
irc.msg(irc.called_by, 'Error: Invalid channel %r.' % channel)
|
irc.reply('Error: Invalid channel %r.' % channel)
|
||||||
return
|
return
|
||||||
entry = getRelay((irc.name, channel))
|
entry = getRelay((irc.name, channel))
|
||||||
if entry:
|
if entry:
|
||||||
if entry[0] == irc.name: # We own this channel.
|
if entry[0] == irc.name: # We own this channel.
|
||||||
if not remotenet:
|
if not remotenet:
|
||||||
irc.msg(irc.called_by, "Error: You must select a network to "
|
irc.reply("Error: You must select a network to "
|
||||||
"delink, or use the 'destroy' command to remove "
|
"delink, or use the 'destroy' command to remove "
|
||||||
"this relay entirely (it was created on the current "
|
"this relay entirely (it was created on the current "
|
||||||
"network).")
|
"network).")
|
||||||
@ -1203,9 +1203,9 @@ def delink(irc, source, args):
|
|||||||
else:
|
else:
|
||||||
removeChannel(irc, channel)
|
removeChannel(irc, channel)
|
||||||
db[entry]['links'].remove((irc.name, channel))
|
db[entry]['links'].remove((irc.name, channel))
|
||||||
irc.msg(irc.called_by, 'Done.')
|
irc.reply('Done.')
|
||||||
else:
|
else:
|
||||||
irc.msg(irc.called_by, 'Error: No such relay %r.' % channel)
|
irc.reply('Error: No such relay %r.' % channel)
|
||||||
|
|
||||||
@utils.add_cmd
|
@utils.add_cmd
|
||||||
def linked(irc, source, args):
|
def linked(irc, source, args):
|
||||||
@ -1247,37 +1247,37 @@ def linkacl(irc, source, args):
|
|||||||
cmd = args[0].lower()
|
cmd = args[0].lower()
|
||||||
channel = utils.toLower(irc, args[1])
|
channel = utils.toLower(irc, args[1])
|
||||||
except IndexError:
|
except IndexError:
|
||||||
irc.msg(irc.called_by, missingargs)
|
irc.reply(missingargs)
|
||||||
return
|
return
|
||||||
if not utils.isChannel(channel):
|
if not utils.isChannel(channel):
|
||||||
irc.msg(irc.called_by, 'Error: Invalid channel %r.' % channel)
|
irc.reply('Error: Invalid channel %r.' % channel)
|
||||||
return
|
return
|
||||||
relay = getRelay((irc.name, channel))
|
relay = getRelay((irc.name, channel))
|
||||||
if not relay:
|
if not relay:
|
||||||
irc.msg(irc.called_by, 'Error: No such relay %r exists.' % channel)
|
irc.reply('Error: No such relay %r exists.' % channel)
|
||||||
return
|
return
|
||||||
if cmd == 'list':
|
if cmd == 'list':
|
||||||
s = 'Blocked networks for \x02%s\x02: \x02%s\x02' % (channel, ', '.join(db[relay]['blocked_nets']) or '(empty)')
|
s = 'Blocked networks for \x02%s\x02: \x02%s\x02' % (channel, ', '.join(db[relay]['blocked_nets']) or '(empty)')
|
||||||
irc.msg(irc.called_by, s)
|
irc.reply(s)
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
remotenet = args[2]
|
remotenet = args[2]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
irc.msg(irc.called_by, missingargs)
|
irc.reply(missingargs)
|
||||||
return
|
return
|
||||||
if cmd == 'deny':
|
if cmd == 'deny':
|
||||||
db[relay]['blocked_nets'].add(remotenet)
|
db[relay]['blocked_nets'].add(remotenet)
|
||||||
irc.msg(irc.called_by, 'Done.')
|
irc.reply('Done.')
|
||||||
elif cmd == 'allow':
|
elif cmd == 'allow':
|
||||||
try:
|
try:
|
||||||
db[relay]['blocked_nets'].remove(remotenet)
|
db[relay]['blocked_nets'].remove(remotenet)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
irc.msg(irc.called_by, 'Error: Network %r is not on the blacklist for %r.' % (remotenet, channel))
|
irc.reply('Error: Network %r is not on the blacklist for %r.' % (remotenet, channel))
|
||||||
else:
|
else:
|
||||||
irc.msg(irc.called_by, 'Done.')
|
irc.reply('Done.')
|
||||||
else:
|
else:
|
||||||
irc.msg(irc.called_by, 'Error: Unknown subcommand %r: valid ones are ALLOW, DENY, and LIST.' % cmd)
|
irc.reply('Error: Unknown subcommand %r: valid ones are ALLOW, DENY, and LIST.' % cmd)
|
||||||
|
|
||||||
@utils.add_cmd
|
@utils.add_cmd
|
||||||
def showuser(irc, source, args):
|
def showuser(irc, source, args):
|
||||||
@ -1322,7 +1322,7 @@ def save(irc, source, args):
|
|||||||
Saves the relay database to disk."""
|
Saves the relay database to disk."""
|
||||||
utils.checkAuthenticated(irc, source)
|
utils.checkAuthenticated(irc, source)
|
||||||
exportDB()
|
exportDB()
|
||||||
irc.msg(irc.called_by, 'Done.')
|
irc.reply('Done.')
|
||||||
|
|
||||||
@utils.add_cmd
|
@utils.add_cmd
|
||||||
def claim(irc, source, args):
|
def claim(irc, source, args):
|
||||||
@ -1335,19 +1335,19 @@ def claim(irc, source, args):
|
|||||||
try:
|
try:
|
||||||
channel = utils.toLower(irc, args[0])
|
channel = utils.toLower(irc, args[0])
|
||||||
except IndexError:
|
except IndexError:
|
||||||
irc.msg(irc.called_by, "Error: Not enough arguments. Needs 1-2: channel, list of networks (optional).")
|
irc.reply("Error: Not enough arguments. Needs 1-2: channel, list of networks (optional).")
|
||||||
return
|
return
|
||||||
|
|
||||||
# We override getRelay() here to limit the search to the current network.
|
# We override getRelay() here to limit the search to the current network.
|
||||||
relay = (irc.name, channel)
|
relay = (irc.name, channel)
|
||||||
if relay not in db:
|
if relay not in db:
|
||||||
irc.msg(irc.called_by, 'Error: No such relay %r exists.' % channel)
|
irc.reply('Error: No such relay %r exists.' % channel)
|
||||||
return
|
return
|
||||||
claimed = db[relay]["claim"]
|
claimed = db[relay]["claim"]
|
||||||
try:
|
try:
|
||||||
nets = args[1].strip()
|
nets = args[1].strip()
|
||||||
except IndexError: # No networks given.
|
except IndexError: # No networks given.
|
||||||
irc.msg(irc.called_by, 'Channel \x02%s\x02 is claimed by: %s' %
|
irc.reply('Channel \x02%s\x02 is claimed by: %s' %
|
||||||
(channel, ', '.join(claimed) or '\x1D(none)\x1D'))
|
(channel, ', '.join(claimed) or '\x1D(none)\x1D'))
|
||||||
else:
|
else:
|
||||||
if nets == '-' or not nets:
|
if nets == '-' or not nets:
|
||||||
@ -1355,5 +1355,5 @@ def claim(irc, source, args):
|
|||||||
else:
|
else:
|
||||||
claimed = set(nets.split(','))
|
claimed = set(nets.split(','))
|
||||||
db[relay]["claim"] = claimed
|
db[relay]["claim"] = claimed
|
||||||
irc.msg(irc.called_by, 'CLAIM for channel \x02%s\x02 set to: %s' %
|
irc.reply('CLAIM for channel \x02%s\x02 set to: %s' %
|
||||||
(channel, ', '.join(claimed) or '\x1D(none)\x1D'))
|
(channel, ', '.join(claimed) or '\x1D(none)\x1D'))
|
||||||
|
Loading…
Reference in New Issue
Block a user