1 # -*- Mode: perl; tab-width: 4; indent-tabs-mode: nil; -*-
2 ################################
4 ################################
5 # Originally by Alex Schuilenburg <alex@schuilenburg.org>
7 package BotModules::Currencies;
16 '' => 'This module gets mid-market currency exchange rates from: http://www.xe.com/ucc/full.shtml',
17 'currency' => 'Call this command with two currency symbols to get the exchange rate. Syntax: \'currency [value] SYM/SYM\'. For the list of supported currencies, see: http://www.xe.com/iso4217.htm',
23 my ($event, $message) = @_;
24 if ($message =~ /^\s*(?:currency|how\s+much\s+is|what\s+is|what\s+are)\s+(\d*(?:.\d+)?)\s*([A-Z]{3})s?\s*(?:\/|in|as)\s*([A-Z]{3})s?[\s?!.]*$/osi) {
28 $self->getURI($event, "http://www.xe.com/ucc/convert.cgi?From=$from&To=$to&Amount=$amount", 'currency', $from, $to);
30 return $self->SUPER::Told(@_);
32 return 0; # we've dealt with it, no need to do anything else.
37 my ($event, $uri, $output, $cmd, $from, $to) = @_;
38 $self->debug($output);
39 my $message = "$event->{'from'}: ";
40 if ($cmd eq 'currency') {
42 if ($output =~ m/([\d,]+\.\d+)\s+$from/s) {
46 if ($output =~ m/([\d,]+\.\d+)\s+$to/s) {
49 if (defined $fromval and defined $toval) {
50 $message .= "$fromval $from = $toval $to (mid-market rates from xe.com)";
51 } elsif ($output =~ m/The following error occurred:<BR><BR>\s*(.+?)\s*<\//os) {
52 $message .= "xe.com said: $1";
54 $message .= 'I\'m afraid I can\'t get currency conversions right now. Sorry.';
57 return $self->SUPER::GotURI(@_);
59 $self->say($event, $message);