Trac is being migrated to new services! Issues can be found in our new
YouTrack instance and WIKI pages can be found on our
website.
- Timestamp:
-
Nov 13, 2009, 11:32:01 PM (14 years ago)
- Author:
-
hamiltont
- Comment:
-
added TOC, changed the command from /debug to /log to avoid builtin /debug command
Legend:
- Unmodified
- Added
- Removed
- Modified
-
v4
|
v5
|
|
3 | 3 | The command API is a method by which you can add commands to libpurple clients. Pidgin and Finch use the / character to denote a command, much like many IRC clients. This document will explain how to make your plugin add commands. Again we will assume that you have completed the [wiki:CHowTo/BasicPluginHowto Basic C Plugin Howto]. We'll also continue to assume that you're using Pidgin 2.0.2 for these How-To documents as described there. |
4 | 4 | |
| 5 | [[TOC(inline,noheading)]] |
5 | 6 | |
6 | 7 | ''This document is incomplete. It has been saved to the wiki to ensure the current work is not lost. It should be finished soon.'' |
… |
… |
|
82 | 83 | |
83 | 84 | |
84 | | /* The callback function for our /debug command. This function simply prints |
| 85 | /* The callback function for our /log command. This function simply prints |
85 | 86 | * whatever was entered as the argument to the debug command into the debug |
86 | 87 | * log. */ |
87 | 88 | static PurpleCmdRet |
88 | | debug_cb(PurpleConversation *conv, const gchar *cmd, gchar **args, gchar **error, void *data) |
89 | | { |
90 | | purple_debug_misc(PLUGIN_ID, "debug_cb called\n"); |
| 89 | log_cb(PurpleConversation *conv, const gchar *cmd, gchar **args, gchar **error, void *data) |
| 90 | { |
| 91 | purple_debug_misc(PLUGIN_ID, "log_cb called\n"); |
91 | 92 | purple_debug_misc(PLUGIN_ID, "message = %s\n", args[0]); |
92 | 93 | |
… |
… |
|
121 | 122 | { |
122 | 123 | /* Declare all vars up front. Avoids warnings on some compilers */ |
123 | | gchar *debug_help = NULL; |
| 124 | gchar *log_help = NULL; |
124 | 125 | gchar *notify_help = NULL; |
125 | 126 | |
… |
… |
|
127 | 128 | command_example = plugin; |
128 | 129 | |
129 | | /* Help message for debug command, in the correct format */ |
130 | | debug_help = "debug <debug message here>: Prints a message to the debug log."; |
131 | | |
132 | | /* Register a command to allow a user to enter /debug some message and have |
| 130 | /* Help message for log command, in the correct format */ |
| 131 | log_help = "log <log message here>: Prints a message to the debug log."; |
| 132 | |
| 133 | /* Register a command to allow a user to enter /log some message and have |
133 | 134 | * that message stored to the log. This command runs with default priority, |
134 | 135 | * can only be used in a standard chat message, not while in group chat |
135 | 136 | * mode */ |
136 | 137 | purple_cmd_register |
137 | | ("debug", /* command name */ |
| 138 | ("log", /* command name */ |
138 | 139 | "s", /* command arguments */ |
139 | 140 | PURPLE_CMD_P_DEFAULT, /* command priority */ |
… |
… |
|
144 | 145 | plugin ID */ |
145 | 146 | |
146 | | debug_cb, /* Name of the callback |
| 147 | log_cb, /* Name of the callback |
147 | 148 | function */ |
148 | | debug_help, |
| 149 | log_help, |
149 | 150 | |
150 | 151 | NULL /* We do not need any special |
… |
… |
|
153 | 154 | |
154 | 155 | |
155 | | /* Help message for debug command, in the correct format */ |
| 156 | /* Help message for notify command, in the correct format */ |
156 | 157 | notify_help = "notify <notify word here>: Pops up a notification with the word you enter."; |
157 | 158 | |
… |
… |
|
221 | 222 | } |
222 | 223 | |
223 | | PURPLE_INIT_PLUGIN(debugexample, init_plugin, info) |
| 224 | PURPLE_INIT_PLUGIN(commandexample, init_plugin, info) |
224 | 225 | |
225 | 226 | }}} |
… |
… |
|
229 | 230 | As before, run make command_example.so (make -f Makefile.mingw command_example.dll for you Windows types) to build the plugin. Copy the resulting command_example.so to ~/.purple/plugins, or copy the resulting command_example.dll to %APPDATA%\.purple\plugins. |
230 | 231 | |
231 | | To test (we will assume you are using Pidgin), go to Tools->Plugins and enable the Command API Example plugin. Also, go to Help->Debug Window to show the Debug Window. Open an IM chat session, and type ''/debug my debug message here''. Your message should show up in the debug window. Then type ''/notify Hello!''. You should receive a notification box saying Hello! Also, be sure to try ''/notify Hello World!'' and not that the command fails, because you input multiple arguments (2) when it was only expecting a single value. |
| 232 | To test (we will assume you are using Pidgin), go to Tools->Plugins and enable the Command API Example plugin. Also, go to Help->Debug Window to show the Debug Window. Open an IM chat session, and type ''/log my log message here''. Your message should show up in the Debug Window. Then type ''/notify Hello!''. You should receive a notification box saying Hello! Also, be sure to try ''/notify Hello World!'' and not that the command fails, because you input multiple arguments (2) when it was only expecting a single value. |
232 | 233 | |
233 | 234 | == Beyond the Command API == |
234 | 235 | The command API provides a basic command framework for plugins, which can be an extremely valuable resource to plugin authors. The other areas we didn't cover here include much of the true power of the command API, but we will leave those as an area for your exploration at least for now. This document is done, but there are still others in the [wiki:CHowTo C Plugin How-To] for you to explore! |
235 | 236 | |
236 | | == Updates to this page == |
237 | | * Don't use /debug, it conflicts with a built in command |
238 | | * add TOC |
| 237 | == Updates Needed to this page == |
239 | 238 | * Need to clean up the commands (purple_cmd_unregister) at unload. |
All information, including names and email addresses, entered onto this website or sent to mailing lists affiliated with this website will be public. Do not post confidential information, especially passwords!