parsing support for channel commands
This commit is contained in:
parent
09c4ab4974
commit
0e52722161
@ -11,7 +11,7 @@ typedef struct
|
||||
|
||||
extern creds_t creds;
|
||||
|
||||
DECL void parse_command(char * cmd);
|
||||
DECL void parse_command(const char * const cmd);
|
||||
DECL int parse_creds(char const * creds_file);
|
||||
DECL void clean_creds(void);
|
||||
|
||||
|
26
src/irc.c
26
src/irc.c
@ -33,11 +33,12 @@
|
||||
#include "help.h"
|
||||
|
||||
#define PREFIX_COMMAND_CHAR '!'
|
||||
#define PREFIX_CHANNEL_COMMAND_CHAR '%'
|
||||
|
||||
irc_session_t * session;
|
||||
irc_callbacks_t callbacks;
|
||||
|
||||
char * current_username;
|
||||
char * current_username = NULL;
|
||||
int f = -1;
|
||||
|
||||
#define IRCMSG(msg) irc_cmd_msg(session, creds.channel, msg)
|
||||
@ -112,20 +113,21 @@ event_channel(irc_session_t * session,
|
||||
/* (void) channel; */
|
||||
(void) message;
|
||||
(void) count;
|
||||
current_username = get_username(origin);
|
||||
/* parses the command */
|
||||
switch(*message){
|
||||
case PREFIX_CHANNEL_COMMAND_CHAR:
|
||||
current_username = strdup(creds.channel);
|
||||
break;
|
||||
case PREFIX_COMMAND_CHAR:
|
||||
current_username = get_username(origin);
|
||||
break;
|
||||
}
|
||||
if(!current_username || *(message+1) == '\00'){ return; }
|
||||
--f;
|
||||
if(f == 0){ ircmsg(fmsg, current_username); }
|
||||
/* parses the command */
|
||||
if (*message == PREFIX_COMMAND_CHAR)
|
||||
{
|
||||
char * pmsg = strdup(++message);
|
||||
if (pmsg)
|
||||
{
|
||||
parse_command(pmsg);
|
||||
free(pmsg);
|
||||
}
|
||||
}
|
||||
parse_command(message+1);
|
||||
free(current_username);
|
||||
current_username = NULL;
|
||||
}
|
||||
|
||||
int
|
||||
|
11
src/parse.c
11
src/parse.c
@ -48,7 +48,7 @@ char const * cred_param_names_g[] = {
|
||||
};
|
||||
|
||||
DECL void
|
||||
parse_command(char * cmd)
|
||||
parse_command(const char * const cmd)
|
||||
{
|
||||
size_t i = 0;
|
||||
char* msgswp = NULL;
|
||||
@ -92,15 +92,14 @@ parse_command(char * cmd)
|
||||
else
|
||||
{
|
||||
/* some arguments */
|
||||
char * arg = cmd + i + 1;
|
||||
cmd[i] = '\0';
|
||||
if (strcmp(cmd, "raw") == 0)
|
||||
const char * const arg = cmd + i + 1;
|
||||
if (strncmp(cmd, "raw", i) == 0)
|
||||
{
|
||||
ircmsg("%s: Executing SQL `%s'.", current_username, arg);
|
||||
msgswp = raw(arg);
|
||||
ircmsg(msgswp);
|
||||
}
|
||||
else if (strcmp(cmd, "set_repo") == 0)
|
||||
else if (strncmp(cmd, "set_repo", i) == 0)
|
||||
{
|
||||
ircmsg("%s: Setting project repository...", current_username);
|
||||
set_repo(creds.channel, arg);
|
||||
@ -108,7 +107,7 @@ parse_command(char * cmd)
|
||||
ircmsg("%s: %s", current_username, msgswp);
|
||||
}
|
||||
// XXX: what is this suppose to do?
|
||||
else if (strcmp(cmd, "submit") == 0) // TODO: implement
|
||||
else if (strncmp(cmd, "submit", i) == 0) // TODO: implement
|
||||
{
|
||||
ircmsg("%s: Submitting project link '%s' to <random janny>",
|
||||
current_username, arg);
|
||||
|
Reference in New Issue
Block a user