Created
July 30, 2011 16:52
-
-
Save toritori0318/1115736 to your computer and use it in GitHub Desktop.
kuru_kuru_bot_retweet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/perl | |
| use strict; | |
| use warnings; | |
| use AnyEvent::Twitter::Stream; | |
| use AnyEvent; | |
| use Encode qw/encode_utf8/; | |
| use Net::Twitter::Lite; | |
| use Log::Minimal; | |
| use Data::Dumper; | |
| use Clone qw/clone/; | |
| binmode STDOUT, ":utf8"; | |
| use utf8; | |
| use Config::Pit; | |
| my $config = pit_get("kuru_kuru_bot"); | |
| die "not preset account data in Pit." if !%$config; | |
| my %CONSUMER_TOKENS = ( | |
| consumer_key => $config->{consumer_key}, | |
| consumer_secret => $config->{consumer_secret}, | |
| ); | |
| my $ACCESS_TOKEN = $config->{access_token}; | |
| my $ACCESS_TOKEN_SECRET = $config->{access_token_secret}; | |
| # constructs a "Net::Twitter::Lite" object | |
| my $t = Net::Twitter::Lite->new(%CONSUMER_TOKENS); | |
| $t->access_token($ACCESS_TOKEN); | |
| $t->access_token_secret($ACCESS_TOKEN_SECRET); | |
| use Text::Xslate; | |
| my $tx = Text::Xslate->new(); | |
| my @retweet_pattern = ( | |
| 'ガ<: "ッ" x $rand :> ( ^o^)o彡 <: $user :>', # ガッ | |
| '昇竜拳<: "!" x $rand :> ( ^o^)ノ <: $user :>', # 昇竜拳 | |
| '<: $user :> ヾ(o^ )よしよし <: " " x $rand :> ', # なでなで | |
| 'うんこどぞどぞ ( ^o^)ノ● <: $user :> <: " " x $rand :>', # うんこ | |
| 'お茶どぞ ( ^o^)つ旦 <: $user :> <: " " x $rand :>', # お茶 | |
| # '', # しょぼん | |
| ); | |
| while (1) { | |
| infof('start!'); | |
| my $cv = AE::cv; | |
| my $connected; | |
| my $streamer = AnyEvent::Twitter::Stream->new( | |
| consumer_key => $CONSUMER_TOKENS{consumer_key}, | |
| consumer_secret => $CONSUMER_TOKENS{consumer_secret}, | |
| token => $ACCESS_TOKEN, | |
| token_secret => $ACCESS_TOKEN_SECRET, | |
| method => "filter", | |
| track => '@kuru_kuru_bot', | |
| on_tweet => sub { | |
| $connected = 1 unless $connected; | |
| my $tweet = shift; | |
| my $user = $tweet->{user}{screen_name}; | |
| my $text = $tweet->{text}; | |
| my $retweet_rand = int(rand($#retweet_pattern)); | |
| # 7割は ガッッッ を表示する | |
| if(rand(1) < 0.7) { | |
| $retweet_rand = 0; | |
| } | |
| my $rand = int(rand(6))+1; | |
| my $update = $tx->render_string($retweet_pattern[$retweet_rand], { user => '@'.$user, rand => $rand }); | |
| eval { | |
| my $status = $t->update( { status => $update } ); | |
| }; | |
| if($@) { | |
| infof('update error!: ' . $@); | |
| } | |
| }, | |
| on_keepalive => sub { | |
| $connected = 1 unless $connected; | |
| }, | |
| on_error => sub { | |
| $cv->send; | |
| }, | |
| ); | |
| $cv->recv; | |
| undef $streamer; | |
| my $wait = $connected ? 0 : 5; #とりあえず5秒まってやる | |
| infof('AE Restart!'); | |
| my $wait_cv = AE::cv; | |
| my $wait_t = AE::timer $wait, 0, $wait_cv; | |
| $wait_cv->recv; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment