Exemplo n.º 1
0
 def notice(self, target: str, message: str) -> None:
     self._outbound_queue.put_nowait(
         IRCMessage(
             command="NOTICE",
             middle=(target, ),
             trailing=message,
         ))
Exemplo n.º 2
0
 def privmsg(self, target: str, message: str) -> None:
     self._outbound_queue.put_nowait(
         IRCMessage(
             command="PRIVMSG",
             middle=(target, ),
             trailing=message,
         ))
Exemplo n.º 3
0
 def user(self, username: str, realname: str) -> None:
     self._outbound_queue.put_nowait(
         IRCMessage(
             command="USER",
             middle=(username, "0", "*"),
             trailing=realname,
         ))
Exemplo n.º 4
0
 def handle_server_invite(self, msg: IRCMessage) -> None:
     self.bus.broadcast(
         InvitedEvent(
             client=self,
             who=msg.parse_prefix_as_user(),
             to=msg.trailing,
         ))
Exemplo n.º 5
0
 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,
             ))
Exemplo n.º 6
0
 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,
         ))
Exemplo n.º 7
0
 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,
             ))
Exemplo n.º 8
0
 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,
             ))
Exemplo n.º 9
0
 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
Exemplo n.º 10
0
 def quit(self, reason: str) -> None:
     self._outbound_queue.put_nowait(
         IRCMessage(
             command="QUIT",
             trailing=reason,
         ))
Exemplo n.º 11
0
 def join(self, channel: str) -> None:
     self._outbound_queue.put_nowait(
         IRCMessage(command="JOIN", middle=(channel, )))
Exemplo n.º 12
0
 def pong(self, payload: str) -> None:
     self._outbound_queue.put_nowait(
         IRCMessage(
             command="PONG",
             trailing=payload,
         ))
Exemplo n.º 13
0
 def nick(self, nickname: str) -> None:
     self._outbound_queue.put_nowait(
         IRCMessage(
             command="NICK",
             trailing=nickname,
         ))
Exemplo n.º 14
0
 def handle_server_nick(self, msg: IRCMessage) -> None:
     who = msg.parse_prefix_as_user()
     if who.nick == self.nickname:
         self.nickname = msg.trailing