Last active
June 18, 2016 22:45
-
-
Save MikeRixWolfe/33281dea073e14ba3625 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use vars qw($VERSION %IRSSI); | |
use Irssi; | |
$VERSION = '0.9'; | |
%IRSSI = ( | |
authors => 'Mike Wolfe', | |
contact => '[email protected]', | |
name => 'salute', | |
description => 'This script salutes', | |
license => 'GPLv3', | |
); | |
my @chans = qw/#geekboy/; | |
my @ignores = qw/M2 Nextrastout extrastout/; | |
my %chanhash = map { $_ => 1 } @chans; | |
my %ignorehash = map { $_ => 1 } @ignores; | |
sub load_salute { | |
if (-s "$ENV{HOME}/.irssi/last_salute") { | |
open HANDLER, "$ENV{HOME}/.irssi/last_salute"; | |
my $last_salute = <HANDLER>; | |
close HANDLER; | |
return $last_salute; | |
} | |
return 0; | |
} | |
sub save_salute { | |
open HANDLER, ">$ENV{HOME}/.irssi/last_salute"; | |
print HANDLER time(); | |
close HANDLER; | |
} | |
sub do_salute { | |
my ($server, $target, $fn, $ln, $hn) = @_; | |
my $last_salute = load_salute(); | |
if (time() - $last_salute > 600) { # Don't spam a legitimate conversation too much | |
sleep(int(rand(5))+2); # Humanize it a little, for fun | |
if ($fn) { | |
$server->command("ACTION " . $target . " salutes " . $hn . " Lee " . ucfirst($ln)); | |
} else { | |
$server->command("ACTION " . $target . " salutes " . $hn . " " . ucfirst($ln)); | |
} | |
save_salute(); | |
} | |
} | |
sub sig_message_public { | |
my ($server, $msg, $nick, $nick_addr, $target) = @_; | |
if (exists($chanhash {$target}) && !exists($ignorehash {$nick})) { | |
$msg =~ s/[[:punct:]]//g; | |
if ($msg =~ m/bot roll call/i) { | |
$server->command("ACTION " . $target . " salutes " . $nick); | |
} else { | |
my ($fn, $ln) = ($msg =~ m/.*?general(ly)? (\S+).*?/i); | |
if ($ln && length($ln) > 3) { # General I and General You are no fun | |
do_salute($server, $target, $fn, $ln, "General"); | |
} else { | |
($fn, $ln) = ($msg =~ m/.*?major(ly)? (\S+).*?/i); | |
if ($ln) { | |
do_salute($server, $target, $fn, $ln, "Major"); | |
} | |
} | |
} | |
} | |
} | |
Irssi::signal_add 'message public', 'sig_message_public'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment