3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-01 09:19:23 +01:00

plugins: change remaining plugins over irc.error() use

This commit is contained in:
Ken Spencer 2016-11-19 01:52:08 -05:00 committed by James Lu
parent 02dfe5aeab
commit d467d27ecd
8 changed files with 79 additions and 79 deletions

View File

@ -92,7 +92,7 @@ def applyhosts(irc, sender, args):
except IndexError: # No network was given
network = irc
except KeyError: # Unknown network
irc.reply("Error: Unknown network '%s'." % network)
irc.error("Unknown network '%s'." % network)
return
for user, userdata in network.users.copy().items():

View File

@ -25,14 +25,14 @@ def showuser(irc, source, args):
try:
target = args[0]
except IndexError:
irc.reply("Error: Not enough arguments. Needs 1: nick.")
irc.error("Not enough arguments. Needs 1: nick.")
return
u = irc.nickToUid(target) or target
# Only show private info if the person is calling 'showuser' on themselves,
# or is an oper.
verbose = irc.isOper(source) or u == source
if u not in irc.users:
irc.reply('Error: Unknown user %r.' % target)
irc.error('Unknown user %r.' % target)
return
f = lambda s: irc.reply(s, private=True)
@ -68,10 +68,10 @@ def showchan(irc, source, args):
try:
channel = irc.toLower(args[0])
except IndexError:
irc.reply("Error: Not enough arguments. Needs 1: channel.")
irc.error("Not enough arguments. Needs 1: channel.")
return
if channel not in irc.channels:
irc.reply('Error: Unknown channel %r.' % channel)
irc.error('Unknown channel %r.' % channel)
return
f = lambda s: irc.reply(s, private=True)
@ -82,7 +82,7 @@ def showchan(irc, source, args):
secret = ('s', None) in c.modes
if secret and not verbose:
# Hide secret channels from normal users.
irc.reply('Error: Unknown channel %r.' % channel, private=True)
irc.error('Unknown channel %r.' % channel, private=True)
return
nicks = [irc.users[u].nick for u in c.users]
@ -140,7 +140,7 @@ def loglevel(irc, source, args):
try:
loglevel = loglevels[level]
except KeyError:
irc.reply('Error: Unknown log level "%s".' % level)
irc.error('Unknown log level "%s".' % level)
return
else:
world.stdout_handler.setLevel(loglevel)

View File

