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

coremods, plugins: migrate to snake case

This commit is contained in:
James Lu 2017-06-29 23:01:39 -07:00
parent a4e321522b
commit 10bca676fc
17 changed files with 169 additions and 169 deletions

View File

@ -18,12 +18,12 @@ def _login(irc, source, username):
irc.users[source].account = username irc.users[source].account = username
irc.reply('Successfully logged in as %s.' % username) irc.reply('Successfully logged in as %s.' % username)
log.info("(%s) Successful login to %r by %s", log.info("(%s) Successful login to %r by %s",
irc.name, username, irc.getHostmask(source)) irc.name, username, irc.get_hostmask(source))
def _loginfail(irc, source, username): def _loginfail(irc, source, username):
"""Internal function to process login failures.""" """Internal function to process login failures."""
irc.error('Incorrect credentials.') irc.error('Incorrect credentials.')
log.warning("(%s) Failed login to %r from %s", irc.name, username, irc.getHostmask(source)) log.warning("(%s) Failed login to %r from %s", irc.name, username, irc.get_hostmask(source))
@utils.add_cmd @utils.add_cmd
def identify(irc, source, args): def identify(irc, source, args):
@ -86,7 +86,7 @@ def load(irc, source, args):
if name in world.plugins: if name in world.plugins:
irc.reply("Error: %r is already loaded." % name) irc.reply("Error: %r is already loaded." % name)
return return
log.info('(%s) Loading plugin %r for %s', irc.name, name, irc.getHostmask(source)) log.info('(%s) Loading plugin %r for %s', irc.name, name, irc.get_hostmask(source))
try: try:
world.plugins[name] = pl = utils.loadPlugin(name) world.plugins[name] = pl = utils.loadPlugin(name)
except ImportError as e: except ImportError as e:
@ -119,7 +119,7 @@ def unload(irc, source, args):
modulename = utils.PLUGIN_PREFIX + name modulename = utils.PLUGIN_PREFIX + name
if name in world.plugins: if name in world.plugins:
log.info('(%s) Unloading plugin %r for %s', irc.name, name, irc.getHostmask(source)) log.info('(%s) Unloading plugin %r for %s', irc.name, name, irc.get_hostmask(source))
pl = world.plugins[name] pl = world.plugins[name]
log.debug('sys.getrefcount of plugin %s is %s', pl, sys.getrefcount(pl)) log.debug('sys.getrefcount of plugin %s is %s', pl, sys.getrefcount(pl))

View File

@ -41,10 +41,10 @@ def account(irc, host, uid):
homenet, realuid) homenet, realuid)
return False return False
slogin = irc.toLower(userobj.services_account) slogin = irc.to_lower(userobj.services_account)
# Split the given exttarget host into parts, so we know how many to look for. # Split the given exttarget host into parts, so we know how many to look for.
groups = list(map(irc.toLower, host.split(':'))) groups = list(map(irc.to_lower, host.split(':')))
log.debug('(%s) exttargets.account: groups to match: %s', irc.name, groups) log.debug('(%s) exttargets.account: groups to match: %s', irc.name, groups)
if len(groups) == 1: if len(groups) == 1:
@ -74,10 +74,10 @@ def ircop(irc, host, uid):
if len(groups) == 1: if len(groups) == 1:
# 1st scenario. # 1st scenario.
return irc.isOper(uid, allowAuthed=False) return irc.is_oper(uid, allowAuthed=False)
else: else:
# 2nd scenario. Use matchHost (ircmatch) to match the opertype glob to the opertype. # 2nd scenario. Use match_host (ircmatch) to match the opertype glob to the opertype.
return irc.matchHost(groups[1], irc.users[uid].opertype) return irc.match_host(groups[1], irc.users[uid].opertype)
@bind @bind
def server(irc, host, uid): def server(irc, host, uid):
@ -93,10 +93,10 @@ def server(irc, host, uid):
log.debug('(%s) exttargets.server: groups to match: %s', irc.name, groups) log.debug('(%s) exttargets.server: groups to match: %s', irc.name, groups)
if len(groups) >= 2: if len(groups) >= 2:
sid = irc.getServer(uid) sid = irc.get_server(uid)
query = groups[1] query = groups[1]
# Return True if the SID matches the query or the server's name glob matches it. # Return True if the SID matches the query or the server's name glob matches it.
return sid == query or irc.matchHost(query, irc.getFriendlyName(sid)) return sid == query or irc.match_host(query, irc.get_friendly_name(sid))
# $server alone is invalid. Don't match anything. # $server alone is invalid. Don't match anything.
return False return False
@ -134,8 +134,8 @@ def pylinkacc(irc, host, uid):
$pylinkacc -> Returns True if the target is logged in to PyLink. $pylinkacc -> Returns True if the target is logged in to PyLink.
$pylinkacc:accountname -> Returns True if the target's PyLink login matches the one given. $pylinkacc:accountname -> Returns True if the target's PyLink login matches the one given.
""" """
login = irc.toLower(irc.users[uid].account) login = irc.to_lower(irc.users[uid].account)
groups = list(map(irc.toLower, host.split(':'))) groups = list(map(irc.to_lower, host.split(':')))
log.debug('(%s) exttargets.pylinkacc: groups to match: %s', irc.name, groups) log.debug('(%s) exttargets.pylinkacc: groups to match: %s', irc.name, groups)
if len(groups) == 1: if len(groups) == 1:
@ -187,6 +187,6 @@ def exttarget_and(irc, host, uid):
targets = targets[1:-1] targets = targets[1:-1]
targets = list(filter(None, targets.split('+'))) targets = list(filter(None, targets.split('+')))
log.debug('exttargets_and: using raw subtargets list %r (original query=%r)', targets, host) log.debug('exttargets_and: using raw subtargets list %r (original query=%r)', targets, host)
# Wrap every subtarget into irc.matchHost and return True if all subtargets return True. # Wrap every subtarget into irc.match_host and return True if all subtargets return True.
return all(map(lambda sub_exttarget: irc.matchHost(sub_exttarget, uid), targets)) return all(map(lambda sub_exttarget: irc.match_host(sub_exttarget, uid), targets))
world.exttarget_handlers['and'] = exttarget_and world.exttarget_handlers['and'] = exttarget_and

View File

@ -14,7 +14,7 @@ def handle_whois(irc, source, command, args):
f = lambda num, source, text: irc.numeric(irc.sid, num, source, text) f = lambda num, source, text: irc.numeric(irc.sid, num, source, text)
# Get the server that the target is on. # Get the server that the target is on.
server = irc.getServer(target) server = irc.get_server(target)
if user is None: # User doesn't exist if user is None: # User doesn't exist
# <- :42X 401 7PYAAAAAB GL- :No such nick/channel # <- :42X 401 7PYAAAAAB GL- :No such nick/channel
@ -22,7 +22,7 @@ def handle_whois(irc, source, command, args):
f(401, source, "%s :No such nick/channel" % nick) f(401, source, "%s :No such nick/channel" % nick)
else: else:
nick = user.nick nick = user.nick
sourceisOper = ('o', None) in irc.users[source].modes sourceis_oper = ('o', None) in irc.users[source].modes
sourceisBot = (irc.umodes.get('bot'), None) in irc.users[source].modes sourceisBot = (irc.umodes.get('bot'), None) in irc.users[source].modes
# Get the full network name. # Get the full network name.
@ -35,7 +35,7 @@ def handle_whois(irc, source, command, args):
# 319: RPL_WHOISCHANNELS; Show public channels of the target, respecting # 319: RPL_WHOISCHANNELS; Show public channels of the target, respecting
# hidechans umodes for non-oper callers. # hidechans umodes for non-oper callers.
isHideChans = (irc.umodes.get('hidechans'), None) in user.modes isHideChans = (irc.umodes.get('hidechans'), None) in user.modes
if (not isHideChans) or (isHideChans and sourceisOper): if (not isHideChans) or (isHideChans and sourceis_oper):
public_chans = [] public_chans = []
for chan in user.channels: for chan in user.channels:
c = irc.channels[chan] c = irc.channels[chan]
@ -44,7 +44,7 @@ def handle_whois(irc, source, command, args):
if ((irc.cmodes.get('secret'), None) in c.modes or \ if ((irc.cmodes.get('secret'), None) in c.modes or \
(irc.cmodes.get('private'), None) in c.modes) \ (irc.cmodes.get('private'), None) in c.modes) \
and not (sourceisOper or source in c.users): and not (sourceis_oper or source in c.users):
continue continue
# Show the highest prefix mode like a regular IRCd does, if there are any. # Show the highest prefix mode like a regular IRCd does, if there are any.
@ -74,7 +74,7 @@ def handle_whois(irc, source, command, args):
# 2) +H is set, but the caller is oper # 2) +H is set, but the caller is oper
# 3) +H is set, but whois_use_hideoper is disabled in config # 3) +H is set, but whois_use_hideoper is disabled in config
isHideOper = (irc.umodes.get('hideoper'), None) in user.modes isHideOper = (irc.umodes.get('hideoper'), None) in user.modes
if (not isHideOper) or (isHideOper and sourceisOper) or \ if (not isHideOper) or (isHideOper and sourceis_oper) or \
(isHideOper and not conf.conf['bot'].get('whois_use_hideoper', True)): (isHideOper and not conf.conf['bot'].get('whois_use_hideoper', True)):
# Let's be gramatically correct. (If the opertype starts with a vowel, # Let's be gramatically correct. (If the opertype starts with a vowel,
# write "an Operator" instead of "a Operator") # write "an Operator" instead of "a Operator")
@ -84,9 +84,9 @@ def handle_whois(irc, source, command, args):
# 379: RPL_WHOISMODES, used by UnrealIRCd and InspIRCd to show user modes. # 379: RPL_WHOISMODES, used by UnrealIRCd and InspIRCd to show user modes.
# Only show this to opers! # Only show this to opers!
if sourceisOper: if sourceis_oper:
f(378, source, "%s :is connecting from %s@%s %s" % (nick, user.ident, user.realhost, user.ip)) f(378, source, "%s :is connecting from %s@%s %s" % (nick, user.ident, user.realhost, user.ip))
f(379, source, '%s :is using modes %s' % (nick, irc.joinModes(user.modes, sort=True))) f(379, source, '%s :is using modes %s' % (nick, irc.join_modes(user.modes, sort=True)))
# 301: used to show away information if present # 301: used to show away information if present
away_text = user.away away_text = user.away
@ -101,7 +101,7 @@ def handle_whois(irc, source, command, args):
# Call custom WHOIS handlers via the PYLINK_CUSTOM_WHOIS hook, unless the # Call custom WHOIS handlers via the PYLINK_CUSTOM_WHOIS hook, unless the
# caller is marked a bot and the whois_show_extensions_to_bots option is False # caller is marked a bot and the whois_show_extensions_to_bots option is False
if (sourceisBot and conf.conf['bot'].get('whois_show_extensions_to_bots')) or (not sourceisBot): if (sourceisBot and conf.conf['bot'].get('whois_show_extensions_to_bots')) or (not sourceisBot):
irc.callHooks([source, 'PYLINK_CUSTOM_WHOIS', {'target': target, 'server': server}]) irc.call_hooks([source, 'PYLINK_CUSTOM_WHOIS', {'target': target, 'server': server}])
else: else:
log.debug('(%s) coremods.handlers.handle_whois: skipping custom whois handlers because ' log.debug('(%s) coremods.handlers.handle_whois: skipping custom whois handlers because '
'caller %s is marked as a bot', irc.name, source) 'caller %s is marked as a bot', irc.name, source)
@ -116,15 +116,15 @@ def handle_mode(irc, source, command, args):
modes = args['modes'] modes = args['modes']
# If the sender is not a PyLink client, and the target IS a protected # If the sender is not a PyLink client, and the target IS a protected
# client, revert any forced deoper attempts. # client, revert any forced deoper attempts.
if irc.isInternalClient(target) and not irc.isInternalClient(source): if irc.is_internal_client(target) and not irc.is_internal_client(source):
if ('-o', None) in modes and (target == irc.pseudoclient.uid or not irc.isManipulatableClient(target)): if ('-o', None) in modes and (target == irc.pseudoclient.uid or not irc.is_manipulatable_client(target)):
irc.mode(irc.sid, target, {('+o', None)}) irc.mode(irc.sid, target, {('+o', None)})
utils.add_hook(handle_mode, 'MODE') utils.add_hook(handle_mode, 'MODE')
def handle_operup(irc, source, command, args): def handle_operup(irc, source, command, args):
"""Logs successful oper-ups on networks.""" """Logs successful oper-ups on networks."""
otype = args.get('text', 'IRC Operator') otype = args.get('text', 'IRC Operator')
log.debug("(%s) Successful oper-up (opertype %r) from %s", irc.name, otype, irc.getHostmask(source)) log.debug("(%s) Successful oper-up (opertype %r) from %s", irc.name, otype, irc.get_hostmask(source))
irc.users[source].opertype = otype irc.users[source].opertype = otype
utils.add_hook(handle_operup, 'CLIENT_OPERED') utils.add_hook(handle_operup, 'CLIENT_OPERED')

