mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Added usage of command parser
This commit is contained in:
parent
312d362eaa
commit
0cec188eb5
@ -970,9 +970,17 @@ _cmd_wins(const char * const inp, struct cmd_help_t help)
|
|||||||
static gboolean
|
static gboolean
|
||||||
_cmd_help(const char * const inp, struct cmd_help_t help)
|
_cmd_help(const char * const inp, struct cmd_help_t help)
|
||||||
{
|
{
|
||||||
if (strcmp(inp, "/help") == 0) {
|
gboolean result = FALSE;
|
||||||
|
int num_args = 0;
|
||||||
|
gchar **args = parse_args(inp, 0, 1, &num_args);
|
||||||
|
|
||||||
|
if (args == NULL) {
|
||||||
|
cons_show("Usage: %s", help.usage);
|
||||||
|
result = TRUE;
|
||||||
|
} else {
|
||||||
|
if (num_args == 0) {
|
||||||
cons_help();
|
cons_help();
|
||||||
} else if (strcmp(inp, "/help list") == 0) {
|
} else if (strcmp(args[0], "list") == 0) {
|
||||||
cons_show("");
|
cons_show("");
|
||||||
cons_show("Basic commands:");
|
cons_show("Basic commands:");
|
||||||
cons_show_time();
|
cons_show_time();
|
||||||
@ -1002,16 +1010,16 @@ _cmd_help(const char * const inp, struct cmd_help_t help)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
cons_show_word("\n");
|
cons_show_word("\n");
|
||||||
} else if (strcmp(inp, "/help basic") == 0) {
|
} else if (strcmp(args[0], "basic") == 0) {
|
||||||
cons_basic_help();
|
cons_basic_help();
|
||||||
} else if (strcmp(inp, "/help presence") == 0) {
|
} else if (strcmp(args[0], "presence") == 0) {
|
||||||
cons_presence_help();
|
cons_presence_help();
|
||||||
} else if (strcmp(inp, "/help settings") == 0) {
|
} else if (strcmp(args[0], "settings") == 0) {
|
||||||
cons_settings_help();
|
cons_settings_help();
|
||||||
} else if (strcmp(inp, "/help navigation") == 0) {
|
} else if (strcmp(args[0], "navigation") == 0) {
|
||||||
cons_navigation_help();
|
cons_navigation_help();
|
||||||
} else {
|
} else {
|
||||||
char *cmd = strndup(inp+6, strlen(inp)-6);
|
char *cmd = args[0];
|
||||||
char cmd_with_slash[1 + strlen(cmd) + 1];
|
char cmd_with_slash[1 + strlen(cmd) + 1];
|
||||||
sprintf(cmd_with_slash, "/%s", cmd);
|
sprintf(cmd_with_slash, "/%s", cmd);
|
||||||
|
|
||||||
@ -1036,7 +1044,11 @@ _cmd_help(const char * const inp, struct cmd_help_t help)
|
|||||||
cons_show("");
|
cons_show("");
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
result = TRUE;
|
||||||
|
}
|
||||||
|
g_strfreev(args);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@ -1058,18 +1070,20 @@ _cmd_prefs(const char * const inp, struct cmd_help_t help)
|
|||||||
static gboolean
|
static gboolean
|
||||||
_cmd_who(const char * const inp, struct cmd_help_t help)
|
_cmd_who(const char * const inp, struct cmd_help_t help)
|
||||||
{
|
{
|
||||||
|
gboolean result = FALSE;
|
||||||
|
int num_args = 0;
|
||||||
|
gchar **args = parse_args(inp, 0, 1, &num_args);
|
||||||
|
|
||||||
|
if (args == NULL) {
|
||||||
|
cons_show("Usage: %s", help.usage);
|
||||||
|
result = TRUE;
|
||||||
|
} else {
|
||||||
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
||||||
|
|
||||||
if (conn_status != JABBER_CONNECTED) {
|
if (conn_status != JABBER_CONNECTED) {
|
||||||
cons_show("You are not currently connected.");
|
cons_show("You are not currently connected.");
|
||||||
} else {
|
} else {
|
||||||
// copy input
|
char *presence = args[0];
|
||||||
char inp_cpy[strlen(inp) + 1];
|
|
||||||
strcpy(inp_cpy, inp);
|
|
||||||
|
|
||||||
// get show
|
|
||||||
strtok(inp_cpy, " ");
|
|
||||||
char *presence = strtok(NULL, " ");
|
|
||||||
|
|
||||||
// bad arg
|
// bad arg
|
||||||
if ((presence != NULL)
|
if ((presence != NULL)
|
||||||
@ -1171,32 +1185,32 @@ _cmd_who(const char * const inp, struct cmd_help_t help)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
result = TRUE;
|
||||||
|
}
|
||||||
|
g_strfreev(args);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
_cmd_msg(const char * const inp, struct cmd_help_t help)
|
_cmd_msg(const char * const inp, struct cmd_help_t help)
|
||||||
{
|
{
|
||||||
char *usr = NULL;
|
gboolean result = FALSE;
|
||||||
char *msg = NULL;
|
int num_args = 0;
|
||||||
|
gchar **args = parse_args_with_freetext(inp, 2, 2, &num_args);
|
||||||
|
|
||||||
|
if (args == NULL) {
|
||||||
|
cons_show("Usage: %s", help.usage);
|
||||||
|
result = TRUE;
|
||||||
|
} else {
|
||||||
|
char *usr = args[0];
|
||||||
|
char *msg = args[1];
|
||||||
|
|
||||||
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
||||||
|
|
||||||
if (conn_status != JABBER_CONNECTED) {
|
if (conn_status != JABBER_CONNECTED) {
|
||||||
cons_show("You are not currently connected.");
|
cons_show("You are not currently connected.");
|
||||||
} else {
|
} else {
|
||||||
// copy input
|
|
||||||
char inp_cpy[strlen(inp) + 1];
|
|
||||||
strcpy(inp_cpy, inp);
|
|
||||||
|
|
||||||
// get user
|
|
||||||
strtok(inp_cpy, " ");
|
|
||||||
usr = strtok(NULL, " ");
|
|
||||||
if ((usr != NULL) && (strlen(inp) > (5 + strlen(usr) + 1))) {
|
|
||||||
// get message
|
|
||||||
msg = strndup(inp+5+strlen(usr)+1, strlen(inp)-(5+strlen(usr)+1));
|
|
||||||
|
|
||||||
if (msg != NULL) {
|
|
||||||
jabber_send(msg, usr);
|
jabber_send(msg, usr);
|
||||||
win_show_outgoing_msg("me", usr, msg);
|
win_show_outgoing_msg("me", usr, msg);
|
||||||
|
|
||||||
@ -1204,16 +1218,13 @@ _cmd_msg(const char * const inp, struct cmd_help_t help)
|
|||||||
const char *jid = jabber_get_jid();
|
const char *jid = jabber_get_jid();
|
||||||
chat_log_chat(jid, usr, msg, OUT, NULL);
|
chat_log_chat(jid, usr, msg, OUT, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
|
||||||
cons_show("Usage: %s", help.usage);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
cons_show("Usage: %s", help.usage);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
result = TRUE;
|
||||||
|
}
|
||||||
|
g_strfreev(args);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
Loading…
Reference in New Issue
Block a user