b4fce7c9072c5f3a162aa4d80c135075e9e88a6c
1 package App
::FonBot
::Plugin
::Common
;
3 our $VERSION = '0.000_3';
9 use parent qw
/Exporter/;
11 use JSON qw
/encode_json/;
12 use Log
::Log4perl qw
//;
15 use Storable qw
/freeze thaw/;
17 use App
::FonBot
::Plugin
::Config qw
/$dir $user $group @supplementary_groups/;
19 ##################################################
21 our (%ok_user_addresses, %commands, %waiting_requests);
22 our @EXPORT = qw
/%ok_user_addresses %commands %waiting_requests sendmsg/;
24 my $log=Log
::Log4perl
->get_logger(__PACKAGE__
);
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;
33 $log->info('initializing '.__PACKAGE__
);
34 tie
%ok_user_addresses, DB_File
=> 'ok_user_addresses.db';
35 tie
%commands, DB_File
=> 'commands.db';
39 $log->info('finishing '.__PACKAGE__
);
40 untie %ok_user_addresses;
44 ##################################################
47 my ($touser,$requestid,$replyto,$command,@args)=@_;
49 my $data={command
=>$command, replyto
=>$replyto, args
=> \
@args };
50 $data->{requestid
} = $requestid if defined $requestid;
52 if (exists $commands{$touser}) {
53 my $temp = thaw
$commands{$touser};
55 $commands{$touser} = freeze
$temp
57 $commands{$touser} = freeze
[$data]
60 if (exists $waiting_requests{$touser}) {
61 $waiting_requests{$touser}->continue;
62 delete $waiting_requests{$touser}
73 App::FonBot::Plugin::Common - FonBot plugin that provides global variables and functions
77 use App::FonBot::Plugin::Common;
78 App::FonBot::Plugin::Common->init;
80 $ok_user_addresses{'marius OFTC mgvx'}=1; # Let user marius send messages to mgvx via the OFTC plugin
81 sendmsg 'marius', 'OFTC mgvx', 'echo', 'Hello', 'world!';
83 App::FonBot::Plugin::Common->fini;
87 This FonBot plugin provides global variables and functions to the other plugins. It also sets the user and group according to the configuration file. It is a required plugin, since most other plugins depend on it.
89 =head1 CONFIGURATION VARIABLES
91 These are the L<App::FonBot::Plugin::Config> configuration variables used in this module
97 Directory to chdir to.
107 =item C<@supplementary_groups>
109 Supplementary groups list to set.
113 =head1 EXPORTED SYMBOLS
117 =item B<%ok_user_addresses>
119 Hash that records combinations of username, driver and address that have sent commands to us. The key format is C<"$username $drivername $address">. B<fonbotd> will never send a message to an address which is not found in this hash.
121 Example entry: C<$ok_user_address{"nobody EMAIL nobody@mailinator.com"}>.
125 Hash from usernames to a C<Storable::freeze>d array of pending commands for the user.
127 =item B<%waiting_requests>
129 Hash from usernames to a waiting HTTP::Response, as defined by the POE::Component::Server::HTTP documentation.
131 =item B<sendmsg>(I<$touser>, I<$requestid>, I<$replyto>, I<$command>, I<@args>)
133 Sends a command to C<$touser>'s phone. The command includes a command name (C<$command>), a list of arguments (C<@args>) and a reply address (C<$replyto>). If I<$requestid> is defined, the command will also include that request ID.
141 =item C<App::FonBot::Plugin::Common-E<gt>init>
143 Sets the user and group according to the configuration variables and reads the exported variables from the disk.
145 =item C<App::FonBot::Plugin::Common-E<gt>fini>
147 Writes the exported variables to the disk.
153 Marius Gavrilescu C<< <marius@ieval.ro> >>
155 =head1 COPYRIGHT AND LICENSE
157 Copyright 2013 Marius Gavrilescu
159 This file is part of fonbotd.
161 fonbotd is free software: you can redistribute it and/or modify
162 it under the terms of the GNU Affero General Public License as published by
163 the Free Software Foundation, either version 3 of the License, or
164 (at your option) any later version.
166 fonbotd is distributed in the hope that it will be useful,
167 but WITHOUT ANY WARRANTY; without even the implied warranty of
168 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
169 GNU Affero General Public License for more details.
171 You should have received a copy of the GNU Affero General Public License
172 along with fonbotd. If not, see <http://www.gnu.org/licenses/>
This page took 0.02919 seconds and 3 git commands to generate.