def post_to_slack(self, user, channel, message): nick = utils.nick_from_irc_user(user) # Don't post to Slack if it came from a Slack bot if '-slack' not in nick and nick != 'defaultnick': log.msg( self.sc.api_call( 'chat.postMessage', channel=channel, text=utils.format_slack_message(message, IRCBot.users), as_user=False, username=nick, icon_url=utils.user_to_gravatar(nick), ))
def post_to_slack( self, user: str, channel: str, message: str, unparsed_nick: bool = True, ) -> None: if unparsed_nick: nick = utils.nick_from_irc_user(user) else: nick = user # Don't post to Slack if it came from a Slack bot if '-slack' not in nick and nick != 'defaultnick': log.msg( self.sc.api_call( 'chat.postMessage', channel=channel, text=utils.format_slack_message(message, IRCBot.users), as_user=False, username=nick, icon_url=utils.user_to_gravatar(nick), ), )
def privmsg(self, user: str, channel: str, message: str) -> None: """ Handler if a private message is received by an IRC user bot. In IRC, this is when the channel is a username. Example: [john]: /msg ocfstaffer-slack hello user = "******" channel = "ocfstaffer-slack" message = "hello" """ if channel == self.nickname: if self.im_id is None: im_channel = self.sc.api_call( 'conversations.open', users=self.user_id, return_im=True, ) self.im_id = im_channel['channel']['id'] assert self.im_id is not None nick = utils.nick_from_irc_user(user) self.post_to_slack(user, self.im_id, nick + ': ' + message)