View File

@ -60,22 +60,22 @@ def checkPermissions(irc, uid, perms, also_show=[]):
""" """
# For old (< 1.1 login blocks): # For old (< 1.1 login blocks):
# If the user is logged in, they automatically have all permissions. # If the user is logged in, they automatically have all permissions.
if irc.matchHost('$pylinkacc', uid) and conf.conf['login'].get('user'): if irc.match_host('$pylinkacc', uid) and conf.conf['login'].get('user'):
log.debug('permissions: overriding permissions check for old-style admin user %s', log.debug('permissions: overriding permissions check for old-style admin user %s',
irc.getHostmask(uid)) irc.get_hostmask(uid))
return True return True
# Iterate over all hostmask->permission list mappings. # Iterate over all hostmask->permission list mappings.
for host, permlist in permissions.copy().items(): for host, permlist in permissions.copy().items():
log.debug('permissions: permlist for %s: %s', host, permlist) log.debug('permissions: permlist for %s: %s', host, permlist)
if irc.matchHost(host, uid): if irc.match_host(host, uid):
# Now, iterate over all the perms we are looking for. # Now, iterate over all the perms we are looking for.
for perm in permlist: for perm in permlist:
# Use irc.matchHost to expand globs in an IRC-case insensitive and wildcard # Use irc.match_host to expand globs in an IRC-case insensitive and wildcard
# friendly way. e.g. 'xyz.*.#Channel\' will match 'xyz.manage.#channel|' on IRCds # friendly way. e.g. 'xyz.*.#Channel\' will match 'xyz.manage.#channel|' on IRCds
# using the RFC1459 casemapping. # using the RFC1459 casemapping.
log.debug('permissions: checking if %s glob matches anything in %s', perm, permlist) log.debug('permissions: checking if %s glob matches anything in %s', perm, permlist)
if any(irc.matchHost(perm, p) for p in perms): if any(irc.match_host(perm, p) for p in perms):
return True return True
raise utils.NotAuthorizedError("You are missing one of the following permissions: %s" % raise utils.NotAuthorizedError("You are missing one of the following permissions: %s" %
(', '.join(perms+also_show))) (', '.join(perms+also_show)))

View File

@ -14,7 +14,7 @@ def spawn_service(irc, source, command, args):
# Service name # Service name
name = args['name'] name = args['name']
if name != 'pylink' and not irc.hasCap('can-spawn-clients'): if name != 'pylink' and not irc.has_cap('can-spawn-clients'):
log.debug("(%s) Not spawning service %s because the server doesn't support spawning clients", log.debug("(%s) Not spawning service %s because the server doesn't support spawning clients",
irc.name, name) irc.name, name)
return return
@ -49,8 +49,8 @@ def spawn_service(irc, source, command, args):
# Track the service's UIDs on each network. # Track the service's UIDs on each network.
log.debug('(%s) spawn_service: Using nick %s for service %s', irc.name, nick, name) log.debug('(%s) spawn_service: Using nick %s for service %s', irc.name, nick, name)
u = irc.nickToUid(nick) u = irc.nick_to_uid(nick)
if u and irc.isInternalClient(u): # If an internal client exists, reuse it. if u and irc.is_internal_client(u): # If an internal client exists, reuse it.
log.debug('(%s) spawn_service: Using existing client %s/%s', irc.name, u, nick) log.debug('(%s) spawn_service: Using existing client %s/%s', irc.name, u, nick)
userobj = irc.users[u] userobj = irc.users[u]
else: else:
@ -101,7 +101,7 @@ def handle_kill(irc, source, command, args):
"""Handle KILLs to PyLink service bots, respawning them as needed.""" """Handle KILLs to PyLink service bots, respawning them as needed."""
target = args['target'] target = args['target']
userdata = args.get('userdata') userdata = args.get('userdata')
sbot = irc.getServiceBot(target) sbot = irc.get_service_bot(target)
servicename = None servicename = None
if userdata and hasattr(userdata, 'service'): # Look for the target's service name attribute if userdata and hasattr(userdata, 'service'): # Look for the target's service name attribute
@ -118,7 +118,7 @@ def handle_kick(irc, source, command, args):
"""Handle KICKs to the PyLink service bots, rejoining channels as needed.""" """Handle KICKs to the PyLink service bots, rejoining channels as needed."""
kicked = args['target'] kicked = args['target']
channel = args['channel'] channel = args['channel']
sbot = irc.getServiceBot(kicked) sbot = irc.get_service_bot(kicked)
if sbot: if sbot:
sbot.join(irc, channel) sbot.join(irc, channel)
utils.add_hook(handle_kick, 'KICK') utils.add_hook(handle_kick, 'KICK')
@ -128,7 +128,7 @@ def handle_commands(irc, source, command, args):
target = args['target'] target = args['target']
text = args['text'] text = args['text']
sbot = irc.getServiceBot(target) sbot = irc.get_service_bot(target)
if sbot: if sbot:
sbot.call_cmd(irc, source, text) sbot.call_cmd(irc, source, text)

View File

@ -58,7 +58,7 @@ def checkAccess(irc, uid, channel, command):
# - automode.<command>.#channel: ability to <command> automode on the given channel. # - automode.<command>.#channel: ability to <command> automode on the given channel.
# - automode.savedb: ability to save the automode DB. # - automode.savedb: ability to save the automode DB.
log.debug('(%s) Automode: checking access for %s/%s for %s capability on %s', irc.name, uid, log.debug('(%s) Automode: checking access for %s/%s for %s capability on %s', irc.name, uid,
irc.getHostmask(uid), command, channel) irc.get_hostmask(uid), command, channel)
baseperm = 'automode.%s' % command baseperm = 'automode.%s' % command
try: try:
@ -99,7 +99,7 @@ def match(irc, channel, uids=None):
for mask, modes in dbentry.items(): for mask, modes in dbentry.items():
for uid in uids: for uid in uids:
if irc.matchHost(mask, uid): if irc.match_host(mask, uid):
# User matched a mask. Filter the mode list given to only those that are valid # User matched a mask. Filter the mode list given to only those that are valid
# prefix mode characters. # prefix mode characters.
outgoing_modes += [('+'+mode, uid) for mode in modes if mode in irc.prefixmodes] outgoing_modes += [('+'+mode, uid) for mode in modes if mode in irc.prefixmodes]
@ -116,7 +116,7 @@ def match(irc, channel, uids=None):
irc.mode(modebot_uid, channel, outgoing_modes) irc.mode(modebot_uid, channel, outgoing_modes)
# Create a hook payload to support plugins like relay. # Create a hook payload to support plugins like relay.
irc.callHooks([modebot_uid, 'AUTOMODE_MODE', irc.call_hooks([modebot_uid, 'AUTOMODE_MODE',
{'target': channel, 'modes': outgoing_modes, 'parse_as': 'MODE'}]) {'target': channel, 'modes': outgoing_modes, 'parse_as': 'MODE'}])
def handle_join(irc, source, command, args): def handle_join(irc, source, command, args):
@ -124,7 +124,7 @@ def handle_join(irc, source, command, args):
Automode JOIN listener. This sets modes accordingly if the person joining matches a mask in the Automode JOIN listener. This sets modes accordingly if the person joining matches a mask in the
ACL. ACL.
""" """
channel = irc.toLower(args['channel']) channel = irc.to_lower(args['channel'])
match(irc, channel, args['users']) match(irc, channel, args['users'])
utils.add_hook(handle_join, 'JOIN') utils.add_hook(handle_join, 'JOIN')
@ -153,7 +153,7 @@ def getChannelPair(irc, source, chanpair, perm=None):
except ValueError: except ValueError:
raise ValueError("Invalid channel pair %r" % chanpair) raise ValueError("Invalid channel pair %r" % chanpair)
channel = '#' + channel channel = '#' + channel
channel = irc.toLower(channel) channel = irc.to_lower(channel)
assert utils.isChannel(channel), "Invalid channel name %s." % channel assert utils.isChannel(channel), "Invalid channel name %s." % channel
@ -202,7 +202,7 @@ def setacc(irc, source, args):
modes = modes.lstrip('+') # remove extraneous leading +'s modes = modes.lstrip('+') # remove extraneous leading +'s
dbentry[mask] = modes dbentry[mask] = modes
log.info('(%s) %s set modes +%s for %s on %s', ircobj.name, irc.getHostmask(source), modes, mask, channel) log.info('(%s) %s set modes +%s for %s on %s', ircobj.name, irc.get_hostmask(source), modes, mask, channel)
reply(irc, "Done. \x02%s\x02 now has modes \x02+%s\x02 in \x02%s\x02." % (mask, modes, channel)) reply(irc, "Done. \x02%s\x02 now has modes \x02+%s\x02 in \x02%s\x02." % (mask, modes, channel))
# Join the Automode bot to the channel if not explicitly told to. # Join the Automode bot to the channel if not explicitly told to.
@ -233,7 +233,7 @@ def delacc(irc, source, args):
if mask in dbentry: if mask in dbentry:
del dbentry[mask] del dbentry[mask]
log.info('(%s) %s removed modes for %s on %s', ircobj.name, irc.getHostmask(source), mask, channel) log.info('(%s) %s removed modes for %s on %s', ircobj.name, irc.get_hostmask(source), mask, channel)
reply(irc, "Done. Removed the Automode access entry for \x02%s\x02 in \x02%s\x02." % (mask, channel)) reply(irc, "Done. Removed the Automode access entry for \x02%s\x02 in \x02%s\x02." % (mask, channel))
else: else:
error(irc, "No Automode access entry for \x02%s\x02 exists in \x02%s\x02." % (mask, channel)) error(irc, "No Automode access entry for \x02%s\x02 exists in \x02%s\x02." % (mask, channel))
@ -299,7 +299,7 @@ def syncacc(irc, source, args):
else: else:
ircobj, channel = getChannelPair(irc, source, chanpair, perm='sync') ircobj, channel = getChannelPair(irc, source, chanpair, perm='sync')
log.info('(%s) %s synced modes on %s', ircobj.name, irc.getHostmask(source), channel) log.info('(%s) %s synced modes on %s', ircobj.name, irc.get_hostmask(source), channel)
match(ircobj, channel) match(ircobj, channel)
reply(irc, 'Done.') reply(irc, 'Done.')
@ -324,7 +324,7 @@ def clearacc(irc, source, args):
if db.get(ircobj.name+channel): if db.get(ircobj.name+channel):
del db[ircobj.name+channel] del db[ircobj.name+channel]
log.info('(%s) %s cleared modes on %s', ircobj.name, irc.getHostmask(source), channel) log.info('(%s) %s cleared modes on %s', ircobj.name, irc.get_hostmask(source), channel)
reply(irc, "Done. Removed all Automode access entries for \x02%s\x02." % channel) reply(irc, "Done. Removed all Automode access entries for \x02%s\x02." % channel)
else: else:
error(irc, "No Automode access entries exist for \x02%s\x02." % channel) error(irc, "No Automode access entries exist for \x02%s\x02." % channel)

