Weechat Slack

broken image


A WeeChat native client for Slack.com. Provides supplemental features only available in the web/mobile clients such as: synchronizing read markers, typing notification, search, (and more)! Connects via the Slack API, and maintains a persistent websocket for notification of events.

18 Nov 2018 · Comments: 0 · Tags: IRC, WeeChat, BridgeBot

President Donald Trump's threat to ban WeChat has already upset millions of users in America who depend on the app as a lifeline to family and friends in China. But it could also become a major. WEECHATRCOK @utf8decode def typingupdatecb (data, remainingcalls): w. Baritemupdate ('slacktypingnotice') return w. WEECHATRCOK @utf8decode def slackneverawaycb (data, remainingcalls): if config. Neveraway: for team in EVENTROUTER. Values : setownpresenceactive (team) return w.

Weechat

Summary

In order for a community (such as the participants of an open source project) to collaborate online in real-time, a chat platform is required. Some communities have adopted multiple platforms such as IRC, Slack and Discord. Consequently a means of bridging these platforms together is required so that the users of each can converse with each other.

One method of doing so is to use a bridge bot. The bot joins the community's channel on each respective platform. Whenever a message is received, the botrelays it to all platforms other than the one it originated from.

The way in which messages from the bot are presented is dependent on the capabilities/limitations of the platform and the creativity of the bot's admin. On IRC such messages typically contain the name of the original sender (along with other metadata) within the message text.

The following excerpt illustrates an IRC channel in which a bot named Kilroy is relaying messages from the users of other platforms:

I'll return to this excerpt in more detail later.

The purpose of this post is to demonstrate a technique whereby the WeeChat IRC client's scripting API can be used (with Python) to format such messages to appear as though they originate from native IRC users, thus making it easier to follow conversations.

There are other solutions available that'll more or less achieve the same thingand may be better suited to your needs. I won't cover these in depth but have listed a few at the end of the post under Alternative Solutions.

format_bridge_bot_output.py

The WeeChat IRC client provides a scripting API with support for several languages including Python, Perl and Ruby. I had wanted an excuse to dabble with Python for quite a while, so that's what I opted to use.

The script can be found here: format_bridge_bot_output.py.It intercepts messages before WeeChat displays them and if found to have been sent by a bridge bot proceeds to alter the message so that when displayed it has the appearance of being sent by a native IRC user.

Installation

Since this script has not been published to the WeeChat Script Repositoryit must be installed manually:

  • Download the script to Weechat's python directory: wget -O ~/.weechat/python/format_bridge_bot_output.py https://raw.githubusercontent.com/thecliguy/WeeChat-Scripts/master/format_bridge_bot_output/format_bridge_bot_output.py
  • Create a link to the autoload directory so that the script is loaded when WeeChat starts:
    • cd ~/.weechat/python/autoload
    • ln -s ../format_bridge_bot_output.py
Weechat

Configuration

Customisable non-volatile settings pertaining to a script are referred to asscript options in WeeChat terminology.

This script groups related options together, the purpose of which is to accommodate users who participate in multiple IRC channels where bridge bots areused. Each channel can have its own group of options.

The available options are:

  • .bot_nicks The bridge bot nick(s). Multiple nicks can be specified using a comma separated list.
  • .channel The channel name.
  • .nick_display_max_length The maximum number of characters to be displayed for nicks of non-IRC users. Those greater than the specified value are truncated with an ellipsis appended. At the time of writing, Slack permits a nick of up to 80 characters, this would dominate too much screen real estate within WeeChat, hence why it is important to impose a limit.
  • .regex A regular expression used to extract the following from messages relayed by the bridge bot:
    • Action: For when a user sends an action message (typically done using /me, EG /me sighs).
    • Network: The external networks bridged to IRC by the bot, EG Slack or Discord.
    • Nick: The nick of the sender (not the nick of the bot).
    • Text: The message text.
  • .server The internal server name used by WeeChat. To obtain a list of server names, use the WeeChat command /server list.

Please refer to the scriptfor details regarding how to add and remove script options.

Example Usage

Returning to the excerpt at the beginning of the post, we already know that thebot's name is Kilroy and its message text is formatted as (network) Message.To expand on that, let's suppose that the channel is called #foobar, the server is GroovyIRC and the maximum permitted nick length is 20. The options for such a channel would be as follows:

Account
Slack

Summary

In order for a community (such as the participants of an open source project) to collaborate online in real-time, a chat platform is required. Some communities have adopted multiple platforms such as IRC, Slack and Discord. Consequently a means of bridging these platforms together is required so that the users of each can converse with each other.

