1
0
Fork 0
mirror of https://github.com/perlbot/perlbuut synced 2025-06-07 18:35:49 -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:
Ryan Voots 2017-03-24 15:33:55 -04:00
parent 237e14e1a9
commit faec5dcd5d
3 changed files with 32 additions and 11 deletions

3
.gitmodules vendored
View file

@ -1,3 +1,6 @@
[submodule "jail"]
path = jail
url = https://github.com/simcop2387/perlbot-jail
[submodule "wiki"]
path = wiki
url = https://github.com/perlbot/perlbuut.wiki.git

View file

@ -23,27 +23,44 @@ my $client = Twitter::API->new_with_traits(
my $_r = $client->oauth2_token;
$client->access_token($_r);
sub {
my( $said ) = @_;
# 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];
sub display_tweet {
my $tweet = shift;
if ($tweet) {
my ($time, $text, $id) = @{$tweet}{qw/created_at text id/};
my $source = $tweet->{user}{name};
my $url = "https://twitter.com/link/status/$id";
print STDERR Dumper($timeline);
print "<$source> $text $url";
} else {
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');
};

1
wiki Submodule

@ -0,0 +1 @@
Subproject commit b31b40fd425f599acf48bb5d16ce26fa9f61fb46