Skip to content

Instantly share code, notes, and snippets.

@mattbailey
Created May 31, 2012 21:56
Show Gist options
  • Save mattbailey/2846601 to your computer and use it in GitHub Desktop.
Save mattbailey/2846601 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
$flood = 0;
use Irssi;
use Image::Magick;
use warnings;
use vars qw($flood $VERSION %IRSSI);
$VERSION = '1.00';
%IRSSI = (
authors => 'Matt Bailey',
contact => 'ribo [at] system42.net',
name => 'YMF script',
description => 'YUM!',
license => 'Public Domain',
);
Irssi::signal_add_last "message public" => sub {
my ($server, $msg, $nick, $address, $target) = @_;
my $floodDelta = time() - $flood;
if ($msg =~ /^\.ymf.*/i && $floodDelta > 5) {
my $comment = ymf($msg);
$server->command("/MSG $target $comment");
$flood = time();
}
};
Irssi::signal_add "message own_public" => sub {
my ($server, $msg, $target) = @_;
if ($msg =~ /^\.ymf.*/i) {
my $comment = ymf($msg);
$server->command("/MSG $target $comment");
$flood = time();
}
};
Irssi::signal_add_last "message private" => sub {
my ($server, $msg, $nick, $address) = @_;
my $floodDelta = time() - $flood;
if ($msg =~ /^\.ymf.*/i && $floodDelta > 5) {
my $comment = ymf($msg);
$server->command("/MSG $nick $comment");
$flood = time();
}
};
Irssi::signal_add "message own_private" => sub {
my ($server, $msg, $target, $orig_target) = @_;
if ($msg =~ /^\.ymf.*/i) {
my $comment = ymf($msg);
$server->command("/MSG $target $comment");
$flood = time();
}
};
sub generate_random_string
{
my $length_of_randomstring=shift;
my @chars=('a'..'z','A'..'Z','0'..'9','_');
my $random_string;
foreach (1..$length_of_randomstring)
{
$random_string.=$chars[rand @chars];
}
return $random_string;
}
sub ymf {
my ($msg) = @_;
my $caption = substr($msg, 5);
my $image = Image::Magick->new;
my $imagename = &generate_random_string(3);
$image->Read('/var/www/ymf.jpg');
$image->Annotate(text=>$caption,geometry=>'+0+0',font=>'/var/www/ymf/Impact.ttf',fill=>'black',stroke=>'white',strokewidth=>2,gravity=>'North',pointsize=>68);
$image->Write("/var/www/ymf/$imagename.jpg");
return("http://system42.net/ymf/$imagename.jpg");
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment