X-Git-Url: http://git.ieval.ro/?p=app-fonbot-daemon.git;a=blobdiff_plain;f=lib%2FApp%2FFonBot%2FPlugin%2FCommon.pm;h=d61d9153660a1d2761ee4bc5bbbb3616bc8dc7ae;hp=b4fce7c9072c5f3a162aa4d80c135075e9e88a6c;hb=962dff7b76ec32cd68e0e96b8d3cc6d1f9759d00;hpb=7be318a6bf7a8f960c4192f52e7e5c8763d002ee diff --git a/lib/App/FonBot/Plugin/Common.pm b/lib/App/FonBot/Plugin/Common.pm index b4fce7c..d61d915 100644 --- a/lib/App/FonBot/Plugin/Common.pm +++ b/lib/App/FonBot/Plugin/Common.pm @@ -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;