line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::TeleGramma::Plugin::Core::Stenographer; |
2
|
|
|
|
|
|
|
$App::TeleGramma::Plugin::Core::Stenographer::VERSION = '0.12'; |
3
|
|
|
|
|
|
|
# ABSTRACT: TeleGramma plugin to log all text messages |
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
1509
|
use Mojo::Base 'App::TeleGramma::Plugin::Base'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
10
|
|
6
|
2
|
|
|
2
|
|
895
|
use App::TeleGramma::BotAction::ListenAll; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
14
|
|
7
|
2
|
|
|
2
|
|
57
|
use App::TeleGramma::Constants qw/:const/; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
162
|
|
8
|
2
|
|
|
2
|
|
12
|
use File::Spec::Functions qw/catfile catdir/; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
683
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub synopsis { |
11
|
0
|
|
|
0
|
1
|
0
|
"Log all the things" |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub default_config { |
15
|
1
|
|
|
1
|
1
|
4
|
my $self = shift; |
16
|
1
|
|
|
|
|
4
|
return { }; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub log_fh_for_message { |
20
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
21
|
0
|
|
|
|
|
|
my $msg = shift; |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
my $data_dir = $self->data_dir; |
24
|
0
|
|
|
|
|
|
my $chat_dir = catdir($data_dir, $msg->chat->id); |
25
|
0
|
|
|
|
|
|
mkdir $chat_dir; |
26
|
0
|
|
|
|
|
|
my $chat_file = sprintf("%04d-%02d.log", (localtime())[5]+1900, (localtime())[4]+1); |
27
|
0
|
|
|
|
|
|
my $log_file = catfile($chat_dir, $chat_file); |
28
|
0
|
|
|
|
|
|
open my $fh, ">>", $log_file; |
29
|
0
|
|
|
|
|
|
return $fh; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub register { |
33
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $logger = App::TeleGramma::BotAction::ListenAll->new( |
36
|
0
|
|
|
0
|
|
|
response => sub { $self->log_message(@_) } |
37
|
0
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
return ($logger); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub log_message { |
43
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
44
|
0
|
|
|
|
|
|
my $msg = shift; |
45
|
|
|
|
|
|
|
|
46
|
0
|
0
|
|
|
|
|
return PLUGIN_NO_RESPONSE unless $msg->text; # don't try to deal with anything but text |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
my $fh = $self->log_fh_for_message($msg); |
49
|
0
|
|
|
|
|
|
my $username; |
50
|
0
|
0
|
0
|
|
|
|
if ($msg->from && $msg->from->username) { |
|
|
0
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
$username = $msg->from->username; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
elsif ($msg->from) { |
54
|
0
|
|
|
|
|
|
$username = $msg->from->id; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
else { |
57
|
0
|
|
|
|
|
|
$username = "unknown"; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
my $text = sprintf("%-26s %s: %s\n", scalar localtime, $username, $msg->text); |
61
|
0
|
|
|
|
|
|
print $fh $text; |
62
|
0
|
|
|
|
|
|
close $fh; |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
return PLUGIN_NO_RESPONSE; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
__END__ |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=pod |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=encoding UTF-8 |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 NAME |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
App::TeleGramma::Plugin::Core::Stenographer - TeleGramma plugin to log all text messages |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 VERSION |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
version 0.12 |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 AUTHOR |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Justin Hawkins <justin@eatmorecode.com> |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
This software is copyright (c) 2017 by Justin Hawkins <justin@eatmorecode.com>. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
92
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=cut |