WeeChat IRC Client - Formatting Bridge Bot Output

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 bot relays 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:

12:07:01 Kilroy | (slack) <Barry> Good afternoon.
12:08:20 Kilroy | (slack) <Charles> Hello Barry.
12:08:43 Kilroy | (discord) <Nigel> Hi Barry.

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 thing and 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 Repository it must be installed manually:

Configuration

Customisable non-volatile settings pertaining to a script are referred to as script 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 are used. Each channel can have its own group of options.

The available options are:

Please refer to the script for 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 the bot’s name is Kilroy and its message text is formatted as (network) <nick> 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:

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

12:07:01 Kilroy | (slack) <Barry> Good afternoon.
12:08:20 Kilroy | (slack) <Charles> Hello Barry.
12:08:43 Kilroy | (discord) <Nigel> Hi Barry.

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:

12:07:01 Barry   | [slack] Good afternoon.
12:08:20 Charles | [slack] Hello Barry.
12:08:43 Nigel   | [discord] Hi Barry.

Alternative Solutions

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

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

Comments

Leaving comments has been disabled for this post.

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