diff --git a/data/channels b/data/channels index a0e6cf67..606db2f4 100644 --- a/data/channels +++ b/data/channels @@ -1,5 +1,5 @@ { - "#pbot2" : { + "#pbot" : { "chanop" : "0", "enabled" : "1" }, diff --git a/data/registry b/data/registry index 927e215d..423fdfe0 100644 --- a/data/registry +++ b/data/registry @@ -276,7 +276,7 @@ }, "max_msg_len" : { "type" : "text", - "value" : "460" + "value" : "510" }, "port" : { "type" : "text", diff --git a/lib/PBot/Core.pm b/lib/PBot/Core.pm index 3447ae66..44fc765d 100644 --- a/lib/PBot/Core.pm +++ b/lib/PBot/Core.pm @@ -222,7 +222,7 @@ sub initialize($self, %conf) { $self->{logger}->log("PBot::Core initialized.\n"); } -sub random_nick($self, $length) { +sub random_nick($self, $length = undef) { $length //= 9; my @chars = ("A" .. "Z", "a" .. "z", "0" .. "9"); my $nick = $chars[rand @chars - 10]; # nicks cannot start with a digit diff --git a/lib/PBot/Core/AntiFlood.pm b/lib/PBot/Core/AntiFlood.pm index 6717512c..7410ea73 100644 --- a/lib/PBot/Core/AntiFlood.pm +++ b/lib/PBot/Core/AntiFlood.pm @@ -155,7 +155,7 @@ sub check_flood($self, $channel, $nick, $user, $host, $text, $max_messages, $max } # do not do flood processing for bot messages - if ($nick eq $self->{pbot}->{registry}->get_value('irc', 'botnick')) { + if ($nick eq $self->{pbot}->{conn}->nick) { $self->{channels}->{$channel}->{last_spoken_nick} = $nick; return; } diff --git a/lib/PBot/Core/ChanOps.pm b/lib/PBot/Core/ChanOps.pm index fe3d79e5..4fb0892d 100644 --- a/lib/PBot/Core/ChanOps.pm +++ b/lib/PBot/Core/ChanOps.pm @@ -69,7 +69,7 @@ sub gain_ops($self, $channel) { # removes OP status in $channel sub lose_ops($self, $channel) { $channel = lc $channel; - $self->{pbot}->{conn}->mode($channel, '-o ' . $self->{pbot}->{registry}->get_value('irc', 'botnick')); + $self->{pbot}->{conn}->mode($channel, '-o ' . $self->{pbot}->{conn}->nick); } # adds a command to the OP command queue @@ -84,7 +84,7 @@ sub perform_op_commands($self, $channel) { $self->{pbot}->{logger}->log("Performing op commands in $channel:\n"); - my $botnick = $self->{pbot}->{registry}->get_value('irc', 'botnick'); + my $botnick = $self->{pbot}->{conn}->nick; while (my $command = shift @{$self->{op_commands}->{$channel}}) { if ($command =~ /^mode (.*?) (.*)/i) { diff --git a/lib/PBot/Core/Commands/ChanOp.pm b/lib/PBot/Core/Commands/ChanOp.pm index 961d62bf..bdef302d 100644 --- a/lib/PBot/Core/Commands/ChanOp.pm +++ b/lib/PBot/Core/Commands/ChanOp.pm @@ -291,7 +291,7 @@ sub cmd_mode($self, $context) { if ($modifier eq '-') { # removing mode -- check against whitelist, etc - next if $nick_data->{nick} eq $self->{pbot}->{registry}->get_value('irc', 'botnick'); + next if $nick_data->{nick} eq $self->{pbot}->{conn}->nick; my $u = $self->{pbot}->{users}->loggedin($channel, $nick_data->{hostmask}); next if $self->{pbot}->{capabilities}->userhas($u, 'is-whitelisted'); } @@ -498,7 +498,7 @@ sub cmd_kick($self, $context) { if ($nl =~ m/^$q_target$/) { my $nick_data = $self->{pbot}->{nicklist}->{nicklist}->{$channel}->{$nl}; - next if $nick_data->{nick} eq $self->{pbot}->{registry}->get_value('irc', 'botnick'); + next if $nick_data->{nick} eq $self->{pbot}->{conn}->nick; my $u = $self->{pbot}->{users}->loggedin($channel, $nick_data->{hostmask}); next if $self->{pbot}->{capabilities}->userhas($u, 'is-whitelisted'); diff --git a/lib/PBot/Core/Handlers/ChanOps.pm b/lib/PBot/Core/Handlers/ChanOps.pm index 573cbb33..deb3579a 100644 --- a/lib/PBot/Core/Handlers/ChanOps.pm +++ b/lib/PBot/Core/Handlers/ChanOps.pm @@ -50,7 +50,7 @@ sub on_modeflag($self, $event_type, $event) { $channel = defined $channel ? lc $channel : ''; $target = defined $target ? lc $target : ''; - if ($target eq lc $self->{pbot}->{registry}->get_value('irc', 'botnick')) { + if ($target eq lc $self->{pbot}->{conn}->nick) { if ($mode eq '+o') { $self->{pbot}->{logger}->log("$source opped me in $channel\n"); diff --git a/lib/PBot/Core/Handlers/Channel.pm b/lib/PBot/Core/Handlers/Channel.pm index 4fd0b560..3da0df81 100644 --- a/lib/PBot/Core/Handlers/Channel.pm +++ b/lib/PBot/Core/Handlers/Channel.pm @@ -167,7 +167,7 @@ sub on_invite($self, $event_type, $event) { $self->{pbot}->{logger}->log("$nick!$user\@$host invited $target to $channel!\n"); # if invited to a channel on our channel list, go ahead and join it - if ($target eq $self->{pbot}->{registry}->get_value('irc', 'botnick')) { + if ($target eq $self->{pbot}->{conn}->nick) { if ($self->{pbot}->{channels}->is_active($channel)) { $self->{pbot}->{interpreter}->add_botcmd_to_command_queue($channel, "join $channel", 0); } diff --git a/lib/PBot/Core/Handlers/SASL.pm b/lib/PBot/Core/Handlers/SASL.pm index 5eda747d..70e97eb8 100644 --- a/lib/PBot/Core/Handlers/SASL.pm +++ b/lib/PBot/Core/Handlers/SASL.pm @@ -57,6 +57,8 @@ sub on_sasl_authenticate($self, $event_type, $event) { sub on_rpl_loggedin($self, $event_type, $event) { $self->{pbot}->{logger}->log($event->{args}[3] . "\n"); + $self->{pbot}->{hostmask} = $event->{args}[1]; + $self->{pbot}->{logger}->log("Set hostmask to $event->{args}[1]\n"); return 1; } diff --git a/lib/PBot/Core/Handlers/Server.pm b/lib/PBot/Core/Handlers/Server.pm index 22c74a11..68d403f3 100644 --- a/lib/PBot/Core/Handlers/Server.pm +++ b/lib/PBot/Core/Handlers/Server.pm @@ -29,6 +29,8 @@ sub initialize($self, %conf) { $self->{pbot}->{event_dispatcher}->register_handler('irc.n_global', sub { $self->log_third_arg (@_) }); $self->{pbot}->{event_dispatcher}->register_handler('irc.nononreg', sub { $self->on_nononreg (@_) }); $self->{pbot}->{event_dispatcher}->register_handler('irc.chghost', sub { $self->on_chghost (@_) }); + $self->{pbot}->{event_dispatcher}->register_handler('irc.whoisuser', sub { $self->on_whoisuser (@_) }); + $self->{pbot}->{event_dispatcher}->register_handler('irc.whoishost', sub { $self->on_whoishost (@_) }); } sub on_init($self, $conn, $event) { @@ -39,7 +41,7 @@ sub on_init($self, $conn, $event) { } sub on_welcome($self, $event_type, $event) { - $self->{pbot}->{logger}->log("Welcome!\n"); + $self->{pbot}->{logger}->log($event->{args}[1] . "\n"); if ($self->{pbot}->{irc_capabilities}->{sasl}) { # using SASL; go ahead and auto-join channels now @@ -47,9 +49,28 @@ sub on_welcome($self, $event_type, $event) { $self->{pbot}->{channels}->autojoin; } + $self->{pbot}->{logger}->log("Getting self-WHOIS for $event->{args}[0] ...\n"); + $self->{pbot}->{conn}->whois($event->{args}[0]); return 1; } +sub on_whoisuser($self, $event_type, $event) { + my $nick = $event->{args}[1]; + my $user = $event->{args}[2]; + my $host = $event->{args}[3]; + + my $botnick = $self->{pbot}->{conn}->nick; + + if ($nick eq $botnick) { + $self->{pbot}->{hostmask} = "$nick!$user\@$host"; + $self->{pbot}->{logger}->log("Set hostmask to $self->{pbot}->{hostmask}\n"); + } +} + +sub on_whoishost($self, $event_type, $event) { + $self->{pbot}->{logger}->log("$event->{args}[1] $event->{args}[2]\n"); +} + sub on_disconnect($self, $event_type, $event) { $self->{pbot}->{logger}->log("Disconnected...\n"); $self->{pbot}->{conn} = undef; @@ -125,8 +146,13 @@ sub on_nickchange($self, $event_type, $event) { $self->{pbot}->{logger}->log("[NICKCHANGE] $nick!$user\@$host changed nick to $newnick\n"); - if ($newnick eq $self->{pbot}->{registry}->get_value('irc', 'botnick') and not $self->{pbot}->{joined_channels}) { - $self->{pbot}->{channels}->autojoin; + if ($newnick eq $self->{pbot}->{registry}->get_value('irc', 'botnick')) { + if (not $self->{pbot}->{joined_channels}) { + $self->{pbot}->{channels}->autojoin; + } + + $self->{pbot}->{hostmask} = "$newnick!$user\@$host"; + $self->{pbot}->{logger}->log("Set hostmask to $self->{pbot}->{hostmask}\n"); return 1; } @@ -185,6 +211,11 @@ sub on_chghost($self, $event_type, $event) { $self->{pbot}->{logger}->log("[CHGHOST] ($account) $nick!$user\@$host changed host to ($id) $nick!$newuser\@$newhost\n"); + if ("$nick!$user\@$host" eq $self->{pbot}->{hostmask}) { + $self->{pbot}->{logger}->log("Set hostmask to $nick!$newuser\@$newhost\n"); + $self->{hostmask} = "$nick!$newuser\@$newhost"; + } + my $channels = $self->{pbot}->{nicklist}->get_channels($nick); foreach my $channel (@$channels) { diff --git a/lib/PBot/Core/IRC/Event.pm b/lib/PBot/Core/IRC/Event.pm index a2eea333..eec343e9 100644 --- a/lib/PBot/Core/IRC/Event.pm +++ b/lib/PBot/Core/IRC/Event.pm @@ -341,7 +341,7 @@ sub trans { 375 => "motdstart", 376 => "endofmotd", 377 => "motd2", # 1997-10-16 -- tkil - 378 => "austmotd", # (July01-01)Austnet Extension, found by Andypoo + 378 => "whoishost", # 2024-04-07 pragma- libera.chat 379 => "whoismodes", # UnrealIrcd, Hendrik Frenzel 381 => "youreoper", 382 => "rehashing", diff --git a/lib/PBot/Core/Interpreter.pm b/lib/PBot/Core/Interpreter.pm index f6a4a088..0bdb58e6 100644 --- a/lib/PBot/Core/Interpreter.pm +++ b/lib/PBot/Core/Interpreter.pm @@ -82,7 +82,7 @@ sub process_line($self, $from, $nick, $user, $host, $text, $tags = '', $is_comma ); # get bot nickname - my $botnick = $self->{pbot}->{registry}->get_value('irc', 'botnick'); + my $botnick = $self->{pbot}->{conn}->nick; # get channel-specific bot trigger if available my $bot_trigger = $self->{pbot}->{registry}->get_value($from, 'trigger'); @@ -484,7 +484,7 @@ sub interpret($self, $context) { if (not $self->{pbot}->{commands}->get_meta($keyword, 'dont-protect-self') and not $self->{pbot}->{factoids}->{data}->get_meta($context->{from}, $keyword, 'dont-protect-self')) { - my $botnick = $self->{pbot}->{registry}->get_value('irc', 'botnick'); + my $botnick = $self->{pbot}->{conn}->nick; if ($arguments =~ m/^(your|him|her|its|it|them|their)(self|selves)$/i || $arguments =~ m/^$botnick$/i) { # build message structure @@ -641,7 +641,7 @@ sub handle_result($self, $context, $result = $context->{result}) { # finish command split if ($context->{command_split}) { - my $botnick = $self->{pbot}->{registry}->get_value('irc', 'botnick'); + my $botnick = $self->{pbot}->{conn}->nick; # update contextual command with next command in split $context->{command} = delete $context->{command_split}; @@ -664,7 +664,7 @@ sub handle_result($self, $context, $result = $context->{result}) { # join command split if ($context->{split_result}) { - my $botnick = $self->{pbot}->{registry}->get_value('irc', 'botnick'); + my $botnick = $self->{pbot}->{conn}->nick; # reformat result to be more suitable for joining together $result =~ s!^/say !\n!i; @@ -753,15 +753,18 @@ sub handle_result($self, $context, $result = $context->{result}) { # $paste_text is the version of text (e.g. with whitespace formatting preserved, etc) # to send to the paste site. sub truncate_result($self, $context, $text, $paste_text) { - my $max_msg_len = $self->{pbot}->{registry}->get_value('irc', 'max_msg_len'); + my $max_msg_len = $self->{pbot}->{registry}->get_value('irc', 'max_msg_len') // 510; - $max_msg_len -= length "PRIVMSG $context->{from} :"; + # reduce max msg len by length of hostmask and PRIVMSG command + $max_msg_len -= length ":$self->{pbot}->{hostmask} PRIVMSG $context->{from} :"; # encode text to utf8 for byte length truncation $text = encode('UTF-8', $text); $paste_text = encode('UTF-8', $paste_text); - if (length $text > $max_msg_len) { + my $text_len = length $text; + + if ($text_len > $max_msg_len) { my $paste_result; if (defined $paste_text) { @@ -780,11 +783,7 @@ sub truncate_result($self, $context, $text, $paste_text) { if (not defined $paste_result) { # no paste $trunc .= '>'; - } elsif ($paste_result =~ m/^http/) { - # a link - $trunc .= "; $paste_result>"; } else { - # an error or something else $trunc .= "; $paste_result>"; } @@ -793,7 +792,6 @@ sub truncate_result($self, $context, $text, $paste_text) { # make room to append the truncation text to the message text # (third argument to truncate_egc is '' to prevent appending its own ellipsis) - my $text_len = length $text; my $trunc_len = $text_len < $max_msg_len ? $text_len : $max_msg_len; $text = truncate_egc $text, $trunc_len - length $trunc, ''; @@ -850,7 +848,7 @@ sub output_result($self, $context) { # nothing more to do here if the command came from STDIN return if $context->{from} eq 'stdin@pbot'; - my $botnick = $self->{pbot}->{registry}->get_value('irc', 'botnick'); + my $botnick = $self->{pbot}->{conn}->nick; my $to = $context->{from}; # log the message if requested @@ -904,7 +902,7 @@ sub output_result($self, $context) { } } - my $bot_nick = $self->{pbot}->{registry}->get_value('irc', 'botnick'); + my $bot_nick = $self->{pbot}->{conn}->nick; my $bot_hostmask = "$bot_nick!pbot3\@pbot"; my $bot_account = $self->{pbot}->{messagehistory}->get_message_account($bot_nick, 'pbot3', 'pbot'); @@ -992,7 +990,7 @@ sub add_to_command_queue($self, $channel, $command, $delay = 0, $repeating = 0) sub add_botcmd_to_command_queue($self, $channel, $command, $delay = 0) { my $botcmd = { - nick => $self->{pbot}->{registry}->get_value('irc', 'botnick'), + nick => $self->{pbot}->{conn}->nick, user => 'stdin', host => 'pbot', command => $command diff --git a/lib/PBot/Core/MessageHistory/Storage/SQLite.pm b/lib/PBot/Core/MessageHistory/Storage/SQLite.pm index 1eebdbd1..f7ad3fb8 100644 --- a/lib/PBot/Core/MessageHistory/Storage/SQLite.pm +++ b/lib/PBot/Core/MessageHistory/Storage/SQLite.pm @@ -1059,7 +1059,7 @@ sub recall_message_by_count($self, $id, $channel, $count, $ignore_command = unde $self->{pbot}->{logger}->log("EXCEPT: $@\n") if $@; if (defined $ignore_command) { - my $botnick = $self->{pbot}->{registry}->get_value('irc', 'botnick'); + my $botnick = $self->{pbot}->{conn}->nick; my $bot_trigger = $self->{pbot}->{registry}->get_value('general', 'trigger'); foreach my $message (@$messages) { next if $message->{msg} =~ m/^$botnick.? $ignore_command/ or $message->{msg} =~ m/^$bot_trigger$ignore_command/; @@ -1126,7 +1126,7 @@ sub recall_message_by_text($self, $id, $channel, $text, $ignore_command = undef, if (defined $ignore_command) { my $bot_trigger = $self->{pbot}->{registry}->get_value('general', 'trigger'); - my $botnick = $self->{pbot}->{registry}->get_value('irc', 'botnick'); + my $botnick = $self->{pbot}->{conn}->nick; foreach my $message (@$messages) { next if $message->{msg} =~ m/^$botnick.? $ignore_command/i diff --git a/lib/PBot/Core/WebPaste.pm b/lib/PBot/Core/WebPaste.pm index e5059025..f312243d 100644 --- a/lib/PBot/Core/WebPaste.pm +++ b/lib/PBot/Core/WebPaste.pm @@ -20,7 +20,8 @@ sub initialize($self, %conf) { # many have died off. :-( $self->{paste_sites} = [ - sub { $self->paste_0x0st(@_) }, + sub { $self->paste_0x0st(@_) }, + sub { $self->paste_sprunge(@_) }, # sub { $self->paste_ixio(@_) }, # removed due to being too slow (temporarily hopefully) ]; @@ -90,13 +91,22 @@ sub paste_0x0st($self, $text) { ); } -sub paste_ixio($self, $text) { - my $ua = LWP::UserAgent::Paranoid->new(request_timeout => 10); +sub paste_sprunge($self, $text) { + my $ua = LWP::UserAgent::Paranoid->new(request_timeout => 10, agent => 'Mozilla/5.0'); push @{$ua->requests_redirectable}, 'POST'; - my %post = ('f:1' => $text); + return $ua->post( + "http://sprunge.us", + Content => [(sprunge => $text)], + Content_Type => 'form-data' + ); +} +sub paste_ixio($self, $text) { + my $ua = LWP::UserAgent::Paranoid->new(request_timeout => 10); + push @{$ua->requests_redirectable}, 'POST'; + my %post = ('f:1' => $text); return $ua->post("http://ix.io", \%post); } diff --git a/lib/PBot/Plugin/AntiRepeat.pm b/lib/PBot/Plugin/AntiRepeat.pm index 807dfe1d..314ae6c2 100644 --- a/lib/PBot/Plugin/AntiRepeat.pm +++ b/lib/PBot/Plugin/AntiRepeat.pm @@ -68,7 +68,7 @@ sub on_public($self, $event_type, $event) { my $messages = $self->{pbot}->{messagehistory}->{database}->get_recent_messages($account, $channel, 6, $self->{pbot}->{messagehistory}->{MSG_CHAT}); - my $botnick = $self->{pbot}->{registry}->get_value('irc', 'botnick'); + my $botnick = $self->{pbot}->{conn}->nick; my $bot_trigger = $self->{pbot}->{registry}->get_value($channel, 'trigger') // $self->{pbot}->{registry}->get_value('general', 'trigger'); diff --git a/lib/PBot/Plugin/AutoRejoin.pm b/lib/PBot/Plugin/AutoRejoin.pm index f106eb6f..b9b8c575 100644 --- a/lib/PBot/Plugin/AutoRejoin.pm +++ b/lib/PBot/Plugin/AutoRejoin.pm @@ -56,7 +56,7 @@ sub on_kick($self, $event_type, $event) { return 0 if not $self->{pbot}->{channels}->is_active($channel); return 0 if $self->{pbot}->{channels}->{storage}->get_data($channel, 'noautorejoin'); - if ($target eq $self->{pbot}->{registry}->get_value('irc', 'botnick')) { + if ($target eq $self->{pbot}->{conn}->nick) { $self->rejoin_channel($channel); } @@ -74,7 +74,7 @@ sub on_part($self, $event_type, $event) { return 0 if not $self->{pbot}->{channels}->is_active($channel); return 0 if $self->{pbot}->{channels}->{storage}->get_data($channel, 'noautorejoin'); - if ($nick eq $self->{pbot}->{registry}->get_value('irc', 'botnick')) { + if ($nick eq $self->{pbot}->{conn}->nick) { $self->rejoin_channel($channel); } diff --git a/lib/PBot/Plugin/TypoSub.pm b/lib/PBot/Plugin/TypoSub.pm index 78a3c5dd..9262de33 100644 --- a/lib/PBot/Plugin/TypoSub.pm +++ b/lib/PBot/Plugin/TypoSub.pm @@ -58,7 +58,7 @@ sub on_public($self, $event_type, $event) { my $messages = $self->{pbot}->{messagehistory}->{database}->get_recent_messages_from_channel($channel, 50, $self->{pbot}->{messagehistory}->{MSG_CHAT}, 'DESC'); - my $botnick = $self->{pbot}->{registry}->get_value('irc', 'botnick'); + my $botnick = $self->{pbot}->{conn}->nick; my $bot_trigger = $self->{pbot}->{registry}->get_value($channel, 'trigger') // $self->{pbot}->{registry}->get_value('general', 'trigger'); diff --git a/lib/PBot/VERSION.pm b/lib/PBot/VERSION.pm index edde7f16..a8a9552a 100644 --- a/lib/PBot/VERSION.pm +++ b/lib/PBot/VERSION.pm @@ -25,8 +25,8 @@ use PBot::Imports; # These are set by the /misc/update_version script use constant { BUILD_NAME => "PBot", - BUILD_REVISION => 4735, - BUILD_DATE => "2024-04-04", + BUILD_REVISION => 4740, + BUILD_DATE => "2024-04-07", }; sub initialize {}