Sat, 22 Sep 2001 09:14:27 +0000
[gaim-migrate @ 2358]
you say potato, i say potato
you say tomato, i say tomato
potato, potato
tomato, tomato
let's call the whole thing off.
*sigh*. it just doesn't work as well when it's typed. but you wouldn't want to hear me sing it.
| 750 | 1 | This is really the wrong place for a HOWTO on writing perl scripts for gaim, |
| 2 | but there didn't seem to be a much better place. | |
| 3 | ||
| 4 | If you've ever written a perl script for X-Chat then you've basically written | |
| 5 | one for gaim as well. perl.c in gaim's source is basically an exact copy of | |
|
1101
d656fabb1d6c
[gaim-migrate @ 1111]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
806
diff
changeset
|
6 | X-Chat's perl.c file, with small modifications to suit GAIM rather than IRC. |
| 750 | 7 | |
| 8 | Basically the reason for including perl is based on the experience with the | |
| 9 | plugins. X-Chat's docs on Perl Scripting sums it up nicely: | |
| 10 | it's not quite as simple to stick a module together in C and make it | |
| 11 | stable compared to the development time of perl code | |
| 12 | ||
| 13 | Plugins are more powerful as they can directly access gaim's functions and | |
| 14 | variables; as such they should be used for things like modifying the UI or | |
| 15 | when something takes quite a bit of trickery not offered by perl. But for | |
| 16 | the most part things should be written in Perl. It's more stable than | |
| 17 | plugins. | |
| 18 | ||
|
806
3e5139e2f16e
[gaim-migrate @ 816]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
802
diff
changeset
|
19 | There's a really quick simple perl script in this directory, gaim.pl, that |
|
3e5139e2f16e
[gaim-migrate @ 816]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
802
diff
changeset
|
20 | should show most of the functions. Most things should be self-explanatory. |
|
3e5139e2f16e
[gaim-migrate @ 816]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
802
diff
changeset
|
21 | |
|
2345
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
22 | There's one thing you need to be aware of in perl scripts for gaim. Gaim |
|
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
23 | supports multiple connections, and perl deals with them by using a unique |
|
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
24 | identifier for each of them (that's a fancy way of saying that perl scripts |
|
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
25 | use the memory address of the connection). |
|
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
26 | |
| 750 | 27 | Everything available in normal perl scripts should be available in gaim's |
| 28 | perl interface, so I'm not going to bother describing that. The important | |
|
1101
d656fabb1d6c
[gaim-migrate @ 1111]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
806
diff
changeset
|
29 | things are the functions provided by gaim's internal GAIM module, which is |
| 750 | 30 | what most of this document is about. So, onto the functions. |
| 31 | ||
|
1101
d656fabb1d6c
[gaim-migrate @ 1111]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
806
diff
changeset
|
32 | GAIM::register(name, version, shutdownroutine, unused) |
| 750 | 33 | Just like X-Chat. This is the first function your script should call. |
| 34 | shutdownroutine is a function that will be called when the script | |
| 35 | gets unloaded (like when gaim gets closed). This function returns | |
| 36 | gaim's version number. | |
| 37 | ||
|
1101
d656fabb1d6c
[gaim-migrate @ 1111]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
806
diff
changeset
|
38 | GAIM::get_info(integer, ...) |
| 750 | 39 | This function returns different information based on the integer passed |
| 40 | to it. | |
| 41 | 0 - the version of gaim you're running ("0.10.0" for example). | |
|
2345
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
42 | 1 - the list of connection ids |
|
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
43 | 2 - given a connection index, the protocol it uses (as an int) |
|
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
44 | 3 - given a connection index, the screenname of the person |
|
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
45 | 4 - given a connection index, the index in the users list |
|
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
46 | 5 - the list of names of users |
|
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
47 | 6 - the list of protocols of the users |
| 750 | 48 | |
|
1101
d656fabb1d6c
[gaim-migrate @ 1111]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
806
diff
changeset
|
49 | GAIM::print(title, message) |
| 750 | 50 | This displays a nice little dialog window. |
| 51 | ||
| 52 | ||
|
2345
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
53 | GAIM::buddy_list(index) |
| 750 | 54 | This returns the buddy list (no groups, just the names of the buddies) |
|
2345
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
55 | for the specified connection. |
| 750 | 56 | |
|
2345
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
57 | GAIM::online_list(index) |
|
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
58 | This returns the list of online buddies for the specified connection. |
| 750 | 59 | |
| 60 | ||
|
1101
d656fabb1d6c
[gaim-migrate @ 1111]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
806
diff
changeset
|
61 | GAIM::command(command, ...) |
| 750 | 62 | This sends commands to the server, and each command takes various |
| 63 | arguments. The command should be self-explanatory: | |
|
2345
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
64 | "signon" - the second arg is the index of the user to sign on |
|
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
65 | "signoff" - the optional second arg is the connection index to sign off. |
|
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
66 | if no args are given, all connections are signed off. |
| 750 | 67 | "away" - the second arg is the away message |
| 68 | "back" - no args. | |
| 69 | "idle" - the second arg is how long (in seconds) to set the idle time | |
|
1101
d656fabb1d6c
[gaim-migrate @ 1111]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
806
diff
changeset
|
70 | (this sets the idle time for all connections) |
|
d656fabb1d6c
[gaim-migrate @ 1111]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
806
diff
changeset
|
71 | "warn" - the second arg is the name of the person to warn. this is |
|
1734
8aafd99f5b62
[gaim-migrate @ 1744]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1101
diff
changeset
|
72 | especially evil since it warns the person from every |
|
8aafd99f5b62
[gaim-migrate @ 1744]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1101
diff
changeset
|
73 | connection. The third argument is 1 if you want to warn |
|
8aafd99f5b62
[gaim-migrate @ 1744]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1101
diff
changeset
|
74 | anonymously. If 0 or ommitted, it will warn normally. |
|
2345
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
75 | "info" - the second arg is the connection index whose info you want to set, |
|
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
76 | and the third arg is what you want to set your profile to. |
| 750 | 77 | |
|
2345
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
78 | GAIM::user_info(index, nick) |
|
1101
d656fabb1d6c
[gaim-migrate @ 1111]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
806
diff
changeset
|
79 | Returns 8 data items: |
| 750 | 80 | the screenname of the buddy |
|
1101
d656fabb1d6c
[gaim-migrate @ 1111]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
806
diff
changeset
|
81 | the alias of the buddy |
| 750 | 82 | "Online" or "Offline" |
| 83 | their warning level | |
| 84 | signon time, in seconds since the epoch | |
| 85 | idle time, in seconds (?) | |
| 86 | user class, an integer with bit values | |
| 87 | AOL 1 | |
| 88 | ADMIN 2 | |
| 89 | UNCONFIRMED 4 | |
| 90 | NORMAL 8 | |
| 91 | AWAY 16 | |
| 92 | their capabilites, an integer with bit values | |
| 93 | BUDDYICON 1 | |
| 94 | VOICE 2 | |
| 95 | IMIMAGE 4 | |
| 96 | CHAT 8 | |
| 97 | GETFILE 16 | |
| 98 | SENDFILE 32 | |
|
1101
d656fabb1d6c
[gaim-migrate @ 1111]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
806
diff
changeset
|
99 | Since buddy lists are per-connection this goes through the connections |
|
d656fabb1d6c
[gaim-migrate @ 1111]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
806
diff
changeset
|
100 | until it finds a matching buddy name. |
| 750 | 101 | |
| 2261 | 102 | GAIM::write_to_conv(to, wflags, what, who) |
| 103 | This displays a message into a conversation window. <wflags> is the | |
| 104 | message-style and works like that: | |
| 105 | wflags==0: display message as if received by <who> | |
| 106 | wflags==1: display message as if sent by <who> | |
| 107 | wflags==2: display system message | |
| 108 | ||
|
2345
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
109 | GAIM::serv_send_im(index, who, what, auto) |
|
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
110 | Sends what from the connection index to who. :) |
| 750 | 111 | |
|
2345
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
112 | GAIM::print_to_conv(index, who, what, auto) |
|
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
113 | Convenience function; combination of write_to_conv and serv_send_im. |
| 750 | 114 | |
|
2345
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
115 | GAIM::print_to_chat(index, room, what) |
|
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
116 | Room is actually an int. Read SIGNALS to find out why. |
|
802
5dd2ba397dfe
[gaim-migrate @ 812]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
785
diff
changeset
|
117 | |
|
1101
d656fabb1d6c
[gaim-migrate @ 1111]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
806
diff
changeset
|
118 | GAIM::add_event_handler(event, function) |
|
785
fcf85892216c
[gaim-migrate @ 795]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
750
diff
changeset
|
119 | This is the most important of them all. This is basically exactly like |
|
802
5dd2ba397dfe
[gaim-migrate @ 812]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
785
diff
changeset
|
120 | gaim_signal_connect for plugins. You pass which event you want to connect to |
|
5dd2ba397dfe
[gaim-migrate @ 812]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
785
diff
changeset
|
121 | (a string with the same name as the events for plugins, see SIGNALS), and a |
|
5dd2ba397dfe
[gaim-migrate @ 812]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
785
diff
changeset
|
122 | string with the name of the function you want called. Simple enough? |
| 750 | 123 | |
|
802
5dd2ba397dfe
[gaim-migrate @ 812]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
785
diff
changeset
|
124 | When this is triggered, the arguments will be passed in @_ and are not |
|
785
fcf85892216c
[gaim-migrate @ 795]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
750
diff
changeset
|
125 | broken into a list, but left as one long string. You'll have to parse those |
|
fcf85892216c
[gaim-migrate @ 795]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
750
diff
changeset
|
126 | yourself with split. (Sounding exactly like X-Chat yet?) The arguments are |
|
fcf85892216c
[gaim-migrate @ 795]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
750
diff
changeset
|
127 | the exact same as those passed to the plugins, and are passed after the |
|
fcf85892216c
[gaim-migrate @ 795]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
750
diff
changeset
|
128 | plugins have had their way with them. Perl scripts cannot modify the values |
|
1101
d656fabb1d6c
[gaim-migrate @ 1111]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
806
diff
changeset
|
129 | so that gaim knows what the changes are. |
|
d656fabb1d6c
[gaim-migrate @ 1111]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
806
diff
changeset
|
130 | |
|
d656fabb1d6c
[gaim-migrate @ 1111]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
806
diff
changeset
|
131 | Perl scripts can short-circuit certain events (namely event_im_send, |
|
d656fabb1d6c
[gaim-migrate @ 1111]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
806
diff
changeset
|
132 | event_im_recv, event_chat_send, and event_chat_recv). To short-circuit an |
|
d656fabb1d6c
[gaim-migrate @ 1111]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
806
diff
changeset
|
133 | event simply return a non-0 value. This will cause all subsequent scripts |
|
d656fabb1d6c
[gaim-migrate @ 1111]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
806
diff
changeset
|
134 | and the event itself to never happen (i.e. the user won't see it happen, |
|
d656fabb1d6c
[gaim-migrate @ 1111]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
806
diff
changeset
|
135 | and _send events won't actually send). |
|
d656fabb1d6c
[gaim-migrate @ 1111]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
806
diff
changeset
|
136 | |
|
d656fabb1d6c
[gaim-migrate @ 1111]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
806
diff
changeset
|
137 | Names of buddies and chat rooms will be in quotes, and all other |
|
806
3e5139e2f16e
[gaim-migrate @ 816]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
802
diff
changeset
|
138 | values (like text messages) will not be. (Watch the debug window to get a |
|
3e5139e2f16e
[gaim-migrate @ 816]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
802
diff
changeset
|
139 | better feel for this, or better yet, look at the bottom of plugins.c.) |
| 750 | 140 | |
|
1101
d656fabb1d6c
[gaim-migrate @ 1111]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
806
diff
changeset
|
141 | GAIM::add_timeout_handler(integer, function) |
| 750 | 142 | This calls function after integer number of seconds. It only calls function |
|
806
3e5139e2f16e
[gaim-migrate @ 816]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
802
diff
changeset
|
143 | once, so if you want to keep calling function, keep readding the handler. |