diff --git a/classes.py b/classes.py index 6a7b3a0..50658c8 100644 --- a/classes.py +++ b/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 diff --git a/plugins/changehost.py b/plugins/changehost.py index 33d8c50..1e29f3e 100644 --- a/plugins/changehost.py +++ b/plugins/changehost.py @@ -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') diff --git a/protocols/clientbot.py b/protocols/clientbot.py index 8b8f5db..e898b6f 100644 --- a/protocols/clientbot.py +++ b/protocols/clientbot.py @@ -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.