Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- # This is a simple IRC bot that just rot13 encrypts public messages.
- # It responds to "rot13 <text to encrypt>".
- use warnings;
- use strict;
- use POE;
- use POE::Component::IRC;
- use POE::Component::IRC::Common qw(matches_mask_array);
- # Create the component that will represent an IRC network.
- my ($irc) = POE::Component::IRC->spawn();
- my %usermodes = (
- '*!*@Raltharg.users.quakenet.org' => 'o',
- );
- # Create the bot session. The new() call specifies the events the bot
- # knows about and the functions that will handle those events.
- POE::Session->create(
- inline_states => {
- _start => \&bot_start,
- irc_001 => \&on_connect,
- irc_public => \&on_public,
- irc_join => \&on_join,
- },
- );
- # The bot session has started. Register this bot with the "magnet"
- # IRC component. Select a nickname. Connect to a server.
- sub bot_start {
- $irc->yield(register => "all");
- my $nick = 'TheCynicalBot';
- $irc->yield(
- connect => {
- Nick => $nick,
- Username => 'TheCynicalBot',
- Ircname => 'A Very Cynical Bot',
- Server => 'localhost',
- Port => '10001',
- Password => '*********',
- }
- );
- }
- # The bot has successfully connected to a server. Join a channel.
- sub on_connect {
- $irc->yield(join => '#cynicalbrit');
- }
- # The bot has received a public message. Parse it for commands, and
- # respond to interesting things.
- sub on_public {
- my ($kernel, $who, $where, $msg) = @_[KERNEL, ARG0, ARG1, ARG2];
- my $nick = (split /!/, $who)[0];
- my $channel = $where->[0];
- my $ts = scalar localtime;
- print " [$ts] <$nick:$channel> $msg\n";
- }
- sub on_join {
- my ($kernel, $who, $channel) = @_[KERNEL, ARG0, ARG1];
- my $nick = (split /!/, $who)[0];
- my $msg = 'Joined';
- my $ts = scalar localtime;
- print " [$ts] $who $msg $channel\n";
- my @matches = matches_mask_array(keys(%usermodes), [$who]);
- print "matches = @matches\n";
- foreach my $match (@matches) {
- print "/mode $channel $nick $usermodes{$match}\n";
- $irc->yield(mode => $channel => $nick => $usermodes{$match$
- }
- }
- # Run the bot until it is done.
- $poe_kernel->run();
- exit 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement