| 1 | package Amethyst::Brain::BarWench; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use vars qw(@ISA); | ||
| 5 | use URI; | ||
| 6 | use Amethyst::Brain; | ||
| 7 | use Amethyst::Message; | ||
| 8 | |||
| 9 | @ISA = qw(Amethyst::Brain); | ||
| 10 | |||
| 11 | sub reply_to { | ||
| 12 | my $self = shift; | ||
| 13 | my $message = $self->SUPER::reply_to(@_); | ||
| 14 | # $message->channel('spam'); | ||
| 15 | return $message; | ||
| 16 | } | ||
| 17 | |||
| 18 | sub init { | ||
| 19 | my $self = shift; | ||
| 20 | |||
| 21 | my %funcs = map { $_ => \&{"action_$_"} } qw( | ||
| 22 | help beer caffeine coffee beat pebkac sex npi | ||
| 23 | fuckup pissybeer base http hotornot jobs | ||
| 24 | rtfs rtfm rtfc | ||
| 25 | ); | ||
| 26 | |||
| 27 | $self->{Funcs} = \%funcs; | ||
| 28 | |||
| 29 | $self->{Http} = [ ]; | ||
| 30 | $self->{Hotornot} = [ ]; | ||
| 31 | $self->{Jobs} = [ ]; | ||
| 32 | $self->{HttpHash} = { }; | ||
| 33 | } | ||
| 34 | |||
| 35 | sub record_http { | ||
| 36 | my ($self, $message) = @_; | ||
| 37 | |||
| 38 | my $content = $message->content; | ||
| 39 | |||
| 40 | return undef if $content =~ /Recorded/; | ||
| 41 | |||
| 42 | my @http = ($content =~ m,(http(?:s)?://[^/]\S*),g); | ||
| 43 | |||
| 44 | @http = map { URI->new($_)->canonical->as_string } @http; | ||
| 45 | |||
| 46 | foreach my $url (@http) { | ||
| 47 | next if $self->{HttpHash}->{$url}; | ||
| 48 | |||
| 49 | my $old = undef; | ||
| 50 | my $new = [ $url, $message->user ]; | ||
| 51 | |||
| 52 | $self->{HttpHash}->{$url} = 1; | ||
| 53 | |||
| 54 | if ($url =~ m/hotornot/) { | ||
| 55 | push(@{ $self->{Hotornot} }, $new); | ||
| 56 | $old = shift(@{ $self->{Hotornot} }) | ||
| 57 | if @{$self->{Hotornot}} > 10; | ||
| 58 | } | ||
| 59 | else { | ||
| 60 | push(@{ $self->{Http} }, $new); | ||
| 61 | $old = shift(@{ $self->{Http} }) | ||
| 62 | if @{$self->{Http}} > 10; | ||
| 63 | } | ||
| 64 | |||
| 65 | if ($content =~ m/job/i) { | ||
| 66 | push(@{ $self->{Jobs} }, $new); | ||
| 67 | $old = shift(@{ $self->{Jobs} }) | ||
| 68 | if @{$self->{Jobs}} > 10; | ||
| 69 | } | ||
| 70 | |||
| 71 | delete $self->{HttpHash}->{$old->[0]} if $old; | ||
| 72 | } | ||
| 73 | } | ||
| 74 | |||
| 75 | sub think { | ||
| 76 | my $self = shift; | ||
| 77 | my $message = shift; | ||
| 78 | |||
| 79 | my $content = $message->content; | ||
| 80 | |||
| 81 | # print STDERR "Content $content\n"; | ||
| 82 | |||
| 83 | $self->record_http($message); | ||
| 84 | |||
| 85 | return undef unless $content =~ /^!([A-Za-z]*)(?:\s+(.*))?$/; | ||
| 86 | |||
| 87 | my $command = $1; | ||
| 88 | my $arg = defined $2 ? $2 : ''; | ||
| 89 | |||
| 90 | # print STDERR "Command $command\n"; | ||
| 91 | |||
| 92 | if (exists $self->{Funcs}->{$command}) { | ||
| 93 | print STDERR "BarWench: $command $arg\n"; | ||
| 94 | return $self->{Funcs}->{$command}->( | ||
| 95 | $self, $message, | ||
| 96 | $command, $arg); | ||
| 97 | } | ||
| 98 | |||
| 99 | return undef; | ||
| 100 | } | ||
| 101 | |||
| 102 | sub action_autolart { | ||
| 103 | my ($self, $message, $command, $arg) = @_; | ||
| 104 | $arg = $message->user; | ||
| 105 | return $self->action_lart($message, $command, $arg); | ||
| 106 | } | ||
| 107 | |||
| 108 | sub action_base { | ||
| 109 | my ($self, $message, $command, $arg) = @_; | ||
| 110 | my $reply = $self->reply_to($message, | ||
| 111 | "intones, \"ALL YOUR BASE ARE BELONG TO US\""); | ||
| 112 | $reply->action(ACT_EMOTE); | ||
| 113 | $reply->send; | ||
| 114 | return 1; | ||
| 115 | } | ||
| 116 | |||
| 117 | sub action_beat { | ||
| 118 | my ($self, $message, $command, $arg) = @_; | ||
| 119 | $arg = $message->user unless length $arg; | ||
| 120 | my $reply = $self->reply_to($message, "beats $arg with a stick."); | ||
| 121 | $reply->action(ACT_EMOTE); | ||
| 122 | $reply->send; | ||
| 123 | return 1; | ||
| 124 | } | ||
| 125 | |||
| 126 | sub action_beer { | ||
| 127 | my ($self, $message, $command, $arg) = @_; | ||
| 128 | $arg = $message->user unless length $arg; | ||
| 129 | my $reply = $self->reply_to($message, "pours a beer for $arg."); | ||
| 130 | $reply->action(ACT_EMOTE); | ||
| 131 | $reply->send; | ||
| 132 | return 1; | ||
| 133 | } | ||
| 134 | |||
| 135 | sub action_caffeine { | ||
| 136 | my ($self, $message, $command, $arg) = @_; | ||
| 137 | $arg = $message->user unless length $arg; | ||
| 138 | my $reply = $self->reply_to($message, | ||
| 139 | "posts a package of pure caffeine to $arg."); | ||
| 140 | $reply->action(ACT_EMOTE); | ||
| 141 | $reply->send; | ||
| 142 | return 1; | ||
| 143 | } | ||
| 144 | |||
| 145 | sub action_coffee { | ||
| 146 | my ($self, $message, $command, $arg) = @_; | ||
| 147 | $arg = $message->user unless length $arg; | ||
| 148 | my $reply = $self->reply_to($message, | ||
| 149 | "pours a steaming hot coffee for $arg."); | ||
| 150 | $reply->action(ACT_EMOTE); | ||
| 151 | $reply->send; | ||
| 152 | return 1; | ||
| 153 | } | ||
| 154 | |||
| 155 | sub action_fuckup { | ||
| 156 | my ($self, $message, $command, $arg) = @_; | ||
| 157 | my $reply = $self->reply_to($message, | ||
| 158 | "mutters, \"Ah, I see the fuckup " . | ||
| 159 | "fairy has visited us again.\""); | ||
| 160 | $reply->action(ACT_EMOTE); | ||
| 161 | $reply->send; | ||
| 162 | return 1; | ||
| 163 | } | ||
| 164 | |||
| 165 | sub action_help { | ||
| 166 | my ($self, $message, $command, $arg) = @_; | ||
| 167 | my @commands = map { "!$_" } sort keys %{$self->{Funcs}}; | ||
| 168 | my $reply = $self->reply_to($message, | ||
| 169 | "BarWench module for Amethyst: " . | ||
| 170 | "Commands are " . join(", ", @commands)); | ||
| 171 | $reply->send; | ||
| 172 | return 1; | ||
| 173 | } | ||
| 174 | |||
| 175 | sub action_hotornot { | ||
| 176 | my ($self, $message, $command, $arg) = @_; | ||
| 177 | my $reply; | ||
| 178 | |||
| 179 | my @data = @{ $self->{Hotornot} }; | ||
| 180 | if (@data) { | ||
| 181 | @data = map { "(" . $_->[1] . ") " . $_->[0] } @data; | ||
| 182 | foreach my $data (@data) { | ||
| 183 | $reply = $self->reply_to($message, $data); | ||
| 184 | $reply->send; | ||
| 185 | } | ||
| 186 | } | ||
| 187 | else { | ||
| 188 | $reply = $self->reply_to($message, "No recorded URLs."); | ||
| 189 | $reply->send; | ||
| 190 | } | ||
| 191 | return 1; | ||
| 192 | } | ||
| 193 | |||
| 194 | sub action_http { | ||
| 195 | my ($self, $message, $command, $arg) = @_; | ||
| 196 | my $reply; | ||
| 197 | |||
| 198 | my @data = @{ $self->{Http} }; | ||
| 199 | if (@data) { | ||
| 200 | @data = map { "(" . $_->[1] . ") " . $_->[0] } @data; | ||
| 201 | foreach my $data (@data) { | ||
| 202 | $reply = $self->reply_to($message, $data); | ||
| 203 | $reply->send; | ||
| 204 | } | ||
| 205 | } | ||
| 206 | else { | ||
| 207 | $reply = $self->reply_to($message, "No recorded URLs."); | ||
| 208 | $reply->send; | ||
| 209 | } | ||
| 210 | return 1; | ||
| 211 | } | ||
| 212 | |||
| 213 | sub action_jobs { | ||
| 214 | my ($self, $message, $command, $arg) = @_; | ||
| 215 | my $reply; | ||
| 216 | |||
| 217 | my @data = @{ $self->{Jobs} }; | ||
| 218 | if (@data) { | ||
| 219 | @data = map { "(" . $_->[1] . ") " . $_->[0] } @data; | ||
| 220 | foreach my $data (@data) { | ||
| 221 | $reply = $self->reply_to($message, $data); | ||
| 222 | $reply->send; | ||
| 223 | } | ||
| 224 | } | ||
| 225 | else { | ||
| 226 | $reply = $self->reply_to($message, "No recorded jobs."); | ||
| 227 | $reply->send; | ||
| 228 | } | ||
| 229 | return 1; | ||
| 230 | } | ||
| 231 | |||
| 232 | sub action_lart { | ||
| 233 | my ($self, $message, $command, $arg) = @_; | ||
| 234 | $arg = $message->user unless length $arg; | ||
| 235 | my $reply = $self->reply_to($message, | ||
| 236 | "applies a hefty LARTing session to $arg."); | ||
| 237 | $reply->action(ACT_EMOTE); | ||
| 238 | $reply->send; | ||
| 239 | return 1; | ||
| 240 | } | ||
| 241 | |||
| 242 | sub action_npi { | ||
| 243 | my ($self, $message, $command, $arg) = @_; | ||
| 244 | my $reply = $self->reply_to($message, | ||
| 245 | "mutters, \"Not Plugged In(tm)\""); | ||
| 246 | $reply->action(ACT_EMOTE); | ||
| 247 | $reply->send; | ||
| 248 | return 1; | ||
| 249 | } | ||
| 250 | |||
| 251 | sub action_pebkac { | ||
| 252 | my ($self, $message, $command, $arg) = @_; | ||
| 253 | my $reply = $self->reply_to($message, | ||
| 254 | "mutters, \"Problem exists between " . | ||
| 255 | "keyboard and chair.\""); | ||
| 256 | $reply->action(ACT_EMOTE); | ||
| 257 | $reply->send; | ||
| 258 | return 1; | ||
| 259 | } | ||
| 260 | |||
| 261 | sub action_pissybeer { | ||
| 262 | my ($self, $message, $command, $arg) = @_; | ||
| 263 | $arg = $message->user unless length $arg; | ||
| 264 | my $reply = $self->reply_to($message, | ||
| 265 | "pours a weak pissy beer for $arg."); | ||
| 266 | $reply->action(ACT_EMOTE); | ||
| 267 | $reply->send; | ||
| 268 | return 1; | ||
| 269 | } | ||
| 270 | |||
| 271 | sub action_rtfc { | ||
| 272 | my ($self, $message, $command, $arg) = @_; | ||
| 273 | my $reply = $self->reply_to($message, | ||
| 274 | "screams, \"Read the fucking code!\""); | ||
| 275 | $reply->action(ACT_EMOTE); | ||
| 276 | $reply->send; | ||
| 277 | return 1; | ||
| 278 | } | ||
| 279 | |||
| 280 | sub action_rtfm { | ||
| 281 | my ($self, $message, $command, $arg) = @_; | ||
| 282 | my $reply = $self->reply_to($message, | ||
| 283 | "screams, \"Read the fucking manual!\""); | ||
| 284 | $reply->action(ACT_EMOTE); | ||
| 285 | $reply->send; | ||
| 286 | return 1; | ||
| 287 | } | ||
| 288 | |||
| 289 | sub action_rtfs { | ||
| 290 | my ($self, $message, $command, $arg) = @_; | ||
| 291 | my $reply = $self->reply_to($message, | ||
| 292 | "screams, \"Read the fucking source!\""); | ||
| 293 | $reply->action(ACT_EMOTE); | ||
| 294 | $reply->send; | ||
| 295 | return 1; | ||
| 296 | } | ||
| 297 | |||
| 298 | sub action_sex { | ||
| 299 | my ($self, $message, $command, $arg) = @_; | ||
| 300 | $arg = $message->user; | ||
| 301 | return $self->action_beat($message, $command, $arg); | ||
| 302 | } | ||
| 303 | |||
| 304 | 1; |