def kick(self, _, line): """Fire a (scope, user_kick) event for users being kicked.""" params = line.params channel = params[0] target = Hostmask(nick=params[1]) reason = params[2] scope = Scope(target, channel, True, reason=reason, cause=line.hostmask) self.call_event("scope", "user_kick", scope)
def test_channel_topic_user(self): """Ensure topic set by user is handled correctly.""" name = '#Sporks' topic = "#Sporks - we'll bring yo dick" setter = Hostmask(nick='lstarnes', username='******', host='interlinked/netadmin/automaton/lstarnes') set_on = int(time()) # 1437288043 irc = self.connection irc.inject_line(join_line(irc, name)) irc.inject_line( Line(hostmask=setter, command='TOPIC', params=(name, topic))) self.assertTopicEqual(topic, setter, set_on)
def parse_stats_opers(self, _, line): """Evaluate a stats line for an oper.""" if line.params[1] != 'p': return match = _charybdis_oper_re.match(line.params[-1]) if not match: return nick = match.group("nick") user = match.group("user") host = match.group("host") hostmask = Hostmask(nick=nick, user=user, host=host) entry = OperEntry(None, None, hostmask, None) return self.call_event("stats", "oper", entry)
def test_channel_topic_server_server(self): """Ensure topic sent from and set by server is handled correctly.""" name = '#help' topic = 'Official help channel | To register a nick : /msg NickServ '\ 'help register | To group a nick, /msg nickserv help group | '\ 'Lost password? /msg nickserv SENDPASS <accountname> | State '\ 'your question and people will answer eventually (It might '\ 'take 10 or so minutes)' setter = 'chrysalis.server' set_on = 1395559296 irc = self.connection irc.inject_line(join_line(irc, name)) irc.inject_line(rpl_topic_line(irc, name, topic)) irc.inject_line(rpl_topiwhotime_line(irc, name, setter, set_on)) self.assertTopicEqual(topic, Hostmask(host=setter), set_on)
def test_channel_topic_server_user(self): """Ensure topic sent from server, set by user, is handled correctly.""" name = '#gentoo-python' topic = 'Set e.g. PYTHON_TARGETS="python2_7 python3_2 python3_3 '\ 'python3_4" in /etc/make.conf if you want to install Python '\ 'modules for multiple Python versions. | '\ 'http://www.gentoo.org/proj/en/Python/#doc_chap5' setter = Hostmask(nick='xiaomiao', username='******', host='gentoo/developer/bonsaikitten') set_on = 1404711155 irc = self.connection irc.inject_line(join_line(irc, name)) irc.inject_line(rpl_topic_line(irc, name, topic)) irc.inject_line(rpl_topiwhotime_line(irc, name, setter, set_on)) self.assertTopicEqual(topic, setter, set_on)
def userhost_parse(mask): """Parse a USERHOST reply. :returns: An object with the following attributes set: :hostmask: :py:class:`~PyIRC.line.Hostmask` of the user. This may be a cloak. :operator: Whether or not the user is an operator. False does not mean they are not an operator, as operators may be hidden on the server. :away: Whether or not the user is away. """ if not mask: raise ValueError("Need a mask to parse") ret = SimpleNamespace(hostmask=None, operator=None, away=None) nick, sep, userhost = mask.partition('=') if not sep: return ret if nick.endswith('*'): nick = nick[:-1] ret.operator = True if userhost.startswith(('+', '-')): away, userhost = userhost[0], userhost[:1] ret.away = (away == '+') # user@host username, sep, host = userhost.partition('@') if not sep: host = username username = None ret.hostmask = Hostmask(nick=nick, username=username, host=host) return ret
def parse_stats_opers(self, _, line): """Evaluate a stats line for an oper.""" if line.params[1] != 'p': return match = _hybrid_oper_re(line.params[-1]) if not match: return flag = match.group("flag") privs = match.group("privs") nick = match.group("nick") user = match.group("user") host = match.group("host") hostmask = Hostmask(nick=nick, user=user, host=host) idle = int(match.group("idle")) entry = OperEntry(flag, privs, hostmask, idle) return self.call_event("stats", "oper", entry)
def conn_mask(connection): return Hostmask(nick=connection.nick, username=connection.username, host='test-connection.local')