mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-27 13:09:23 +01:00
Add User.get_fields(), and rework plugins to fix $nick broken expansions
User.nick is no longer a writable attribute since a085aed924
, so it won't show up in __dict__ now.
get_fields() replaces the User.__dict__ hack various plugins used and also provides some new expansion variables:
- $sid and $server expand to the server ID and name respectively
- $modes and $channels are now preformatted strings
- $netname expands to the network name
$manipulatable and $_irc were removed since their values aren't quite meaningful as strings
This commit is contained in:
parent
108d4b86d9
commit
f20fa5e995
31
classes.py
31
classes.py
@ -116,6 +116,37 @@ class User():
|
||||
# Update the new nick.
|
||||
self._irc.users.bynick.setdefault(self.lower_nick, []).append(self.uid)
|
||||
|
||||
def get_fields(self):
|
||||
"""
|
||||
Returns all template/substitution-friendly fields for the User object in a read-only dictionary.
|
||||
"""
|
||||
fields = self.__dict__.copy()
|
||||
|
||||
# These don't really make sense in text substitutions
|
||||
for field in ('manipulatable', '_irc'):
|
||||
del fields[field]
|
||||
|
||||
# Pre-format the channels list. FIXME: maybe this should be configurable somehow?
|
||||
fields['channels'] = ','.join(sorted(self.channels))
|
||||
|
||||
# Swap SID and server name for convenience
|
||||
fields['sid'] = self.server
|
||||
try:
|
||||
fields['server'] = self._irc.get_friendly_name(self.server)
|
||||
except KeyError:
|
||||
pass # Keep it as is (i.e. as the SID) if grabbing the server name fails
|
||||
|
||||
# Network name
|
||||
fields['netname'] = self._irc.name
|
||||
|
||||
# Join umodes together
|
||||
fields['modes'] = self._irc.join_modes(self.modes)
|
||||
|
||||
# Add the nick attribute; this isn't in __dict__ because it's a property
|
||||
fields['nick'] = self._nick
|
||||
|
||||
return fields
|
||||
|
||||
def __repr__(self):
|
||||
return 'User(%s/%s)' % (self.uid, self.nick)
|
||||
IrcUser = User
|
||||
|
@ -114,9 +114,9 @@ def handle_chghost(irc, sender, command, args):
|
||||
irc.name, target, ex)
|
||||
return
|
||||
|
||||
userdata = irc.users.get(target)
|
||||
if userdata:
|
||||
_changehost(irc, target, userdata.__dict__)
|
||||
userobj = irc.users.get(target)
|
||||
if userobj:
|
||||
_changehost(irc, target, userobj.get_fields())
|
||||
|
||||
utils.add_hook(handle_chghost, 'CHGHOST')
|
||||
|
||||
|
@ -647,7 +647,11 @@ class ClientbotWrapperProtocol(IRCCommonProtocol):
|
||||
for line in self.serverdata.get("autoperform", []):
|
||||
# Expand substitutions like $nick, $ident, $host
|
||||
tmpl = string.Template(line)
|
||||
line = tmpl.safe_substitute(**self.pseudoclient.__dict__)
|
||||
|
||||
args = self.pseudoclient.get_fields()
|
||||
|
||||
log.debug('(%s) handle_376: bot user fields are %s', self.name, args)
|
||||
line = tmpl.safe_substitute(**args)
|
||||
self.send(line)
|
||||
|
||||
# Virtual endburst hook.
|
||||
|
Loading…
Reference in New Issue
Block a user