Irssi Plugin: auto reply
Written on September 15th 2009, 16:09 by sYnie
Some days ago I wrote a small irssi plugin, which automatically replies to specific words or phrases. It’s really basic, but I thought to post it anyway, as I couldn’t find any.
It’s based on the 8-ball plugin – so thanks to Patrik Jansson.
That’s the code:
use strict;
use vars qw($VERSION %IRSSI);
use Irssi qw(command_bind signal_add);
$VERSION = '1.00';
%IRSSI = (
authors => 'synie',
name => 'auto reply',
description => 'auto reply',
license => 'GPL',
);
sub own_question {
my ($server, $msg, $target) = @_;
question($server, $msg, "", $target);
}
sub public_question {
my ($server, $msg, $nick, $address, $target) = @_;
question($server, $msg, $nick, $target);
}
sub question($server, $msg, $nick, $target) {
my ($server, $msg, $nick, $target) = @_;
$_ = $msg;
my $answer = "";
// Edit this:
if (/^how are you?/i) {
$answer = "I'm fine, thanks.";
} elsif (/ping/i) {
$answer = "pong";
} elsif (/^I hate you/i) {
if ($nick ne "fishbot" and $nick ne "snailbot")
{
$server->command('kick '.$target.' '.$nick.' bye!');
return 0;
}
}
if ($answer)
{
$server->command('msg '.$target.' '.($nick ? $nick.': ' : '').$answer);
}
return 0;
}
signal_add("message public", "public_question");
signal_add("message own_public", "own_question");
Just c&p it into a file (e.g. called autoreply) located at ~/.irssi/scripts or ~/.irssi/scripts/autorun and load it via `/script load autoreply`. Make sure you edited the phrases you want to answer to automatically first – but I think this script is self-explanatory.
