summaryrefslogtreecommitdiff
path: root/bot.pl
diff options
context:
space:
mode:
Diffstat (limited to 'bot.pl')
-rw-r--r--bot.pl119
1 files changed, 119 insertions, 0 deletions
diff --git a/bot.pl b/bot.pl
new file mode 100644
index 0000000..486765f
--- /dev/null
+++ b/bot.pl
@@ -0,0 +1,119 @@
1#!/usr/bin/perl
2#
3# ircbot.pl written by detour@metalshell.com
4#
5# This irc bot will handle and print the motd, users on a channel
6# joins, parts, quits, nick changes, and public msgs's.
7#
8# You can bind a sub to any numeric reply by using irc_<num>.
9# For example 376 is the RPL_ENDOFMOTD, so to catch this response
10# you add irc_376 => \&your_sub to your session.
11#
12# This requires that you have POE and POE::Component::IRC
13# installed. A simple way to do this is using the cpan module.
14# perl -MCPAN -eshell
15# cpan> install POE
16# cpan> install POE::Component::IRC
17#
18# http://www.metalshell.com
19
20
21use strict;
22
23use POE;
24use POE::Component::IRC;
25
26POE::Component::IRC->new("irc_client");
27
28POE::Session->new ( _start => \&irc_start,
29 irc_join => \&irc_join,
30 irc_part => \&irc_part,
31 irc_nick => \&irc_nick,
32 irc_quit => \&irc_quit,
33 irc_376 => \&irc_connect, #end of motd
34 irc_372 => \&irc_motd,
35 irc_353 => \&irc_names,
36 irc_public => \&irc_pub_msg, );
37
38sub irc_start {
39 # KERNEL, HEAP, and SESSION are constants exported by POE
40 my $kernel = $_[KERNEL];
41 my $heap = $_[HEAP];
42 my $session = $_[SESSION];
43
44 $kernel->refcount_increment( $session->ID(), "my bot");
45 $kernel->post(irc_client=> register=> "all");
46
47 $kernel->post(irc_client=>connect=> { Nick => 'francoise',
48 Username => 'francoise',
49 Ircname => 'francoise',
50 Server => 'irc.kiffer.de',
51 Port => '6667',
52 }
53 );
54}
55
56sub irc_connect {
57 my $kernel = $_[KERNEL];
58
59 $kernel->post(irc_client=>join=>'#kiffer.de');
60}
61
62sub irc_motd {
63 my $msg = $_[ARG1];
64
65 print "MOTD: $msg\n";
66}
67
68sub irc_names {
69 my $names = (split /:/, $_[ARG1])[1];
70 my $channel = (split /:/, $_[ARG1])[0];
71
72 $channel =~ s/[@|=] (.*?) /$1/;
73
74 print "#-> Users on $channel [ $names ]\n";
75}
76
77#nick change
78sub irc_nick {
79 my $oldnick = (split /!/, $_[ARG0])[0];
80 my $newnick = $_[ARG1];
81
82 print "#-> $oldnick is now known as $newnick\n";
83}
84
85#user parted
86sub irc_part {
87 my $nick = (split /!/, $_[ARG0])[0];
88 my $channel = $_[ARG1];
89
90 print "#-> $nick has parted $channel\n";
91}
92
93#user joined
94sub irc_join {
95 my $nick = (split /!/, $_[ARG0])[0];
96 my $channel = $_[ARG1];
97
98 print "#-> $nick has joined $channel\n";
99}
100
101#user quit
102sub irc_quit {
103 my $nick = $_[ARG0];
104 my $reason = $_[ARG1];
105
106 print "#-> $nick has quit ($reason)\n";
107}
108
109sub irc_pub_msg{
110 my $kernel = $_[KERNEL];
111 my $nick = (split /!/, $_[ARG0])[0];
112 my $channel = $_[ARG1]->[0];
113 my $msg = $_[ARG2];
114
115 print "$channel: <$nick> $msg\n";
116}
117
118#start everything
119$poe_kernel->run();