From 5238b3353737d9fa1892bd74b80909750daf3505 Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Wed, 20 Jul 2005 02:10:54 +0000 Subject: Auf ein Neues --- bot.pl | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 bot.pl diff --git a/bot.pl b/bot.pl new file mode 100644 index 0000000..486765f --- /dev/null +++ b/bot.pl @@ -0,0 +1,119 @@ +#!/usr/bin/perl +# +# ircbot.pl written by detour@metalshell.com +# +# This irc bot will handle and print the motd, users on a channel +# joins, parts, quits, nick changes, and public msgs's. +# +# You can bind a sub to any numeric reply by using irc_. +# For example 376 is the RPL_ENDOFMOTD, so to catch this response +# you add irc_376 => \&your_sub to your session. +# +# This requires that you have POE and POE::Component::IRC +# installed. A simple way to do this is using the cpan module. +# perl -MCPAN -eshell +# cpan> install POE +# cpan> install POE::Component::IRC +# +# http://www.metalshell.com + + +use strict; + +use POE; +use POE::Component::IRC; + +POE::Component::IRC->new("irc_client"); + +POE::Session->new ( _start => \&irc_start, + irc_join => \&irc_join, + irc_part => \&irc_part, + irc_nick => \&irc_nick, + irc_quit => \&irc_quit, + irc_376 => \&irc_connect, #end of motd + irc_372 => \&irc_motd, + irc_353 => \&irc_names, + irc_public => \&irc_pub_msg, ); + +sub irc_start { + # KERNEL, HEAP, and SESSION are constants exported by POE + my $kernel = $_[KERNEL]; + my $heap = $_[HEAP]; + my $session = $_[SESSION]; + + $kernel->refcount_increment( $session->ID(), "my bot"); + $kernel->post(irc_client=> register=> "all"); + + $kernel->post(irc_client=>connect=> { Nick => 'francoise', + Username => 'francoise', + Ircname => 'francoise', + Server => 'irc.kiffer.de', + Port => '6667', + } + ); +} + +sub irc_connect { + my $kernel = $_[KERNEL]; + + $kernel->post(irc_client=>join=>'#kiffer.de'); +} + +sub irc_motd { + my $msg = $_[ARG1]; + + print "MOTD: $msg\n"; +} + +sub irc_names { + my $names = (split /:/, $_[ARG1])[1]; + my $channel = (split /:/, $_[ARG1])[0]; + + $channel =~ s/[@|=] (.*?) /$1/; + + print "#-> Users on $channel [ $names ]\n"; +} + +#nick change +sub irc_nick { + my $oldnick = (split /!/, $_[ARG0])[0]; + my $newnick = $_[ARG1]; + + print "#-> $oldnick is now known as $newnick\n"; +} + +#user parted +sub irc_part { + my $nick = (split /!/, $_[ARG0])[0]; + my $channel = $_[ARG1]; + + print "#-> $nick has parted $channel\n"; +} + +#user joined +sub irc_join { + my $nick = (split /!/, $_[ARG0])[0]; + my $channel = $_[ARG1]; + + print "#-> $nick has joined $channel\n"; +} + +#user quit +sub irc_quit { + my $nick = $_[ARG0]; + my $reason = $_[ARG1]; + + print "#-> $nick has quit ($reason)\n"; +} + +sub irc_pub_msg{ + my $kernel = $_[KERNEL]; + my $nick = (split /!/, $_[ARG0])[0]; + my $channel = $_[ARG1]->[0]; + my $msg = $_[ARG2]; + + print "$channel: <$nick> $msg\n"; +} + +#start everything +$poe_kernel->run(); -- cgit v1.2.3