1
0
Fork 0
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

102 lines
2.5 KiB
Perl

#!/usr/bin/perl
use Net::IRC;
use Data::Dumper;
use strict;
my $irc = new Net::IRC;
my $mynick = "puddingbrumsel";
my $conn = $irc->newconn(Nick => "$mynick",
Server => shift || 'irc.belwue.de');
$conn->{channel} = shift || "!6ZVX3puddingtest";
$conn->{lastpudding} = time();
$conn->{specialwday} = 0;
# hmm, pudding!
sub pudding {
my $pudding;
if (rand(4) > 3) {
$pudding = "hmm, ",
} elsif (rand(4) > 3) {
$pudding = "ah, ",
}
if (rand(4) > 3) {
$pudding = "mehr ",
} elsif (rand(4) > 3) {
$pudding = "viel ",
}
my (undef, undef, undef, undef, undef, undef, $wday) = localtime(time());
if ($wday == $conn->{specialwday}) {
my @foo = ( "spinat", "wirsing", "eisbein", "sauerkraut", "tomaten", "hafer" );
$pudding .= $foo[int(rand($#foo))];
}
$pudding .= "pudding";
if (rand(4) > 3) {
$pudding .= "!";
} elsif (rand(4) > 3) {
$pudding .= "?";
} else {
$pudding .= ".";
}
my $brums = "*brums*";
if (rand(4) > 3) {
$brums .= " *brums*";
}
if ($wday == $conn->{specialwday}) {
$brums .= " *brums*";
}
if (rand(5) > 4) {
$brums .= " :)";
}
return "$pudding $brums";
}
# What to do when the bot successfully connects.
sub on_connect {
my $conn = shift;
print "Joining $conn->{channel}...\n";
$conn->join($conn->{channel});
$conn->privmsg($conn->{channel}, pudding);
}
$conn->add_handler('376', \&on_connect);
sub on_msg {
my ($conn, $event) = @_;
if ($event->{to}[0] eq $conn->{channel}) {
my $nick = $event->{nick};
my $text = $event->{args}[0];
if ($nick ne $mynick && ($text =~ /pudding/ || $text =~ /brums/)) {
print Dumper($event);
my $wait = 300;
if (time() > $conn->{lastpudding} + $wait) {
sleep(rand(30));
print "=> $conn->{channel}\n";
$conn->privmsg($conn->{channel}, "$nick: " . pudding);
$conn->{lastpudding} = time();
}
} else {
my $wait = 24 * 3600 * (0.5 + 0.5*rand());
my (undef, undef, undef, undef, undef, undef, $wday) = localtime(time());
if ($wday == $conn->{specialwday}) {
$wait = 6 * 3600 * (0.5 + 0.5*rand());
}
if (time() > $conn->{lastpudding} + $wait) {
print "=> $conn->{channel}\n";
$conn->privmsg($conn->{channel}, pudding);
$conn->{lastpudding} = time();
}
}
} else {
sleep(rand(30));
print "=> $event->{nick}\n";
$conn->privmsg($event->{nick}, pudding);
}
}
$conn->add_handler('msg', \&on_msg);
$irc->start;