| 1 | package Bot::Backbone::Service::DirectChat; | ||
| 2 | $Bot::Backbone::Service::DirectChat::VERSION = '0.160630'; | ||
| 3 | use v5.10; | ||
| 4 | use Bot::Backbone::Service; | ||
| 5 | |||
| 6 | with qw( | ||
| 7 | Bot::Backbone::Service::Role::Service | ||
| 8 | Bot::Backbone::Service::Role::Dispatch | ||
| 9 | Bot::Backbone::Service::Role::ChatConsumer | ||
| 10 | ); | ||
| 11 | |||
| 12 | with 'Bot::Backbone::Service::Role::Chat' => { | ||
| 13 | -excludes => [ qw( send_message ) ], | ||
| 14 | }; | ||
| 15 | |||
| 16 | # ABSTRACT: A helper for doing direct chats | ||
| 17 | |||
| 18 | |||
| 19 | sub initialize { } | ||
| 20 | |||
| 21 | |||
| 22 | sub send_message { | ||
| 23 | my ($self, $params) = @_; | ||
| 24 | |||
| 25 | my $to = $params->{to} // Bot::Backbone::Identity->new( | ||
| 26 | username => $params->{to_username}, | ||
| 27 | (defined $params->{to_nickname} ? (nickname => $params->{to_nickname}) : ()), | ||
| 28 | ); | ||
| 29 | |||
| 30 | my $text = $params->{text}; | ||
| 31 | |||
| 32 | $self->chat->send_message({ | ||
| 33 | to => $to, | ||
| 34 | text => $text, | ||
| 35 | }); | ||
| 36 | } | ||
| 37 | |||
| 38 | |||
| 39 | sub receive_message { | ||
| 40 | my ($self, $message) = @_; | ||
| 41 | |||
| 42 | return unless not $message->is_group | ||
| 43 | and $message->is_direct; | ||
| 44 | |||
| 45 | $self->resend_message($message); | ||
| 46 | $self->dispatch_message($message); | ||
| 47 | } | ||
| 48 | |||
| 49 | __PACKAGE__->meta->make_immutable; | ||
| 50 | |||
| 51 | __END__ | ||
| 52 | |||
| 53 | =pod | ||
| 54 | |||
| 55 | =encoding UTF-8 | ||
| 56 | |||
| 57 | =head1 NAME | ||
| 58 | |||
| 59 | Bot::Backbone::Service::DirectChat - A helper for doing direct chats | ||
| 60 | |||
| 61 | =head1 VERSION | ||
| 62 | |||
| 63 | version 0.160630 | ||
| 64 | |||
| 65 | =head1 SYNOPSIS | ||
| 66 | |||
| 67 | service private_chat => ( | ||
| 68 | service => 'DirectChat', | ||
| 69 | chat => 'jabber_chat', | ||
| 70 | ); | ||
| 71 | |||
| 72 | =head1 DESCRIPTION | ||
| 73 | |||
| 74 | This is a chat service layered on top of an existing chat service. It only | ||
| 75 | passes on direct chats received and only sends direct chages back. | ||
| 76 | |||
| 77 | =head1 METHODS | ||
| 78 | |||
| 79 | =head2 initialize | ||
| 80 | |||
| 81 | Does nothing. | ||
| 82 | |||
| 83 | =head2 send_message | ||
| 84 | |||
| 85 | Sends a direct message chat to the nested chat service. | ||
| 86 | |||
| 87 | =head2 receive_message | ||
| 88 | |||
| 89 | If the message is not to a group and is sent direct, it will be passed on to | ||
| 90 | any chat consumers and dispatched. | ||
| 91 | |||
| 92 | =head1 AUTHOR | ||
| 93 | |||
| 94 | Andrew Sterling Hanenkamp <hanenkamp@cpan.org> | ||
| 95 | |||
| 96 | =head1 COPYRIGHT AND LICENSE | ||
| 97 | |||
| 98 | This software is copyright (c) 2016 by Qubling Software LLC. | ||
| 99 | |||
| 100 | This is free software; you can redistribute it and/or modify it under | ||
| 101 | the same terms as the Perl 5 programming language system itself. | ||
| 102 | |||
| 103 | =cut |