Wed, 20 Aug 2003 11:08:19 +0000
[gaim-migrate @ 7046]
The fortunateprofile.pl script works again. At least, I think it works, but
it's never worked here, but all the events and suff work, so that's good,
and i added a test.pl that people acan also see. now I'm going to bebd.
| 3551 | 1 | So, you wanna write a perl script. |
| 2 | ||
| 3 | Perl scripts in Gaim can be very useful. Although they can't directly manipulate | |
| 4 | Gaim data like a plugin, or provide any sort of UI, they're portable, easy to develop | |
| 5 | rapidly and extremely powerful when manipulating incoming and outgoing messages. | |
| 750 | 6 | |
| 3551 | 7 | This document assumes you know perl--Gaim perl scripts work exactly like normal perl |
| 8 | scripts, with a few extra commands you can use. | |
| 750 | 9 | |
| 3551 | 10 | The first thing Gaim will do with your plugin (provided it's in $prefix/lib/gaim or |
| 11 | $HOME/.gaim/) is look for and call a function called "description". description() | |
| 12 | gives Gaim the information it will use in the plugins dialog--script name, version, | |
| 13 | your name--all sorts of good things. Let's look at an example: | |
| 750 | 14 | |
| 3551 | 15 | sub description { |
| 16 | my($a, $b, $c, $d, $e, $f) = @_; | |
| 17 | ("Example", "1.0", "An example Gaim perl script that does nothing | |
| 18 | particularly useful:\n\t-Show a dialog on load\n\t-Set user idle for | |
| 19 | 6,000 seconds\n\t-Greets people signing on with \"Hello\"\n\t-Informs | |
| 20 | you when script has been loaded for one minute.", | |
| 21 | "Eric Warmenhoven <eric\@warmenhoven.org>", "http://gaim.sf.net", | |
| 22 | "/dev/null"); | |
| 23 | } | |
|
806
3e5139e2f16e
[gaim-migrate @ 816]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
802
diff
changeset
|
24 | |
| 3551 | 25 | This pushes what's needed to the perl stack. What is all that stuff? |
| 26 | $a - Name | |
| 27 | $b - Version | |
| 28 | $c - Description | |
| 29 | $d - Authors | |
| 30 | $e - Webpage | |
| 31 | $f - Icon (this is the path to an icon Gaim will use for your script) | |
|
2345
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
32 | |
| 3551 | 33 | It should be noted that this information will be formatted according to Pango's |
| 34 | markup language--a language akin to HTML. This is neat in that it lets you bold | |
| 35 | and italicize your description and stuff, but it's important you take care to | |
| 36 | properly escape stuff (notice the < in $d). | |
| 37 | ||
| 38 | Now, for the Gaim-specific perl functions (if you know x-chat scripts, you'll | |
| 39 | feel right at home): | |
| 750 | 40 | |
|
1101
d656fabb1d6c
[gaim-migrate @ 1111]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
806
diff
changeset
|
41 | GAIM::register(name, version, shutdownroutine, unused) |
| 750 | 42 | Just like X-Chat. This is the first function your script should call. |
| 43 | shutdownroutine is a function that will be called when the script | |
| 44 | gets unloaded (like when gaim gets closed). This function returns | |
| 3563 | 45 | gaim's version number. This function MUST use the same Name and Version |
| 46 | given in description()--the plugin won't work otherwise. This returns a | |
| 47 | handle--you want to hold on to this. | |
| 48 | ||
| 49 | The handle is what Gaim will use to distinguish your script from any others | |
| 50 | running. It's actually a string--the path to the script, but you'll probably | |
| 51 | never need to know that. As long as you just hold on to it and don't change it | |
| 52 | everything should work fine. You need it for GAIM::add_event_handler and | |
| 53 | GAIM::add_timeout_handler. | |
| 750 | 54 | |
|
1101
d656fabb1d6c
[gaim-migrate @ 1111]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
806
diff
changeset
|
55 | GAIM::get_info(integer, ...) |
| 750 | 56 | This function returns different information based on the integer passed |
| 57 | to it. | |
| 58 | 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
|
59 | 1 - the list of connection ids |
|
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
60 | 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
|
61 | 3 - given a connection index, the screenname of the person |
|
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
62 | 4 - given a connection index, the index in the users list |
|
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
63 | 5 - the list of names of users |
|
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
64 | 6 - the list of protocols of the users |
|
2355
3bf7d403faa6
[gaim-migrate @ 2368]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2345
diff
changeset
|
65 | 7 - given a connection index, the name of the protocol (as a string) |
| 750 | 66 | |
|
1101
d656fabb1d6c
[gaim-migrate @ 1111]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
806
diff
changeset
|
67 | GAIM::print(title, message) |
| 750 | 68 | This displays a nice little dialog window. |
| 69 | ||
| 70 | ||
|
2345
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
71 | GAIM::buddy_list(index) |
| 750 | 72 | 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
|
73 | for the specified connection. |
| 750 | 74 | |
|
2345
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
75 | GAIM::online_list(index) |
|
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
76 | This returns the list of online buddies for the specified connection. |
| 750 | 77 | |
| 78 | ||
|
1101
d656fabb1d6c
[gaim-migrate @ 1111]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
806
diff
changeset
|
79 | GAIM::command(command, ...) |
| 750 | 80 | This sends commands to the server, and each command takes various |
| 81 | arguments. The command should be self-explanatory: | |
|
2345
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
82 | "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
|
83 | "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
|
84 | if no args are given, all connections are signed off. |
| 750 | 85 | "away" - the second arg is the away message |
| 86 | "back" - no args. | |
| 87 | "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
|
88 | (this sets the idle time for all connections) |
|
d656fabb1d6c
[gaim-migrate @ 1111]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
806
diff
changeset
|
89 | "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
|
90 | especially evil since it warns the person from every |
|
8aafd99f5b62
[gaim-migrate @ 1744]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1101
diff
changeset
|
91 | connection. The third argument is 1 if you want to warn |
|
8aafd99f5b62
[gaim-migrate @ 1744]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1101
diff
changeset
|
92 | anonymously. If 0 or ommitted, it will warn normally. |
|
2345
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
93 | "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
|
94 | and the third arg is what you want to set your profile to. |
| 750 | 95 | |
|
2345
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
96 | GAIM::user_info(index, nick) |
|
1101
d656fabb1d6c
[gaim-migrate @ 1111]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
806
diff
changeset
|
97 | Returns 8 data items: |
| 750 | 98 | the screenname of the buddy |
|
1101
d656fabb1d6c
[gaim-migrate @ 1111]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
806
diff
changeset
|
99 | the alias of the buddy |
| 750 | 100 | "Online" or "Offline" |
| 101 | their warning level | |
| 102 | signon time, in seconds since the epoch | |
| 103 | idle time, in seconds (?) | |
|
1101
d656fabb1d6c
[gaim-migrate @ 1111]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
806
diff
changeset
|
104 | Since buddy lists are per-connection this goes through the connections |
|
d656fabb1d6c
[gaim-migrate @ 1111]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
806
diff
changeset
|
105 | until it finds a matching buddy name. |
| 750 | 106 | |
| 2261 | 107 | GAIM::write_to_conv(to, wflags, what, who) |
| 108 | This displays a message into a conversation window. <wflags> is the | |
| 109 | message-style and works like that: | |
| 110 | wflags==0: display message as if received by <who> | |
| 111 | wflags==1: display message as if sent by <who> | |
| 112 | wflags==2: display system message | |
| 113 | ||
|
2345
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
114 | GAIM::serv_send_im(index, who, what, auto) |
|
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
115 | Sends what from the connection index to who. :) |
| 750 | 116 | |
|
2345
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
117 | GAIM::print_to_conv(index, who, what, auto) |
|
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
118 | Convenience function; combination of write_to_conv and serv_send_im. |
| 750 | 119 | |
|
2345
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
120 | GAIM::print_to_chat(index, room, what) |
|
2d59281e13fd
[gaim-migrate @ 2358]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2261
diff
changeset
|
121 | 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
|
122 | |
| 3563 | 123 | GAIM::add_event_handler(handle, event, function) |
|
785
fcf85892216c
[gaim-migrate @ 795]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
750
diff
changeset
|
124 | This is the most important of them all. This is basically exactly like |
| 3563 | 125 | gaim_signal_connect for plugins. You pass the handle returned by GAIM::register, |
| 126 | which event you want to connect to (a string with the same name as the events for | |
| 127 | plugins, see SIGNALS), and a string with the name of the function you want called. | |
| 128 | Simple enough? | |
| 750 | 129 | |
|
2511
cea8ce69dec0
[gaim-migrate @ 2524]
Dennis Lambe Jr. <malsyned@users.sourceforge.net>
parents:
2355
diff
changeset
|
130 | When this is triggered, the arguments will be passed in @_ and are broken |
|
cea8ce69dec0
[gaim-migrate @ 2524]
Dennis Lambe Jr. <malsyned@users.sourceforge.net>
parents:
2355
diff
changeset
|
131 | into a list. This is different from all previous versions of Gaim, where you |
|
cea8ce69dec0
[gaim-migrate @ 2524]
Dennis Lambe Jr. <malsyned@users.sourceforge.net>
parents:
2355
diff
changeset
|
132 | had to parse the arguments yourself. The arguments are quite different from |
|
cea8ce69dec0
[gaim-migrate @ 2524]
Dennis Lambe Jr. <malsyned@users.sourceforge.net>
parents:
2355
diff
changeset
|
133 | what's passed to the plugins, though they are very similar, and you should |
|
cea8ce69dec0
[gaim-migrate @ 2524]
Dennis Lambe Jr. <malsyned@users.sourceforge.net>
parents:
2355
diff
changeset
|
134 | read perl.c to figure out what they are. The arguments are passed after the |
|
785
fcf85892216c
[gaim-migrate @ 795]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
750
diff
changeset
|
135 | 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
|
136 | so that gaim knows what the changes are. |
|
d656fabb1d6c
[gaim-migrate @ 1111]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
806
diff
changeset
|
137 | |
|
d656fabb1d6c
[gaim-migrate @ 1111]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
806
diff
changeset
|
138 | Perl scripts can short-circuit certain events (namely event_im_send, |
| 3456 | 139 | event_im_recv, event_chat_send, event_chat_recv and event_set_info). To |
| 140 | short-circuit an event simply return a non-0 value. This will cause all | |
| 141 | subsequent scripts and the event itself to never happen (i.e. the user | |
| 142 | won't see it happen, and _send events won't actually send). | |
| 143 | ||
| 144 | GAIM::remove_event_handler(event, function) | |
| 145 | This removes the event handler for the specified event that | |
| 146 | calls "function" as its handler. The event handler must have been | |
| 147 | previously added with GAIM::add_event_handler. | |
|
1101
d656fabb1d6c
[gaim-migrate @ 1111]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
806
diff
changeset
|
148 | |
| 3563 | 149 | GAIM::add_timeout_handler(handle, integer, function, args) |
| 750 | 150 | 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
|
151 | once, so if you want to keep calling function, keep readding the handler. |
| 2512 | 152 | Args is a string that you'd like to have passed to your timeout handler; it's |
| 3563 | 153 | optional. Handle is the handle returned by GAIM::register--it is not optional. |
| 3280 | 154 | |
| 155 | GAIM::play_sound(int sound) | |
| 156 | Plays a sound using whatever method the user has selected. The argument is | |
| 157 | one of the following numbers: | |
| 158 | ||
| 159 | 0 Buddy logs in | |
| 160 | 1 Buddy logs out | |
| 161 | 2 Message received | |
| 162 | 3 Message received begins conversation | |
| 163 | 4 Message sent | |
| 164 | 5 Person enters chat | |
| 165 | 6 Person leaves chat | |
| 166 | 7 You talk in chat | |
| 167 | 8 Others talk in chat | |
| 168 | 9 Default buddy pounce sound | |
| 169 | 10 Someone says your name in chat |