line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::FonBot::Plugin::Common; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.001'; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
9
|
use v5.14; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
6
|
1
|
|
|
1
|
|
3
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
30
|
|
7
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
21
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
3
|
use parent qw/Exporter/; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
6
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
570
|
use JSON qw/encode_json/; |
|
1
|
|
|
|
|
8190
|
|
|
1
|
|
|
|
|
7
|
|
12
|
1
|
|
|
1
|
|
170
|
use Log::Log4perl qw//; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
11
|
|
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
239
|
use DB_File qw//; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use Storable qw/freeze thaw/; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
use App::FonBot::Plugin::Config qw/$dir $user $group @supplementary_groups/; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
################################################## |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our (%ok_user_addresses, %commands, %waiting_requests); |
22
|
|
|
|
|
|
|
our @EXPORT = qw/%ok_user_addresses %commands %waiting_requests sendmsg/; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $log=Log::Log4perl->get_logger(__PACKAGE__); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub init{ |
27
|
|
|
|
|
|
|
$log->info('setting user and group'); |
28
|
|
|
|
|
|
|
$)=join ' ', scalar getgrnam $group, map {scalar getgrnam $_} @supplementary_groups; |
29
|
|
|
|
|
|
|
$(=scalar getgrnam $group; |
30
|
|
|
|
|
|
|
$<=$>=scalar getpwnam $user; |
31
|
|
|
|
|
|
|
chdir $dir; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
$log->info('initializing '.__PACKAGE__); |
34
|
|
|
|
|
|
|
tie %ok_user_addresses, DB_File => 'ok_user_addresses.db'; |
35
|
|
|
|
|
|
|
tie %commands, DB_File => 'commands.db'; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub fini{ |
39
|
|
|
|
|
|
|
$log->info('finishing '.__PACKAGE__); |
40
|
|
|
|
|
|
|
untie %ok_user_addresses; |
41
|
|
|
|
|
|
|
untie %commands; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
################################################## |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub sendmsg{ |
47
|
|
|
|
|
|
|
my ($touser,$requestid,$replyto,$command,@args)=@_; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my $data={command=>$command, replyto=>$replyto, args => \@args }; |
50
|
|
|
|
|
|
|
$data->{requestid} = $requestid if defined $requestid; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
if (exists $commands{$touser}) { |
53
|
|
|
|
|
|
|
my $temp = thaw $commands{$touser}; |
54
|
|
|
|
|
|
|
push @$temp, $data; |
55
|
|
|
|
|
|
|
$commands{$touser} = freeze $temp |
56
|
|
|
|
|
|
|
} else { |
57
|
|
|
|
|
|
|
$commands{$touser} = freeze [$data] |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
if (exists $waiting_requests{$touser}) { |
61
|
|
|
|
|
|
|
$waiting_requests{$touser}->continue; |
62
|
|
|
|
|
|
|
delete $waiting_requests{$touser} |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |
67
|
|
|
|
|
|
|
__END__ |