View File

@ -33,21 +33,21 @@ def quit(irc, source, args):
except IndexError: except IndexError:
irc.error("Not enough arguments. Needs 1-2: nick, reason (optional).") irc.error("Not enough arguments. Needs 1-2: nick, reason (optional).")
return return
if irc.pseudoclient.uid == irc.nickToUid(nick): if irc.pseudoclient.uid == irc.nick_to_uid(nick):
irc.error("Cannot quit the main PyLink client!") irc.error("Cannot quit the main PyLink client!")
return return
u = irc.nickToUid(nick) u = irc.nick_to_uid(nick)
quitmsg = ' '.join(args[1:]) or 'Client Quit' quitmsg = ' '.join(args[1:]) or 'Client Quit'
if not irc.isManipulatableClient(u): if not irc.is_manipulatable_client(u):
irc.error("Cannot force quit a protected PyLink services client.") irc.error("Cannot force quit a protected PyLink services client.")
return return
irc.quit(u, quitmsg) irc.quit(u, quitmsg)
irc.reply("Done.") irc.reply("Done.")
irc.callHooks([u, 'PYLINK_BOTSPLUGIN_QUIT', {'text': quitmsg, 'parse_as': 'QUIT'}]) irc.call_hooks([u, 'PYLINK_BOTSPLUGIN_QUIT', {'text': quitmsg, 'parse_as': 'QUIT'}])
def joinclient(irc, source, args): def joinclient(irc, source, args):
"""[<target>] <channel1>[,<channel2>,<channel3>,...] """[<target>] <channel1>[,<channel2>,<channel3>,...]
@ -63,9 +63,9 @@ def joinclient(irc, source, args):
try: try:
# Check if the first argument is an existing PyLink client. If it is not, # Check if the first argument is an existing PyLink client. If it is not,
# then assume that the first argument was actually the channels being joined. # then assume that the first argument was actually the channels being joined.
u = irc.nickToUid(args[0]) u = irc.nick_to_uid(args[0])
if not irc.isInternalClient(u): # First argument isn't one of our clients if not irc.is_internal_client(u): # First argument isn't one of our clients
raise IndexError raise IndexError
clist = args[1] clist = args[1]
@ -82,7 +82,7 @@ def joinclient(irc, source, args):
irc.error("No valid channels given.") irc.error("No valid channels given.")
return return
if not (irc.isManipulatableClient(u) or irc.getServiceBot(u)): if not (irc.is_manipulatable_client(u) or irc.get_service_bot(u)):
irc.error("Cannot force join a protected PyLink services client.") irc.error("Cannot force join a protected PyLink services client.")
return return
@ -104,7 +104,7 @@ def joinclient(irc, source, args):
irc.join(u, real_channel) irc.join(u, real_channel)
# Call a join hook manually so other plugins like relay can understand it. # Call a join hook manually so other plugins like relay can understand it.
irc.callHooks([u, 'PYLINK_BOTSPLUGIN_JOIN', {'channel': real_channel, 'users': [u], irc.call_hooks([u, 'PYLINK_BOTSPLUGIN_JOIN', {'channel': real_channel, 'users': [u],
'modes': irc.channels[real_channel].modes, 'modes': irc.channels[real_channel].modes,
'parse_as': 'JOIN'}]) 'parse_as': 'JOIN'}])
irc.reply("Done.") irc.reply("Done.")
@ -128,7 +128,7 @@ def nick(irc, source, args):
except IndexError: except IndexError:
irc.error("Not enough arguments. Needs 1-2: nick (optional), newnick.") irc.error("Not enough arguments. Needs 1-2: nick (optional), newnick.")
return return
u = irc.nickToUid(nick) u = irc.nick_to_uid(nick)
if newnick in ('0', u): # Allow /nick 0 to work if newnick in ('0', u): # Allow /nick 0 to work
newnick = u newnick = u
@ -137,14 +137,14 @@ def nick(irc, source, args):
irc.error('Invalid nickname %r.' % newnick) irc.error('Invalid nickname %r.' % newnick)
return return
elif not (irc.isManipulatableClient(u) or irc.getServiceBot(u)): elif not (irc.is_manipulatable_client(u) or irc.get_service_bot(u)):
irc.error("Cannot force nick changes for a protected PyLink services client.") irc.error("Cannot force nick changes for a protected PyLink services client.")
return return
irc.nick(u, newnick) irc.nick(u, newnick)
irc.reply("Done.") irc.reply("Done.")
# Ditto above: manually send a NICK change hook payload to other plugins. # Ditto above: manually send a NICK change hook payload to other plugins.
irc.callHooks([u, 'PYLINK_BOTSPLUGIN_NICK', {'newnick': newnick, 'oldnick': nick, 'parse_as': 'NICK'}]) irc.call_hooks([u, 'PYLINK_BOTSPLUGIN_NICK', {'newnick': newnick, 'oldnick': nick, 'parse_as': 'NICK'}])
@utils.add_cmd @utils.add_cmd
def part(irc, source, args): def part(irc, source, args):
@ -161,8 +161,8 @@ def part(irc, source, args):
# First, check if the first argument is an existing PyLink client. If it is not, # First, check if the first argument is an existing PyLink client. If it is not,
# then assume that the first argument was actually the channels being parted. # then assume that the first argument was actually the channels being parted.
u = irc.nickToUid(nick) u = irc.nick_to_uid(nick)
if not irc.isInternalClient(u): # First argument isn't one of our clients if not irc.is_internal_client(u): # First argument isn't one of our clients
raise IndexError raise IndexError
except IndexError: # No nick was given; shift arguments one to the left. except IndexError: # No nick was given; shift arguments one to the left.
@ -180,7 +180,7 @@ def part(irc, source, args):
irc.error("No valid channels given.") irc.error("No valid channels given.")
return return
if not (irc.isManipulatableClient(u) or irc.getServiceBot(u)): if not (irc.is_manipulatable_client(u) or irc.get_service_bot(u)):
irc.error("Cannot force part a protected PyLink services client.") irc.error("Cannot force part a protected PyLink services client.")
return return
@ -191,7 +191,7 @@ def part(irc, source, args):
irc.part(u, channel, reason) irc.part(u, channel, reason)
irc.reply("Done.") irc.reply("Done.")
irc.callHooks([u, 'PYLINK_BOTSPLUGIN_PART', {'channels': clist, 'text': reason, 'parse_as': 'PART'}]) irc.call_hooks([u, 'PYLINK_BOTSPLUGIN_PART', {'channels': clist, 'text': reason, 'parse_as': 'PART'}])
@utils.add_cmd @utils.add_cmd
def msg(irc, source, args): def msg(irc, source, args):
@ -208,8 +208,8 @@ def msg(irc, source, args):
# First, check if the first argument is an existing PyLink client. If it is not, # First, check if the first argument is an existing PyLink client. If it is not,
# then assume that the first argument was actually the message TARGET. # then assume that the first argument was actually the message TARGET.
sourceuid = irc.nickToUid(msgsource) sourceuid = irc.nick_to_uid(msgsource)
if not irc.isInternalClient(sourceuid): # First argument isn't one of our clients if not irc.is_internal_client(sourceuid): # First argument isn't one of our clients
raise IndexError raise IndexError
if not text: if not text:
@ -229,7 +229,7 @@ def msg(irc, source, args):
if not utils.isChannel(target): if not utils.isChannel(target):
# Convert nick of the message target to a UID, if the target isn't a channel # Convert nick of the message target to a UID, if the target isn't a channel
real_target = irc.nickToUid(target) real_target = irc.nick_to_uid(target)
if real_target is None: # Unknown target user, if target isn't a valid channel name if real_target is None: # Unknown target user, if target isn't a valid channel name
irc.error('Unknown user %r.' % target) irc.error('Unknown user %r.' % target)
return return
@ -238,5 +238,5 @@ def msg(irc, source, args):
irc.message(sourceuid, real_target, text) irc.message(sourceuid, real_target, text)
irc.reply("Done.") irc.reply("Done.")
irc.callHooks([sourceuid, 'PYLINK_BOTSPLUGIN_MSG', {'target': real_target, 'text': text, 'parse_as': 'PRIVMSG'}]) irc.call_hooks([sourceuid, 'PYLINK_BOTSPLUGIN_MSG', {'target': real_target, 'text': text, 'parse_as': 'PRIVMSG'}])
utils.add_cmd(msg, 'say') utils.add_cmd(msg, 'say')

View File

