libpurple/plugins/perl/scripts/buddy_list.pl

Wed, 13 May 2009 20:29:03 +0000

author
Marcus Lundblad <malu@pidgin.im>
date
Wed, 13 May 2009 20:29:03 +0000
changeset 27110
05ca719b901b
parent 15894
765ec644ac47
child 16238
33bf2fd32108
child 18068
b6554e3c8224
child 20478
46933dc62880
child 29935
d28b5dcc7554
permissions
-rw-r--r--

Support custom smileys in MUCs (when all participants support BoB and a maximum
of 10 participants are in the chat).
Always announce support for BoB, since disable custom smileys will still turn
off fetching them, and BoB can be used for other purposes further on.

11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
1 $MODULE_NAME = "Buddy List Test";
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
2
15894
765ec644ac47 Perl fixes for s/gaim/purple/. This hasn't really been tested yet.
Daniel Atallah <datallah@pidgin.im>
parents: 15435
diff changeset
3 use Purple;
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
4
15894
765ec644ac47 Perl fixes for s/gaim/purple/. This hasn't really been tested yet.
Daniel Atallah <datallah@pidgin.im>
parents: 15435
diff changeset
5 # All the information Purple gets about our nifty plugin
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
6 %PLUGIN_INFO = (
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
7 perl_api_version => 2,
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
8 name => "Perl: $MODULE_NAME",
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
9 version => "0.1",
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
10 summary => "Test plugin for the Perl interpreter.",
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
11 description => "Implements a set of test proccedures to ensure all functions that work in the C API still work in the Perl plugin interface. As XSUBs are added, this *should* be updated to test the changes. Furthermore, this will function as the tutorial perl plugin.",
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
12 author => "John H. Kelm <johnhkelm\@gmail.com>",
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
13 url => "http://sourceforge.net/users/johnhkelm/",
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
14
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
15 load => "plugin_load",
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
16 unload => "plugin_unload"
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
17 );
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
18
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
19
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
20 # These names must already exist
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
21 my $USERNAME = "johnhkelm2";
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
22
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
23 # We will create these on load then destroy them on unload
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
24 my $TEST_GROUP = "UConn Buddies";
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
25 my $TEST_NAME = "johnhkelm";
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
26 my $TEST_ALIAS = "John Kelm";
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
27 my $PROTOCOL_ID = "prpl-oscar";
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
28
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
29
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
30 sub plugin_init {
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
31 return %PLUGIN_INFO;
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
32 }
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
33
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
34
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
35 # This is the sub defined in %PLUGIN_INFO to be called when the plugin is loaded
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
36 # Note: The plugin has a reference to itself on top of the argument stack.
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
37 sub plugin_load {
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
38 my $plugin = shift;
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
39
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
40 # This is how we get an account to use in the following tests. You should replace the username
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
41 # with an existing user
15894
765ec644ac47 Perl fixes for s/gaim/purple/. This hasn't really been tested yet.
Daniel Atallah <datallah@pidgin.im>
parents: 15435
diff changeset
42 $account = Purple::Accounts::find($USERNAME, $PROTOCOL_ID);
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
43
15894
765ec644ac47 Perl fixes for s/gaim/purple/. This hasn't really been tested yet.
Daniel Atallah <datallah@pidgin.im>
parents: 15435
diff changeset
44 # Testing a find function: Note Purple::Find not Purple::Buddy:find!
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
45 # Furthermore, this should work the same for chats and groups
15894
765ec644ac47 Perl fixes for s/gaim/purple/. This hasn't really been tested yet.
Daniel Atallah <datallah@pidgin.im>
parents: 15435
diff changeset
46 Purple::Debug::info($MODULE_NAME, "Testing: Purple::Find::buddy()...");
765ec644ac47 Perl fixes for s/gaim/purple/. This hasn't really been tested yet.
Daniel Atallah <datallah@pidgin.im>
parents: 15435
diff changeset
47 $buddy = Purple::Find::buddy($account, $TEST_NAME);
765ec644ac47 Perl fixes for s/gaim/purple/. This hasn't really been tested yet.
Daniel Atallah <datallah@pidgin.im>
parents: 15435
diff changeset
48 Purple::Debug::info("", ($buddy ? "ok." : "fail.") . "\n");
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
49
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
50 # If you should need the handle for some reason, here is how you do it
15894
765ec644ac47 Perl fixes for s/gaim/purple/. This hasn't really been tested yet.
Daniel Atallah <datallah@pidgin.im>
parents: 15435
diff changeset
51 Purple::Debug::info($MODULE_NAME, "Testing: Purple::BuddyList::get_handle()...");
765ec644ac47 Perl fixes for s/gaim/purple/. This hasn't really been tested yet.
Daniel Atallah <datallah@pidgin.im>
parents: 15435
diff changeset
52 $handle = Purple::BuddyList::get_handle();
765ec644ac47 Perl fixes for s/gaim/purple/. This hasn't really been tested yet.
Daniel Atallah <datallah@pidgin.im>
parents: 15435
diff changeset
53 Purple::Debug::info("", ($handle ? "ok." : "fail.") . "\n");
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
54
15894
765ec644ac47 Perl fixes for s/gaim/purple/. This hasn't really been tested yet.
Daniel Atallah <datallah@pidgin.im>
parents: 15435
diff changeset
55 # This gets the Purple::BuddyList and references it by $blist
765ec644ac47 Perl fixes for s/gaim/purple/. This hasn't really been tested yet.
Daniel Atallah <datallah@pidgin.im>
parents: 15435
diff changeset
56 Purple::Debug::info($MODULE_NAME, "Testing: Purple::get_blist()...");
765ec644ac47 Perl fixes for s/gaim/purple/. This hasn't really been tested yet.
Daniel Atallah <datallah@pidgin.im>
parents: 15435
diff changeset
57 $blist = Purple::get_blist();
765ec644ac47 Perl fixes for s/gaim/purple/. This hasn't really been tested yet.
Daniel Atallah <datallah@pidgin.im>
parents: 15435
diff changeset
58 Purple::Debug::info("", ($blist ? "ok." : "fail.") . "\n");
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
59
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
60 # This is how you would add a buddy named $TEST_NAME" with the alias $TEST_ALIAS
15894
765ec644ac47 Perl fixes for s/gaim/purple/. This hasn't really been tested yet.
Daniel Atallah <datallah@pidgin.im>
parents: 15435
diff changeset
61 Purple::Debug::info($MODULE_NAME, "Testing: Purple::BuddyList::Buddy::new...");
765ec644ac47 Perl fixes for s/gaim/purple/. This hasn't really been tested yet.
Daniel Atallah <datallah@pidgin.im>
parents: 15435
diff changeset
62 $buddy = Purple::BuddyList::Buddy::new($account, $TEST_NAME, $TEST_ALIAS);
765ec644ac47 Perl fixes for s/gaim/purple/. This hasn't really been tested yet.
Daniel Atallah <datallah@pidgin.im>
parents: 15435
diff changeset
63 Purple::Debug::info("", ($buddy ? "ok." : "fail.") . "\n");
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
64
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
65 # Here we add the new buddy '$buddy' to the group $TEST_GROUP
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
66 # so first we must find the group
15894
765ec644ac47 Perl fixes for s/gaim/purple/. This hasn't really been tested yet.
Daniel Atallah <datallah@pidgin.im>
parents: 15435
diff changeset
67 Purple::Debug::info($MODULE_NAME, "Testing: Purple::Find::group...");
765ec644ac47 Perl fixes for s/gaim/purple/. This hasn't really been tested yet.
Daniel Atallah <datallah@pidgin.im>
parents: 15435
diff changeset
68 $group = Purple::Find::group($TEST_GROUP);
765ec644ac47 Perl fixes for s/gaim/purple/. This hasn't really been tested yet.
Daniel Atallah <datallah@pidgin.im>
parents: 15435
diff changeset
69 Purple::Debug::info("", ($group ? "ok." : "fail.") . "\n");
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
70
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
71 # To add the buddy we need to have the buddy, contact, group and node for insertion.
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
72 # For this example we can let contact be undef and set the insertion node as the group
15894
765ec644ac47 Perl fixes for s/gaim/purple/. This hasn't really been tested yet.
Daniel Atallah <datallah@pidgin.im>
parents: 15435
diff changeset
73 Purple::Debug::info($MODULE_NAME, "Testing: Purple::BuddyList::add_buddy...\n");
765ec644ac47 Perl fixes for s/gaim/purple/. This hasn't really been tested yet.
Daniel Atallah <datallah@pidgin.im>
parents: 15435
diff changeset
74 Purple::BuddyList::add_buddy($buddy, undef, $group, $group);
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
75
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
76 # The example that follows gives an indication of how an API call that returns a list is handled.
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
77 # In this case the buddies of the account found earlier are retrieved and put in an array '@buddy_array'
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
78 # Further down an accessor method is used, 'get_name()' -- see source for details on the full set of methods
15894
765ec644ac47 Perl fixes for s/gaim/purple/. This hasn't really been tested yet.
Daniel Atallah <datallah@pidgin.im>
parents: 15435
diff changeset
79 Purple::Debug::info($MODULE_NAME, "Testing: Purple::Find::buddies...\n");
765ec644ac47 Perl fixes for s/gaim/purple/. This hasn't really been tested yet.
Daniel Atallah <datallah@pidgin.im>
parents: 15435
diff changeset
80 @buddy_array = Purple::Find::buddies($account, undef);
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
81 if (@buddy_array) {
15894
765ec644ac47 Perl fixes for s/gaim/purple/. This hasn't really been tested yet.
Daniel Atallah <datallah@pidgin.im>
parents: 15435
diff changeset
82 Purple::Debug::info($MODULE_NAME, "Buddies in list (" . @buddy_array . "): \n");
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
83 foreach $bud (@buddy_array) {
15894
765ec644ac47 Perl fixes for s/gaim/purple/. This hasn't really been tested yet.
Daniel Atallah <datallah@pidgin.im>
parents: 15435
diff changeset
84 Purple::Debug::info($MODULE_NAME, Purple::BuddyList::Buddy::get_name($bud) . "\n");
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
85 }
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
86 }
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
87 }
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
88
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
89 sub plugin_unload {
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
90 my $plugin = shift;
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
91
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
92 print "#" x 80 . "\n\n";
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
93 ######### TEST CODE HERE ##########
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
94
15894
765ec644ac47 Perl fixes for s/gaim/purple/. This hasn't really been tested yet.
Daniel Atallah <datallah@pidgin.im>
parents: 15435
diff changeset
95 print "Testing: Purple::Find::buddy()...";
765ec644ac47 Perl fixes for s/gaim/purple/. This hasn't really been tested yet.
Daniel Atallah <datallah@pidgin.im>
parents: 15435
diff changeset
96 $buddy = Purple::Find::buddy($account, $TEST_NAME . TEST);
15166
8febc283dead [gaim-migrate @ 17890]
Daniel Atallah <datallah@pidgin.im>
parents: 14254
diff changeset
97 if ($buddy) {
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
98 print "ok.\n";
15894
765ec644ac47 Perl fixes for s/gaim/purple/. This hasn't really been tested yet.
Daniel Atallah <datallah@pidgin.im>
parents: 15435
diff changeset
99 print "Testing: Purple::BuddyList::remove_buddy()...";
765ec644ac47 Perl fixes for s/gaim/purple/. This hasn't really been tested yet.
Daniel Atallah <datallah@pidgin.im>
parents: 15435
diff changeset
100 Purple::BuddyList::remove_buddy($buddy);
765ec644ac47 Perl fixes for s/gaim/purple/. This hasn't really been tested yet.
Daniel Atallah <datallah@pidgin.im>
parents: 15435
diff changeset
101 if (Purple::Find::buddy($account, $TEST_NAME . TEST)) { print "fail.\n"; } else { print "ok.\n"; }
11170
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
102 } else { print "fail.\n"; }
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
103
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
104
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
105 print "\n\n" . "#" x 80 . "\n\n";
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
106 }
d8941580d87f [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents:
diff changeset
107

mercurial