mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Added /whoami command plugin
This commit is contained in:
parent
5464d5079b
commit
c3acda5da7
@ -10,6 +10,4 @@ def prof_init(version, status):
|
|||||||
|
|
||||||
def cmd_whoami():
|
def cmd_whoami():
|
||||||
me = getpass.getuser()
|
me = getpass.getuser()
|
||||||
prof.cons_show("")
|
|
||||||
prof.cons_show(me)
|
prof.cons_show(me)
|
||||||
prof.cons_show("")
|
|
||||||
|
@ -20,13 +20,12 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "plugins/command.h"
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <glib.h>
|
|
||||||
|
|
||||||
#include "chat_session.h"
|
#include "chat_session.h"
|
||||||
#include "command/command.h"
|
#include "command/command.h"
|
||||||
#include "command/history.h"
|
#include "command/history.h"
|
||||||
@ -1102,6 +1101,8 @@ cmd_execute(const char * const command, const char * const inp)
|
|||||||
g_strfreev(args);
|
g_strfreev(args);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
} else if (plugin_command_run(command)) {
|
||||||
|
return TRUE;
|
||||||
} else {
|
} else {
|
||||||
return cmd_execute_default(inp);
|
return cmd_execute_default(inp);
|
||||||
}
|
}
|
||||||
|
@ -20,25 +20,30 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <Python.h>
|
#include "plugins/command.h"
|
||||||
#include <glib.h>
|
|
||||||
|
|
||||||
// API functions
|
// API functions
|
||||||
|
|
||||||
static GSList *p_commands = NULL;
|
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
|
void
|
||||||
add_command(PluginCommand *command)
|
add_command(PluginCommand *command)
|
||||||
{
|
{
|
||||||
p_commands = g_slist_append(p_commands, 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;
|
||||||
|
}
|
||||||
|
@ -20,8 +20,13 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef PLUGIN_COMMAND_H
|
||||||
|
#define PLUGIN_COMMAND_H
|
||||||
|
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
typedef struct p_command {
|
typedef struct p_command {
|
||||||
const char *command_name;
|
const char *command_name;
|
||||||
int min_args;
|
int min_args;
|
||||||
@ -33,3 +38,6 @@ typedef struct p_command {
|
|||||||
} PluginCommand;
|
} PluginCommand;
|
||||||
|
|
||||||
void add_command(PluginCommand *command);
|
void add_command(PluginCommand *command);
|
||||||
|
gboolean plugin_command_run(const char * const cmd);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@ -24,9 +24,7 @@
|
|||||||
#define PLUGINS_H
|
#define PLUGINS_H
|
||||||
|
|
||||||
void plugins_init(void);
|
void plugins_init(void);
|
||||||
|
|
||||||
void plugins_on_connect(void);
|
void plugins_on_connect(void);
|
||||||
|
|
||||||
void plugins_shutdown(void);
|
void plugins_shutdown(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user