diff --git a/plugins/whoami.py b/plugins/whoami.py index c2d12b0c..d48d1c40 100644 --- a/plugins/whoami.py +++ b/plugins/whoami.py @@ -10,6 +10,4 @@ def prof_init(version, status): def cmd_whoami(): me = getpass.getuser() - prof.cons_show("") prof.cons_show(me) - prof.cons_show("") diff --git a/src/command/command.c b/src/command/command.c index 2e31605d..c59c6a78 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -20,13 +20,12 @@ * */ +#include "plugins/command.h" #include #include #include #include -#include - #include "chat_session.h" #include "command/command.h" #include "command/history.h" @@ -1102,6 +1101,8 @@ cmd_execute(const char * const command, const char * const inp) g_strfreev(args); return result; } + } else if (plugin_command_run(command)) { + return TRUE; } else { return cmd_execute_default(inp); } diff --git a/src/plugins/command.c b/src/plugins/command.c index f703705d..1f49bc51 100644 --- a/src/plugins/command.c +++ b/src/plugins/command.c @@ -20,25 +20,30 @@ * */ -#include -#include +#include "plugins/command.h" // API functions static GSList *p_commands = NULL; -typedef struct p_command { - const char *command_name; - int min_args; - int max_args; - const char *usage; - const char *short_help; - const char *long_help; - PyObject *p_callback; -} PluginCommand; - void add_command(PluginCommand *command) { p_commands = g_slist_append(p_commands, command); } + +gboolean +plugin_command_run(const char * const cmd) +{ + GSList *p_command = p_commands; + + while (p_command != NULL) { + PluginCommand *command = p_command->data; + if (strcmp(command->command_name, cmd) == 0) { + PyObject_CallObject(command->p_callback, NULL); + return TRUE; + } + p_command = g_slist_next(p_command); + } + return FALSE; +} diff --git a/src/plugins/command.h b/src/plugins/command.h index db1f0a69..6d4f1941 100644 --- a/src/plugins/command.h +++ b/src/plugins/command.h @@ -20,8 +20,13 @@ * */ +#ifndef PLUGIN_COMMAND_H +#define PLUGIN_COMMAND_H + #include +#include + typedef struct p_command { const char *command_name; int min_args; @@ -33,3 +38,6 @@ typedef struct p_command { } PluginCommand; void add_command(PluginCommand *command); +gboolean plugin_command_run(const char * const cmd); + +#endif diff --git a/src/plugins/plugins.h b/src/plugins/plugins.h index de70970a..11a1791b 100644 --- a/src/plugins/plugins.h +++ b/src/plugins/plugins.h @@ -24,9 +24,7 @@ #define PLUGINS_H void plugins_init(void); - void plugins_on_connect(void); - void plugins_shutdown(void); #endif