def on_welcome(self, c: ServerConnection, e: Event) -> None: if len(self.nickserv_password) > 0: msg = 'identify %s' % (self.nickserv_password,) c.privmsg('NickServ', msg) c.join(self.channel) def forward_to_irc(msg: Dict[str, Any]) -> None: not_from_zulip_bot = msg["sender_email"] != self.zulip_client.email if not not_from_zulip_bot: # Do not forward echo return is_a_stream = msg["type"] == "stream" if is_a_stream: in_the_specified_stream = msg["display_recipient"] == self.stream at_the_specified_subject = msg["subject"].casefold() == self.topic.casefold() if in_the_specified_stream and at_the_specified_subject: msg["content"] = ("@**%s**: " % (msg["sender_full_name"],)) + msg["content"] send = lambda x: self.c.privmsg(self.channel, x) else: return else: recipients = [u["short_name"] for u in msg["display_recipient"] if u["email"] != msg["sender_email"]] if len(recipients) == 1: send = lambda x: self.c.privmsg(recipients[0], x) else: send = lambda x: self.c.privmsg_many(recipients, x) for line in msg["content"].split("\n"): send(line) z2i = mp.Process(target=self.zulip_client.call_on_each_message, args=(forward_to_irc,)) z2i.start()
def _send_xdcc_request_message(self, conn: ServerConnection): """ Sends an XDCC request message :param conn: The connection to use :return: None """ msg = self.pack.get_request_message() self.logger.info("Send XDCC Message: " + msg) self.message_sent = True conn.privmsg(self.pack.bot, msg)
def on_dccmsg(self, conn:ServerConnection, event:Event): """ Triggered when a non-chat DCC message has been received. DCC messages are raw bytes so there's potential for using this for file transfer. Currently for testing we merely decode them as text messages :param conn: ServerConnection :param event: Event :return:None """ text = event.arguments[0].decode('utf-8') conn.privmsg("You said: " + text)
def handler(self, connection: ServerConnection, event: Event): if event.arguments: occurrence_key = connection.server, event.target if not self.throttle.is_throttled(*occurrence_key): for pattern, response in self.responses: if pattern.match(event.arguments[0]): if not self.throttle.occurrence(*occurrence_key): if event.type == "privmsg": target = event.source.nick else: target = event.target connection.privmsg(target, response) break
def _send_xdcc_request_message(self, conn: ServerConnection): """ Sends an XDCC request message :param conn: The connection to use :return: None """ self.logger.info("Waiting for {}s before sending message".format( self.wait_time)) time.sleep(self.wait_time) msg = self.pack.get_request_message() self.logger.info("Send XDCC Message: " + msg) self.message_sent = True conn.privmsg(self.pack.bot, msg)
def handle_command(self, conn: ServerConnection, channel: str, message: str, tags: TwitchTags) -> None: """Command Handler for the chat bot""" try: command_name, *msg = message[1:].split() command_name = command_name.lower() msg = ' '.join(msg) if command_name == 'me': self._command_manager.store( command_name=tags.user.lower(), message=msg ) conn.privmsg(channel, f'The command !{tags.user.lower()} has been updated!') return command = self._command_manager.get(command_name) if not command: return command.handle(tags.permission, msg) if command and command.response: conn.privmsg(channel, command.response) except Exception as e: print(f"Uh Oh: {e}")
def on_dccmsg(self, c: ServerConnection, e: Event) -> None: c.privmsg("You said: " + e.arguments[0])
def on_pubmsg(self, conn: ServerConnection, event: Event): if event.arguments[0] == 'test123': conn.privmsg(CHANNEL, '#familyfriendly, bitte!')