try to strip IRC codes before sending to owncast
This commit is contained in:
parent
b0240b0dac
commit
c1a303e19f
1 changed files with 51 additions and 27 deletions
68
myapp.pl
68
myapp.pl
|
@ -19,7 +19,7 @@ use Mojo::JSON qw(decode_json);
|
|||
use Mojo::UserAgent;
|
||||
use Mojo::IRC;
|
||||
use Carp qw(croak);
|
||||
#use Smart::Comments;
|
||||
use Smart::Comments;
|
||||
use MIME::Base64 qw(encode_base64);
|
||||
## no critic (prototype)
|
||||
|
||||
|
@ -32,20 +32,46 @@ my $owncast_chat_closes = 60 * 5; # 5 minutes
|
|||
# yoinked from IRC::Utils
|
||||
use constant {
|
||||
# cancel all formatting and colors
|
||||
NORMAL => "\x0f",
|
||||
NORMAL => "\x0f", # 0
|
||||
|
||||
# formatting
|
||||
BOLD => "\x02", # 1
|
||||
UNDERLINE => "\x1f", # 2
|
||||
REVERSE => "\x16", # 3
|
||||
ITALIC => "\x1d", # 4
|
||||
FIXED => "\x11", # 5
|
||||
BLINK => "\x06", # 6
|
||||
|
||||
# mIRC colors
|
||||
WHITE => "\x0300",
|
||||
BLUE => "\x0302",
|
||||
RED => "\x0304",
|
||||
BROWN => "\x0305",
|
||||
PURPLE => "\x0306",
|
||||
YELLOW => "\x0308",
|
||||
LIGHT_GREEN => "\x0309",
|
||||
TEAL => "\x0310",
|
||||
PINK => "\x0313",
|
||||
WHITE => "\x0300", # 7
|
||||
BLACK => "\x0301", # 8
|
||||
BLUE => "\x0302", # 9
|
||||
GREEN => "\x0303", # 10
|
||||
RED => "\x0304", # 11
|
||||
BROWN => "\x0305", # 12
|
||||
PURPLE => "\x0306", # 13
|
||||
ORANGE => "\x0307", # 14
|
||||
YELLOW => "\x0308", # 15
|
||||
LIGHT_GREEN => "\x0309", # 16
|
||||
TEAL => "\x0310", # 17
|
||||
LIGHT_CYAN => "\x0311", # 18
|
||||
LIGHT_BLUE => "\x0312", # 19
|
||||
PINK => "\x0313", # 20
|
||||
GREY => "\x0314", # 21
|
||||
LIGHT_GREY => "\x0315", # 22
|
||||
};
|
||||
|
||||
my %colors = (
|
||||
0 => RED,
|
||||
1 => YELLOW,
|
||||
2 => BROWN,
|
||||
3 => LIGHT_GREEN,
|
||||
4 => TEAL,
|
||||
5 => BLUE,
|
||||
6 => PURPLE,
|
||||
7 => PINK,
|
||||
);
|
||||
|
||||
{
|
||||
# OWNCAST_URL: should not have '/' at end, eg 'http://hostname'
|
||||
my $death_string = '';
|
||||
|
@ -82,6 +108,15 @@ $irc->on(irc_privmsg => sub ($self, $message) {
|
|||
#say $name[0] . " said: " . $message->{params}[1];
|
||||
# ACTION in owncast chat is ugly
|
||||
$message->{params}[1] =~ s|^\x01ACTION|/me|; # ty for the \x01 hint, Irish
|
||||
|
||||
# strip IRC codes because owncast seems to treat it as emoji
|
||||
for my $irc_code (NORMAL, BOLD, UNDERLINE, REVERSE, ITALIC, FIXED, BLINK)
|
||||
{
|
||||
$message->{params}[1] =~ s|$irc_code||g;
|
||||
}
|
||||
$message->{params}[1] =~ s|\x03\d?\d||g; # colors
|
||||
$message->{params}[1] =~ s|\x03||g; # bare color code ????
|
||||
|
||||
send_chat_to_owncast($message->{params}[1], $name[0]);
|
||||
}
|
||||
});
|
||||
|
@ -121,17 +156,6 @@ my %events = (
|
|||
#'VISIBILITY-UPDATE' => \&visibility-update # don't care.
|
||||
);
|
||||
|
||||
my %colors = (
|
||||
0 => RED,
|
||||
1 => YELLOW,
|
||||
2 => BROWN,
|
||||
3 => LIGHT_GREEN,
|
||||
4 => TEAL,
|
||||
5 => BLUE,
|
||||
6 => PURPLE,
|
||||
7 => PINK,
|
||||
);
|
||||
|
||||
# TODO: actually parse this. it'll do for now™, I guess. (Aug 2024)
|
||||
if ($ENV{ IRC_SERVER } =~ m/:6697$/) {
|
||||
$irc->tls({});
|
||||
|
|
Loading…
Reference in a new issue