Last active
December 30, 2016 15:19
-
-
Save Forecaster/47acccee9e36d9e21a3d54ce4573f560 to your computer and use it in GitHub Desktop.
Discord relay bot message parsing (turns BotName: <discord_user> message into discord_user: message)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use vars qw($VERSION %IRSSI); | |
use Irssi; | |
$VERSION = '1.02'; | |
%IRSSI = ( | |
authors => 'Forecaster', | |
contact => '[email protected]', | |
name => 'Relay Substitution Script', | |
description => 'This script allows ' . | |
'you to print Hello ' . | |
'World using a command.', | |
license => 'Public Domain', | |
); | |
sub relay_sub { | |
my $regex = qr/\xe2\x80\x8b/p; | |
my $subst = ''; | |
my $regex1 = qr/^<(.*?)> (.*)/p; | |
my $regex2 = qr/^\* (\S*) (.*)/p; | |
my ($server, $data, $nick, $address) = @_; | |
my $bots = Irssi::settings_get_str("relay_bots"); | |
if (index($bots, $nick) != -1) { | |
my ($target, $msg) = split(/ :/, $data,2); | |
if ( $msg =~ /$regex1/g ) { | |
$nick = $1; | |
$msg = "> " . $2; | |
$nick =~ s/$regex/$subst/g; | |
Irssi::signal_emit('event privmsg', ($server, "$target :$msg", $nick, $address)); | |
Irssi::signal_stop(); | |
} | |
if ( $msg =~ /$regex2/g ) { | |
$nick = $1; | |
$msg = "> " . $2; | |
$nick =~ s/$regex/$subst/g; | |
Irssi::signal_continue($server, "$target :\x01ACTION $msg\x01", $nick, $address); | |
# Irssi::signal_emit('event privmsg', ($server, "$target :\x01ACTION $msg\x01", $nick, $address)); | |
# Irssi::signal_stop(); | |
} | |
} | |
# my ($target, $msg) = split(/ :/, $data,2); | |
# | |
# foreach my $key (keys %replaces) { | |
# if ($msg =~ /$key/) { | |
# $msg =~ s/$key/$replaces{$key}/; | |
# | |
# Irssi::signal_emit('event privmsg', ($server, "$target :$msg", $nick, $address)); | |
# Irssi::signal_stop(); | |
# } | |
# } | |
} | |
Irssi::signal_add_first('event privmsg', 'relay_sub'); | |
Irssi::settings_add_str('misc', 'relay_bots', 'Corded'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment