def topic_details(self, _, line): """Show the details of a topic.""" channel = line.params[1] setter = self.nick_colour(Hostmask.parse(line.params[2]).nick) set_on = str(datetime.utcfromtimestamp(int(line.params[3]))) self._printf("*** Topic of {} set by {} on {}.".format(channel, setter, set_on))
def topic_details(self, _, line): """Show the details of a topic.""" channel = line.params[1] setter = self.nick_colour(Hostmask.parse(line.params[2]).nick) set_on = str(datetime.utcfromtimestamp(int(line.params[3]))) self._printf("*** Topic of {} set by {} on {}.".format( channel, setter, set_on))
def topic_who_time(self, _, line): """Update the channel's topic metadata.""" channel = self.get_channel(line.params[1]) if channel is None: _logger.debug("Topic time for unknown channel: %s", line.params[1]) return channel.topicwho = Hostmask.parse(line.params[2]) channel.topictime = int(line.params[3])
def prefix(self, _, setter, target, mode): # Parse into hostmask in case of usernames-in-host channel = self.get_channel(target) if channel is None: _logger.warning("Got a PREFIX event for an unknown channel: %s", target) return hostmask = Hostmask.parse(mode.param) if mode.adding: channel.users[hostmask.nick].add(mode.mode) else: channel.users[hostmask.nick].discard(mode.mode)
def monitor_offline(self, _, line): """Remove users who go offline on MONITOR.""" if not self._usable: return monitor = [Hostmask.parse(h) for h in line.params[-1].split(",")] if not monitor: return user_track = self.base.user_track for user in monitor: if user_track.get_user(user.nick): user_track.remove_user(user.nick)
def monitor_online(self, _, line): """Add users who come online on MONITOR.""" if not self._usable: return monitor = [Hostmask.parse(h) for h in line.params[-1].split(",")] if not monitor: return user_track = self.base.user_track for user in monitor: user_track.add_user(user.nick, username=user.username, host=user.host)
def prefix(self, event): # Parse into hostmask in case of usernames-in-host hostmask = Hostmask.parse(event.param) assert hostmask user = self.get_user(hostmask.nick) if not user: # Add the user user = self.add_user(hostmask.nick, user=hostmask.username, host=hostmask.host) channel = user.channels[event.target] if event.adding: channel.add(event.mode) else: channel.discard(event.mode)
def prefix(self, _, setter, target, mode): """Update the channel mode of a user.""" # pylint: disable=unused-argument # Parse into hostmask in case of usernames-in-host hostmask = Hostmask.parse(mode.param) assert hostmask user = self.get_user(hostmask.nick) if user is None: # This can happen from override or ChanServ guard off user = self.add_user(hostmask.nick, username=hostmask.username, host=hostmask.host) self.timeout_user(hostmask.nick) channel = user.channels[target] if mode.adding: channel.add(mode.mode) else: channel.discard(mode.mode)
def names(self, _, line): """Handle bursting of new users from NAMES.""" params = line.params channel = params[2] isupport = self.base.isupport prefix = prefix_parse(isupport.get("PREFIX")) for hostmask in params[3].split(' '): if not hostmask: continue modes, hostmask = status_prefix_parse(hostmask, prefix) hostmask = Hostmask.parse(hostmask) modes = [(m, hostmask, True, None) for m in modes] scope = Scope( hostmask, channel, False, cause=line.hostmask, modes=modes) self.call_event("scope", "user_burst", scope)
def handle_list(self, event, mode): line = event.line params = line.params try: target = params[1] mask = params[2] if len(params) > 3: setter = Hostmask.parse(params[3]) if len(params) > 4: timestamp = int(params[4]) else: setter = line.hostmask timestamp = None except Exception as e: logger.warning("Bogus list mode received: %s (exception: %s)", mode, e) return self.call_event("modes", "mode_list", line, setter, target, True, mode, mask, timestamp)
def handle_list(self, caller, line): modechar = self.mode_chars[caller.eventpair[1]] params = line.params try: target = params[1] mask = params[2] if len(params) > 3: setter = Hostmask.parse(params[3]) if len(params) > 4: timestamp = int(params[4]) else: setter = line.hostmask timestamp = None except Exception as e: _logger.warning("Bogus list mode received: %s (exception: %s)", modechar, e) return mode = Mode(modechar, mask, True, timestamp) self.call_event("modes", "mode_list", setter, target, mode)
def banmask_parse(string, supported_extban): """Normalise a ban mask into either an extban or nick!user@host set""" ret = SimpleNamespace() ret.nick = ret.user = ret.host = None extban = extban_parse(string, supported_extban) if extban: # Unpack ret.extban, ret.extban_target = extban return ret ret.extban = ret.extban_target = None try: hostmask = Hostmask.parse(string) except Exception: return ret if not hostmask: return ret ret.nick, ret.user, ret.host = hostmask.nick, hostmask.user, hostmask.host return ret
def _parse_ban_lines(line): """Parse a foo:line in Hybrid-derived servers, excluding RESV and X:lines.""" params = line.params match = _stats_ban_re.match(params[-1]) assert match, "Bug in the stats matching regex!" t = match.group("type") if t == "K" or t == "G": # Don't use Hostmask, because this is for matching purposes. mask = (params[3], params[4], params[2]) elif t == "D": mask = params[2] else: _logger.warning("Unknown bantype, just guessing!") mask = params[:-1] duration = int(match.group("duration")) * 60 year = int(match.group("year")) month = int(match.group("month")) day = int(match.group("day")) hour = int(match.group("hour")) minute = int(match.group("minute")) if all(x is not None for x in (year, month, day)): setdate = datetime(year, month, day, hour, minute) else: setdate = None reason = match.group("reason") oreason = match.group("oreason") settermask = Hostmask.parse(match.group("settermask")) setter = match.group("setter") return BanEntry(mask, settermask, setter, setdate, duration, reason, oreason)
def banmask_parse(string, supported_extban): """Normalise a ban mask into either an extban or nick!user@host set.""" ret = SimpleNamespace() ret.nick = ret.user = ret.host = None extban = extban_parse(string, supported_extban) if extban: # Unpack ret.extban, ret.extban_target = extban return ret ret.extban = ret.extban_target = None try: hostmask = Hostmask.parse(string) except ValueError: return ret if not hostmask: return ret ret.nick, ret.user, ret.host = (hostmask.nick, hostmask.username, hostmask.host) return ret