1

link_to_memc.pl: fix var name, now it _can_ add links :)

link_to_memc.pl: now it can add all links in string
This commit is contained in:
eleksir
2018-04-28 15:34:11 +03:00
parent 9ce9552c8b
commit f4d783107c

View File

@@ -10,32 +10,32 @@ use vars qw($VERSION %IRSSI);
sub hookfn; sub hookfn;
$VERSION = '1.00a'; $VERSION = '1.01';
%IRSSI = ( %IRSSI = (
authors => 'Eleksir', authors => 'Eleksir',
contact => 'eleksir@exs-elm.ru', contact => 'eleksir@exs-elm.ru',
name => 'Image link saver', name => 'Image link saver',
description => 'Saves image link to memcache', description => 'Saves image link to memcache',
license => 'BSD', license => 'BSD',
changed => 'Sun Mar 11 15:39 CET 2018', changed => 'Sat Apr 28 15:25 CET 2018',
); );
Irssi::signal_add_last("message public", "hookfn"); Irssi::signal_add_last("message public", "hookfn");
my $mc = '127.0.0.1:11211';
sub hookfn { sub hookfn {
my ($a, $text, $b, $c) = @_; my ($a, $text, $b, $c) = @_;
my @words = split(/\s+/, $text); my @words = split(/\s+/, $text);
foreach (@words) { foreach my $word (@words) {
if ($_ =~ m{:?https?://([a-zA-Z0-9.-]+\.[a-zA-Z]+)/(?:.*)}) { if ($word =~ m{:?https?://([a-zA-Z0-9.-]+\.[a-zA-Z]+)/(?:.*)}) {
my $memd = new Cache::Memcached { 'servers' => [ "127.0.0.1:11211" ] }; my $memd = new Cache::Memcached { 'servers' => [ $mc ] };
$memd->set('irssi_' . md5_base64($str), $str); $memd->set(sprintf("irssi_%s", md5_base64($word)), $word);
$memd->disconnect_all; $memd->disconnect_all;
last;
} }
} }
return; return;
} }