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
78
myapp.pl
78
myapp.pl
|
@ -8,18 +8,18 @@
|
||||||
#
|
#
|
||||||
# This program is distributed in the hope that it will be useful,
|
# This program is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# 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.
|
# GNU General Public License for more details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use Mojolicious::Lite -signatures;
|
use Mojolicious::Lite -signatures;
|
||||||
use Mojo::JSON qw(decode_json);
|
use Mojo::JSON qw(decode_json);
|
||||||
use Mojo::UserAgent;
|
use Mojo::UserAgent;
|
||||||
use Mojo::IRC;
|
use Mojo::IRC;
|
||||||
use Carp qw(croak);
|
use Carp qw(croak);
|
||||||
#use Smart::Comments;
|
use Smart::Comments;
|
||||||
use MIME::Base64 qw(encode_base64);
|
use MIME::Base64 qw(encode_base64);
|
||||||
## no critic (prototype)
|
## no critic (prototype)
|
||||||
|
|
||||||
|
@ -31,23 +31,49 @@ my $owncast_chat_closes = 60 * 5; # 5 minutes
|
||||||
|
|
||||||
# yoinked from IRC::Utils
|
# yoinked from IRC::Utils
|
||||||
use constant {
|
use constant {
|
||||||
# cancel all formatting and colors
|
# cancel all formatting and colors
|
||||||
NORMAL => "\x0f",
|
NORMAL => "\x0f", # 0
|
||||||
|
|
||||||
# mIRC colors
|
# formatting
|
||||||
WHITE => "\x0300",
|
BOLD => "\x02", # 1
|
||||||
BLUE => "\x0302",
|
UNDERLINE => "\x1f", # 2
|
||||||
RED => "\x0304",
|
REVERSE => "\x16", # 3
|
||||||
BROWN => "\x0305",
|
ITALIC => "\x1d", # 4
|
||||||
PURPLE => "\x0306",
|
FIXED => "\x11", # 5
|
||||||
YELLOW => "\x0308",
|
BLINK => "\x06", # 6
|
||||||
LIGHT_GREEN => "\x0309",
|
|
||||||
TEAL => "\x0310",
|
# mIRC colors
|
||||||
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'
|
# OWNCAST_URL: should not have '/' at end, eg 'http://hostname'
|
||||||
my $death_string = '';
|
my $death_string = '';
|
||||||
for my $e (qw(OWNCAST_ACCESS_TOKEN OWNCAST_URL IRC_CHANNEL IRC_NICK IRC_USER IRC_SERVER))
|
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];
|
#say $name[0] . " said: " . $message->{params}[1];
|
||||||
# ACTION in owncast chat is ugly
|
# ACTION in owncast chat is ugly
|
||||||
$message->{params}[1] =~ s|^\x01ACTION|/me|; # ty for the \x01 hint, Irish
|
$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]);
|
send_chat_to_owncast($message->{params}[1], $name[0]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -121,17 +156,6 @@ my %events = (
|
||||||
#'VISIBILITY-UPDATE' => \&visibility-update # don't care.
|
#'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)
|
# TODO: actually parse this. it'll do for now™, I guess. (Aug 2024)
|
||||||
if ($ENV{ IRC_SERVER } =~ m/:6697$/) {
|
if ($ENV{ IRC_SERVER } =~ m/:6697$/) {
|
||||||
$irc->tls({});
|
$irc->tls({});
|
||||||
|
|
Loading…
Reference in a new issue