-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBassyBot.pm
156 lines (144 loc) · 3.51 KB
/
BassyBot.pm
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package BassyBot;
use strict;
use warnings;
use utf8;
use base qw(TwitterBot);
use Time::ParseDate;
$BassyBot::VERSION = '0.4pre';
sub new {
my $class = shift;
my $self = $class->SUPER::new(@_);
$self->timer->add_target("12:00", sub {
my $self = shift;
$self->tweet("今日もバッシータイム開始!冷やしパーコ!");
$self->update_friends();
});
$self->timer->add_target("15:00", sub {
my $self = shift;
$self->tweet("しょうもねぇーな!");
});
$self->timer->add_target("18:00", sub {
my $self = shift;
$self->tweet("一人で焼肉食いにいってくる。18000円だけどな!");
});
$self->timer->add_target("21:00", sub {
my $self = shift;
$self->tweet("「ででーん」は大事につかえ!");
});
$self->logger->info("bassy-bot initialized.");
return $self;
}
my @ACTIONS = (
# print out message
sub {
my $self = shift;
my $tweet = shift;
$self->logger->info("Searching reaction for ". &_format_tweet($tweet));
return ();
},
# ignore myself
sub {
my $self = shift;
my $tweet = shift;
return $tweet->{user}{id} eq $self->util->user->{id};
},
# ignore non-friend
sub {
my $self = shift;
my $tweet = shift;
my @friends = @{$self->util->friends_ids};
$self->logger->debug("check if user:$tweet->{user}{id} is in friends-list(".join(",", @friends).")");
return ! grep {$tweet->{user}{id} eq $_} @friends;
},
# ignore official RT
sub {
my $self = shift;
my $tweet = shift;
if ($tweet->{retweeted_status}) {
return 1;
}
return ();
},
# RT
sub {
my $self = shift;
my $tweet = shift;
if ($tweet->{text} =~ /RT \@bassytime\:/) {
$self->tweet("いってねーよバーカ! RT \@$tweet->{user}{screen_name}: $tweet->{text}", $tweet->{id});
return 1;
}
return ();
},
# 俺のVM
#sub {
# my $self = shift;
# my $tweet = shift;
# if ($tweet->{text} =~ /揺れた|ゆれた|地震|yrt/) {
# $self->tweet("俺のVM RT \@$tweet->{user}{screen_name}: $tweet->{text}", $tweet->{id});
# return 1;
# }
# return ();
# },
# わかめじゃねーよ!!
sub {
my $self = shift;
my $tweet = shift;
if ($tweet->{text} =~ /(わかめ|ワカメ)/) {
$self->tweet("$1じゃねーよ!! RT \@$tweet->{user}{screen_name}: $tweet->{text}", $tweet->{id});
return 1;
}
return ();
},
# Reply
sub {
my $self = shift;
my $tweet = shift;
if ($tweet->{text} =~ /\@bassytime/) {
$self->tweet("\@$tweet->{user}{screen_name} ホントしょうもねぇーな! RT \@$tweet->{user}{screen_name}: $tweet->{text}", $tweet->{id});
return 1;
}
return ();
},
# この厨二がっ!
sub {
my $self = shift;
my $tweet = shift;
if ($tweet->{text} =~ /unko|utm|ちん[○こ]|チン[○コ]/) {
$self->tweet("\@$tweet->{user}{screen_name} この厨二がっ!", $tweet->{id});
return 1;
}
return ();
},
# # @riue(18943492)
# sub {
# my $self = shift;
# my $tweet = shift;
# if ($tweet->{user}{id} eq '18943492') {
# $self->tweet("\@$tweet->{user}{screen_name} しょうもねぇーな!", $tweet->{id});
# return 1;
# }
# return ();
# },
);
sub tweet {
my $self = shift;
$_[0] .= ' #bassytime';
$self->SUPER::tweet(@_);
}
sub actions {
return \@ACTIONS;
}
sub _format_tweet {
my $tweet = shift;
my $time = parsedate($tweet->{created_at});
my $ago = time - $time;
if ($ago < 60) {
$ago = $ago . 's';
} elsif ($ago < 60 * 60) {
$ago = int($ago/60) . 'm';
} else {
$ago = int($ago/60/60) . 'h';
}
return "$ago ago: $tweet->{id} <$tweet->{user}{screen_name}/$tweet->{user}{id}> $tweet->{text}";
}
1;