@ -13,7 +13,7 @@ mydesc = "The \x02Games\x02 plugin provides simple games for IRC."
gameclient = utils.registerService("Games", manipulatable=True, desc=mydesc)
reply = gameclient.reply # TODO find a better syntax for ServiceBot.reply()
error = gameclient.error # TODO find a better syntax for ServiceBot.error()
# commands
def dice(irc, source, args):
"""<num>d<sides>
@ -92,7 +92,7 @@ def fml(irc, source, args):
try:
data = urllib.request.urlopen(url).read()
except urllib.error as e:
reply(irc, 'Error: %s' % e)
error(irc, '%s' % e)
return
tree = ElementTree.fromstring(data.decode('utf-8'))
@ -106,12 +106,12 @@ def fml(irc, source, args):
except AttributeError as e:
log.debug("games.FML: Error fetching FML %s from URL %s: %s",
query, url, e)
reply(irc, "Error: That FML does not exist or there was an error "
error(irc, "That FML does not exist or there was an error "
"fetching data from the API.")
return
if not fmlid:
reply(irc, "Error: That FML does not exist.")
error(irc, "That FML does not exist.")
return
# TODO: customizable formatting

View File

@ -16,10 +16,10 @@ def disconnect(irc, source, args):
netname = args[0]
network = world.networkobjects[netname]
except IndexError: # No argument given.
irc.reply('Error: Not enough arguments (needs 1: network name (case sensitive)).')
irc.error('Not enough arguments (needs 1: network name (case sensitive)).')
return
except KeyError: # Unknown network.
irc.reply('Error: No such network "%s" (case sensitive).' % netname)
irc.error('No such network "%s" (case sensitive).' % netname)
return
irc.reply("Done. If you want to reconnect this network, use the 'rehash' command.")
@ -37,13 +37,13 @@ def autoconnect(irc, source, args):
seconds = float(args[1])
network = world.networkobjects[netname]
except IndexError: # Arguments not given.
irc.reply('Error: Not enough arguments (needs 2: network name (case sensitive), autoconnect time (in seconds)).')
irc.error('Not enough arguments (needs 2: network name (case sensitive), autoconnect time (in seconds)).')
return
except KeyError: # Unknown network.
irc.reply('Error: No such network "%s" (case sensitive).' % netname)
irc.error('No such network "%s" (case sensitive).' % netname)
return
except ValueError:
irc.reply('Error: Invalid argument "%s" for <seconds>.' % seconds)
irc.error('Invalid argument "%s" for <seconds>.' % seconds)
return
network.serverdata['autoconnect'] = seconds
irc.reply("Done.")
@ -60,10 +60,10 @@ def remote(irc, source, args):
cmd_args = ' '.join(args[1:]).strip()
remoteirc = world.networkobjects[netname]
except IndexError: # Arguments not given.
irc.reply('Error: Not enough arguments (needs 2 or more: network name (case sensitive), command name & arguments).')
irc.error('Not enough arguments (needs 2 or more: network name (case sensitive), command name & arguments).')
return
except KeyError: # Unknown network.
irc.reply('Error: No such network "%s" (case sensitive).' % netname)
irc.error('No such network "%s" (case sensitive).' % netname)
return
if not cmd_args:
@ -93,7 +93,7 @@ def reloadproto(irc, source, args):
try:
name = args[0]
except IndexError:
irc.reply('Error: Not enough arguments (needs 1: protocol module name)')
irc.error('Not enough arguments (needs 1: protocol module name)')
return
proto = utils.getProtocolModule(name)

View File

@ -14,7 +14,7 @@ def checkban(irc, source, args):
try:
banmask = args[0]
except IndexError:
irc.reply("Error: Not enough arguments. Needs 1-2: banmask, nick or hostmask to check (optional).")
irc.error("Not enough arguments. Needs 1-2: banmask, nick or hostmask to check (optional).")
return
try:
@ -62,11 +62,11 @@ def jupe(irc, source, args):
reason = ' '.join(args[1:]) or "No reason given"
desc = "Juped by %s: [%s]" % (irc.getHostmask(source), reason)
except IndexError:
irc.reply('Error: Not enough arguments. Needs 1-2: servername, reason (optional).')
irc.error('Not enough arguments. Needs 1-2: servername, reason (optional).')
return
if not utils.isServerName(servername):
irc.reply("Error: Invalid server name '%s'." % servername)
irc.error("Invalid server name '%s'." % servername)
return
sid = irc.proto.spawnServer(servername, desc=desc)
@ -89,7 +89,7 @@ def kick(irc, source, args):
target = args[2]
reason = ' '.join(args[3:])
except IndexError:
irc.reply("Error: Not enough arguments. Needs 3-4: source nick, channel, target, reason (optional).")
irc.error("Not enough arguments. Needs 3-4: source nick, channel, target, reason (optional).")
return
# Convert the source and target nicks to UIDs.
@ -97,21 +97,21 @@ def kick(irc, source, args):
targetu = irc.nickToUid(target)
if channel not in irc.channels: # KICK only works on channels that exist.
irc.reply("Error: Unknown channel %r." % channel)
irc.error("Unknown channel %r." % channel)
return
if (not irc.isInternalClient(sender)) and \
(not irc.isInternalServer(sender)):
# Whatever we were told to send the kick from wasn't valid; try to be
# somewhat user friendly in the error message
irc.reply("Error: No such PyLink client '%s'. The first argument to "
irc.error("No such PyLink client '%s'. The first argument to "
"KICK should be the name of a PyLink client (e.g. '%s'; see "
"'help kick' for details." % (sourcenick,
irc.pseudoclient.nick))
return
elif not targetu:
# Whatever we were told to kick doesn't exist!
irc.reply("Error: No such target nick '%s'." % target)
irc.error("No such target nick '%s'." % target)
return
irc.proto.kick(sender, channel, targetu, reason)
@ -129,7 +129,7 @@ def kill(irc, source, args):
target = args[1]
reason = ' '.join(args[2:])
except IndexError:
irc.reply("Error: Not enough arguments. Needs 3-4: source nick, target, reason (optional).")
irc.error("Not enough arguments. Needs 3-4: source nick, target, reason (optional).")
return
# Convert the source and target nicks to UIDs.
@ -141,14 +141,14 @@ def kill(irc, source, args):
(not irc.isInternalServer(sender)):
# Whatever we were told to send the kick from wasn't valid; try to be
# somewhat user friendly in the error message
irc.reply("Error: No such PyLink client '%s'. The first argument to "
irc.error("No such PyLink client '%s'. The first argument to "
"KILL should be the name of a PyLink client (e.g. '%s'; see "
"'help kill' for details." % (sourcenick,
irc.pseudoclient.nick))
return
elif targetu not in irc.users:
# Whatever we were told to kick doesn't exist!
irc.reply("Error: No such nick '%s'." % target)
irc.error("No such nick '%s'." % target)
return
irc.proto.kill(sender, targetu, reason)
@ -171,15 +171,15 @@ def mode(irc, source, args):
try:
target, modes = args[0], args[1:]
except IndexError:
irc.reply('Error: Not enough arguments. Needs 2: target, modes to set.')
irc.error('Not enough arguments. Needs 2: target, modes to set.')
return
if target not in irc.channels:
irc.reply("Error: Unknown channel '%s'." % target)
irc.error("Unknown channel '%s'." % target)
return
elif not modes:
# No modes were given before parsing (i.e. mode list was blank).
irc.reply("Error: No valid modes were given.")
irc.error("No valid modes were given.")
return
parsedmodes = irc.parseModes(target, modes)
@ -188,7 +188,7 @@ def mode(irc, source, args):
# Modes were given but they failed to parse into anything meaningful.
# For example, "mode #somechan +o" would be erroneous because +o
# requires an argument!
irc.reply("Error: No valid modes were given.")
irc.error("No valid modes were given.")
return
irc.proto.mode(irc.pseudoclient.uid, target, parsedmodes)
@ -209,11 +209,11 @@ def topic(irc, source, args):
channel = args[0]
topic = ' '.join(args[1:])
except IndexError:
irc.reply("Error: Not enough arguments. Needs 2: channel, topic.")
irc.error("Not enough arguments. Needs 2: channel, topic.")
return
if channel not in irc.channels:
irc.reply("Error: Unknown channel %r." % channel)
irc.error("Unknown channel %r." % channel)
return
irc.proto.topic(irc.pseudoclient.uid, channel, topic)

View File

@ -1101,14 +1101,14 @@ def handle_messages(irc, numeric, command, args):
# on the remote network, and we won't have anything to send our
# messages from.
if homenet not in remoteusers.keys():
irc.msg(numeric, 'Error: You must be in a common channel '
irc.msg(numeric, 'You must be in a common channel '
'with %r in order to send messages.' % \
irc.users[target].nick, notice=True)
return
remoteirc = world.networkobjects[homenet]
if remoteirc.protoname == 'clientbot' and not conf.conf.get('relay', {}).get('allow_clientbot_pms'):
irc.msg(numeric, 'Error: Private messages to users connected via Clientbot have '
irc.msg(numeric, 'Private messages to users connected via Clientbot have '
'been administratively disabled.', notice=True)
return
@ -1402,12 +1402,12 @@ def handle_invite(irc, source, command, args):
remotechan = getRemoteChan(irc, remoteirc, channel)
remotesource = getRemoteUser(irc, remoteirc, source, spawnIfMissing=False)
if remotesource is None:
irc.msg(source, 'Error: You must be in a common channel '
irc.msg(source, 'You must be in a common channel '
'with %s to invite them to channels.' % \
irc.users[target].nick,
notice=True)
elif remotechan is None:
irc.msg(source, 'Error: You cannot invite someone to a '
irc.msg(source, 'You cannot invite someone to a '
'channel not on their network!',
notice=True)
else:
@ -1517,16 +1517,16 @@ def create(irc, source, args):
try:
channel = irc.toLower(args[0])
except IndexError:
irc.reply("Error: Not enough arguments. Needs 1: channel.")
irc.error("Not enough arguments. Needs 1: channel.")
return
if not utils.isChannel(channel):
irc.reply('Error: Invalid channel %r.' % channel)
irc.error('Invalid channel %r.' % channel)
return
if irc.protoname == 'clientbot':
irc.reply('Error: Clientbot networks cannot be used to host a relay.')
irc.error('Clientbot networks cannot be used to host a relay.')
return
if source not in irc.channels[channel].users:
irc.reply('Error: You must be in %r to complete this operation.' % channel)
irc.error('You must be in %r to complete this operation.' % channel)
return
permissions.checkPermissions(irc, source, ['relay.create'])
@ -1535,7 +1535,7 @@ def create(irc, source, args):
# relay.
localentry = getRelay((irc.name, channel))
if localentry:
irc.reply('Error: Channel %r is already part of a relay.' % channel)
irc.error('Channel %r is already part of a relay.' % channel)
return
creator = irc.getHostmask(source)
@ -1561,11 +1561,11 @@ def destroy(irc, source, args):
channel = irc.toLower(args[0])
network = irc.name
except IndexError:
irc.reply("Error: Not enough arguments. Needs 1-2: channel, network (optional).")
irc.error("Not enough arguments. Needs 1-2: channel, network (optional).")
return
if not utils.isChannel(channel):
irc.reply('Error: Invalid channel %r.' % channel)
irc.error('Invalid channel %r.' % channel)
return
# Check for different permissions based on whether we're destroying a local channel or
@ -1588,7 +1588,7 @@ def destroy(irc, source, args):
channel, irc.getHostmask(source))
irc.reply('Done.')
else:
irc.reply("Error: No such channel %r exists. If you're trying to delink a channel from "
irc.error("No such channel %r exists. If you're trying to delink a channel from "
"another network, use the DESTROY command." % channel)
return
destroy = utils.add_cmd(destroy, featured=True)
@ -1602,7 +1602,7 @@ def link(irc, source, args):
channel = irc.toLower(args[1])
remotenet = args[0]
except IndexError:
irc.reply("Error: Not enough arguments. Needs 2-3: remote netname, channel, local channel name (optional).")
irc.error("Not enough arguments. Needs 2-3: remote netname, channel, local channel name (optional).")
return
try:
@ -1612,11 +1612,11 @@ def link(irc, source, args):
for c in (channel, localchan):
if not utils.isChannel(c):
irc.reply('Error: Invalid channel %r.' % c)
irc.error('Invalid channel %r.' % c)
return
if remotenet == irc.name:
irc.reply('Error: Cannot link two channels on the same network.')
irc.error('Cannot link two channels on the same network.')
return
if source not in irc.channels[localchan].users:
@ -1630,36 +1630,36 @@ def link(irc, source, args):
irc.reply('Joining %r now to check for op status; please run this command again after I join.' % localchan)
return
elif not irc.channels[localchan].isOpPlus(source):
irc.reply('Error: You must be opped in %r to complete this operation.' % localchan)
irc.error('You must be opped in %r to complete this operation.' % localchan)
return
else:
irc.reply('Error: You must be in %r to complete this operation.' % localchan)
irc.error('You must be in %r to complete this operation.' % localchan)
return
permissions.checkPermissions(irc, source, ['relay.link'])
if remotenet not in world.networkobjects:
irc.reply('Error: No network named %r exists.' % remotenet)
irc.error('No network named %r exists.' % remotenet)
return
localentry = getRelay((irc.name, localchan))
if localentry:
irc.reply('Error: Channel %r is already part of a relay.' % localchan)
irc.error('Channel %r is already part of a relay.' % localchan)
return
try:
entry = db[(remotenet, channel)]
except KeyError:
irc.reply('Error: No such relay %r exists.' % channel)
irc.error('No such relay %r exists.' % channel)
return
else:
if irc.name in entry['blocked_nets']:
irc.reply('Error: Access denied (target channel is not open to links).')
irc.error('Access denied (target channel is not open to links).')
return
for link in entry['links']:
if link[0] == irc.name:
irc.reply("Error: Remote channel '%s%s' is already linked here "
irc.error("Remote channel '%s%s' is already linked here "
"as %r." % (remotenet, channel, link[1]))
return
@ -1668,7 +1668,7 @@ def link(irc, source, args):
if (our_ts < their_ts) and irc.protoname != 'clientbot':
log.debug('(%s) relay: Blocking link request %s%s -> %s%s due to bad TS (%s < %s)', irc.name,
irc.name, localchan, remotenet, channel, our_ts, their_ts)
irc.reply("Error: the channel creation date (TS) on %s is lower than the target "
irc.error("the channel creation date (TS) on %s is lower than the target "
"channel's; refusing to link. You should clear the local channel %s first "
"before linking, or use a different local channel." % (localchan, localchan))
return
@ -1688,7 +1688,7 @@ def delink(irc, source, args):
try:
channel = irc.toLower(args[0])
except IndexError:
irc.reply("Error: Not enough arguments. Needs 1-2: channel, remote netname (optional).")
irc.error("Not enough arguments. Needs 1-2: channel, remote netname (optional).")
return
try:
remotenet = args[1]
@ -1698,13 +1698,13 @@ def delink(irc, source, args):
permissions.checkPermissions(irc, source, ['relay.delink'])
if not utils.isChannel(channel):
irc.reply('Error: Invalid channel %r.' % channel)
irc.error('Invalid channel %r.' % channel)
return
entry = getRelay((irc.name, channel))
if entry:
if entry[0] == irc.name: # We own this channel.
if not remotenet:
irc.reply("Error: You must select a network to "
irc.error("You must select a network to "
"delink, or use the 'destroy' command to remove "
"this relay entirely (it was created on the current "
"network).")
@ -1721,7 +1721,7 @@ def delink(irc, source, args):
log.info('(%s) relay: Channel %s delinked from %s%s by %s.', irc.name,
channel, entry[0], entry[1], irc.getHostmask(source))
else:
irc.reply('Error: No such relay %r.' % channel)
irc.error('No such relay %r.' % channel)
delink = utils.add_cmd(delink, featured=True)
def linked(irc, source, args):
@ -1811,20 +1811,20 @@ def linkacl(irc, source, args):
Allows blocking / unblocking certain networks from linking to a relayed channel, based on a blacklist.
LINKACL LIST returns a list of blocked networks for a channel, while the ALLOW and DENY subcommands allow manipulating this blacklist."""
missingargs = "Error: Not enough arguments. Needs 2-3: subcommand (ALLOW/DENY/LIST), channel, remote network (for ALLOW/DENY)."
missingargs = "Not enough arguments. Needs 2-3: subcommand (ALLOW/DENY/LIST), channel, remote network (for ALLOW/DENY)."
try:
cmd = args[0].lower()
channel = irc.toLower(args[1])
except IndexError:
irc.reply(missingargs)
irc.error(missingargs)
return
if not utils.isChannel(channel):
irc.reply('Error: Invalid channel %r.' % channel)
irc.error('Invalid channel %r.' % channel)
return
relay = getRelay((irc.name, channel))
if not relay:
irc.reply('Error: No such relay %r exists.' % channel)
irc.error('No such relay %r exists.' % channel)
return
if cmd == 'list':
permissions.checkPermissions(irc, source, ['relay.linkacl.view'])
@ -1836,7 +1836,7 @@ def linkacl(irc, source, args):
try:
remotenet = args[2]
except IndexError:
irc.reply(missingargs)
irc.error(missingargs)
return
if cmd == 'deny':
db[relay]['blocked_nets'].add(remotenet)
@ -1845,11 +1845,11 @@ def linkacl(irc, source, args):
try:
db[relay]['blocked_nets'].remove(remotenet)
except KeyError:
irc.reply('Error: Network %r is not on the blacklist for %r.' % (remotenet, channel))
irc.error('Network %r is not on the blacklist for %r.' % (remotenet, channel))
else:
irc.reply('Done.')
else:
irc.reply('Error: Unknown subcommand %r: valid ones are ALLOW, DENY, and LIST.' % cmd)
irc.error('Unknown subcommand %r: valid ones are ALLOW, DENY, and LIST.' % cmd)
@utils.add_cmd
def showuser(irc, source, args):
@ -1937,7 +1937,7 @@ def claim(irc, source, args):
try:
channel = irc.toLower(args[0])
except IndexError:
irc.reply("Error: Not enough arguments. Needs 1-2: channel, list of networks (optional).")
irc.error("Not enough arguments. Needs 1-2: channel, list of networks (optional).")
return
permissions.checkPermissions(irc, source, ['relay.claim'])
@ -1945,7 +1945,7 @@ def claim(irc, source, args):
# We override getRelay() here to limit the search to the current network.
relay = (irc.name, channel)
if relay not in db:
irc.reply('Error: No such relay %r exists.' % channel)
irc.error('No such relay %r exists.' % channel)
return
claimed = db[relay]["claim"]
try:

