-
Notifications
You must be signed in to change notification settings - Fork 2
/
pastebin.pl
126 lines (104 loc) · 2.8 KB
/
pastebin.pl
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
use strict;
#
# Irssi Pastebin
#
# Copyright (C) 2010 Samuel Vandamme
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Change Log:
# v1.0b:
# - Initial release
# v1.0:
# - Looks stable
#
# Requirements:
# - perl-libwww
#
# Problems ?
# http://github.com/kidk/irssi-pastebin/issues
# OR
# email : [email protected]
use vars qw($VERSION %IRSSI);
$VERSION = "1.0";
%IRSSI = (
authors => "Samuel 'kidk' Vandamme",
contact => "samuel\@sava.be",
name => "pastebin",
description => "Automatically catche large paste's, add them to pastebin and return the url.",
license => "",
url => "",
changed => "",
modules => "",
commands => ""
);
use Irssi;
use LWP::UserAgent;
use HTTP::Request::Common;
use vars qw($timer $channel $server @log);
sub microtime {
my ($secs, $microsecs) = gettimeofday();
return $secs + ($microsecs * 1e-6);
}
sub sig_send_text ($$$) {
my ($line, $lserver, $witem) = @_;
$channel = $witem->{name};
$server = $lserver;
# Checks
return unless (ref $server);
return unless ($witem && ($witem->{type} eq 'CHANNEL' || $witem->{type} eq 'QUERY'));
if ( !@log ) {
@log = ();
}
# Time check
Irssi::timeout_remove($timer);
$timer = Irssi::timeout_add(10, \&pastebin, undef);
# Add message to log
push(@log, $line);
Irssi::signal_stop();
}
sub pastebin {
my $size = @log;
if ( $size >= Irssi::settings_get_int('pastebin_lines') ) {
# Prepare message
my $code = join("\n", @log);
my %fields = (
"api_dev_key" => "0ab63310e602442c43ae1753955aa345",
"api_option" => "paste",
"api_paste_code" => $code,
);
# Pastebin
my $browser = new LWP::UserAgent;
my $page = $browser->post("http://pastebin.com/api/api_post.php", \%fields);
if ($page->is_success)
{
$server->command('MSG -- '.$channel.' '.$page->decoded_content);
}
else
{
$server->command('MSG -- '.$channel.' pastebin upload failed');
}
} else {
# Output normally
foreach (@log) {
$server->command('MSG -- '.$channel.' '.$_);
}
}
# Clean
@log = ();
Irssi::timeout_remove($timer);
}
Irssi::settings_add_int($IRSSI{name}, 'pastebin_lines', 5);
Irssi::signal_add('send text', 'sig_send_text');
print CLIENTCRAP "%B>>%n ".$IRSSI{name}." ".$VERSION." loaded";