#!perl -T # # everything works for now # designed to run in Irssi, i deleted my initial xchat version # 01/02/08 # added !forex, i could use some help cleaning this up # #use strict; use CGI qw/unescapeHTML/; use LWP::Simple; use LWP::UserAgent; use vars qw($VERSION %IRSSI); use Irssi qw(command_bind signal_add); use IO::File; $VERSION = '0.0.7'; %IRSSI = ( author => 'Soul_keeper', contact => '#linuxsociety', name => 'lsquote', descriotion => 'A better quote bot i had to write because there were no good ones out there in perl', license => 'GPL', ); sub own_question { my ($server, $msg, $target) = @_; question($server, $msg, "", $target); } sub public_question { my ($server, $msg, $nick, $address, $target) = @_; question($server, $msg, $nick.": ", $target); } sub get_data { my $data = shift; my @params = split / +/, $data; my $trigger = shift @params; my $count = 1; if (defined $params[0] && int($params[0]) > 0) { $count = shift @params; $count = 10 if $count > 10; } $data = join ' ', @params; $data =~ s/[^[:print:]]/ /g; $data =~ s/ */ /g; return ($trigger, $count, $data); } sub question($server, $msg, $nick, $target) { my ($server, $msg, $nick, $target, $url, $data) = @_; $_ = $msg; my $ua = LWP::UserAgent->new(agent => "google suck"); my $result = $ua->get($url); #if (!/^indices/i) { return 0; } # These options will be for the portfolio tracking functions when i get around to setting them up # if (/^!in/i) { # $data = $msg; # #$symbol =~ s/^!in //; # #$price =~ s/^!in //; # $data =~ s/^!in //; # $data =~ /^\s*(\w+)\s+(\w+)\s*$/; # #$fh = new IO::File; # $server->command('msg '.$target.' '.$nick.'Added '.$1.' at '.$2. ' to your portfolio'); # } # if (/^!out/i) { # $data = $msg; # #$symbol =~ s/^!in //; # #$price =~ s/^!in //; # $data =~ s/^!in //; # $data =~ /^\s*(\w+)\s+(\w+)\s*$/; # # #$fh = new IO::File; # $server->command('msg '.$target.' '.$nick.'You've exited '.$1.' at '.$2. ' for a ' .$return 'return'); # } # if (/^!portfolio/i) { # $data = $msg; # $data =~ s/^!portfolio //; # # # } if (/^!help/i) { $server->command('msg '.$target.' '.$nick.'This is lsquote version '.$VERSION.' use !americas, !asia, !europe, !other, !quote ticker, !metals, !energy, !fut, !forex'); } if (/^!indices/i) { $server->command('msg '.$target.' '.$nick.' !indices has been replaced with regional triggers: !americas, !asia, !europe, and !other'); } if (/^!americas/i) { my $site1=get "http://finance.yahoo.com/d?s=^dji&f=s0l1t1cn"; $site1 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'yahoo: '.$site1); my $site2=get "http://finance.yahoo.com/d?s=^gspc&f=s0l1t1cn"; $site2 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'yahoo: '.$site2); my $site3=get "http://finance.yahoo.com/d?s=^ixic&f=s0l1t1cn"; $site3 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'yahoo: '.$site3); my $site4=get "http://finance.yahoo.com/d?s=^MERV&f=s0l1t1cn"; $site4 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'yahoo: '.$site4); my $site5=get "http://finance.yahoo.com/d?s=^BVSP&f=s0l1t1cn"; $site5 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'yahoo: '.$site5); my $site6=get "http://finance.yahoo.com/d?s=^GSPTSE&f=s0l1t1cn"; $site6 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'yahoo: '.$site6); my $site7=get "http://finance.yahoo.com/d?s=^SPCDNX&f=s0l1t1cn"; $site7 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'yahoo: '.$site7); my $site8=get "http://finance.yahoo.com/d?s=^mxx&f=s0l1t1cn"; $site8 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'yahoo: '.$site8); } if (/^!asia/i) { my $site1=get "http://finance.yahoo.com/d?s=^aord&f=s0l1t1cn"; $site1 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'yahoo: '.$site1); my $site2=get "http://finance.yahoo.com/d?s=^axjo&f=s0l1t1cn"; $site2 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'yahoo: '.$site2); my $site3=get "http://finance.yahoo.com/d?s=^ssec&f=s0l1t1cn"; $site3 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'yahoo: '.$site3); my $site4=get "http://finance.yahoo.com/d?s=^n225&f=s0l1t1cn"; $site4 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'yahoo: '.$site4); my $site5=get "http://finance.yahoo.com/d?s=^KS11&f=s0l1t1cn"; $site5 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'yahoo: '.$site5); my $site6=get "http://finance.yahoo.com/d?s=^TWII&f=s0l1t1cn"; $site6 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'yahoo: '.$site6); my $site7=get "http://finance.yahoo.com/d?s=^BSESN&f=s0l1t1cn"; $site7 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'yahoo: '.$site7); } if (/^!europe/i) { my $site1=get "http://finance.yahoo.com/d?s=^FCHI&f=s0l1t1cn"; $site1 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'yahoo: '.$site1); my $site2=get "http://finance.yahoo.com/d?s=^GDAXI&f=s0l1t1cn"; $site2 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'yahoo: '.$site2); my $site3=get "http://finance.yahoo.com/d?s=^SMSI&f=s0l1t1cn"; $site3 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'yahoo: '.$site3); my $site4=get "http://finance.yahoo.com/d?s=^SSMI&f=s0l1t1cn"; $site4 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'yahoo: '.$site4); my $site5=get "http://finance.yahoo.com/d?s=^FTSE&f=s0l1t1cn"; $site5 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'yahoo: '.$site5); my $site6=get "http://finance.yahoo.com/d?s=^MIBTEL&f=s0l1t1cn"; $site6 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'yahoo: '.$site6); my $site7=get "http://finance.yahoo.com/d?s=RTS.RS&f=s0l1t1cn"; $site7 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'yahoo: '.$site7); } if (/^!other/i) { my $site1=get "http://finance.yahoo.com/d?s=^CCSI&f=s0l1t1cn"; $site1 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'yahoo: '.$site1); my $site2=get "http://finance.yahoo.com/d?s=^TA100&f=s0l1t1cn"; $site2 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'yahoo: '.$site2); # my $site3=get "http://finance.yahoo.com/d?s=^SMSI&f=s0l1t1cn"; # $site3 =~ tr/"/ /; # $server->command('msg '.$target.' '.$nick.'yahoo: '.$site3); # my $site4=get "http://finance.yahoo.com/d?s=^SSMI&f=s0l1t1cn"; # $site4 =~ tr/"/ /; # $server->command('msg '.$target.' '.$nick.'yahoo: '.$site4); # my $site5=get "http://finance.yahoo.com/d?s=^FTSE&f=s0l1t1cn"; # $site5 =~ tr/"/ /; # $server->command('msg '.$target.' '.$nick.'yahoo: '.$site5); # my $site6=get "http://finance.yahoo.com/d?s=^MIBTEL&f=s0l1t1cn"; # $site6 =~ tr/"/ /; # $server->command('msg '.$target.' '.$nick.'yahoo: '.$site6); } if (/^!quote/i) { # $data needs to be set to whatever follows !quote here # $data = $msg; $data =~ s/^!quote //; my $ticker = $data; my $CGISITE = 'http://finance.yahoo.com'; my $CGIROOT = $CGISITE . '/d?s=' . $ticker . '&f=s0l1t1cn'; my $content=get "$CGIROOT"; my $answer = ""; $content =~ tr/"/ /; $answer = "$content"; $server->command('msg '.$target.' '.$nick.'yahoo: '.$answer); } if (/^!metals/i) { # my $site1=get "http://finance.yahoo.com/d?s=PLg08.NYM&f=s0l1t1cn"; my $site2=get "http://finance.yahoo.com/d?s=PLj08.NYM&f=s0l1t1cn"; # my $site3=get "http://finance.yahoo.com/d?s=GCg08.CMX&f=s0l1t1cn"; my $site4=get "http://finance.yahoo.com/d?s=ZGj08.CBT&f=s0l1t1cn"; my $site5=get "http://finance.yahoo.com/d?s=PAH08.NYM&f=s0l1t1cn"; # my $site4=get "http://finance.yahoo.com/d?s=PAH08.NYM&f=s0l1t1cn"; # my $site6=get "http://finance.yahoo.com/d?s=SIg08.CMX&f=s0l1t1cn"; my $site7=get "http://finance.yahoo.com/d?s=ZIJ08.CBT&f=s0l1t1cn"; # my $site8=get "http://finance.yahoo.com/d?s=HGg08.CMX&f=s0l1t1cn"; my $site9=get "http://finance.yahoo.com/d?s=HGj08.CMX&f=s0l1t1cn"; # my $site10=get "http://finance.yahoo.com/d?s=ALg08.CMX&f=s0l1t1cn"; my $site11=get "http://finance.yahoo.com/d?s=ALj08.CMX&f=s0l1t1cn"; # $site1 =~ tr/"/ /; # $server->command('msg '.$target.' '.$nick.'futures: '.$site1); $site2 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'futures: '.$site2); # $site3 =~ tr/"/ /; # $server->command('msg '.$target.' '.$nick.'futures: '.$site3); $site4 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'futures: '.$site4); $site5 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'futures: '.$site5); # $site6 =~ tr/"/ /; # $server->command('msg '.$target.' '.$nick.'futures: '.$site6); $site7 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'futures: '.$site7); # $site8 =~ tr/"/ /; # $server->command('msg '.$target.' '.$nick.'futures: '.$site8); $site9 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'futures: '.$site9); # $site10 =~ tr/"/ /; # $server->command('msg '.$target.' '.$nick.'futures: '.$site10); $site11 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'futures: '.$site11); } if (/^!energy/i) { my $site1=get "http://finance.yahoo.com/d?s=CLj08.NYM&f=s0l1t1cn"; my $site2=get "http://finance.yahoo.com/d?s=NGj08.NYM&f=s0l1t1cn"; my $site3=get "http://finance.yahoo.com/d?s=PNj08.NYM&f=s0l1t1cn"; #my $site4=get "http://finance.yahoo.com/d?s=&f=s0l1t1cn"; $site1 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'futures: '.$site1); $site2 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'futures: '.$site2); $site3 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'futures: '.$site3); #$site4 =~ tr/"/ /; #$server->command('msg '.$target.' '.$nick.'futures: '.$site4); } if (/^!fut/i) { #my $site1=get "http://finance.yahoo.com/d?s=CRU07.NYB&f=s0l1t1cn"; my $site2=get "http://finance.yahoo.com/d?s=^DJS2&f=s0l1t1cn"; my $site3=get "http://finance.yahoo.com/d?s=^DJC&f=s0l1t1cn"; my $site4=get "http://finance.yahoo.com/d?s=^XAU&f=s0l1t1cn"; #$site1 =~ tr/"/ /; #$server->command('msg '.$target.' '.$nick.'futures: '.$site1); $site2 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'futures: '.$site2); $site3 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'futures: '.$site3); $site4 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'futures: '.$site4); } #This is a special menu for someone named sp00nge :) if (/^!sp00nge/i) { my $site1=get "http://finance.yahoo.com/d?s=aun.ax&f=s0l1t1cn"; my $site2=get "http://finance.yahoo.com/d?s=aeo.ax&f=s0l1t1cn"; my $site3=get "http://finance.yahoo.com/d?s=iin.ax&f=s0l1t1cn"; my $site4=get "http://finance.yahoo.com/d?s=cti.ax&f=s0l1t1cn"; my $site5=get "http://finance.yahoo.com/d?s=spn.ax&f=s0l1t1cn"; my $site6=get "http://finance.yahoo.com/d?s=sgt.ax&f=s0l1t1cn"; $site1 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'special menu: '.$site1); $site2 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'special menu: '.$site2); $site3 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'special menu: '.$site3); $site4 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'special menu: '.$site4); $site5 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'special menu: '.$site5); $site6 =~ tr/"/ /; $server->command('msg '.$target.' '.$nick.'special menu: '.$site6); } #These are some forex options that were requested by some people i just havn't figured out how/where to snag the exchange rate data yet #Ok the crap works, but i could sure use some help cleaning it up, thanks if (/^!forex/i) { #my $site1=get "http://secure.efxnow.com/MarketData/ENG/Rates.aspx"; #my $command=~"links -dump"; #my $site1= ""; #my $forexsite=~"http://secure.efxnow.com/MarketData/ENG/Rates.aspx"; #my $site1=system("links -dump http://secure.efxnow.com/MarketData/ENG/Rates.aspx"); #my $site="lynx -dump http://secure.efxnow.com/MarketData/ENG/Rates.aspx > /tmp/rates.txt "; #$site=system($site); my $site1="lynx -dump http://secure.efxnow.com/MarketData/ENG/Rates.aspx |grep EUR/USD > /tmp/eurusd"; my $site2="lynx -dump http://secure.efxnow.com/MarketData/ENG/Rates.aspx |grep USD/JPY > /tmp/usdjpy"; my $site3="lynx -dump http://secure.efxnow.com/MarketData/ENG/Rates.aspx |grep GBP/USD > /tmp/gbpusd"; my $site4="lynx -dump http://secure.efxnow.com/MarketData/ENG/Rates.aspx |grep EUR/GBP > /tmp/eurgbp"; my $site5="lynx -dump http://secure.efxnow.com/MarketData/ENG/Rates.aspx |grep USD/CHF > /tmp/usdchf"; my $site6="lynx -dump http://secure.efxnow.com/MarketData/ENG/Rates.aspx |grep AUD/USD > /tmp/audusd"; my $site7="lynx -dump http://secure.efxnow.com/MarketData/ENG/Rates.aspx |grep USD/CAD > /tmp/usdcad"; $site1=system($site1); $site2=system($site2); $site3=system($site3); $site4=system($site4); $site5=system($site5); $site6=system($site6); $site7=system($site7); #$site1= rates.txt IO::File; my $fh = new IO::File; if ($fh->open("< /tmp/eurusd")) { #print <$fh>; $site1 = <$fh>; $fh->close; } if ($fh->open("< /tmp/usdjpy")) { #print <$fh>; $site2 = <$fh>; $fh->close; } if ($fh->open("< /tmp/gbpusd")) { #print <$fh>; $site3 = <$fh>; $fh->close; } if ($fh->open("< /tmp/eurgbp")) { #print <$fh>; $site4 = <$fh>; $fh->close; } if ($fh->open("< /tmp/usdchf")) { #print <$fh>; $site5 = <$fh>; $fh->close; } if ($fh->open("< /tmp/audusd")) { #print <$fh>; $site6 = <$fh>; $fh->close; } if ($fh->open("< /tmp/usdcad")) { #print <$fh>; $site7 = <$fh>; $fh->close; } #my $site1 = system ("echo $site1"); #$site1 =~ 'grep USD'; #$site1 =~ /[0-9]*/ /; #$site1 =~ /(?<=