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.

Changes between Version 4 and Version 5 of CHowTo/CommandAPIHowTo


Ignore:
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
  • CHowTo/CommandAPIHowTo

    v4 v5  
    33The 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.
    44
     5[[TOC(inline,noheading)]]
    56
    67''This document is incomplete.  It has been saved to the wiki to ensure the current work is not lost.  It should be finished soon.''
     
    8283
    8384
    84 /* The callback function for our /debug command. This function simply prints
     85/* The callback function for our /log command. This function simply prints
    8586 * whatever was entered as the argument to the debug command into the debug
    8687 * log. */
    8788static 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");
     89log_cb(PurpleConversation *conv, const gchar *cmd, gchar **args, gchar **error, void *data)
     90{
     91  purple_debug_misc(PLUGIN_ID, "log_cb called\n");
    9192  purple_debug_misc(PLUGIN_ID, "message = %s\n", args[0]);
    9293
     
    121122{
    122123  /* Declare all vars up front. Avoids warnings on some compilers */
    123   gchar *debug_help = NULL;
     124  gchar *log_help = NULL;
    124125  gchar *notify_help = NULL;
    125126 
     
    127128  command_example = plugin;
    128129
    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
    133134   * that message stored to the log. This command runs with default priority,
    134135   * can only be used in a standard chat message, not while in group chat
    135136   * mode */
    136137  purple_cmd_register
    137     ("debug",                       /* command name */
     138    ("log",                         /* command name */
    138139     "s",                           /* command arguments */
    139140     PURPLE_CMD_P_DEFAULT,          /* command priority */ 
     
    144145                                       plugin ID */
    145146     
    146      debug_cb,                      /* Name of the callback
     147     log_cb,                        /* Name of the callback
    147148                                       function */
    148      debug_help,
     149     log_help,
    149150
    150151     NULL                           /* We do not need any special
     
    153154       
    154155
    155   /* Help message for debug command, in the correct format */
     156  /* Help message for notify command, in the correct format */
    156157  notify_help = "notify <notify word here>:  Pops up a notification with the word you enter.";
    157158
     
    221222}
    222223
    223 PURPLE_INIT_PLUGIN(debugexample, init_plugin, info)
     224PURPLE_INIT_PLUGIN(commandexample, init_plugin, info)
    224225
    225226}}}
     
    229230As 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.
    230231
    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.
     232To 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.
    232233
    233234== Beyond the Command API ==
    234235The 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!
    235236
    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 ==
    239238  * 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!