mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-22 03:49:29 +01:00
Multiple bugfixes
* obtain bot nick from connection details instead of registry where appropriate * irc.random_nick works again * record own hostmask when connecting * fix web-paste truncation by subtracting length of own hostmask from message length * set irc.max_msg_len back to 510 * updated IRC numeric 378 to whoishost * add sprunge.us to WebPaste
This commit is contained in:
parent
94b7706358
commit
5d3f188a09
2
data/channels
vendored
2
data/channels
vendored
@ -1,5 +1,5 @@
|
||||
{
|
||||
"#pbot2" : {
|
||||
"#pbot" : {
|
||||
"chanop" : "0",
|
||||
"enabled" : "1"
|
||||
},
|
||||
|
2
data/registry
vendored
2
data/registry
vendored
@ -276,7 +276,7 @@
|
||||
},
|
||||
"max_msg_len" : {
|
||||
"type" : "text",
|
||||
"value" : "460"
|
||||
"value" : "510"
|
||||
},
|
||||
"port" : {
|
||||
"type" : "text",
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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');
|
||||
|
||||
|
@ -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");
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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 <andypoo@secret.com.au>
|
||||
378 => "whoishost", # 2024-04-07 pragma- libera.chat
|
||||
379 => "whoismodes", # UnrealIrcd, Hendrik Frenzel
|
||||
381 => "youreoper",
|
||||
382 => "rehashing",
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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');
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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');
|
||||
|
||||
|
@ -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 {}
|
||||
|
Loading…
Reference in New Issue
Block a user