One method of doing so is to use a bridge bot. The bot joins the community's channel on each respective platform. Whenever a message is received, the botrelays it to all platforms other than the one it originated from.

The way in which messages from the bot are presented is dependent on the capabilities/limitations of the platform and the creativity of the bot's admin. On IRC such messages typically contain the name of the original sender (along with other metadata) within the message text.

The following excerpt illustrates an IRC channel in which a bot named Kilroy is relaying messages from the users of other platforms:

I'll return to this excerpt in more detail later.

The purpose of this post is to demonstrate a technique whereby the WeeChat IRC client's scripting API can be used (with Python) to format such messages to appear as though they originate from native IRC users, thus making it easier to follow conversations.

There are other solutions available that'll more or less achieve the same thingand may be better suited to your needs. I won't cover these in depth but have listed a few at the end of the post under Alternative Solutions.

format_bridge_bot_output.py

The WeeChat IRC client provides a scripting API with support for several languages including Python, Perl and Ruby. I had wanted an excuse to dabble with Python for quite a while, so that's what I opted to use.

The script can be found here: format_bridge_bot_output.py.It intercepts messages before WeeChat displays them and if found to have been sent by a bridge bot proceeds to alter the message so that when displayed it has the appearance of being sent by a native IRC user.

Installation

Since this script has not been published to the WeeChat Script Repositoryit must be installed manually:

  • Download the script to Weechat's python directory: wget -O ~/.weechat/python/format_bridge_bot_output.py https://raw.githubusercontent.com/thecliguy/WeeChat-Scripts/master/format_bridge_bot_output/format_bridge_bot_output.py
  • Create a link to the autoload directory so that the script is loaded when WeeChat starts:
    • cd ~/.weechat/python/autoload
    • ln -s ../format_bridge_bot_output.py

Configuration

Customisable non-volatile settings pertaining to a script are referred to asscript options in WeeChat terminology.

This script groups related options together, the purpose of which is to accommodate users who participate in multiple IRC channels where bridge bots areused. Each channel can have its own group of options.

The available options are:

  • .bot_nicks The bridge bot nick(s). Multiple nicks can be specified using a comma separated list.
  • .channel The channel name.
  • .nick_display_max_length The maximum number of characters to be displayed for nicks of non-IRC users. Those greater than the specified value are truncated with an ellipsis appended. At the time of writing, Slack permits a nick of up to 80 characters, this would dominate too much screen real estate within WeeChat, hence why it is important to impose a limit.
  • .regex A regular expression used to extract the following from messages relayed by the bridge bot:
    • Action: For when a user sends an action message (typically done using /me, EG /me sighs).
    • Network: The external networks bridged to IRC by the bot, EG Slack or Discord.
    • Nick: The nick of the sender (not the nick of the bot).
    • Text: The message text.
  • .server The internal server name used by WeeChat. To obtain a list of server names, use the WeeChat command /server list.

Please refer to the scriptfor details regarding how to add and remove script options.

Example Usage

Returning to the excerpt at the beginning of the post, we already know that thebot's name is Kilroy and its message text is formatted as (network) Message.To expand on that, let's suppose that the channel is called #foobar, the server is GroovyIRC and the maximum permitted nick length is 20. The options for such a channel would be as follows:

  • MyGroup.bot_nicks = Kilroy
  • MyGroup.channel = #foobar
  • MyGroup.nick_display_max_length = 20
  • MyGroup.regex = (?P(?:^[x01]ACTION |^))((?P(?:slack|discord))) <(?P.+?)> (?P.*)
  • MyGroup.server = GroovyIRC

Weechat Slack Download

This is the conversation as it would appear without any modification:

This is the same conversation as it would appear using format_bridge_bot_output.py, the messages would be intercepted and amended to appear as though Barry, Charles and Nigel are native IRC users:

Alternative Solutions

These are a few alternative ways to format messages from bridge bots using the WeeChat IRC client:

  • parse_relay_msg.pl - A Perl script in the official WeeChat scriptsrepository.
  • weechat_bot2human.py - My script (format_bridge_bot_output.py) started life as weechat_bot2human.py (version 0.1.1) from the scripts repository of the TUNA (Tsinghua University TUNA Association) organization on Github. It has since been heavily modified and thus now bears little resemblance to the original script.
  • WeeChat Triggers - Run the command /help trigger for more information.

Weechat Slack Sign In

NB: I cannot personally vouch for parse_relay_msg.pl or WeeChat triggers as I have not tried them myself.

Weechat Slack App

Leaving comments has been disabled for this post.

Weechat Slack Plugin

Copyright © 2018 - 2020 thecliguy.co.uk
For details, see Licences and Copyright





broken image