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()
Beispiel #2
0
 def on_welcome(self, conn:ServerConnection, event:Event):
     """
     Triggered when a welcome message is received meaning
     that the server connections has been established. Joins the channel
     specified by self.channel.
     :param conn: ServerConnection
     :param event: Event
     :return: None
     """
     conn.join(self.channel)
Beispiel #3
0
    def on_whoischannels(self, conn: ServerConnection, event: Event):
        """
        The 'whoischannels' event indicates that a whois request has found
        channels that the bot is a part of.
        Channels that the bot has joined will be joined as well.
        :param conn: The connection
        :param event: The 'whoischannels' event
        :return: None
        """
        self.logger.info("WHOIS: " + str(event.arguments))
        channels = event.arguments[1].split("#")
        channels.pop(0)
        channels = list(map(lambda x: "#" + x.split(" ")[0], channels))
        self.channels = channels

        for channel in self.channels:
            # Join all channels to avoid only joining a members-only channel
            conn.join(channel)
Beispiel #4
0
 def on_endofwhois(self, conn: ServerConnection, _: Event):
     """
     The 'endofwhois' event indicates the end of a whois request.
     This manually calls on_join in case the bot
     has not joined any channels.
     :param conn: The connection
     :param _: The 'endofwhois' event
     :return: None
     """
     self.logger.info("WHOIS End")
     if self.channels is None:
         if self.fallback_channel is not None:
             channel = self.fallback_channel
             if not channel.startswith("#"):
                 channel = "#" + channel
             conn.join(channel)
             return
         else:
             self.on_join(conn, _, True)
    def on_welcome(self, connection: ServerConnection, event: Event):
        """Callback for when connection has been established

        Joins the Twitch chat and sends a message to confirm
        connection.

        Parameters
        ----------
        connection : ServerConnection
            Connection to Twitch server
        event : Event
            Event object for connection
        """

        for req in ("membership", "tags", "commands"):
            connection.cap("REQ", f":twitch.tv/{req}")

        connection.join(self.CHANNEL)
        self.send_message("Connected")
        LOG.info(
            f"Connected user {self.USERNAME} to twitch channel {self.CHANNEL[1:]}."
        )
Beispiel #6
0
 def on_invite(self, connection: ServerConnection, event: Event):
     if event.target == connection.get_nickname() and event.arguments:
         if event.arguments[0] not in self.channels:
             connection.join(event.arguments[0])
Beispiel #7
0
 def on_kick(self, connection: ServerConnection, event: Event):
     if event.arguments and connection.get_nickname() in event.arguments:
         connection.join(event.target)
Beispiel #8
0
 def on_welcome(self, connection: ServerConnection, event: Event):
     for channel in self.initial_channels:
         connection.join(channel)
Beispiel #9
0
 def on_welcome(self, c: ServerConnection, e: Event):
     logger.info(f"Successfully joined irc!")
     c.join(self.channel)
 def on_endofmotd(self, conn: ServerConnection, event: Event):
     print('Well, we are done here.')
     conn.join(CHANNEL)
Beispiel #11
0
 def on_welcome(self, connection: client.ServerConnection,
                _: client.Event) -> None:
     if self.capabilities:
         connection.cap('REQ', *self.capabilities)
         connection.cap('END')
     connection.join(self.channel)