I searched through the site and found one person trying to do something similar to this but the discussion didn't really apply. What I'm trying to do is pull a funny quote from a file of quotes by a user and say it when they join a channel. I use an external call to fortune to actually grab the quote. Everything works great so far, except that the script only seems to run every other time a user joins (1st, 3rd, 5th...).
Does anyone see something I don't that may be causing this? If so, what?
use strict;
use vars qw($NAME $VERSION %IRSSI);
use Irssi qw(command_bind signal_add_first);
$VERSION = "1.03";
%IRSSI = (
authors => "Stuart Freeman",
contact => "stuart\@tyro.homelinux.com",
name => "greet",
description => "Greets your friends with a message from a file nam
+ed after them.",
license => "GPL"
);
sub greet ($server, $channel, $nick, $address)
{
my ($server, $channel, $nick, $address) = @_;
$address =~ s/\~(.*)\@.*/$1/;
my $filename = glob( "~/.quotes/$address");
if (-r $filename)
{
my @quote=split(/\n/,`/usr/games/fortune $filename`);
foreach my $quote (@quote)
{
$server->command('msg '.$channel.' '.$nick.'>
+'.$quote);
}
}
}
signal_add_first 'message join' => 'greet';
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.