« blib/lib/auto/share/dist/Beekeeper/chat/flood.pl
↑ Summary
blib/lib/auto/share/dist/Beekeeper/chat/lib/MyApp/Service/Auth.pm »
| 1 | package MyApp::Bot; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use MyApp::Service::Chat; | ||
| 7 | use MyApp::Service::Auth; | ||
| 8 | |||
| 9 | use Beekeeper::Client; | ||
| 10 | use Beekeeper::Config; | ||
| 11 | |||
| 12 | sub new { | ||
| 13 | my ($class, %args) = @_; | ||
| 14 | |||
| 15 | my $self = { | ||
| 16 | username => $args{'username'}, | ||
| 17 | }; | ||
| 18 | |||
| 19 | my $config = Beekeeper::Config->read_config_file('client.config.json'); | ||
| 20 | |||
| 21 | # Force a new connection | ||
| 22 | local $Beekeeper::Client::singleton; | ||
| 23 | |||
| 24 | # Connect to bus 'frontend', wich will forward requests to 'backend' | ||
| 25 | $self->{client} = Beekeeper::Client->instance( | ||
| 26 | bus_role => "frontend", | ||
| 27 | forward_to => "backend", | ||
| 28 | %$config, | ||
| 29 | ); | ||
| 30 | |||
| 31 | $self->{chat} = MyApp::Service::Chat->new; | ||
| 32 | $self->{auth} = MyApp::Service::Auth->new; | ||
| 33 | |||
| 34 | $self->{chat}->receive_messages( | ||
| 35 | callback => $args{'on_message'}, | ||
| 36 | ); | ||
| 37 | |||
| 38 | $self->{auth}->login( | ||
| 39 | username => $self->{username}, | ||
| 40 | password => '123456', | ||
| 41 | ); | ||
| 42 | |||
| 43 | bless $self, $class; | ||
| 44 | return $self; | ||
| 45 | } | ||
| 46 | |||
| 47 | sub username { | ||
| 48 | my $self = shift; | ||
| 49 | |||
| 50 | $self->{username}; | ||
| 51 | } | ||
| 52 | |||
| 53 | sub talk { | ||
| 54 | my ($self, %args) = @_; | ||
| 55 | |||
| 56 | local $Beekeeper::Client::singleton = $self->{client}; | ||
| 57 | |||
| 58 | $self->{client}->fire_remote( | ||
| 59 | method => 'myapp.chat.pmessage', | ||
| 60 | params => { | ||
| 61 | to_user => $args{'to_user'}, | ||
| 62 | message => $args{'message'}, | ||
| 63 | }, | ||
| 64 | ); | ||
| 65 | } | ||
| 66 | |||
| 67 | 1; |