diff --git a/src/command.c b/src/command.c index 7b60c8f..a234faf 100644 --- a/src/command.c +++ b/src/command.c @@ -12,6 +12,7 @@ struct pager { int page; int i; int is_poll; + hashmap *cmd; }; struct verifier { @@ -61,8 +62,18 @@ int inv_handler(const void *key, size_t size, uintptr_t val, void *usr) { char *val2 = (char *)val; if (i->is_poll) { - char *key3 = calloc(strlen(key2)+1,sizeof(char)); - memcpy(key3,key2,strstr(key2,"_") - key2); + char *key3 = calloc(strlen(key2) + 1, sizeof(char)); + memcpy(key3, key2, strstr(key2, "_") - key2); + + char *val3 = strstr(val2, ";") + 1; + uintptr_t result; + + hashmap_get(i->cmd, val3, strlen(val3) - 1, &result); + + if (result != 0) { + free(key3); + return 1; + } if (val2[strlen(val2) - 1] == '\n') { printf("- %s suggested %s", key3, val2); @@ -198,7 +209,7 @@ int help_command(char *command) { return 1; } -int polls_command(char *command, hashmap *polls) { +int polls_command(char *command, hashmap *polls, hashmap *cmd) { char *invs = "/polls "; @@ -213,7 +224,7 @@ int polls_command(char *command, hashmap *polls) { } printf("Current polls (page %i):\n", page); - struct pager i = {.page = page - 1, .i = -1, .is_poll = 1}; + struct pager i = {.page = page - 1, .i = -1, .is_poll = 1, .cmd = cmd}; hashmap_iterate(polls, inv_handler, &i); return 1; } diff --git a/src/command.h b/src/command.h index 24d7e36..f2f2ec4 100644 --- a/src/command.h +++ b/src/command.h @@ -4,4 +4,4 @@ int slash_command(char *command, hashmap *inv); int suggest_command(char *command, char *command_re, hashmap *polls, char *name); int help_command(char *command); -int polls_command(char *command, hashmap *polls); \ No newline at end of file +int polls_command(char *command, hashmap *polls, hashmap *cmd); \ No newline at end of file diff --git a/src/main.c b/src/main.c index 3d94128..2ad9aa7 100644 --- a/src/main.c +++ b/src/main.c @@ -78,7 +78,7 @@ int main(int argc, char *argv[]) { wasCombination = 0; if (help_command(command)) continue; - if (polls_command(command, polls)) + if (polls_command(command, polls, elements)) continue; if (slash_command(command, inv)) continue;