@ -19,7 +19,7 @@ def _changehost(irc, target, args):
if target not in irc.users: if target not in irc.users:
return return
elif irc.isInternalClient(target): elif irc.is_internal_client(target):
log.debug('(%s) Skipping changehost on internal client %s', irc.name, target) log.debug('(%s) Skipping changehost on internal client %s', irc.name, target)
return return
@ -48,7 +48,7 @@ def _changehost(irc, target, args):
for host_glob, host_template in changehost_hosts.items(): for host_glob, host_template in changehost_hosts.items():
log.debug('(%s) Changehost: checking mask %s', irc.name, host_glob) log.debug('(%s) Changehost: checking mask %s', irc.name, host_glob)
if irc.matchHost(host_glob, target, ip=match_ip, realhost=match_realhosts): if irc.match_host(host_glob, target, ip=match_ip, realhost=match_realhosts):
log.debug('(%s) Changehost matched mask %s', irc.name, host_glob) log.debug('(%s) Changehost matched mask %s', irc.name, host_glob)
# This uses template strings for simple substitution: # This uses template strings for simple substitution:
# https://docs.python.org/3/library/string.html#template-strings # https://docs.python.org/3/library/string.html#template-strings
@ -103,13 +103,13 @@ def handle_chghost(irc, sender, command, args):
target = args['target'] target = args['target']
if (not irc.isInternalClient(sender)) and (not irc.isInternalServer(sender)): if (not irc.is_internal_client(sender)) and (not irc.is_internal_server(sender)):
if irc.name in changehost_conf.get('enforced_nets', []): if irc.name in changehost_conf.get('enforced_nets', []):
log.debug('(%s) Enforce for network is on, re-checking host for target %s/%s', log.debug('(%s) Enforce for network is on, re-checking host for target %s/%s',
irc.name, target, irc.getFriendlyName(target)) irc.name, target, irc.get_friendly_name(target))
for ex in changehost_conf.get("enforce_exceptions", []): for ex in changehost_conf.get("enforce_exceptions", []):
if irc.matchHost(ex, target): if irc.match_host(ex, target):
log.debug('(%s) Skipping host change for target %s; they are exempted by mask %s', log.debug('(%s) Skipping host change for target %s; they are exempted by mask %s',
irc.name, target, ex) irc.name, target, ex)
return return

View File

