don't show polls that passed

This commit is contained in:
biglyderv 2025-03-29 04:59:17 -04:00
parent 177f9025e0
commit 745a306b04
Signed by: biglyderv
GPG key ID: 0E2EB0B4CD7397B5
3 changed files with 17 additions and 6 deletions

View file

@ -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;
}

View file

@ -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);
int polls_command(char *command, hashmap *polls, hashmap *cmd);

View file

@ -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;