Wikipedia is a great source of information on the web. This script grabs a summary of a wikipedia page and presents the result back to the channel the bot was activated from.
The script uses a functionality that a lot of people don't know about: someone has created a small database of wikipedia summaries that are requested and returned via a DNS query.
Since we're in Perl, there's a nifty Perl implementation as well:
- use Net::DNS;
- my $res = Net::DNS::Resolver->new;
- sub wikipedia {
- my($name) = @_;
- my $q = $res->query("$name.wp.dg.cx", "TXT");
- if($q) {
- for my $rr($q->answer) {
- next unless $rr->type eq "TXT";
- return join "", $rr->char_str_list;
- }
- }
- }
The script responds to a message in a channel or a query containing:
!wp <WIKIPEDIA PAGE>
And presents the information back to the channel or query as an action.
The script can be found here: http://public.tamaratemple.com/irssi/wp.pl.txt
| Tags: | Categories: ComputerStuff |
Recent Changes |
Printable View |
Page History |
Edit Page
Page last modified on October 08, 2011, at 04:58 PM by tamara