Today I reworked my IRC setup and found out about irssi scripts.
I HAD to write this one:
# Polygen # # Runs polygen when asked # # usage # # Anyone in the same channel as the one who runs this script may ask me: # !polygen <grammar> # And I'll automatically reply with the proper output. # # Script features include help, and avoiding flood if polygen generates too # much output. # # Based on the /usr/share/irssi/scripts/8-ball.pl script written by Patrik # Jansson. # use strict; use vars qw($VERSION %IRSSI); use Irssi qw(command_bind signal_add); use IO::File; $VERSION = '0.20'; %IRSSI = ( author => 'Enrico Zini', contact => 'enrico@enricozini.org', name => 'polygen', description => 'Runs polygen for you', license => 'GPL', ); sub run_polygen ($) { my ($arg) = @_; my $res = `polygen $arg 2>/dev/null | fmt`; chomp $res; return "Sorry, I could not find the grammar $arg (you can see a list in the polygen-data(6) manpage)." if $res eq ''; my @lines = split("\n", $res); return join(" ", @lines[0..2])." [...]" if @lines > 3; return $res; } 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; s/^enrico_*:\s*//; if (!/^!poly/i) { return 0; } if (/^!poly\w+\s+(\w+)\s*$/i) { my $answer = run_polygen($1); $server->command('msg '.$target.' '.$nick.$answer); return 0; } elsif (/^!poly\w+\s*version$/i){ $server->command('msg '.$target.' My version is: '.$VERSION); return 0; } else { my $answer = "What ".run_polygen('polygen')." grammar do you want? (you can see a list in the polygen-data(6) manpage)"; $server->command('msg '.$target.' '.$nick.$answer); return 0; } } signal_add("message public", "public_question"); signal_add("message own_public", "own_question");