| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Bot::BasicBot::Pluggable::Module::Twitter; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
28671
|
use warnings; |
|
|
1
|
|
|
|
|
101
|
|
|
|
1
|
|
|
|
|
63
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
42
|
|
|
5
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
|
1
|
|
|
|
|
7
|
|
|
|
1
|
|
|
|
|
124
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
593
|
use Bot::BasicBot::Pluggable::Module; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use base qw(Bot::BasicBot::Pluggable::Module); |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use Net::Twitter; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.0.3'; |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Bot::BasicBot::Pluggable::Module::Twitter - Post message to twitter |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
$bot->load( "Twitter" ); |
|
22
|
|
|
|
|
|
|
my $twi_handler = $bot->handler( "Twitter" ); |
|
23
|
|
|
|
|
|
|
$twi_handler->set( |
|
24
|
|
|
|
|
|
|
{ username => "myusername", |
|
25
|
|
|
|
|
|
|
password => "mypassword", |
|
26
|
|
|
|
|
|
|
} |
|
27
|
|
|
|
|
|
|
); |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
A plugin module for L<Bot::BasicBot::Pluggable> to send message to a twitter account. |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head2 METHODS |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=cut |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head3 init |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=cut |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub init { |
|
42
|
|
|
|
|
|
|
my $self = shift; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head3 help |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
!help |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
will return a help message |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=cut |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub help { |
|
54
|
|
|
|
|
|
|
my $self = shift; |
|
55
|
|
|
|
|
|
|
my $mess = "!twitter <str> : will post a message to twitter"; |
|
56
|
|
|
|
|
|
|
$mess |
|
57
|
|
|
|
|
|
|
.= "\n!twitter_all : will return the last 5 public messages from the public timeline"; |
|
58
|
|
|
|
|
|
|
return $mess; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head3 said |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
!twitter my message |
|
64
|
|
|
|
|
|
|
!twitter_all |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
will send to twitter your message |
|
67
|
|
|
|
|
|
|
will get the last 5 messages from the public timeline |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=cut |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub said { |
|
72
|
|
|
|
|
|
|
my ( $self, $mess, $pri ) = @_; |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
return unless $pri == 2; |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
$self->{ body } = $mess->{ body }; |
|
77
|
|
|
|
|
|
|
$self->{ who } = $mess->{ who }; |
|
78
|
|
|
|
|
|
|
$self->{ channel } = $mess->{ channel }; |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
if ( $self->{ body } =~ /^!twitter\s(.*)$/ ) { |
|
81
|
|
|
|
|
|
|
my $result = $self->{ twit }->update( $1 ); |
|
82
|
|
|
|
|
|
|
if ( !defined $result ) { |
|
83
|
|
|
|
|
|
|
$self->tell( $self->{ channel }, |
|
84
|
|
|
|
|
|
|
$self->{ who } . ": an error occurs." ); |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
else { |
|
87
|
|
|
|
|
|
|
$self->tell( $self->{ channel }, |
|
88
|
|
|
|
|
|
|
$self->{ who } . ": consider it noted." ); |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
elsif ( $self->{ body } =~ /^!twitter_all/ ) { |
|
92
|
|
|
|
|
|
|
my $result = $self->{ twit }->public_timeline; |
|
93
|
|
|
|
|
|
|
my $i = 0; |
|
94
|
|
|
|
|
|
|
foreach my $t ( @{ $result } ) { |
|
95
|
|
|
|
|
|
|
my $str = $t->{ user }->{ name }. " :". $t->{text}; |
|
96
|
|
|
|
|
|
|
$self->tell( $self->{ channel }, $str ); |
|
97
|
|
|
|
|
|
|
$i++; |
|
98
|
|
|
|
|
|
|
last if $i == 5; |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head3 set |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
$twitter_handler->set( |
|
106
|
|
|
|
|
|
|
{ username => "myusername", |
|
107
|
|
|
|
|
|
|
password => "mypassword", |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
); |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
will set the username and the password for the bot. |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=cut |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub set { |
|
116
|
|
|
|
|
|
|
my ( $self, $params ) = @_; |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
foreach my $key ( keys %{ $params } ) { |
|
119
|
|
|
|
|
|
|
$self->{ $key } = $$params{ $key }; |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
croak "Error: no twitter username specified" unless $self->{ username }; |
|
123
|
|
|
|
|
|
|
croak "Error: no twitter password specified" unless $self->{ password }; |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
$self->{ twit } = Net::Twitter->new( |
|
126
|
|
|
|
|
|
|
username => $self->{ username }, |
|
127
|
|
|
|
|
|
|
password => $self->{ password } |
|
128
|
|
|
|
|
|
|
); |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
return $self; |
|
131
|
|
|
|
|
|
|
} |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
1; |
|
134
|
|
|
|
|
|
|
__END__ |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
No bugs have been reported. |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
|
141
|
|
|
|
|
|
|
C<bug-bot-basicbot-pluggable-module-twitter@rt.cpan.org>, or through the web interface at |
|
142
|
|
|
|
|
|
|
L<http://rt.cpan.org>. |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head1 AUTHOR |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
franck cuny C<< <franck.cuny@gmail.com> >> |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 LICENCE AND COPYRIGHT |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Copyright (c) 2007, franck cuny C<< <franck.cuny@gmail.com> >>. All rights reserved. |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or |
|
155
|
|
|
|
|
|
|
modify it under the same terms as Perl itself. See L<perlartistic>. |