def notice(self, target: str, message: str) -> None: self._outbound_queue.put_nowait( IRCMessage( command="NOTICE", middle=(target, ), trailing=message, ))
def privmsg(self, target: str, message: str) -> None: self._outbound_queue.put_nowait( IRCMessage( command="PRIVMSG", middle=(target, ), trailing=message, ))
def user(self, username: str, realname: str) -> None: self._outbound_queue.put_nowait( IRCMessage( command="USER", middle=(username, "0", "*"), trailing=realname, ))
def handle_server_invite(self, msg: IRCMessage) -> None: self.bus.broadcast( InvitedEvent( client=self, who=msg.parse_prefix_as_user(), to=msg.trailing, ))
def handle_server_kick(self, msg: IRCMessage) -> None: who = msg.parse_prefix_as_user() chan, target, *_ = msg.middle if target == self.nickname: try: self._channel_list.remove(msg.trailing) except ValueError: getLogger(__name__).error( "Kicked from a channel that was never joined.") self.bus.broadcast( BotKickedEvent( client=self, channel=chan, who=who, target=target, message=msg.trailing, )) else: self.bus.broadcast( ChannelKickedEvent( client=self, channel=chan, who=who, target=target, message=msg.trailing, ))
def handle_server_notice(self, msg: IRCMessage) -> None: # If command param is the client nick, set the user as the location who = msg.parse_prefix_as_user() where = msg.middle[0] if where == self.nickname: where = who.nick self.bus.broadcast( NoticedEvent( client=self, who=who, where=where, message=msg.trailing, ))
def handle_server_join(self, msg: IRCMessage) -> None: who = msg.parse_prefix_as_user() if who.nick == self.nickname: self._channel_list.append(msg.trailing) self.bus.broadcast( BotJoinedEvent( client=self, channel=msg.trailing, who=who, )) else: self.bus.broadcast( ChannelJoinedEvent( client=self, channel=msg.trailing, who=who, ))
def handle_server_part(self, msg: IRCMessage) -> None: who = msg.parse_prefix_as_user() if who.nick == self.nickname: try: self._channel_list.remove(msg.trailing) except ValueError: getLogger(__name__).error( "Parted a channel that was never joined.") self.bus.broadcast( BotPartedEvent( client=self, channel=msg.middle[0], who=who, message=msg.trailing, )) else: self.bus.broadcast( ChannelPartedEvent( client=self, channel=msg.middle[0], who=who, message=msg.trailing, ))
async def create(cls, name: str, config: ServerConfig) -> "IRCClient": if config.port.startswith("+"): secure = True port = int(config.port) else: secure = False port = int(config.port) stream = await IRCStream.create(config.host, port, secure) obj = cls(name, config, stream) obj.nick(config.nick) obj.user(config.user, config.realname) if config.service_auth: cmd = config.service_auth.command or "IDENTIFY " if config.service_auth.username: cmd += config.service_auth.username + " " cmd += config.service_auth.password obj._on_register.append( IRCMessage( command="PRIVMSG", middle=(config.service_auth.service or "NickServ", ), trailing=cmd, )) return obj
def quit(self, reason: str) -> None: self._outbound_queue.put_nowait( IRCMessage( command="QUIT", trailing=reason, ))
def join(self, channel: str) -> None: self._outbound_queue.put_nowait( IRCMessage(command="JOIN", middle=(channel, )))
def pong(self, payload: str) -> None: self._outbound_queue.put_nowait( IRCMessage( command="PONG", trailing=payload, ))
def nick(self, nickname: str) -> None: self._outbound_queue.put_nowait( IRCMessage( command="NICK", trailing=nickname, ))
def handle_server_nick(self, msg: IRCMessage) -> None: who = msg.parse_prefix_as_user() if who.nick == self.nickname: self.nickname = msg.trailing