Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
HexChat plugin to map bot messages in `<nick> message` format to messages coming from nick directly instead
# Name:
# Author: carstene1ns < dev f4ke de >
# Date: 2017-08-04
# License: This code is put in the public domain.
use strict;
use warnings;
use utf8;
use v5.26.0;
use HexChat;
my $PLUGIN_NAME = 'discord-bot-bridge';
my $PLUGIN_VERS = '0.2';
my $PLUGIN_DESC = 'Rewrites bot messages to display discord users as IRC users';
# bot + channel(s), lowercase
my %bot_chans = (
'_dc_' => [
HexChat::register($PLUGIN_NAME, $PLUGIN_VERS, $PLUGIN_DESC, \&on_unload);
HexChat::printf("Loaded %s (version %s).", $PLUGIN_NAME, $PLUGIN_VERS);
sub on_unload {
HexChat::printf("Unloaded %s (version %s).", $PLUGIN_NAME, $PLUGIN_VERS);
# hook channel message events
HexChat::hook_print($_, \&on_message) for ('Channel Msg Hilight', 'Channel Message');
sub on_message {
# get needed info
my $from = lc HexChat::strip_code($_[0][0]);
my $chan = lc HexChat::context_info->{'channel'};
my $text = $_[0][1];
# match user and channel
if (defined $bot_chans{$from} && grep($chan eq $_ , @{ $bot_chans{$from} })) {
# split bot message
if (my ($nick, $message) = $text =~ /^<(.+?)>\s+?(.+)$/) {
# replace whitespaces
$nick =~ s/\s+/_/g;
# receive message from discord user
HexChat::command("RECV :$nick!someone\@discord.server PRIVMSG $chan :$message");
# discard bot message
return HexChat::EAT_ALL;
# nothing to do
return HexChat::EAT_NONE;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.