mirror of
https://github.com/perlbot/perlbuut
synced 2025-06-07 22:15:45 -04:00
Add a some new features to the twitter plugin. get multiple tweets from a user, and search for hashtags
This commit is contained in:
parent
237e14e1a9
commit
faec5dcd5d
3 changed files with 32 additions and 11 deletions
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -1,3 +1,6 @@
|
||||||
[submodule "jail"]
|
[submodule "jail"]
|
||||||
path = jail
|
path = jail
|
||||||
url = https://github.com/simcop2387/perlbot-jail
|
url = https://github.com/simcop2387/perlbot-jail
|
||||||
|
[submodule "wiki"]
|
||||||
|
path = wiki
|
||||||
|
url = https://github.com/perlbot/perlbuut.wiki.git
|
||||||
|
|
|
@ -23,27 +23,44 @@ my $client = Twitter::API->new_with_traits(
|
||||||
my $_r = $client->oauth2_token;
|
my $_r = $client->oauth2_token;
|
||||||
$client->access_token($_r);
|
$client->access_token($_r);
|
||||||
|
|
||||||
sub {
|
sub display_tweet {
|
||||||
my( $said ) = @_;
|
my $tweet = shift;
|
||||||
|
|
||||||
# TODO make this also support getting more than one tweet.
|
|
||||||
|
|
||||||
my ($userid) = $said->{body} =~ /^\s*(\S+)/g;
|
|
||||||
|
|
||||||
my $timeline=$client->user_timeline($userid);
|
|
||||||
|
|
||||||
my $tweet = $timeline->[0];
|
|
||||||
|
|
||||||
if ($tweet) {
|
if ($tweet) {
|
||||||
my ($time, $text, $id) = @{$tweet}{qw/created_at text id/};
|
my ($time, $text, $id) = @{$tweet}{qw/created_at text id/};
|
||||||
my $source = $tweet->{user}{name};
|
my $source = $tweet->{user}{name};
|
||||||
my $url = "https://twitter.com/link/status/$id";
|
my $url = "https://twitter.com/link/status/$id";
|
||||||
|
|
||||||
print STDERR Dumper($timeline);
|
|
||||||
print "<$source> $text $url";
|
print "<$source> $text $url";
|
||||||
} else {
|
} else {
|
||||||
print "No tweets found";
|
print "No tweets found";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sub {
|
||||||
|
my( $said ) = @_;
|
||||||
|
|
||||||
|
# TODO make this also support getting more than one tweet.
|
||||||
|
|
||||||
|
if ($said->{body} =~ /^\s*(#\S+)/) {
|
||||||
|
# hash tags. omg.
|
||||||
|
my $search = $client->search($1);
|
||||||
|
|
||||||
|
open (my $fh, ">", "/tmp/twitter");
|
||||||
|
print $fh Dumper($search);
|
||||||
|
|
||||||
|
my $tweets = $search->{statuses};
|
||||||
|
my $tweet = $tweets->@[rand() * $tweets->@*];
|
||||||
|
|
||||||
|
display_tweet $tweet;
|
||||||
|
} else {
|
||||||
|
my ($userid, $count) = $said->{body} =~ /^\s*(\S+)(?:\s+(\d+))?/g;
|
||||||
|
|
||||||
|
my $timeline=$client->user_timeline($userid);
|
||||||
|
my $tweet = $timeline->[$count//0];
|
||||||
|
|
||||||
|
display_tweet $tweet;
|
||||||
|
}
|
||||||
|
|
||||||
return ('handled', 'handled');
|
return ('handled', 'handled');
|
||||||
};
|
};
|
||||||
|
|
1
wiki
Submodule
1
wiki
Submodule
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit b31b40fd425f599acf48bb5d16ce26fa9f61fb46
|
Loading…
Add table
Reference in a new issue