@ -29,7 +29,7 @@ def status(irc, source, args):
irc.reply('You are identified as \x02%s\x02.' % identified) irc.reply('You are identified as \x02%s\x02.' % identified)
else: else:
irc.reply('You are not identified as anyone.') irc.reply('You are not identified as anyone.')
irc.reply('Operator access: \x02%s\x02' % bool(irc.isOper(source))) irc.reply('Operator access: \x02%s\x02' % bool(irc.is_oper(source)))
_none = '\x1D(none)\x1D' _none = '\x1D(none)\x1D'
@utils.add_cmd @utils.add_cmd
@ -43,10 +43,10 @@ def showuser(irc, source, args):
except IndexError: except IndexError:
irc.error("Not enough arguments. Needs 1: nick.") irc.error("Not enough arguments. Needs 1: nick.")
return return
u = irc.nickToUid(target) or target u = irc.nick_to_uid(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 = irc.isOper(source) or u == source verbose = irc.is_oper(source) or u == source
if u not in irc.users: if u not in irc.users:
irc.error('Unknown user %r.' % target) irc.error('Unknown user %r.' % target)
return return
@ -57,7 +57,7 @@ def showuser(irc, source, args):
f('Showing information on user \x02%s\x02 (%s@%s): %s' % (userobj.nick, userobj.ident, f('Showing information on user \x02%s\x02 (%s@%s): %s' % (userobj.nick, userobj.ident,
userobj.host, userobj.realname)) userobj.host, userobj.realname))
sid = irc.getServer(u) sid = irc.get_server(u)
serverobj = irc.servers[sid] serverobj = irc.servers[sid]
ts = userobj.ts ts = userobj.ts
@ -67,7 +67,7 @@ def showuser(irc, source, args):
if verbose: # Oper only data: user modes, channels on, account info, etc. if verbose: # Oper only data: user modes, channels on, account info, etc.
f('\x02User modes\x02: %s' % irc.joinModes(userobj.modes, sort=True)) f('\x02User modes\x02: %s' % irc.join_modes(userobj.modes, sort=True))
f('\x02Protocol UID\x02: %s; \x02Real host\x02: %s; \x02IP\x02: %s' % \ f('\x02Protocol UID\x02: %s; \x02Real host\x02: %s; \x02IP\x02: %s' % \
(u, userobj.realhost, userobj.ip)) (u, userobj.realhost, userobj.ip))
channels = sorted(userobj.channels) channels = sorted(userobj.channels)
@ -83,7 +83,7 @@ def showchan(irc, source, args):
Shows information about <channel>.""" Shows information about <channel>."""
permissions.checkPermissions(irc, source, ['commands.showchan']) permissions.checkPermissions(irc, source, ['commands.showchan'])
try: try:
channel = irc.toLower(args[0]) channel = irc.to_lower(args[0])
except IndexError: except IndexError:
irc.error("Not enough arguments. Needs 1: channel.") irc.error("Not enough arguments. Needs 1: channel.")
return return
@ -95,7 +95,7 @@ def showchan(irc, source, args):
c = irc.channels[channel] c = irc.channels[channel]
# Only show verbose info if caller is oper or is in the target channel. # Only show verbose info if caller is oper or is in the target channel.
verbose = source in c.users or irc.isOper(source) verbose = source in c.users or irc.is_oper(source)
secret = ('s', None) in c.modes secret = ('s', None) in c.modes
if secret and not verbose: if secret and not verbose:
# Hide secret channels from normal users. # Hide secret channels from normal users.
@ -110,10 +110,10 @@ def showchan(irc, source, args):
# Mark TS values as untrusted on Clientbot and others (where TS is read-only or not trackable) # Mark TS values as untrusted on Clientbot and others (where TS is read-only or not trackable)
f('\x02Channel creation time\x02: %s (%s)%s' % (ctime(c.ts), c.ts, f('\x02Channel creation time\x02: %s (%s)%s' % (ctime(c.ts), c.ts,
' [UNTRUSTED]' if not irc.hasCap('has-ts') else '')) ' [UNTRUSTED]' if not irc.has_cap('has-ts') else ''))
# Show only modes that aren't list-style modes. # Show only modes that aren't list-style modes.
modes = irc.joinModes([m for m in c.modes if m[0] not in irc.cmodes['*A']], sort=True) modes = irc.join_modes([m for m in c.modes if m[0] not in irc.cmodes['*A']], sort=True)
f('\x02Channel modes\x02: %s' % modes) f('\x02Channel modes\x02: %s' % modes)
if verbose: if verbose:
nicklist = [] nicklist = []
@ -179,7 +179,7 @@ def logout(irc, source, args):
irc.error("You are not logged in!") irc.error("You are not logged in!")
return return
else: else:
otheruid = irc.nickToUid(othernick) otheruid = irc.nick_to_uid(othernick)
if not otheruid: if not otheruid:
irc.error("Unknown user %s." % othernick) irc.error("Unknown user %s." % othernick)
return return

View File

@ -34,7 +34,7 @@ def _exec(irc, source, args, locals_dict=None):
return return
log.info('(%s) Executing %r for %s', irc.name, args, log.info('(%s) Executing %r for %s', irc.name, args,
irc.getHostmask(source)) irc.get_hostmask(source))
if locals_dict is None: if locals_dict is None:
locals_dict = locals() locals_dict = locals()
else: else:
@ -86,7 +86,7 @@ def _eval(irc, source, args, locals_dict=None, pretty_print=False):
locals_dict['args'] = args locals_dict['args'] = args
log.info('(%s) Evaluating %r for %s', irc.name, args, log.info('(%s) Evaluating %r for %s', irc.name, args,
irc.getHostmask(source)) irc.get_hostmask(source))
result = eval(args, globals(), locals_dict) result = eval(args, globals(), locals_dict)
@ -150,7 +150,7 @@ def raw(irc, source, args):
return return
log.debug('(%s) Sending raw text %r to IRC for %s', irc.name, args, log.debug('(%s) Sending raw text %r to IRC for %s', irc.name, args,
irc.getHostmask(source)) irc.get_hostmask(source))
irc.send(args) irc.send(args)
irc.reply("Done.") irc.reply("Done.")
@ -170,5 +170,5 @@ def inject(irc, source, args):
return return
log.info('(%s) Injecting raw text %r into protocol module for %s', irc.name, log.info('(%s) Injecting raw text %r into protocol module for %s', irc.name,
args, irc.getHostmask(source)) args, irc.get_hostmask(source))
irc.reply(irc.runline(args)) irc.reply(irc.runline(args))

View File

@ -12,7 +12,7 @@ def handle_fantasy(irc, source, command, args):
channel = args['target'] channel = args['target']
orig_text = args['text'] orig_text = args['text']
if utils.isChannel(channel) and not irc.isInternalClient(source): if utils.isChannel(channel) and not irc.is_internal_client(source):
# The following conditions must be met for an incoming message for # The following conditions must be met for an incoming message for
# fantasy to trigger: # fantasy to trigger:
# 1) The message target is a channel. # 1) The message target is a channel.
@ -42,7 +42,7 @@ def handle_fantasy(irc, source, command, args):
# If responding to nick is enabled, add variations of the current nick # If responding to nick is enabled, add variations of the current nick
# to the prefix list: "<nick>," and "<nick>:" # to the prefix list: "<nick>," and "<nick>:"
nick = irc.toLower(irc.users[servuid].nick) nick = irc.to_lower(irc.users[servuid].nick)
nick_prefixes = [nick+',', nick+':'] nick_prefixes = [nick+',', nick+':']
if respondtonick: if respondtonick:
@ -52,7 +52,7 @@ def handle_fantasy(irc, source, command, args):
# No prefixes were set, so skip. # No prefixes were set, so skip.
continue continue
lowered_text = irc.toLower(orig_text) lowered_text = irc.to_lower(orig_text)
for prefix in filter(None, prefixes): # Cycle through the prefixes list we finished with. for prefix in filter(None, prefixes): # Cycle through the prefixes list we finished with.
if lowered_text.startswith(prefix): if lowered_text.startswith(prefix):

View File

@ -20,12 +20,12 @@ def g(irc, source, args):
for name, ircd in world.networkobjects.items(): for name, ircd in world.networkobjects.items():
if ircd.connected.is_set(): # Only attempt to send to connected networks if ircd.connected.is_set(): # Only attempt to send to connected networks
for channel in ircd.pseudoclient.channels: for channel in ircd.pseudoclient.channels:
subst = {'sender': irc.getFriendlyName(source), subst = {'sender': irc.get_friendly_name(source),
'network': irc.name, 'network': irc.name,
'fullnetwork': irc.getFullNetworkName(), 'fullnetwork': irc.get_full_network_name(),
'current_channel': channel, 'current_channel': channel,
'current_network': ircd.name, 'current_network': ircd.name,
'current_fullnetwork': ircd.getFullNetworkName(), 'current_fullnetwork': ircd.get_full_network_name(),
'text': message} 'text': message}
# Disable relaying or other plugins handling the global message. # Disable relaying or other plugins handling the global message.

View File

@ -27,10 +27,10 @@ def checkban(irc, source, args):
results = 0 results = 0
for uid, userobj in irc.users.copy().items(): for uid, userobj in irc.users.copy().items():
if irc.matchHost(banmask, uid): if irc.match_host(banmask, uid):
if results < 50: # XXX rather arbitrary limit if results < 50: # XXX rather arbitrary limit
s = "\x02%s\x02 (%s@%s) [%s] {\x02%s\x02}" % (userobj.nick, userobj.ident, s = "\x02%s\x02 (%s@%s) [%s] {\x02%s\x02}" % (userobj.nick, userobj.ident,
userobj.host, userobj.realname, irc.getFriendlyName(irc.getServer(uid))) userobj.host, userobj.realname, irc.get_friendly_name(irc.get_server(uid)))
# Always reply in private to prevent information leaks. # Always reply in private to prevent information leaks.
irc.reply(s, private=True) irc.reply(s, private=True)
@ -42,9 +42,9 @@ def checkban(irc, source, args):
else: else:
irc.msg(source, "No results found.", notice=True) irc.msg(source, "No results found.", notice=True)
else: else:
# Target can be both a nick (of an online user) or a hostmask. irc.matchHost() handles this # Target can be both a nick (of an online user) or a hostmask. irc.match_host() handles this
# automatically. # automatically.
if irc.matchHost(banmask, targetmask): if irc.match_host(banmask, targetmask):
irc.reply('Yes, \x02%s\x02 matches \x02%s\x02.' % (targetmask, banmask)) irc.reply('Yes, \x02%s\x02 matches \x02%s\x02.' % (targetmask, banmask))
else: else:
irc.reply('No, \x02%s\x02 does not match \x02%s\x02.' % (targetmask, banmask)) irc.reply('No, \x02%s\x02 does not match \x02%s\x02.' % (targetmask, banmask))
@ -61,7 +61,7 @@ def jupe(irc, source, args):
try: try:
servername = args[0] servername = args[0]
reason = ' '.join(args[1:]) or "No reason given" reason = ' '.join(args[1:]) or "No reason given"
desc = "Juped by %s: [%s]" % (irc.getHostmask(source), reason) desc = "Juped by %s: [%s]" % (irc.get_hostmask(source), reason)
except IndexError: except IndexError:
irc.error('Not enough arguments. Needs 1-2: servername, reason (optional).') irc.error('Not enough arguments. Needs 1-2: servername, reason (optional).')
return return
@ -72,7 +72,7 @@ def jupe(irc, source, args):
sid = irc.spawnServer(servername, desc=desc) sid = irc.spawnServer(servername, desc=desc)
irc.callHooks([irc.pseudoclient.uid, 'OPERCMDS_SPAWNSERVER', irc.call_hooks([irc.pseudoclient.uid, 'OPERCMDS_SPAWNSERVER',
{'name': servername, 'sid': sid, 'text': desc}]) {'name': servername, 'sid': sid, 'text': desc}])
irc.reply("Done.") irc.reply("Done.")
@ -85,14 +85,14 @@ def kick(irc, source, args):
Admin only. Kicks <user> from the specified channel.""" Admin only. Kicks <user> from the specified channel."""
permissions.checkPermissions(irc, source, ['opercmds.kick']) permissions.checkPermissions(irc, source, ['opercmds.kick'])
try: try:
channel = irc.toLower(args[0]) channel = irc.to_lower(args[0])
target = args[1] target = args[1]
reason = ' '.join(args[2:]) reason = ' '.join(args[2:])
except IndexError: except IndexError:
irc.error("Not enough arguments. Needs 2-3: channel, target, reason (optional).") irc.error("Not enough arguments. Needs 2-3: channel, target, reason (optional).")
return return
targetu = irc.nickToUid(target) targetu = irc.nick_to_uid(target)
if channel not in irc.channels: # KICK only works on channels that exist. if channel not in irc.channels: # KICK only works on channels that exist.
irc.error("Unknown channel %r." % channel) irc.error("Unknown channel %r." % channel)
@ -106,7 +106,7 @@ def kick(irc, source, args):
sender = irc.pseudoclient.uid sender = irc.pseudoclient.uid
irc.kick(sender, channel, targetu, reason) irc.kick(sender, channel, targetu, reason)
irc.reply("Done.") irc.reply("Done.")
irc.callHooks([sender, 'CHANCMDS_KICK', {'channel': channel, 'target': targetu, irc.call_hooks([sender, 'CHANCMDS_KICK', {'channel': channel, 'target': targetu,
'text': reason, 'parse_as': 'KICK'}]) 'text': reason, 'parse_as': 'KICK'}])
@utils.add_cmd @utils.add_cmd
@ -124,7 +124,7 @@ def kill(irc, source, args):
# Convert the source and target nicks to UIDs. # Convert the source and target nicks to UIDs.
sender = irc.pseudoclient.uid sender = irc.pseudoclient.uid
targetu = irc.nickToUid(target) targetu = irc.nick_to_uid(target)
userdata = irc.users.get(targetu) userdata = irc.users.get(targetu)
if targetu not in irc.users: if targetu not in irc.users:
@ -135,10 +135,10 @@ def kill(irc, source, args):
irc.kill(sender, targetu, reason) irc.kill(sender, targetu, reason)
# Format the kill reason properly in hooks. # Format the kill reason properly in hooks.
reason = "Killed (%s (%s))" % (irc.getFriendlyName(sender), reason) reason = "Killed (%s (%s))" % (irc.get_friendly_name(sender), reason)
irc.reply("Done.") irc.reply("Done.")
irc.callHooks([sender, 'CHANCMDS_KILL', {'target': targetu, 'text': reason, irc.call_hooks([sender, 'CHANCMDS_KILL', {'target': targetu, 'text': reason,
'userdata': userdata, 'parse_as': 'KILL'}]) 'userdata': userdata, 'parse_as': 'KILL'}])
@utils.add_cmd @utils.add_cmd
@ -164,7 +164,7 @@ def mode(irc, source, args):
irc.error("No valid modes were given.") irc.error("No valid modes were given.")
return return
parsedmodes = irc.parseModes(target, modes) parsedmodes = irc.parse_modes(target, modes)
if not parsedmodes: if not parsedmodes:
# Modes were given but they failed to parse into anything meaningful. # Modes were given but they failed to parse into anything meaningful.
@ -176,7 +176,7 @@ def mode(irc, source, args):
irc.mode(irc.pseudoclient.uid, target, parsedmodes) irc.mode(irc.pseudoclient.uid, target, parsedmodes)
# Call the appropriate hooks for plugins like relay. # Call the appropriate hooks for plugins like relay.
irc.callHooks([irc.pseudoclient.uid, 'OPERCMDS_MODEOVERRIDE', irc.call_hooks([irc.pseudoclient.uid, 'OPERCMDS_MODEOVERRIDE',
{'target': target, 'modes': parsedmodes, 'parse_as': 'MODE'}]) {'target': target, 'modes': parsedmodes, 'parse_as': 'MODE'}])
irc.reply("Done.") irc.reply("Done.")
@ -201,6 +201,6 @@ def topic(irc, source, args):
irc.topic(irc.pseudoclient.uid, channel, topic) irc.topic(irc.pseudoclient.uid, channel, topic)
irc.reply("Done.") irc.reply("Done.")
irc.callHooks([irc.pseudoclient.uid, 'CHANCMDS_TOPIC', irc.call_hooks([irc.pseudoclient.uid, 'CHANCMDS_TOPIC',
{'channel': channel, 'text': topic, 'setter': source, {'channel': channel, 'text': topic, 'setter': source,
'parse_as': 'TOPIC'}]) 'parse_as': 'TOPIC'}])

View File

@ -105,7 +105,7 @@ def normalize_nick(irc, netname, nick, times_tagged=0, uid=''):
forcetag_nicks = conf.conf.get('relay', {}).get('forcetag_nicks', []) forcetag_nicks = conf.conf.get('relay', {}).get('forcetag_nicks', [])
log.debug('(%s) relay.normalize_nick: checking if globs %s match %s.', irc.name, forcetag_nicks, nick) log.debug('(%s) relay.normalize_nick: checking if globs %s match %s.', irc.name, forcetag_nicks, nick)
for glob in forcetag_nicks: for glob in forcetag_nicks:
if irc.matchHost(glob, nick): if irc.match_host(glob, nick):
# User matched a nick to force tag nicks for. Tag them. # User matched a nick to force tag nicks for. Tag them.
times_tagged = 1 times_tagged = 1
break break
@ -117,7 +117,7 @@ def normalize_nick(irc, netname, nick, times_tagged=0, uid=''):
# Charybdis, IRCu, etc. don't allow / in nicks, and will SQUIT with a protocol # Charybdis, IRCu, etc. don't allow / in nicks, and will SQUIT with a protocol
# violation if it sees one. Or it might just ignore the client introduction and # violation if it sees one. Or it might just ignore the client introduction and
# cause bad desyncs. # cause bad desyncs.
protocol_allows_slashes = irc.hasCap('slash-in-nicks') or \ protocol_allows_slashes = irc.has_cap('slash-in-nicks') or \
irc.serverdata.get('relay_force_slashes') irc.serverdata.get('relay_force_slashes')
if '/' not in separator or not protocol_allows_slashes: if '/' not in separator or not protocol_allows_slashes:
@ -153,7 +153,7 @@ def normalize_nick(irc, netname, nick, times_tagged=0, uid=''):
if char not in allowed_chars: if char not in allowed_chars:
nick = nick.replace(char, fallback_separator) nick = nick.replace(char, fallback_separator)
while irc.nickToUid(nick) and irc.nickToUid(nick) != uid: while irc.nick_to_uid(nick) and irc.nick_to_uid(nick) != uid:
# The nick we want exists: Increase the separator length by 1 if the user was already # The nick we want exists: Increase the separator length by 1 if the user was already
# tagged, but couldn't be created due to a nick conflict. This can happen when someone # tagged, but couldn't be created due to a nick conflict. This can happen when someone
# steals a relay user's nick. # steals a relay user's nick.
@ -176,11 +176,11 @@ def normalize_host(irc, host):
log.debug('(%s) relay.normalize_host: IRCd=%s, host=%s', irc.name, irc.protoname, host) log.debug('(%s) relay.normalize_host: IRCd=%s, host=%s', irc.name, irc.protoname, host)
allowed_chars = string.ascii_letters + string.digits + '-.:' allowed_chars = string.ascii_letters + string.digits + '-.:'
if irc.hasCap('slash-in-hosts'): if irc.has_cap('slash-in-hosts'):
# UnrealIRCd and IRCd-Hybrid don't allow slashes in hostnames # UnrealIRCd and IRCd-Hybrid don't allow slashes in hostnames
allowed_chars += '/' allowed_chars += '/'
if irc.hasCap('underscore-in-hosts'): if irc.has_cap('underscore-in-hosts'):
# Most IRCds allow _ in hostnames, but hybrid/charybdis/ratbox IRCds do not. # Most IRCds allow _ in hostnames, but hybrid/charybdis/ratbox IRCds do not.
allowed_chars += '_' allowed_chars += '_'
@ -221,7 +221,7 @@ def spawn_relay_server(irc, remoteirc):
suffix = suffix.strip('.') suffix = suffix.strip('.')
sid = irc.spawnServer('%s.%s' % (remoteirc.name, suffix), sid = irc.spawnServer('%s.%s' % (remoteirc.name, suffix),
desc="PyLink Relay network - %s" % desc="PyLink Relay network - %s" %
(remoteirc.getFullNetworkName()), endburst_delay=3) (remoteirc.get_full_network_name()), endburst_delay=3)
except (RuntimeError, ValueError): # Network not initialized yet, or a server name conflict. except (RuntimeError, ValueError): # Network not initialized yet, or a server name conflict.
log.exception('(%s) Failed to spawn server for %r (possible jupe?):', log.exception('(%s) Failed to spawn server for %r (possible jupe?):',
irc.name, remoteirc.name) irc.name, remoteirc.name)
@ -296,7 +296,7 @@ def spawn_relay_user(irc, remoteirc, user, times_tagged=0):
else: else:
opertype = 'IRC Operator' opertype = 'IRC Operator'
opertype += ' (on %s)' % irc.getFullNetworkName() opertype += ' (on %s)' % irc.get_full_network_name()
# Set hideoper on remote opers, to prevent inflating # Set hideoper on remote opers, to prevent inflating
# /lusers and various /stats # /lusers and various /stats
@ -351,7 +351,7 @@ def get_remote_user(irc, remoteirc, user, spawn_if_missing=True, times_tagged=0)
# Wait until the network is working before trying to spawn anything. # Wait until the network is working before trying to spawn anything.
if irc.connected.wait(TCONDITION_TIMEOUT): if irc.connected.wait(TCONDITION_TIMEOUT):
# Don't spawn clones for registered service bots. # Don't spawn clones for registered service bots.
sbot = irc.getServiceBot(user) sbot = irc.get_service_bot(user)
if sbot: if sbot:
return sbot.uids.get(remoteirc.name) return sbot.uids.get(remoteirc.name)
@ -538,8 +538,8 @@ def check_claim(irc, channel, sender, chanobj=None):
return (not relay) or irc.name == relay[0] or not db[relay]['claim'] or \ return (not relay) or irc.name == relay[0] or not db[relay]['claim'] or \
irc.name in db[relay]['claim'] or \ irc.name in db[relay]['claim'] or \
any([mode in sender_modes for mode in ('y', 'q', 'a', 'o', 'h')]) \ any([mode in sender_modes for mode in ('y', 'q', 'a', 'o', 'h')]) \
or irc.isInternalClient(sender) or \ or irc.is_internal_client(sender) or \
irc.isInternalServer(sender) irc.is_internal_server(sender)
def get_supported_umodes(irc, remoteirc, modes): def get_supported_umodes(irc, remoteirc, modes):
"""Given a list of user modes, filters out all of those not supported by the """Given a list of user modes, filters out all of those not supported by the
@ -648,7 +648,7 @@ def relay_joins(irc, channel, users, ts, burst=True):
# Fetch the known channel TS and all the prefix modes for each user. This ensures # Fetch the known channel TS and all the prefix modes for each user. This ensures
# the different sides of the relay are merged properly. # the different sides of the relay are merged properly.
if not irc.hasCap('has-ts'): if not irc.has_cap('has-ts'):
# Special hack for clientbot: just use the remote's modes so mode changes # Special hack for clientbot: just use the remote's modes so mode changes
# take precendence. (TS is always outside the clientbot's control) # take precendence. (TS is always outside the clientbot's control)
ts = remoteirc.channels[remotechan].ts ts = remoteirc.channels[remotechan].ts
@ -677,7 +677,7 @@ def relay_joins(irc, channel, users, ts, burst=True):
for remoteirc, hookdata in joined_nets.items(): for remoteirc, hookdata in joined_nets.items():
# HACK: Announce this JOIN as a special hook on each network, for plugins like Automode. # HACK: Announce this JOIN as a special hook on each network, for plugins like Automode.
remoteirc.callHooks([remoteirc.sid, 'PYLINK_RELAY_JOIN', hookdata]) remoteirc.call_hooks([remoteirc.sid, 'PYLINK_RELAY_JOIN', hookdata])
def relay_part(irc, channel, user): def relay_part(irc, channel, user):
""" """
@ -783,7 +783,7 @@ def get_supported_cmodes(irc, remoteirc, channel, modes):
"for network %r.", "for network %r.",
irc.name, modechar, arg, remoteirc.name) irc.name, modechar, arg, remoteirc.name)
if (not irc.hasCap('can-spawn-clients')) and irc.pseudoclient and arg == irc.pseudoclient.uid: if (not irc.has_cap('can-spawn-clients')) and irc.pseudoclient and arg == irc.pseudoclient.uid:
# Skip modesync on the main PyLink client. # Skip modesync on the main PyLink client.
log.debug("(%s) relay.get_supported_cmodes: filtering prefix change (%r, %r) on Clientbot relayer", log.debug("(%s) relay.get_supported_cmodes: filtering prefix change (%r, %r) on Clientbot relayer",
irc.name, name, arg) irc.name, name, arg)
@ -857,7 +857,7 @@ def handle_relay_whois(irc, source, command, args):
setting = conf.conf.get('relay', {}).get(infoline, '').lower() setting = conf.conf.get('relay', {}).get(infoline, '').lower()
if setting == 'all': if setting == 'all':
return True return True
elif setting == 'opers' and irc.isOper(source, allowAuthed=False): elif setting == 'opers' and irc.is_oper(source, allowAuthed=False):
return True return True
return False return False
@ -867,7 +867,7 @@ def handle_relay_whois(irc, source, command, args):
homenet, uid = origuser homenet, uid = origuser
realirc = world.networkobjects[homenet] realirc = world.networkobjects[homenet]
realuser = realirc.users[uid] realuser = realirc.users[uid]
netname = realirc.getFullNetworkName() netname = realirc.get_full_network_name()
wreply(320, ":is a remote user connected via PyLink Relay. Home network: %s; " wreply(320, ":is a remote user connected via PyLink Relay. Home network: %s; "
"Home nick: %s" % (netname, realuser.nick)) "Home nick: %s" % (netname, realuser.nick))
@ -876,9 +876,9 @@ def handle_relay_whois(irc, source, command, args):
# Send account information if told to and the target is logged in. # Send account information if told to and the target is logged in.
wreply(330, "%s :is logged in (on %s) as" % (realuser.services_account, netname)) wreply(330, "%s :is logged in (on %s) as" % (realuser.services_account, netname))
if checkSendKey('whois_show_server') and realirc.hasCap('can-track-servers'): if checkSendKey('whois_show_server') and realirc.has_cap('can-track-servers'):
wreply(320, ":is actually connected via the following server:") wreply(320, ":is actually connected via the following server:")
realserver = realirc.getServer(uid) realserver = realirc.get_server(uid)
realserver = realirc.servers[realserver] realserver = realirc.servers[realserver]
wreply(312, "%s :%s" % (realserver.name, realserver.desc)) wreply(312, "%s :%s" % (realserver.name, realserver.desc))
@ -888,7 +888,7 @@ def handle_operup(irc, numeric, command, args):
""" """
Handles setting oper types on relay clients during oper up. Handles setting oper types on relay clients during oper up.
""" """
newtype = '%s (on %s)' % (args['text'], irc.getFullNetworkName()) newtype = '%s (on %s)' % (args['text'], irc.get_full_network_name())
for netname, user in relayusers[(irc.name, numeric)].items(): for netname, user in relayusers[(irc.name, numeric)].items():
log.debug('(%s) relay.handle_opertype: setting OPERTYPE of %s/%s to %s', log.debug('(%s) relay.handle_opertype: setting OPERTYPE of %s/%s to %s',
irc.name, user, netname, newtype) irc.name, user, netname, newtype)
@ -935,7 +935,7 @@ def handle_join(irc, numeric, command, args):
modes.append(('-%s' % modechar, user)) modes.append(('-%s' % modechar, user))
if modes: if modes:
log.debug('(%s) relay.handle_join: reverting modes on BURST: %s', irc.name, irc.joinModes(modes)) log.debug('(%s) relay.handle_join: reverting modes on BURST: %s', irc.name, irc.join_modes(modes))
irc.mode(irc.sid, channel, modes) irc.mode(irc.sid, channel, modes)
relay_joins(irc, channel, users, ts, burst=False) relay_joins(irc, channel, users, ts, burst=False)
@ -1017,11 +1017,11 @@ def handle_part(irc, numeric, command, args):
if numeric == irc.pseudoclient.uid: if numeric == irc.pseudoclient.uid:
# For clientbot: treat forced parts to the bot as clearchan, and attempt to rejoin only # For clientbot: treat forced parts to the bot as clearchan, and attempt to rejoin only
# if it affected a relay. # if it affected a relay.
if not irc.hasCap('can-spawn-clients'): if not irc.has_cap('can-spawn-clients'):
for channel in [c for c in channels if get_relay((irc.name, c))]: for channel in [c for c in channels if get_relay((irc.name, c))]:
for user in irc.channels[channel].users: for user in irc.channels[channel].users:
if (not irc.isInternalClient(user)) and (not isRelayClient(irc, user)): if (not irc.is_internal_client(user)) and (not isRelayClient(irc, user)):
irc.callHooks([irc.sid, 'CLIENTBOT_SERVICE_KICKED', {'channel': channel, 'target': user, irc.call_hooks([irc.sid, 'CLIENTBOT_SERVICE_KICKED', {'channel': channel, 'target': user,
'text': 'Clientbot was force parted (Reason: %s)' % text or 'None', 'text': 'Clientbot was force parted (Reason: %s)' % text or 'None',
'parse_as': 'KICK'}]) 'parse_as': 'KICK'}])
irc.join(irc.pseudoclient.uid, channel) irc.join(irc.pseudoclient.uid, channel)
@ -1045,7 +1045,7 @@ def handle_messages(irc, numeric, command, args):
notice = (command in ('NOTICE', 'PYLINK_SELF_NOTICE')) notice = (command in ('NOTICE', 'PYLINK_SELF_NOTICE'))
target = args['target'] target = args['target']
text = args['text'] text = args['text']
if irc.isInternalClient(numeric) and irc.isInternalClient(target): if irc.is_internal_client(numeric) and irc.is_internal_client(target):
# Drop attempted PMs between internal clients (this shouldn't happen, # Drop attempted PMs between internal clients (this shouldn't happen,
# but whatever). # but whatever).
return return
@ -1089,8 +1089,8 @@ def handle_messages(irc, numeric, command, args):
# Skip "from:" formatting for servers; it's messy with longer hostnames. # Skip "from:" formatting for servers; it's messy with longer hostnames.
# Also skip this formatting for servicebot relaying. # Also skip this formatting for servicebot relaying.
if numeric not in irc.servers and not irc.getServiceBot(numeric): if numeric not in irc.servers and not irc.get_service_bot(numeric):
displayedname = irc.getFriendlyName(numeric) displayedname = irc.get_friendly_name(numeric)
real_text = '<%s/%s> %s' % (displayedname, irc.name, text) real_text = '<%s/%s> %s' % (displayedname, irc.name, text)
else: else:
real_text = text real_text = text
@ -1149,7 +1149,7 @@ def handle_messages(irc, numeric, command, args):
return return
remoteirc = world.networkobjects[homenet] remoteirc = world.networkobjects[homenet]
if (not remoteirc.hasCap('can-spawn-clients')) and not conf.conf.get('relay', {}).get('allow_clientbot_pms'): if (not remoteirc.has_cap('can-spawn-clients')) and not conf.conf.get('relay', {}).get('allow_clientbot_pms'):
irc.msg(numeric, 'Private messages to users connected via Clientbot have ' irc.msg(numeric, 'Private messages to users connected via Clientbot have '
'been administratively disabled.', notice=True) 'been administratively disabled.', notice=True)
return return
@ -1180,17 +1180,17 @@ def handle_kick(irc, source, command, args):
relay = get_relay((irc.name, channel)) relay = get_relay((irc.name, channel))
# Special case for clientbot: treat kicks to the PyLink service bot as channel clear. # Special case for clientbot: treat kicks to the PyLink service bot as channel clear.
if (not irc.hasCap('can-spawn-clients')) and irc.pseudoclient and target == irc.pseudoclient.uid: if (not irc.has_cap('can-spawn-clients')) and irc.pseudoclient and target == irc.pseudoclient.uid:
for user in irc.channels[channel].users: for user in irc.channels[channel].users:
if (not irc.isInternalClient(user)) and (not isRelayClient(irc, user)): if (not irc.is_internal_client(user)) and (not isRelayClient(irc, user)):
reason = "Clientbot kicked by %s (Reason: %s)" % (irc.getFriendlyName(source), text) reason = "Clientbot kicked by %s (Reason: %s)" % (irc.get_friendly_name(source), text)
irc.callHooks([irc.sid, 'CLIENTBOT_SERVICE_KICKED', {'channel': channel, 'target': user, irc.call_hooks([irc.sid, 'CLIENTBOT_SERVICE_KICKED', {'channel': channel, 'target': user,
'text': reason, 'parse_as': 'KICK'}]) 'text': reason, 'parse_as': 'KICK'}])
return return
# Don't relay kicks to protected service bots. # Don't relay kicks to protected service bots.
if relay is None or irc.getServiceBot(target): if relay is None or irc.get_service_bot(target):
return return
origuser = get_orig_user(irc, target) origuser = get_orig_user(irc, target)
@ -1247,7 +1247,7 @@ def handle_kick(irc, source, command, args):
# common channels with the target relay network. # common channels with the target relay network.
rsid = get_remote_sid(remoteirc, irc) rsid = get_remote_sid(remoteirc, irc)
log.debug('(%s) relay.handle_kick: Kicking %s from channel %s via %s on behalf of %s/%s', irc.name, real_target, remotechan, rsid, kicker, irc.name) log.debug('(%s) relay.handle_kick: Kicking %s from channel %s via %s on behalf of %s/%s', irc.name, real_target, remotechan, rsid, kicker, irc.name)
if not irc.hasCap('can-spawn-clients'): if not irc.has_cap('can-spawn-clients'):
# Special case for clientbot: no kick prefixes are needed. # Special case for clientbot: no kick prefixes are needed.
text = args['text'] text = args['text']
else: else:
@ -1328,7 +1328,7 @@ def handle_mode(irc, numeric, command, args):
rsid = rsid or remoteirc.sid rsid = rsid or remoteirc.sid
remoteirc.mode(rsid, remotechan, supported_modes) remoteirc.mode(rsid, remotechan, supported_modes)
else: # Mode change blocked by CLAIM. else: # Mode change blocked by CLAIM.
reversed_modes = irc.reverseModes(target, modes, oldobj=oldchan) reversed_modes = irc.reverse_modes(target, modes, oldobj=oldchan)
log.debug('(%s) relay.handle_mode: Reversing mode changes of %r with %r (CLAIM).', log.debug('(%s) relay.handle_mode: Reversing mode changes of %r with %r (CLAIM).',
irc.name, modes, reversed_modes) irc.name, modes, reversed_modes)
if reversed_modes: if reversed_modes:
@ -1468,7 +1468,7 @@ def handle_services_login(irc, numeric, command, args):
""" """
for netname, user in relayusers[(irc.name, numeric)].items(): for netname, user in relayusers[(irc.name, numeric)].items():
remoteirc = world.networkobjects[netname] remoteirc = world.networkobjects[netname]
remoteirc.callHooks([user, 'PYLINK_RELAY_SERVICES_LOGIN', args]) remoteirc.call_hooks([user, 'PYLINK_RELAY_SERVICES_LOGIN', args])
utils.add_hook(handle_services_login, 'CLIENT_SERVICES_LOGIN') utils.add_hook(handle_services_login, 'CLIENT_SERVICES_LOGIN')
def handle_disconnect(irc, numeric, command, args): def handle_disconnect(irc, numeric, command, args):
@ -1575,14 +1575,14 @@ def create(irc, source, args):
Opens up the given channel over PyLink Relay.""" Opens up the given channel over PyLink Relay."""
try: try:
channel = irc.toLower(args[0]) channel = irc.to_lower(args[0])
except IndexError: except IndexError:
irc.error("Not enough arguments. Needs 1: channel.") irc.error("Not enough arguments. Needs 1: channel.")
return return
if not utils.isChannel(channel): if not utils.isChannel(channel):
irc.error('Invalid channel %r.' % channel) irc.error('Invalid channel %r.' % channel)
return return
if not irc.hasCap('can-host-relay'): if not irc.has_cap('can-host-relay'):
irc.error('Clientbot networks cannot be used to host a relay.') irc.error('Clientbot networks cannot be used to host a relay.')
return return
if source not in irc.channels[channel].users: if source not in irc.channels[channel].users:
@ -1598,7 +1598,7 @@ def create(irc, source, args):
irc.error('Channel %r is already part of a relay.' % channel) irc.error('Channel %r is already part of a relay.' % channel)
return return
creator = irc.getHostmask(source) creator = irc.get_hostmask(source)
# Create the relay database entry with the (network name, channel name) # Create the relay database entry with the (network name, channel name)
# pair - this is just a dict with various keys. # pair - this is just a dict with various keys.
db[(irc.name, channel)] = {'claim': [irc.name], 'links': set(), db[(irc.name, channel)] = {'claim': [irc.name], 'links': set(),
@ -1622,11 +1622,11 @@ def destroy(irc, source, args):
Removes the given channel from the PyLink Relay, delinking all networks linked to it. If the home network is given and you are logged in as admin, this can also remove relay channels from other networks.""" Removes the given channel from the PyLink Relay, delinking all networks linked to it. If the home network is given and you are logged in as admin, this can also remove relay channels from other networks."""
try: # Two args were given: first one is network name, second is channel. try: # Two args were given: first one is network name, second is channel.
channel = irc.toLower(args[1]) channel = irc.to_lower(args[1])
network = args[0] network = args[0]
except IndexError: except IndexError:
try: # One argument was given; assume it's just the channel. try: # One argument was given; assume it's just the channel.
channel = irc.toLower(args[0]) channel = irc.to_lower(args[0])
network = irc.name network = irc.name
except IndexError: except IndexError:
irc.error("Not enough arguments. Needs 1-2: channel, network (optional).") irc.error("Not enough arguments. Needs 1-2: channel, network (optional).")
@ -1649,7 +1649,7 @@ def destroy(irc, source, args):
del db[entry] del db[entry]
log.info('(%s) relay: Channel %s destroyed by %s.', irc.name, log.info('(%s) relay: Channel %s destroyed by %s.', irc.name,
channel, irc.getHostmask(source)) channel, irc.get_hostmask(source))
irc.reply('Done.') irc.reply('Done.')
else: else:
irc.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 "
@ -1703,8 +1703,8 @@ def link(irc, source, args):
args = link_parser.parse_args(args) args = link_parser.parse_args(args)
# Normalize channel case # Normalize channel case
channel = irc.toLower(args.channel) channel = irc.to_lower(args.channel)
localchan = irc.toLower(args.localchannel or args.channel) localchan = irc.to_lower(args.localchannel or args.channel)
remotenet = args.remotenet remotenet = args.remotenet
for c in (channel, localchan): for c in (channel, localchan):
@ -1774,7 +1774,7 @@ def link(irc, source, args):
our_ts = irc.channels[localchan].ts our_ts = irc.channels[localchan].ts
their_ts = world.networkobjects[remotenet].channels[channel].ts their_ts = world.networkobjects[remotenet].channels[channel].ts
if (our_ts < their_ts) and irc.hasCap('has-ts'): if (our_ts < their_ts) and irc.has_cap('has-ts'):
log.debug('(%s) relay: Blocking link request %s%s -> %s%s due to bad TS (%s < %s)', irc.name, log.debug('(%s) relay: Blocking link request %s%s -> %s%s due to bad TS (%s < %s)', irc.name,
irc.name, localchan, remotenet, args.channel, our_ts, their_ts) irc.name, localchan, remotenet, args.channel, our_ts, their_ts)
irc.error("The channel creation date (TS) on %s (%s) is lower than the target " irc.error("The channel creation date (TS) on %s (%s) is lower than the target "
@ -1785,7 +1785,7 @@ def link(irc, source, args):
entry['links'].add((irc.name, localchan)) entry['links'].add((irc.name, localchan))
log.info('(%s) relay: Channel %s linked to %s%s by %s.', irc.name, log.info('(%s) relay: Channel %s linked to %s%s by %s.', irc.name,
localchan, remotenet, args.channel, irc.getHostmask(source)) localchan, remotenet, args.channel, irc.get_hostmask(source))
initialize_channel(irc, localchan) initialize_channel(irc, localchan)
irc.reply('Done.') irc.reply('Done.')
link = utils.add_cmd(link, featured=True) link = utils.add_cmd(link, featured=True)
@ -1796,7 +1796,7 @@ def delink(irc, source, args):
Delinks the given channel from PyLink Relay. \x02network\x02 must and can only be specified if you are on the host network for the channel given, and allows you to pick which network to delink. Delinks the given channel from PyLink Relay. \x02network\x02 must and can only be specified if you are on the host network for the channel given, and allows you to pick which network to delink.
To remove a relay channel entirely, use the 'destroy' command instead.""" To remove a relay channel entirely, use the 'destroy' command instead."""
try: try:
channel = irc.toLower(args[0]) channel = irc.to_lower(args[0])
except IndexError: except IndexError:
irc.error("Not enough arguments. Needs 1-2: channel, remote netname (optional).") irc.error("Not enough arguments. Needs 1-2: channel, remote netname (optional).")
return return
@ -1829,7 +1829,7 @@ def delink(irc, source, args):
db[entry]['links'].remove((irc.name, channel)) db[entry]['links'].remove((irc.name, channel))
irc.reply('Done.') irc.reply('Done.')
log.info('(%s) relay: Channel %s delinked from %s%s by %s.', irc.name, log.info('(%s) relay: Channel %s delinked from %s%s by %s.', irc.name,
channel, entry[0], entry[1], irc.getHostmask(source)) channel, entry[0], entry[1], irc.get_hostmask(source))
else: else:
irc.error('No such relay %r.' % channel) irc.error('No such relay %r.' % channel)
delink = utils.add_cmd(delink, featured=True) delink = utils.add_cmd(delink, featured=True)
@ -1880,7 +1880,7 @@ def linked(irc, source, args):
# Only show secret channels to opers or those in the channel, and tag them as # Only show secret channels to opers or those in the channel, and tag them as
# [secret]. # [secret].
localchan = get_remote_channel(remoteirc, irc, channel) localchan = get_remote_channel(remoteirc, irc, channel)
if irc.isOper(source) or (localchan and source in irc.channels[localchan].users): if irc.is_oper(source) or (localchan and source in irc.channels[localchan].users):
s += '\x02[secret]\x02 ' s += '\x02[secret]\x02 '
else: else:
continue continue
@ -1896,7 +1896,7 @@ def linked(irc, source, args):
irc.reply(s, private=True) irc.reply(s, private=True)
if irc.isOper(source): if irc.is_oper(source):
s = '' s = ''
# If the caller is an oper, we can show the hostmasks of people # If the caller is an oper, we can show the hostmasks of people
@ -1927,7 +1927,7 @@ def linkacl(irc, source, args):
try: try:
cmd = args[0].lower() cmd = args[0].lower()
channel = irc.toLower(args[1]) channel = irc.to_lower(args[1])
except IndexError: except IndexError:
irc.error(missingargs) irc.error(missingargs)
return return
@ -1974,7 +1974,7 @@ def showuser(irc, source, args):
# No errors here; showuser from the commands plugin already does this # No errors here; showuser from the commands plugin already does this
# for us. # for us.
return return
u = irc.nickToUid(target) u = irc.nick_to_uid(target)
if u: if u:
irc.reply("Showing relay information on user \x02%s\x02:" % irc.users[u].nick, private=True) irc.reply("Showing relay information on user \x02%s\x02:" % irc.users[u].nick, private=True)
try: try:
@ -1997,7 +1997,7 @@ def showuser(irc, source, args):
relay = get_relay((irc.name, ch)) relay = get_relay((irc.name, ch))
if relay: if relay:
relaychannels.append(''.join(relay)) relaychannels.append(''.join(relay))
if relaychannels and (irc.isOper(source) or u == source): if relaychannels and (irc.is_oper(source) or u == source):
irc.reply("\x02Relay channels\x02: %s" % ' '.join(relaychannels), private=True) irc.reply("\x02Relay channels\x02: %s" % ' '.join(relaychannels), private=True)
@utils.add_cmd @utils.add_cmd
@ -2006,7 +2006,7 @@ def showchan(irc, source, args):
Shows relay data about the given channel. This supplements the 'showchan' command in the 'commands' plugin, which provides more general information.""" Shows relay data about the given channel. This supplements the 'showchan' command in the 'commands' plugin, which provides more general information."""
try: try:
channel = irc.toLower(args[0]) channel = irc.to_lower(args[0])
except IndexError: except IndexError:
return return
if channel not in irc.channels: if channel not in irc.channels:
@ -2017,7 +2017,7 @@ def showchan(irc, source, args):
c = irc.channels[channel] c = irc.channels[channel]
# Only show verbose info if caller is oper or is in the target channel. # Only show verbose info if caller is oper or is in the target channel.
verbose = source in c.users or irc.isOper(source) verbose = source in c.users or irc.is_oper(source)
secret = ('s', None) in c.modes secret = ('s', None) in c.modes
if secret and not verbose: if secret and not verbose:
# Hide secret channels from normal users. # Hide secret channels from normal users.
@ -2055,7 +2055,7 @@ def claim(irc, source, args):
as well). as well).
""" """
try: try:
channel = irc.toLower(args[0]) channel = irc.to_lower(args[0])
except IndexError: except IndexError:
irc.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 return

View File

@ -45,7 +45,7 @@ def cb_relay_core(irc, source, command, args):
if irc.pseudoclient and relay: if irc.pseudoclient and relay:
try: try:
sourcename = irc.getFriendlyName(source) sourcename = irc.get_friendly_name(source)
except KeyError: # User has left due to /quit except KeyError: # User has left due to /quit
sourcename = args['userdata'].nick sourcename = args['userdata'].nick
@ -87,7 +87,7 @@ def cb_relay_core(irc, source, command, args):
text_template = string.Template(text_template) text_template = string.Template(text_template)
if text_template: if text_template:
if irc.getServiceBot(source): if irc.get_service_bot(source):
# HACK: service bots are global and lack the relay state we look for. # HACK: service bots are global and lack the relay state we look for.
# just pretend the message comes from the current network. # just pretend the message comes from the current network.
log.debug('(%s) relay_cb_core: Overriding network origin to local (source=%s)', irc.name, source) log.debug('(%s) relay_cb_core: Overriding network origin to local (source=%s)', irc.name, source)
@ -131,7 +131,7 @@ def cb_relay_core(irc, source, command, args):
if source in irc.users: if source in irc.users:
try: try:
identhost = irc.getHostmask(source).split('!')[-1] identhost = irc.get_hostmask(source).split('!')[-1]
except KeyError: # User got removed due to quit except KeyError: # User got removed due to quit
identhost = '%s@%s' % (args['olduser'].ident, args['olduser'].host) identhost = '%s@%s' % (args['olduser'].ident, args['olduser'].host)
# This is specifically spaced so that ident@host is only shown for users that have # This is specifically spaced so that ident@host is only shown for users that have
@ -142,7 +142,7 @@ def cb_relay_core(irc, source, command, args):
# $target_nick: Convert the target for kicks, etc. from a UID to a nick # $target_nick: Convert the target for kicks, etc. from a UID to a nick
if args.get("target") in irc.users: if args.get("target") in irc.users:
args["target_nick"] = irc.getFriendlyName(args['target']) args["target_nick"] = irc.get_friendly_name(args['target'])
args.update({'netname': netname, 'sender': sourcename, 'sender_identhost': identhost, args.update({'netname': netname, 'sender': sourcename, 'sender_identhost': identhost,
'colored_sender': color_text(sourcename), 'colored_netname': color_text(netname)}) 'colored_sender': color_text(sourcename), 'colored_netname': color_text(netname)})
@ -204,7 +204,7 @@ def rpm(irc, source, args):
return return
relay = world.plugins.get('relay') relay = world.plugins.get('relay')
if irc.hasCap('can-spawn-clients'): if irc.has_cap('can-spawn-clients'):
irc.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 return
elif relay is None: elif relay is None:
@ -218,7 +218,7 @@ def rpm(irc, source, args):
'administratively disabled.') 'administratively disabled.')
return return
uid = irc.nickToUid(target) uid = irc.nick_to_uid(target)
if not uid: if not uid:
irc.error('Unknown user %s.' % target) irc.error('Unknown user %s.' % target)
return return
@ -226,7 +226,7 @@ def rpm(irc, source, args):
irc.error('%s is not a relay user.' % target) irc.error('%s is not a relay user.' % target)
return return
else: else:
assert not irc.isInternalClient(source), "rpm is not allowed from PyLink bots" assert not irc.is_internal_client(source), "rpm is not allowed from PyLink bots"
# Send the message through relay by faking a hook for its handler. # Send the message through relay by faking a hook for its handler.
relay.handle_messages(irc, source, 'RELAY_CLIENTBOT_PRIVMSG', {'target': uid, 'text': text}) relay.handle_messages(irc, source, 'RELAY_CLIENTBOT_PRIVMSG', {'target': uid, 'text': text})
irc.reply('Message sent.') irc.reply('Message sent.')

