-
Notifications
You must be signed in to change notification settings - Fork 6
/
irc_bot.pl
68 lines (59 loc) · 1.53 KB
/
irc_bot.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/perl
# vim:ft=perl
# IRC bot
# (C) 2014 Adam Ziaja <[email protected]> http://adamziaja.com
use warnings;
use strict;
# apt-get install -y libemail-sender-perl
use Email::Sender::Simple qw(sendmail);
use Email::Simple;
use Email::Simple::Creator;
sub alert {
my ($body) = @_;
my $email = Email::Simple->create(
header => [
To => '<master@bot>',
From => '<irc@bot>',
Subject => 'IRC',
],
body => $body,
);
main::sendmail($email);
}
# apt-get remove --purge libbot-basicbot-perl
# apt-get install -y build-essential
# cpan> install Bot::BasicBot
package MyBot;
use base qw( Bot::BasicBot );
# wywoływane kiedy ktoś coś napisze w zasięgu bota
sub said {
my ( $self, $message ) = @_;
if ( $message->{body} =~ /\bperl\b/ ) {
my $body = $message->{channel};
$body .= " <" . $message->{who} . "> ";
$body .= $message->{body} . "\n";
main::alert($body);
}
return;
}
# wywoływane kiedy ktoś zostanie wykopany
sub kicked {
my ( $self, $kicked ) = @_;
# jeśli wykopany został bot
if ( $self->nick eq $kicked->{kicked} ) {
my $body = $kicked->{channel};
$body .= " " . $kicked->{who};
main::alert($body);
$self->join( $kicked->{channel} );
}
return;
}
my $nick = 'bot';
MyBot->new(
server => 'irc.freenode.net',
channels => ['#channel'],
username => $nick,
name => $nick,
nick => $nick . $$,
#alt_nicks => [ '', '' ],
)->run();