| 1 | package Bot::Backbone::Service::OFun::Insult; | ||
| 2 | $Bot::Backbone::Service::OFun::Insult::VERSION = '0.142230'; | ||
| 3 | use Bot::Backbone::Service; | ||
| 4 | |||
| 5 | with qw( | ||
| 6 | Bot::Backbone::Service::Role::Service | ||
| 7 | Bot::Backbone::Service::Role::Responder | ||
| 8 | ); | ||
| 9 | |||
| 10 | use Acme::Scurvy::Whoreson::BilgeRat; | ||
| 11 | |||
| 12 | # ABSTRACT: Ask the bot to insult your friends, enemies, and applications | ||
| 13 | |||
| 14 | |||
| 15 | service_dispatcher as { | ||
| 16 | command '!insult' => given_parameters { | ||
| 17 | parameter 'thing' => ( match_original => qr/.+/ ); | ||
| 18 | } respond_by_method 'insult_the_thing'; | ||
| 19 | }; | ||
| 20 | |||
| 21 | |||
| 22 | has language => ( | ||
| 23 | is => 'ro', | ||
| 24 | isa => 'Str', | ||
| 25 | required => 1, | ||
| 26 | default => 'pirate', | ||
| 27 | ); | ||
| 28 | |||
| 29 | |||
| 30 | has insult_generator => ( | ||
| 31 | is => 'ro', | ||
| 32 | isa => 'Acme::Scurvy::Whoreson::BilgeRat', | ||
| 33 | lazy_build => 1, | ||
| 34 | ); | ||
| 35 | |||
| 36 | sub _build_insult_generator { | ||
| 37 | my $self = shift; | ||
| 38 | my $language = $self->language; | ||
| 39 | |||
| 40 | return Acme::Scurvy::Whoreson::BilgeRat->new( | ||
| 41 | language => $language, | ||
| 42 | ); | ||
| 43 | } | ||
| 44 | |||
| 45 | |||
| 46 | sub insult_the_thing { | ||
| 47 | my ($self, $message) = @_; | ||
| 48 | |||
| 49 | my $thing = $message->parameters->{thing}; | ||
| 50 | |||
| 51 | my $insult = ''.$self->insult_generator; | ||
| 52 | my $a = $insult =~ /^[aeiou]/i ? 'an' : 'a'; | ||
| 53 | return "$thing is $a $insult."; | ||
| 54 | } | ||
| 55 | |||
| 56 | |||
| 57 | sub initialize { } | ||
| 58 | |||
| 59 | __PACKAGE__->meta->make_immutable; | ||
| 60 | |||
| 61 | __END__ |