Merge branch 'indev' of github.com:Xelhua/Auto into indev
This commit is contained in:
commit
cb7d1930dd
2 files changed
+30
-25
No files matched your search
+14
-12
@@ -4,8 +4,8 @@
|
|||||||
package m_Bitly;
|
package m_Bitly;
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use API::Std qw(cmd_add cmd_del conf_get err);
|
use API::Std qw(cmd_add cmd_del conf_get err trans);
|
||||||
use API::IRC qw(privmsg);
|
use API::IRC qw(privmsg notice);
|
||||||
use LWP::UserAgent;
|
use LWP::UserAgent;
|
||||||
|
|
||||||
# Initialization subroutine.
|
# Initialization subroutine.
|
||||||
@@ -62,6 +62,10 @@ sub shorten
|
|||||||
|
|
||||||
# Put together the call to the Bit.ly API.
|
# Put together the call to the Bit.ly API.
|
||||||
my @args = @{ $data{args} };
|
my @args = @{ $data{args} };
|
||||||
|
if (!defined $args[0]) {
|
||||||
|
notice($data{svr}, $data{nick}, trans("Not enough parameters").".");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
my ($surl, $user, $key) = ($args[0], (conf_get('bitly_user'))[0][0], (conf_get('bitly_key'))[0][0]);
|
my ($surl, $user, $key) = ($args[0], (conf_get('bitly_user'))[0][0], (conf_get('bitly_key'))[0][0]);
|
||||||
my $url = "http://api.bit.ly/v3/shorten?version=3.0.1&longUrl=".$surl."&apiKey=".$key."&login=".$user."&format=txt";
|
my $url = "http://api.bit.ly/v3/shorten?version=3.0.1&longUrl=".$surl."&apiKey=".$key."&login=".$user."&format=txt";
|
||||||
# Get the response via HTTP.
|
# Get the response via HTTP.
|
||||||
@@ -71,14 +75,8 @@ sub shorten
|
|||||||
# If successful, decode the content.
|
# If successful, decode the content.
|
||||||
my $d = $response->decoded_content;
|
my $d = $response->decoded_content;
|
||||||
chomp $d;
|
chomp $d;
|
||||||
if ($d =~ m/bit.ly/i) {
|
# And send to channel.
|
||||||
# And send to channel.
|
privmsg($data{svr}, $data{chan}, "URL: ".$d);
|
||||||
privmsg($data{svr}, $data{chan}, "URL: ".$d);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
# Otherwise, send an error message.
|
|
||||||
privmsg($data{svr}, $data{chan}, "An error occurred while shortening your URL.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
# Otherwise, send an error message.
|
# Otherwise, send an error message.
|
||||||
@@ -99,7 +97,11 @@ sub reverse
|
|||||||
$ua->timeout(2);
|
$ua->timeout(2);
|
||||||
|
|
||||||
# Put together the call to the Bit.ly API.
|
# Put together the call to the Bit.ly API.
|
||||||
my @args = @{ $data{args} };
|
my @args = @{ $data{args} };
|
||||||
|
if (!defined $args[0]) {
|
||||||
|
notice($data{svr}, $data{nick}, trans("Not enough parameters").".");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
my ($surl, $user, $key) = ($args[0], (conf_get('bitly_user'))[0][0], (conf_get('bitly_key'))[0][0]);
|
my ($surl, $user, $key) = ($args[0], (conf_get('bitly_user'))[0][0], (conf_get('bitly_key'))[0][0]);
|
||||||
my $url = "http://api.bit.ly/v3/expand?version=3.0.1&shortURL=".$surl."&apiKey=".$key."&login=".$user."&format=txt";
|
my $url = "http://api.bit.ly/v3/expand?version=3.0.1&shortURL=".$surl."&apiKey=".$key."&login=".$user."&format=txt";
|
||||||
# Get the response via HTTP.
|
# Get the response via HTTP.
|
||||||
@@ -110,7 +112,7 @@ sub reverse
|
|||||||
my $d = $response->decoded_content;
|
my $d = $response->decoded_content;
|
||||||
chomp $d;
|
chomp $d;
|
||||||
# And send it to channel.
|
# And send it to channel.
|
||||||
privmsg($data{svr}, $data{chan}, "URL: ".$d);
|
privmsg($data{svr}, $data{chan}, "URL: ".$d);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
# Otherwise, send an error message.
|
# Otherwise, send an error message.
|
||||||
|
|||||||
+16
-13
@@ -32,12 +32,12 @@ sub _void
|
|||||||
|
|
||||||
# Help hashes.
|
# Help hashes.
|
||||||
our %SHELP_CALC = (
|
our %SHELP_CALC = (
|
||||||
'en' => "Calculate an expression.",
|
'en' => "Calculate an expression.",
|
||||||
);
|
);
|
||||||
|
|
||||||
our %FHELP_CALC = (
|
our %FHELP_CALC = (
|
||||||
'en' => "This command will calculate an expression using Google Calculator. Syntax: CALC <expression>",
|
'en' => "This command will calculate an expression using Google Calculator. Syntax: CALC <expression>",
|
||||||
);
|
);
|
||||||
|
|
||||||
# Callback for CALC command.
|
# Callback for CALC command.
|
||||||
sub calc
|
sub calc
|
||||||
@@ -58,19 +58,20 @@ sub calc
|
|||||||
my $response = $ua->get($url);
|
my $response = $ua->get($url);
|
||||||
|
|
||||||
if ($response->is_success) {
|
if ($response->is_success) {
|
||||||
# If successful, decode the content.
|
# If successful, decode the content.
|
||||||
my $d = $json->allow_nonref->utf8->relaxed->escape_slash->loose->allow_singlequote->allow_barekey->decode($response->decoded_content);
|
my $d = $json->allow_nonref->utf8->relaxed->escape_slash->loose->allow_singlequote->allow_barekey->decode($response->decoded_content);
|
||||||
# And send to channel
|
|
||||||
if ($d->{error} eq "" or $d->{error} == 0) {
|
if ($d->{error} eq "" or $d->{error} == 0) {
|
||||||
privmsg($data{svr}, $data{chan}, "Result: ".$d->{lhs}." = ".$d->{rhs});
|
# And send to channel
|
||||||
|
privmsg($data{svr}, $data{chan}, "Result: ".$d->{lhs}." = ".$d->{rhs});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
# Otherwise, send an error message.
|
# Otherwise, send an error message.
|
||||||
privmsg($data{svr}, $data{chan}, "Google calculator sent an error.");
|
privmsg($data{svr}, $data{chan}, "Google Calculator sent an error.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
# Otherwise, send an error message.
|
# Otherwise, send an error message.
|
||||||
privmsg($data{svr}, $data{chan}, "An error occurred while sending your expression to Google Calculator.");
|
privmsg($data{svr}, $data{chan}, "An error occurred while sending your expression to Google Calculator.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,8 +89,8 @@ __END__
|
|||||||
|
|
||||||
=over
|
=over
|
||||||
|
|
||||||
This module adds the CALC command for evaluating an
|
This module adds the CALC command for evaluating an expression using
|
||||||
expression using Google Calculator.
|
Google Calculator.
|
||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
@@ -122,7 +123,9 @@ Add Calc to the module autoload.
|
|||||||
|
|
||||||
=over
|
=over
|
||||||
|
|
||||||
This module requires LWP::UserAgent, URI::Escape and JSON both obtainable from CPAN (http://cpan.org)
|
This module requires LWP::UserAgent, URI::Escape and JSON. All are obtainable
|
||||||
|
from the CPAN <http://www.cpan.org>.
|
||||||
|
|
||||||
This module is compatible with Auto version 3.0a2+.
|
This module is compatible with Auto version 3.0a2+.
|
||||||
|
|
||||||
=back
|
=back
|
||||||
Reference in new issue
Block a user