package plugins dumpz use strict use warnings use Exporter use LWP use

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package plugins::dumpz;
use strict;
use warnings;
use Exporter;
use LWP;
use Encode;
use HTTP::Request::Common;
use JSON::XS;
use utf8;
use FindBin qw($Bin);
use vars qw(@ISA @EXPORT $VERSION);
$VERSION = '0.02';
@ISA = ('Exporter');
@EXPORT = qw( myINIT cache dumpz );
my %config = (
paths => {
dumpz_folder => $Bin . "/plugins/dumpz/",
},
URI => "http://dumpz.org/api/upload/",
);
sub myINIT {
main::registerEvent('^\.(?:d|)\s+\*(.+?)\s+(.+?)$', \&dumpz);
main::registerHelp('.d dump_text . ');
}
sub dumpz {
my %args = (@_);
my $result;
my $lwp = LWP::UserAgent->new;
$lwp->timeout(20);
my $request = POST "$config{URI}",
[
'lexer' => $args{saved1},
'code' => $args{saved2},
'comment' => '',
];
$request->header('pragma' => 'no-cache', 'max-age' => '0');
my $response = $lwp->request($request);
open CACHE, ">:utf8", $config{paths}{dumpz_folder} . $args{senderJID} . "_" . $args{saved1} . "_" . time . ".txt" || die $!;
print CACHE $args{saved2};
close CACHE;
if ($response->status_line eq "200 OK") {
my $jsonHash = decode_json $response->content;
$result = ${$jsonHash}{url};
} else {
$result = "Error:" . $response->status_line;
}
$result;
}
1;