X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FApp%2FFonBot%2FPlugin%2FCommon.pm;h=4866db92b4116456e6d164f4cf6e318f1a901191;hb=31d9adeefab30e0e8902454d677d0df1ca26c6ee;hp=b4fce7c9072c5f3a162aa4d80c135075e9e88a6c;hpb=8dc70d07c47947a1b1a9de7d377aee1003aca0ae;p=app-fonbot-daemon.git diff --git a/lib/App/FonBot/Plugin/Common.pm b/lib/App/FonBot/Plugin/Common.pm index b4fce7c..4866db9 100644 --- a/lib/App/FonBot/Plugin/Common.pm +++ b/lib/App/FonBot/Plugin/Common.pm @@ -1,6 +1,6 @@ package App::FonBot::Plugin::Common; -our $VERSION = '0.000_3'; +our $VERSION = '0.000_5'; use v5.14; use strict; @@ -24,43 +24,43 @@ our @EXPORT = qw/%ok_user_addresses %commands %waiting_requests sendmsg/; my $log=Log::Log4perl->get_logger(__PACKAGE__); sub init{ - $log->info('setting user and group'); - $)=join ' ', scalar getgrnam $group, map {scalar getgrnam $_} @supplementary_groups; - $(=scalar getgrnam $group; - $<=$>=scalar getpwnam $user; - chdir $dir; - - $log->info('initializing '.__PACKAGE__); - tie %ok_user_addresses, DB_File => 'ok_user_addresses.db'; - tie %commands, DB_File => 'commands.db'; + $log->info('setting user and group'); + $)=join ' ', scalar getgrnam $group, map {scalar getgrnam $_} @supplementary_groups; + $(=scalar getgrnam $group; + $<=$>=scalar getpwnam $user; + chdir $dir; + + $log->info('initializing '.__PACKAGE__); + tie %ok_user_addresses, DB_File => 'ok_user_addresses.db'; + tie %commands, DB_File => 'commands.db'; } sub fini{ - $log->info('finishing '.__PACKAGE__); - untie %ok_user_addresses; - untie %commands; + $log->info('finishing '.__PACKAGE__); + untie %ok_user_addresses; + untie %commands; } ################################################## sub sendmsg{ - my ($touser,$requestid,$replyto,$command,@args)=@_; - - my $data={command=>$command, replyto=>$replyto, args => \@args }; - $data->{requestid} = $requestid if defined $requestid; - - if (exists $commands{$touser}) { - my $temp = thaw $commands{$touser}; - push $temp, $data; - $commands{$touser} = freeze $temp - } else { - $commands{$touser} = freeze [$data] - } - - if (exists $waiting_requests{$touser}) { - $waiting_requests{$touser}->continue; - delete $waiting_requests{$touser} - } + my ($touser,$requestid,$replyto,$command,@args)=@_; + + my $data={command=>$command, replyto=>$replyto, args => \@args }; + $data->{requestid} = $requestid if defined $requestid; + + if (exists $commands{$touser}) { + my $temp = thaw $commands{$touser}; + push @$temp, $data; + $commands{$touser} = freeze $temp + } else { + $commands{$touser} = freeze [$data] + } + + if (exists $waiting_requests{$touser}) { + $waiting_requests{$touser}->continue; + delete $waiting_requests{$touser} + } } 1;