I'm insulted!
Have your trixbox insult you as a pirate.
Create an extension in extensions_custom.conf in the from-internal-custom context:
exten => *800,1,Answer
exten => *800,2,AGI(pirate.agi)
exten => *800,3,Hangup
Create a file called pirate.agi in /var/lib/asterisk/agi-bin and put this in it:
[code]
#!/usr/bin/perl
use warnings;
use strict;
use Acme::Scurvy::Whoreson::BilgeRat;
use Asterisk::AGI;
my $txfilename = "insult.txt";
my $AGI = new Asterisk::AGI;
my @lines;
my $prepend = "You are a";
my $insultgenerator = Acme::Scurvy::Whoreson::BilgeRat->new(
language => 'pirate'
);
open(OUTPUT,">/tmp/$txfilename.$$") || die "Could not open /tmp/$txfilename.$$\n";
print OUTPUT $prepend . " " . $insultgenerator;
close OUTPUT;
open(INPUT,") {
push(@lines,$_);
print "$_\n";
}
for(my $i = 0; $i < scalar(@lines); $i++) {
$AGI->exec('AGI',"festival-weather-script.pl|\"$lines[$i]\"");
}
unlink("/tmp/$txfilename.$$");
exit;
[/code]
chown asterisk.asterisk /var/lib/asterisk/agi-bin/pirate.agi
chmod +x /var/lib/asterisk/agi-bin/pirate.agi
reload asterisk
Dial *800
You may need to install Acme::Scurvy::Whoreson::BilgeRat. If so run:
perl -MCPAN -e "Acme::Scurvy::Whoreson::BilgeRat"
taking care to preserve the capitalization.
There is a way to do this from random insult generators on the Internet too, but you'll need to get permission from the owners of the site. This uses a local database.
If you want to do the one from the Internet, use this code:
[code]
#!/usr/bin/perl
use warnings;
use strict;
use Asterisk::AGI;
use LWP::Simple;
my $AGI = new Asterisk::AGI;
my $url="yoururlhere";
my $htfilename = "insult.html";
my @lines;
getstore($url,"/tmp/$htfilename.$$")or die "Cannot connect to $url: $@";
open(INPUT,") {
$_ =~ s/\<[^\<]+\>//g;
push(@lines,$_);
print "$_\n";
}
for(my $i = 0; $i < scalar(@lines); $i++) {
$AGI->exec('AGI',"festival-weather-script.pl|\"$lines[$i]\"");
}
unlink("/tmp/$htfilename.$$");
exit;
[/code]
But you'll have to find your own url. Google "random insult generator" and that will get you started.
Enjoy.
Just thought I'd mention that I set a bunch of these up and set up an IVR:
If you'd like to be insulted by a pirate, press 1.
If you'd like to be insulted by a famous person, press 2.
If you'd like to have your mother insulted, press 3.
And if you'd just like a general insult, press 4.
So far my cow-orkers love it.
I did something like this for a few people here who have problems deciding where to go for lunch. Dial LUNCH on the phone and it gives you a random restaurant name. It kind of mangles some of the names but that is half the fun. We like to go to "Rail Head" (Trail Head) or "Cool Peppers" (Culpeppers)
Mine dies because it can't find the pirate phrases:
[root@asterisk1 ~]# /var/lib/asterisk/agi-bin/pirate.agi
Can't locate Acme/Scurvy/Whoreson/BilgeRat.pm in @INC ... a t /var/lib/asterisk/agi-bin/pirate.agi line 4.
I ran this:
perl -MCPAN -e "Acme::Scurvy::Whoreson::BilgeRat"
but no joy...
Did:
perl -MCPAN -e "Acme::Scurvy::Whoreson::BilgeRat"
finish without errors?
You can try installing it interactively to see if it wants a dependancy or something.
run:
perl -MCPAN -e shell
(say "no" if it asks if you want to set up your cpan environment or whatever -- I forget the exact wording. It might tell you "sorry, we have to rerun the configuration ... blah blah blah. If so, then just do it.)
Anyway, once you have a command prompt (should look similar to "cpan>") you can type:
install Acme::Scurvy::Whoreson::BilgeRat
And folllow along. Say "yes" if it asks to prepend anything. Post the output if you get errors.
You can try installing it interactively to see if it wants a dependancy or something.
run:
perl -MCPAN -e shell
(say "no" if it asks if you want to set up your cpan environment or whatever -- I forget the exact wording. It might tell you "sorry, we have to rerun the configuration ... blah blah blah. If so, then just do it.)
Anyway, once you have a command prompt (should look similar to "cpan>") you can type:
install Acme::Scurvy::Whoreson::BilgeRat
This worked fine - It went through a lot of cpan setup (it had never been setup on my box) and then when I finally got the "cpan>" prompt it installed no problem.
That that you scurvy bilge rats.
[root@asterisk1 agi-bin]# /var/lib/asterisk/agi-bin/pirate.agi
Scalar found where operator expected at /var/lib/asterisk/agi-bin/pirate.agi line 22, near "print "$_"
(Might be a runaway multi-line "" string starting on line 20)
(Do you need to predeclare print?)
Backslash found where operator expected at /var/lib/asterisk/agi-bin/pirate.agi line 22, near "$_\"
(Missing operator before \?)
String found where operator expected at /var/lib/asterisk/agi-bin/pirate.agi line 25, near "$AGI->exec('AGI',""
(Might be a runaway multi-line "" string starting on line 22)
(Missing semicolon on previous line?)
Bareword found where operator expected at /var/lib/asterisk/agi-bin/pirate.agi line 25, near "$AGI->exec('AGI',"festival"
(Missing operator before festival?)
syntax error at /var/lib/asterisk/agi-bin/pirate.agi line 22, near "print "$_"
Global symbol "$i" requires explicit package name at /var/lib/asterisk/agi-bin/pirate.agi line 22.
Global symbol "$i" requires explicit package name at /var/lib/asterisk/agi-bin/pirate.agi line 22.
Global symbol "$i" requires explicit package name at /var/lib/asterisk/agi-bin/pirate.agi line 22.
Global symbol "$i" requires explicit package name at /var/lib/asterisk/agi-bin/pirate.agi line 25.
Unmatched right curly bracket at /var/lib/asterisk/agi-bin/pirate.agi line 26, at end of line
Execution of /var/lib/asterisk/agi-bin/pirate.agi aborted due to compilation errors.
:/
Here is what I get:
Scalar found where operator expected at /var/lib/asterisk/agi-bin/pirate.agi line 20, near "print "$_"
(Might be a runaway multi-line "" string starting on line 18)
(Do you need to predeclare print?)
Backslash found where operator expected at /var/lib/asterisk/agi-bin/pirate.agi line 20, near "$_\"
(Missing operator before \?)
String found where operator expected at /var/lib/asterisk/agi-bin/pirate.agi line 23, near "#my $test = $prepend . ""
(Might be a runaway multi-line "" string starting on line 20)
(Missing semicolon on previous line?)
String found where operator expected at /var/lib/asterisk/agi-bin/pirate.agi line 24, near "$AGI->exec('AGI',""
(Might be a runaway multi-line "" string starting on line 23)
(Missing semicolon on previous line?)
Bareword found where operator expected at /var/lib/asterisk/agi-bin/pirate.agi line 24, near "$AGI->exec('AGI',"festival"
(Missing operator before festival?)
syntax error at /var/lib/asterisk/agi-bin/pirate.agi line 20, near "print "$_"
Global symbol "$i" requires explicit package name at /var/lib/asterisk/agi-bin/pirate.agi line 20.
Global symbol "$i" requires explicit package name at /var/lib/asterisk/agi-bin/pirate.agi line 20.
Global symbol "$i" requires explicit package name at /var/lib/asterisk/agi-bin/pirate.agi line 20.
Global symbol "$test" requires explicit package name at /var/lib/asterisk/agi-bin/pirate.agi line 20.
Global symbol "$test" requires explicit package name at /var/lib/asterisk/agi-bin/pirate.agi line 24.
Unmatched right curly bracket at /var/lib/asterisk/agi-bin/pirate.agi line 25, at end of line
Execution of /var/lib/asterisk/agi-bin/pirate.agi aborted due to compilation errors.
Any clue as to what's going on? I don't...
replace
open(INPUT,") {
push(@lines,$_);
print "$_\n";
}
for(my $i = 0; $i < scalar(@lines); $i++) {
$AGI->exec('AGI',"festival-weather-script.pl|\"$lines[$i]\"");
}
with
my $test = $prepend . " " . $insultgenerator;
$AGI->exec('AGI',"festival-weather-script.pl|\"$test");
and it will work, the problem comes form the open, push, print part i dont know AGI enough to know why...


Member Since:
2006-06-14