line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::TeleGramma; |
2
|
|
|
|
|
|
|
$App::TeleGramma::VERSION = '0.14'; |
3
|
|
|
|
|
|
|
# ABSTRACT: A modular Telegram Bot |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
293255
|
use Mojo::Base 'Telegram::Bot::Brain'; |
|
2
|
|
|
|
|
127015
|
|
|
2
|
|
|
|
|
13
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
418028
|
use App::TeleGramma::Config; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
34
|
|
9
|
2
|
|
|
2
|
|
859
|
use App::TeleGramma::PluginManager; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
20
|
|
10
|
2
|
|
|
2
|
|
937
|
use App::TeleGramma::Plugin::Base; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
14
|
|
11
|
2
|
|
|
2
|
|
64
|
use App::TeleGramma::Constants qw/:const/; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
171
|
|
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
11
|
use feature 'say'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
835
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has 'config'; |
16
|
|
|
|
|
|
|
has 'plugins'; |
17
|
|
|
|
|
|
|
has 'token'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# prepare/read config |
20
|
|
|
|
|
|
|
sub startup { |
21
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# prep config |
24
|
0
|
|
|
|
|
|
my $config_was_created = 0; |
25
|
0
|
|
|
|
|
|
$self->config(App::TeleGramma::Config->new); |
26
|
|
|
|
|
|
|
$self->config->create_if_necessary && do |
27
|
0
|
0
|
|
|
|
|
{ |
28
|
0
|
|
|
|
|
|
say $self->config->config_created_message; |
29
|
0
|
|
|
|
|
|
$config_was_created = 1; |
30
|
|
|
|
|
|
|
}; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# prep plugins |
33
|
0
|
|
|
|
|
|
$self->plugins(App::TeleGramma::PluginManager->new(config => $self->config, app => $self)); |
34
|
0
|
|
|
|
|
|
$self->plugins->load_plugins; |
35
|
|
|
|
|
|
|
|
36
|
0
|
0
|
|
|
|
|
exit 0 if $config_was_created; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# load token |
39
|
0
|
|
|
|
|
|
$self->config->read; |
40
|
0
|
|
|
|
|
|
$self->token($self->config->config->{_}->{bot_token}); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub bail_if_misconfigured { |
45
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
46
|
|
|
|
|
|
|
|
47
|
0
|
0
|
|
|
|
|
if (! $self->token) { |
48
|
0
|
|
|
|
|
|
die "config file does not have a bot token - bailing out\n"; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
|
if ($self->token =~ /please/i) { |
52
|
0
|
|
|
|
|
|
die "config file has the default bot token - bailing out\n"; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub init { |
57
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# add a listener which will pass every message to each listen plugin |
60
|
|
|
|
|
|
|
$self->add_listener( |
61
|
0
|
|
|
0
|
|
|
sub { 1 }, # everything matches |
62
|
0
|
|
|
|
|
|
\&incoming_message |
63
|
|
|
|
|
|
|
); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub incoming_message { |
68
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
69
|
0
|
|
|
|
|
|
my $msg = shift; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# pass it to all registered plugin listeners |
72
|
0
|
|
|
|
|
|
foreach my $listener (@{ $self->plugins->listeners }) { |
|
0
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# call each one |
74
|
0
|
|
|
|
|
|
my $res = $listener->process_message($msg); |
75
|
0
|
0
|
|
|
|
|
if (! $res) { |
76
|
0
|
|
|
|
|
|
warn "listener did not provide a response"; |
77
|
0
|
|
|
|
|
|
next; |
78
|
|
|
|
|
|
|
} |
79
|
0
|
0
|
0
|
|
|
|
if (($res eq PLUGIN_NO_RESPONSE_LAST) || |
80
|
|
|
|
|
|
|
($res eq PLUGIN_RESPONDED_LAST)) { |
81
|
0
|
|
|
|
|
|
last; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
__END__ |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=pod |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=encoding UTF-8 |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 NAME |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
App::TeleGramma - A modular Telegram Bot |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 VERSION |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
version 0.14 |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 SYNOPSIS |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Install App::TeleGramma and its dependencies |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
$ cpanm App::TeleGramma |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
The first time run, a basic configuration file is automatically created for you. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
$ telegramma |
111
|
|
|
|
|
|
|
Your new config has been created in /Users/username/.telegramma/telegramma.ini |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Please edit it now and update the Telegram Bot token, then |
114
|
|
|
|
|
|
|
re-run bin/telegramma. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
The configuration will have an entry for each plugin currently available on |
117
|
|
|
|
|
|
|
your system, but disabled. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Edit the config file, adding (at least) the Telegram Bot API key. You can get |
120
|
|
|
|
|
|
|
an API key from the @botfather bot on Telegram. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Now you can run, first in foreground mode for testing purposes: |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
$ telegramma --nodaemon |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
When it's all good, you'll want to run it as a daemon: |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
$ telegramma |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
You can monitor the status of the running process, and shut it down. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
$ telegramma --status |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
$ telegramma --shutdown |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 DESCRIPTION |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
TeleGramma is an easy to use, extensible bot to use with Telegram C<www.telegram.org>. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Its plugin architecture makes it easy to add new modules either from other authors, |
141
|
|
|
|
|
|
|
or yourself. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 NAME |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
App::TeleGramma - A modular Telegram Bot |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 BUGS |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
None known. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 AUTHOR |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Justin Hawkins C<justin@eatmorecode.com> |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head1 SEE ALSO |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
L<Telegram::Bot> - the lower level API |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head1 AUTHOR |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Justin Hawkins <justin@hawkins.id.au> |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
This software is copyright (c) 2019 by Justin Hawkins <justin@eatmorecode.com>. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
168
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=cut |