View File

@ -78,7 +78,7 @@ def _map(irc, source, args, show_relay=True):
# This is a relay server - display the remote map of the network it represents # This is a relay server - display the remote map of the network it represents
relay_server = serverlist[leaf].remote relay_server = serverlist[leaf].remote
remoteirc = world.networkobjects[relay_server] remoteirc = world.networkobjects[relay_server]
if remoteirc.hasCap('can-track-servers'): if remoteirc.has_cap('can-track-servers'):
# Only ever show relay subservers once - this prevents infinite loops. # Only ever show relay subservers once - this prevents infinite loops.
showall(remoteirc, remoteirc.sid, hops=hops, is_relay_server=True) showall(remoteirc, remoteirc.sid, hops=hops, is_relay_server=True)

View File

@ -18,7 +18,7 @@ def handle_kill(irc, numeric, command, args):
automatically disconnects from the network. automatically disconnects from the network.
""" """
if (args['userdata'] and irc.isInternalServer(args['userdata'].server)) or irc.isInternalClient(args['target']): if (args['userdata'] and irc.is_internal_server(args['userdata'].server)) or irc.is_internal_client(args['target']):
if killcache.setdefault(irc.name, 1) >= length: if killcache.setdefault(irc.name, 1) >= length:
log.error('(%s) servprotect: Too many kills received, aborting!', irc.name) log.error('(%s) servprotect: Too many kills received, aborting!', irc.name)
irc.disconnect() irc.disconnect()
@ -33,7 +33,7 @@ def handle_save(irc, numeric, command, args):
Tracks SAVEs (nick collision) against PyLink clients. If too many are received, Tracks SAVEs (nick collision) against PyLink clients. If too many are received,
automatically disconnects from the network. automatically disconnects from the network.
""" """
if irc.isInternalClient(args['target']): if irc.is_internal_client(args['target']):
if savecache.setdefault(irc.name, 0) >= length: if savecache.setdefault(irc.name, 0) >= length:
log.error('(%s) servprotect: Too many nick collisions, aborting!', irc.name) log.error('(%s) servprotect: Too many nick collisions, aborting!', irc.name)
irc.disconnect() irc.disconnect()