1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
|
#!/usr/bin/perl -w
#
# irctest
# Sample Net::IRC script that starts a vapid little annoybot.
# Please don't test your bots in #perl... we are easily annoyed.
#
use strict;
use Net::IRC;
#
# Create the IRC and Connection objects
#
my $irc = new Net::IRC;
print << 'INIT_WARN';
+------------------------------------------------------------
| IMPORTANT NOTE
|
| Running this script might constitute a severe security risk
| This script will send ANY FILE it is requested as a response
| to the message 'Send me <filename>'
|
| You have been warned.
+------------------------------------------------------------
(sleeping for two seconds)
INIT_WARN
sleep 2;
print "Creating connection to IRC server...\n";
my $conn = $irc->newconn(Server => ($ARGV[0] || 'irc.prison.net'),
Port => 6667,
Nick => 'Boolahman',
Ircname => 'This bot brought to you by Net::IRC.',
Username => 'quetzal')
or die "irctest: Can't connect to IRC server.\n";
#
# Here's some stuff to print at odd moments.
#
my @zippy = (
"I am a traffic light, and Alan Ginsberg kidnapped my laundry in 1927!",
"I'm a GENIUS! I want to dispute sentence structure with SUSAN SONTAG!!",
"Now I'm telling MISS PIGGY about MONEY MARKET FUNDS!",
"I have a VISION! It's a RANCID double-FISHWICH on an ENRICHED BUN!!",
"My pants just went on a wild rampage through a Long Island Bowling Alley!!",
"I always liked FLAG DAY!!",
"I will establish the first SHOPPING MALL in NUTLEY, New Jersey...",
"I used to be STUPID, too..before I started watching UHF-TV!!",
"I smell like a wet reducing clinic on Columbus Day!",
"Just walk along and try NOT to think about your INTESTINES being almost FORTY YARDS LONG!!",
"It's the RINSE CYCLE!! They've ALL IGNORED the RINSE CYCLE!!",
"Yow! It's some people inside the wall! This is better than mopping!",
"Is the EIGHTIES when they had ART DECO and GERALD McBOING-BOING lunch boxes??",
"This PIZZA symbolizes my COMPLETE EMOTIONAL RECOVERY!!",
"I call it a \"SARDINE ON WHEAT\"!",
"Is it FUN to be a MIDGET?",
"Someone in DAYTON, Ohio is selling USED CARPETS to a SERBO-CROATIAN!!",
);
#
# Here are the handler subroutines. Fascinating, huh?
#
# What to do when the bot successfully connects.
sub on_connect {
my $self = shift;
print "Joining #IRC.pm...\n";
$self->join("#net-irc2");
$self->privmsg("#net-irc2", &pickrandom());
$self->topic("#net-irc2");
}
# Handles some messages you get when you connect
sub on_init {
my ($self, $event) = @_;
my (@args) = ($event->args);
shift (@args);
print "*** @args\n";
}
# What to do when someone leaves a channel the bot is on.
sub on_part {
my ($self, $event) = @_;
my ($channel) = ($event->to)[0];
printf "*** %s has left channel %s\n", $event->nick, $channel;
}
# What to do when someone joins a channel the bot is on.
sub on_join {
my ($self, $event) = @_;
my ($channel) = ($event->to)[0];
printf "*** %s (%s) has joined channel %s\n",
$event->nick, $event->userhost, $channel;
if ($event->userhost =~ /^corbeau\@.*execpc\.com/) { # Auto-ops anyone who
$self->mode("#IRC.pm", "+o", $event->nick); # matches hostmask.
}
}
# What to do when we receive a private PRIVMSG.
sub on_msg {
my ($self, $event) = @_;
my ($nick) = $event->nick;
print "*$nick* ", ($event->args), "\n";
# $self->privmsg($nick, &pickrandom()); # Say a Zippy quote.
}
# What to do when we receive channel text.
sub on_public {
my ($self, $event) = @_;
my @to = $event->to;
my ($nick, $mynick) = ($event->nick, $self->nick);
my ($arg) = ($event->args);
# Note that $event->to() returns a list (or arrayref, in scalar
# context) of the message's recipients, since there can easily be
# more than one.
print "<$nick> $arg\n";
if ($arg =~ /$mynick/i) { # Say a Zippy quote if our nick
$self->privmsg([ @to ], &pickrandom()); # appears in the message.
}
if ($arg =~ /Go away/i) { # Tell him to leave, and he does.
$self->quit("Yow!!");
exit 0;
}
if ($arg =~ /^chat/i) { # Request a DCC Chat initiation
$self->new_chat(1, $event->nick, $event->host);
}
# You can invoke this next part with "Send me Filename" or
# "Send Filename to me". It doesn't much like ending punctuation, though.
$arg =~ s/[^"'\w]*?\b(to|me)\b[^'"\w]*?//g;
if ($arg =~ /^send\s+(\S+)\s*/i) {
if (-e $1) {
$self->privmsg($nick, "Sending $1 in 10 seconds...");
$self->schedule(10, \&Net::IRC::Connection::new_send, $nick, $1);
} else {
$self->privmsg($nick, "No such file as $1, sorry.");
}
}
}
sub on_umode {
my ($self, $event) = @_;
my @to = $event->to;
my ($nick, $mynick) = ($event->nick, $self->nick);
my ($arg) = ($event->args);
# Note that $event->to() returns a list (or arrayref, in scalar
# context) of the message's recipients, since there can easily be
# more than one.
print "<$nick> $arg\n";
if ($arg =~ /$mynick/i) { # Say a Zippy quote if our nick
$self->privmsg([ @to ], &pickrandom()); # appears in the message.
}
if ($arg =~ /Go away/i) { # Tell him to leave, and he does.
$self->quit("Yow!!");
exit 0;
}
if ($arg =~ /^chat/i) { # Request a DCC Chat initiation
$self->new_chat(1, $event->nick, $event->host);
}
# You can invoke this next part with "Send me Filename" or
# "Send Filename to me". It doesn't much like ending punctuation, though.
$arg =~ s/[^"'\w]*?\b(to|me)\b[^'"\w]*?//g;
if ($arg =~ /^send\s+(\S+)\s*/i) {
if (-e $1) {
$self->privmsg($nick, "Sending $1 in 10 seconds...");
$self->schedule(10, \&Net::IRC::Connection::new_send, $nick, $1);
} else {
$self->privmsg($nick, "No such file as $1, sorry.");
}
}
}
# What to do when we receive a message via DCC CHAT.
sub on_chat {
my ($self, $event) = @_;
my ($sock) = ($event->to)[0];
print '*' . $event->nick . '* ' . join(' ', $event->args), "\n";
$self->privmsg($sock, &pickrandom()); # Say a Zippy quote.
}
# Prints the names of people in a channel when we enter.
sub on_names {
my ($self, $event) = @_;
my (@list, $channel) = ($event->args); # eat yer heart out, mjd!
# splice() only works on real arrays. Sigh.
($channel, @list) = splice @list, 2;
print "Users on $channel: @list\n";
}
# What to do when we receive a DCC SEND or CHAT request.
sub on_dcc {
my ($self, $event) = @_;
my $type = ($event->args)[1];
if (uc($type) eq 'SEND') {
open TEST, ">/tmp/net-irc.dcctest"
or do { warn "Can't open test file: $!"; return; };
$self->new_get($event, \*TEST);
print "Saving incoming DCC SEND to /tmp/net-irc.dcctest\n";
} elsif(uc($type) eq 'CHAT') {
$self->new_chat($event);
} else {
print STDERR ("Unknown DCC type: " . $type);
}
}
# Yells about incoming CTCP PINGs.
sub on_ping {
my ($self, $event) = @_;
my $nick = $event->nick;
$self->ctcp_reply($nick, join (' ', ($event->args)));
print "*** CTCP PING request from $nick received\n";
}
# Gives lag results for outgoing PINGs.
sub on_ping_reply {
my ($self, $event) = @_;
my ($args) = ($event->args)[1];
my ($nick) = $event->nick;
$args = time - $args;
print "*** CTCP PING reply from $nick: $args sec.\n";
}
# Change our nick if someone stole it.
sub on_nick_taken {
my ($self) = shift;
$self->nick(substr($self->nick, -1) . substr($self->nick, 0, 8));
}
# Display formatted CTCP ACTIONs.
sub on_action {
my ($self, $event) = @_;
my ($nick, @args) = ($event->nick, $event->args);
print "* $nick @args\n";
}
# Reconnect to the server when we die.
sub on_disconnect {
my ($self, $event) = @_;
print "Disconnected from ", $event->from(), " (",
($event->args())[0], "). Attempting to reconnect...\n";
$self->connect();
}
# Look at the topic for a channel you join.
sub on_topic {
my ($self, $event) = @_;
my @args = $event->args();
# Note the use of the same handler sub for different events.
if ($event->type() eq 'notopic') {
print "No topic set for $args[1].\n";
# If it's being done _to_ the channel, it's a topic change.
} elsif ($event->type() eq 'topic' and $event->to()) {
print "Topic change for ", $event->to(), ": $args[0]\n";
} else {
print "The topic for $args[1] is \"$args[2]\".\n";
}
}
sub pickrandom { # Choose a random quote from the @zippy array.
return $zippy[ rand scalar @zippy ];
}
sub blah {
my ($self, $event) = @_;
print "Got event of type: " . $event->type . "\n";
}
print "Installing handler routines...";
#$conn->add_default_handler(\&blah);
$conn->add_handler('cping', \&on_ping);
$conn->add_handler('crping', \&on_ping_reply);
$conn->add_handler('msg', \&on_msg);
$conn->add_handler('chat', \&on_chat);
$conn->add_handler('public', \&on_public);
$conn->add_handler('caction', \&on_action);
$conn->add_handler('join', \&on_join);
$conn->add_handler('umode', \&on_umode);
$conn->add_handler('part', \&on_part);
$conn->add_handler('cdcc', \&on_dcc);
$conn->add_handler('topic', \&on_topic);
$conn->add_handler('notopic', \&on_topic);
$conn->add_global_handler([ 251,252,253,254,302,255 ], \&on_init);
$conn->add_global_handler('disconnect', \&on_disconnect);
$conn->add_global_handler(376, \&on_connect);
$conn->add_global_handler(433, \&on_nick_taken);
$conn->add_global_handler(353, \&on_names);
print " done.\n";
print "starting...\n";
$irc->start;
|