0

Compare commits

..

3 Commits

Author SHA1 Message Date
Sergei Fedosov
8a28f01992 Implemented !coin !монетка !roll !dies !кости commands 2021-08-11 15:32:08 +03:00
Sergei Fedosov
952e509e92 Fix url handling in answer 2021-08-06 14:16:49 +03:00
Sergei Fedosov
eecb73a718 Re-Join on kick 2021-08-06 12:53:27 +03:00
5 changed files with 88 additions and 5 deletions

View File

@@ -598,7 +598,7 @@ sub say {
for my $s (@_) {
if ($s =~ /^PRIVMSG /) {
foreach my $buf (split_irc_msg ($s)) {
foreach my $buf (split_irc_msg ($self, $s)) {
my $string = $buf;
_utf8_off ($buf);
$self->{socket}->syswrite( $buf . "\r\n");
@@ -681,6 +681,7 @@ sub health {
}
sub split_irc_msg {
my $self = shift;
my $str = shift;
chomp $str;
@@ -701,8 +702,13 @@ sub split_irc_msg {
$prefix = CORE::join ':', @message;
$prefix .= ':';
} else {
$prefix = CORE::join ':', @message;
$prefix .= ', ';
if ($message [1] eq $self->{nick} || $message [1] eq $self->{in}->{nick}) {
$prefix = CORE::join ':', @message;
$prefix .= ', ';
} else {
$prefix = CORE::join ':', @message;
$prefix .= ':';
}
}
$MAXLEN = $MAXLEN - bytes::length ($prefix) - 100;

View File

@@ -140,7 +140,7 @@ sub init {
},
);
$bot->helps(
$bot->helps (
anek => "$c->{csign}anek - рандомный анекдот с anekdot.ru",
анек => "$c->{csign}анек - рандомный анекдот с anekdot.ru",
анекдот => "$c->{csign}анекдот - рандомный анекдот с anekdot.ru",
@@ -149,7 +149,12 @@ sub init {
rabbit => "$c->{csign}rabbit - рандомный кролик",
кролик => "$c->{csign}кролик - рандомный кролик",
cat => "$c->{csign}cat - рандомная кошечка",
coin => "$c->{csign}cat - подбросить монетку - орёл или решка?",
монетка => "$c->{csign}cat - подбросить монетку - орёл или решка?",
кис => "$c->{csign}кис - рандомная кошечка",
dice => "$c->{csign}dice - бросить кости",
roll => "$c->{csign}roll - бросить кости",
кости => "$c->{csign}кости - бросить кости",
dig => "$c->{csign}dig - заняться археологией",
копать => "$c->{csign}копать - заняться археологией",
drink => "$c->{csign}drink - какой сегодня праздник?",

52
lib/Bot/IRC/ReJoin.pm Normal file
View File

@@ -0,0 +1,52 @@
package Bot::IRC::ReJoin;
# Re-Join to channel on /kick
use 5.018;
use strict;
use warnings;
use utf8;
use open qw (:std :utf8);
use English qw ( -no_match_vars );
use Encode qw (_utf8_on);
our $VERSION = '1.35'; # VERSION
# Most gears are spinning here.
sub init {
my ($bot) = @_;
$bot->hook (
{
command => 'KICK',
},
sub {
my $bot = shift;
my $msg = shift;
# fix some utf8 flags, that are lost
_utf8_on $msg->{forum};
_utf8_on $msg->{full_text};
_utf8_on $msg->{user};
my ($who, $why) = split / \:/, $msg->{text}, 2;
if ($who eq $bot->{nick}) {
$bot->note ("I was kicked from $msg->{forum} by $msg->{nick} with reason $why");
sleep 5;
$bot->join ($msg->{forum});
$bot->note ("Re-joining to $msg->{forum}");
}
return 1;
},
);
return 1;
}
1;
__END__
# vim: set ft=perl noet ai ts=4 sw=4 sts=4:

View File

@@ -60,6 +60,26 @@ sub Command {
$reply = Weather ($city) =~ tr/\n/ /r;
} elsif (substr ($text, 1) eq 'anek' || substr ($text, 1) eq 'анек' || substr ($text, 1) eq 'анекдот' ) {
$reply = Anek ();
} elsif (substr ($text, 1) eq 'coin' || substr ($text, 1) eq 'монетка') {
if (rand (101) < 0.016) {
$reply = "ребро";
} else {
if (irand (2) == 0) {
if (irand (2) == 0) {
$reply = 'орёл';
} else {
$reply = 'аверс';
}
} else {
if (irand (2) == 0) {
$reply = 'решка';
} else {
$reply = 'реверс';
}
}
}
} elsif (substr ($text, 1) eq 'roll' || substr ($text, 1) eq 'dice' || substr ($text, 1) eq 'кости') {
$reply = sprintf "На первой кости выпало %d, а на второй — %d.", irand (6) + 1, irand (6) + 1;
} elsif (substr ($text, 1) eq 'version' || substr ($text, 1) eq 'ver') {
$reply = 'Версия нуль.чего-то_там.чего-то_там';
} elsif (substr ($text, 1) eq 'help' || substr ($text, 1) eq 'помощь') {

View File

@@ -36,7 +36,7 @@ sub RunIRCBot {
},
);
$bot->load ('OnMessage'); # our main plugin that handles all the incomming messages, mostly
$bot->load ('OnMessage', 'ReJoin'); # our main plugin that handles all the incomming messages, mostly
$bot->helps(
about => 'I am just another chatty bot.',
);