-
Notifications
You must be signed in to change notification settings - Fork 3
/
DuckHunt.pm
279 lines (226 loc) · 7.1 KB
/
DuckHunt.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
package plugins::DuckHunt;
#---------------------------------------------------------------------------
# Copyright (C) 2013 [email protected]
# https://github.com/egretsareherons/RocksBot
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#-----------------------------------------------------------------------------
# I ripped this idea off from Matthias Meusburger.
# His supybot plugin: https://github.com/veggiematts/supybot-duckhunt/blob/master/plugin.py
#-----------------------------------------------------------------------------
use strict;
use warnings;
use base qw (modules::PluginBaseClass);
use modules::PluginBaseClass;
use Data::Dumper;
use constant DUCK => '\_o<';
use constant GOOSE => '(o)< ・゜゜・。。・゜゜HONK';
my $testing; #launch ducks every 8 seconds
sub plugin_init{
my $self = shift;
$self->{testing} = 0;
$self->useChannelCookies();
return $self;
}
sub getOutput {
my $self = shift;
my $cmd = $self->{command};
my $options = $self->{options};
my $channel = $self->{channel};
my $nick = $self->{nick};
my $output = "";
#
# bang bang bang
#
if ($cmd eq 'bang'){
return "You can't do that via PM. Sorry, bud." if ($channel!~/^#/);
if (!$self->globalCookie("hunt_on")){
return "The game is not currently in progress.";
}
if (!$self->globalCookie("duck_launched")){
$self->returnType("irc_yield");
$self->yieldCommand('kick');
$self->yieldArgs([$self->{channel}, $nick, "There was no goose! You shot yourself right out of the channel!"]);
return "What are you shooting at?";
}
$self->globalCookie("duck_launched", 0);
# shoot this duck
my $ducks = $self->cookie("num_ducks");
$ducks--;
$self->cookie("num_ducks", $ducks);
# schedule next duck
$self->scheduleDuck();
return "You shot a goose! You monster! You lose a point. Score: $ducks";
}
if ($cmd eq 'befriend'){
if (!$self->globalCookie("hunt_on")){
return "A game is not currently in progress.";
}
if (!$self->globalCookie("duck_launched")){
$self->returnType("irc_yield");
$self->yieldCommand('kick');
$self->yieldArgs([$self->{channel}, $nick, "You tried befriending a nonexistent goose. That's creepy, dude."]);
return "There was no goose!";
}
$self->globalCookie("duck_launched", 0);
my $ducks = $self->cookie("num_ducks");
$ducks++;
$self->cookie("num_ducks", $ducks);
$self->scheduleDuck();
return "You've befriended $ducks geese in $self->{channel}!";
}
if ($cmd eq 'launched'){
if (!$self->globalCookie("hunt_on")){
return "A game is not currently in progress.";
}
if (!$self->globalCookie("duck_launched")){
return "There is no goose right now. Wait for one to be launched.";
}
if ($self->globalCookie("duck_launched")){
return "There is currently a goose!";
}
}
#
# start the hunt
#
if ($cmd eq 'start'){
return "You can't do that via PM. Sorry, bud." if ($channel!~/^#/);
if ($self->globalCookie("hunt_on")){
return "A game is already in progress."
}
$self->scheduleDuck();
$self->globalCookie("hunt_on", 1);
return "Game started";
}
#
# stop the hunt
#
if ($cmd eq 'stop'){
return "You can't do that via PM. Sorry, bud." if ($channel!~/^#/);
if (!$self->globalCookie("hunt_on")){
return "A game is not currently in progress.";
}
$self->globalCookie("hunt_on", 0);
return "Game ended";
}
#
# launch a duck
#
if ($cmd eq '_launchduck'){
return if (!$self->globalCookie("hunt_on"));
if ($self->globalCookie("duck_launched")){
# a duck is already launched.
return;
}
$self->suppressNick("true");
$self->globalCookie("duck_launched", 1);
return $self->GOOSE;
}
#
# scores
#
if ($cmd eq 'friends'){
my @cookies = $self->allCookies();
@cookies = sort {$b->{value} <=> $a->{value}} @cookies;
#print Dumper (@cookies);
foreach my $cookie (@cookies){
next if ($cookie->{owner} eq ':package');
$self->addToList("$cookie->{owner}: $cookie->{value}", $self->BULLET );
}
my $list = $self->getList();
if ($list){
$output = BOLD."Goose Friend Scores for $self->{channel}: ".NORMAL . $list;
}else{
$output = NORMAL."No one has befriended any geese in $self->{channel} yet.";
}
return $output;
}
#
# monster scores!
#
if ($cmd eq 'monsters'){
my @cookies = $self->allCookies();
@cookies = sort {$a->{value} <=> $b->{value}} @cookies;
#print Dumper (@cookies);
foreach my $cookie (@cookies){
next if ($cookie->{owner} eq ':package');
$self->addToList("$cookie->{owner}: $cookie->{value}", $self->BULLET );
}
my $list = $self->getList();
if ($list){
$output = BOLD."Goose Killer Scores for $self->{channel}: ".NORMAL . $list;
}else{
$output = NORMAL."No one has killed any geese in $self->{channel} yet.";
}
return $output;
}
#
# clear_scores
#
if ($cmd eq 'clear_scores'){
$self->deletePackageCookies();
return ("Scores cleared");
}
}
sub scheduleDuck{
my $self = shift;
my $next_time;
if ($self->{testing}){
$next_time = time() + 8;
}else{
$next_time = time() + int(rand($self->s('goose_window'))) + $self->s('goose_delay');
}
print "now is " . time() . " next duck at " . $next_time . " which is in " . ($next_time - time ()) . " seconds\n";
my $args = {
timestamp => $next_time,
command => '_launchduck',
options => '',
internal => 1,
desc => 'quack'
};
$self->scheduleEvent($args);
}
sub listeners{
my $self = shift;
my @commands = [qw(bang befriend launched clear_scores _launchduck start stop friends monsters)];
my $default_permissions =[
{command=>"_launchduck", require_group => UA_INTERNAL },
{command=>"clear_scores", require_group => UA_TRUSTED},
{command=>"start", require_group => UA_TRUSTED},
];
return { commands=>@commands,
permissions=>$default_permissions,
};
}
sub settings{
my $self = shift;
$self->defineSetting({
name=>'goose_delay',
default=>60*12,
desc=>'The minimum time (in seconds) until the next duck appears.'
});
$self->defineSetting({
name=>'goose_window',
default=>60*15,
desc=>'The window of time (in seconds) in which the next goose might appear. We\'ll pick a random time in this window, following the goose_delay period.'
});
}
sub addHelp{
my $self = shift;
$self->addHelpItem("[plugin_description]", "Goose!");
$self->addHelpItem("[befriend]", "Command: befriend. Befriend a goose");
$self->addHelpItem("[bang]", "Command: bang. Kill a goose :(");
$self->addHelpItem("[clear_scores]", "clear the scores");
}1;
__END__