View File

@ -202,30 +202,30 @@ def rpm(irc, source, args):
target = args[0]
text = ' '.join(args[1:])
except IndexError:
irc.reply('Error: Not enough arguments. Needs 2: target nick and text.')
irc.error('Not enough arguments. Needs 2: target nick and text.')
return
relay = world.plugins.get('relay')
if irc.protoname != 'clientbot':
irc.reply('Error: This command is only supported on Clientbot networks. Try /msg %s <text>' % target)
irc.error('This command is only supported on Clientbot networks. Try /msg %s <text>' % target)
return
elif relay is None:
irc.reply('Error: PyLink Relay is not loaded.')
irc.error('PyLink Relay is not loaded.')
return
elif not text:
irc.reply('Error: No text given.')
irc.error('No text given.')
return
elif not conf.conf.get('relay').get('allow_clientbot_pms'):
irc.reply('Error: Private messages with users connected via Clientbot have been '
irc.error('Private messages with users connected via Clientbot have been '
'administratively disabled.')
return
uid = irc.nickToUid(target)
if not uid:
irc.reply('Error: Unknown user %s.' % target)
irc.error('Unknown user %s.' % target)
return
elif not relay.isRelayClient(irc, uid):
irc.reply('Error: %s is not a relay user.' % target)
irc.error('%s is not a relay user.' % target)
return
else:
assert not irc.isInternalClient(source), "rpm is not allowed from PyLink bots"

View File

@ -24,7 +24,7 @@ def _map(irc, source, args, show_relay=True):
try:
ircobj = world.networkobjects[netname]
except KeyError:
irc.reply('Error: no such network %s' % netname)
irc.error('no such network %s' % netname)
return
servers = collections.defaultdict(set)