Add to git.
[monolith.git] / chat / bots / chatbotlib.pl
1 #!/usr/bin/perl -w -T
2
3 =pod
4
5 =head1 NAME
6
7 chatbotlib.pl - Library for accessing chatbots
8
9 =head1 SYNOPSIS
10
11 require "/usr/share/monolith-chat/bots/chatbotlib.pl";
12
13 cb_init (\@ARGV);
14 @rooms = cb_get_all_rooms ();
15 $msg = cb_wait_message (rooms => \@rooms, msgtypes => CB_POSTING|CB_ENTER);
16 cb_post_message (room => $roomid, text => "the message");
17
18 =over 4
19
20 =cut
21
22 use strict;
23
24 use LWP;
25 use LWP::UserAgent;
26
27 use vars qw($_cb_server $_cb_userid);
28
29 =item cb_init (\@ARGV);
30
31 Initialize the chatbot library. This parses and removes parameters
32 from the global C<@ARGV> which control the behaviour of the chatbot.
33 These parameters are:
34
35 =over 4
36
37 =item -s http://server/so-bin/chatbot.so
38
39 The URL of the C<chatbox.so> shared object script on the
40 server. This defaults to C<http://localhost/so-bin/chatbox.so>
41
42 =item -u userid
43
44 The user ID to use. The default is 0 (anonymous).
45
46 =back
47
48 =cut
49
50 sub cb_init
51   {
52     # This is a reference to the global @ARGV array.
53     my $ARGV = shift;
54
55     for (my $i = 0; $i < @$ARGV-1; ++$i)
56       {
57         if ($ARGV->[$i] eq '-s')
58           {
59             ($_, $_cb_server) = splice @$ARGV, $i, 2;
60           }
61         elsif ($ARGV->[$i] eq '-u')
62           {
63             ($_, $_cb_userid) = splice @$ARGV, $i, 2;
64           }
65       }
66   }
67
68 =item @rooms = cb_get_all_rooms ()
69
70 Return a list of all rooms.
71
72 =cut
73
74
75
76 =back
77
78 =head1 COPYRIGHT
79
80 Copyright (C) 2003 Richard W.M. Jones.
81
82 =cut