diff --git a/myapp.pl b/myapp.pl index d16e081..1b08c53 100755 --- a/myapp.pl +++ b/myapp.pl @@ -8,18 +8,18 @@ # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# along with this program. If not, see . use Mojolicious::Lite -signatures; 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) @@ -31,23 +31,49 @@ my $owncast_chat_closes = 60 * 5; # 5 minutes # yoinked from IRC::Utils use constant { - # cancel all formatting and colors - NORMAL => "\x0f", + # cancel all formatting and colors + NORMAL => "\x0f", # 0 - # mIRC colors - WHITE => "\x0300", - BLUE => "\x0302", - RED => "\x0304", - BROWN => "\x0305", - PURPLE => "\x0306", - YELLOW => "\x0308", - LIGHT_GREEN => "\x0309", - TEAL => "\x0310", - PINK => "\x0313", + # formatting + BOLD => "\x02", # 1 + UNDERLINE => "\x1f", # 2 + REVERSE => "\x16", # 3 + ITALIC => "\x1d", # 4 + FIXED => "\x11", # 5 + BLINK => "\x06", # 6 + + # mIRC colors + 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' + # OWNCAST_URL: should not have '/' at end, eg 'http://hostname' my $death_string = ''; for my $e (qw(OWNCAST_ACCESS_TOKEN OWNCAST_URL IRC_CHANNEL IRC_NICK IRC_USER IRC_SERVER)) { @@ -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({});