#!/usr/bin/perl use strict; use warnings; package GreetBot; use base qw(Bot::BasicBot); sub chanjoin { my $self = shift; my $arguments = shift; my $nick = $arguments->{who}; if ($nick eq $self->pocoirc->nick_name()) { return; } $self->say( channel => $arguments->{channel}, body => "Welcome, $nick!", ); } sub chanpart { my $self = shift; my $arguments = shift; $self->say( channel => $arguments->{channel}, body => "I'm sad to see $arguments->{who} go.", ); } sub emoted { my $self = shift; my $arguments = shift; $self->emote( channel => $arguments->{channel}, body => "$arguments->{body} too", ); } sub noticed { my $self = shift; my $arguments = shift; my $nick = $arguments->{who}; my @notices = ( "$nick, please resend this in a normal message", "I'm having a hard time reading your notice.", "Good point, $nick.", "Can you message on the public channel instead?", ); $self->notice( who => $nick, channel => $arguments->{channel}, body => $notices[int(rand(4))], ); } sub topic { my $self = shift; my $arguments = shift; if ($arguments->{who} eq $self->pocoirc->nick_name()) { return; } $self->pocoirc->yield('topic' => $arguments->{channel} => "$arguments->{topic} || Don't change the topic!"); } sub nick_change { my $self = shift; my $oldnick = shift; my $newnick = shift; if ($newnick eq $self->pocoirc->nick_name()) { return; } $self->pocoirc->yield('nick' => "$oldnick"); $self->say( who => "$newnick", body => "If you don't mind, I'd like to use your old nick.", ); } package main; my $bot = GreetBot->new( server => 'irc.example.com', port => '6667', channels => ['#perl102'], nick => 'nickname', name => 'username', ); $bot->run();