diff options
author | erdgeist <> | 2005-07-20 02:10:54 +0000 |
---|---|---|
committer | erdgeist <> | 2005-07-20 02:10:54 +0000 |
commit | 5238b3353737d9fa1892bd74b80909750daf3505 (patch) | |
tree | 7c62c9da9afea32b49a6913c977646f49bd1d848 | |
parent | e8bf97b4a633d84ec13dafc6c5d1e72e1f1ac07c (diff) |
Auf ein Neues
-rw-r--r-- | bot.pl | 119 |
1 files changed, 119 insertions, 0 deletions
@@ -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 | |||
21 | use strict; | ||
22 | |||
23 | use POE; | ||
24 | use POE::Component::IRC; | ||
25 | |||
26 | POE::Component::IRC->new("irc_client"); | ||
27 | |||
28 | POE::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 | |||
38 | sub 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 | |||
56 | sub irc_connect { | ||
57 | my $kernel = $_[KERNEL]; | ||
58 | |||
59 | $kernel->post(irc_client=>join=>'#kiffer.de'); | ||
60 | } | ||
61 | |||
62 | sub irc_motd { | ||
63 | my $msg = $_[ARG1]; | ||
64 | |||
65 | print "MOTD: $msg\n"; | ||
66 | } | ||
67 | |||
68 | sub 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 | ||
78 | sub 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 | ||
86 | sub 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 | ||
94 | sub 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 | ||
102 | sub irc_quit { | ||
103 | my $nick = $_[ARG0]; | ||
104 | my $reason = $_[ARG1]; | ||
105 | |||
106 | print "#-> $nick has quit ($reason)\n"; | ||
107 | } | ||
108 | |||
109 | sub 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(); | ||