From 6ab474231c22de74540558e06e15be5880faee30 Mon Sep 17 00:00:00 2001 From: jdeokkim Date: Sun, 31 Jul 2022 16:43:22 +0900 Subject: [PATCH] Fix wrong format specifiers in `get_avatar_url()` --- include/saerom.h | 2 +- src/bot.c | 13 ++++--------- src/krdict.c | 20 +++++--------------- src/papago.c | 6 ++---- src/utils.c | 9 ++++----- 5 files changed, 16 insertions(+), 34 deletions(-) diff --git a/include/saerom.h b/include/saerom.h index d8e8ae0..8d82197 100644 --- a/include/saerom.h +++ b/include/saerom.h @@ -27,7 +27,7 @@ /* | 매크로 정의... | */ #define APPLICATION_NAME "jdeokkim/saerom" -#define APPLICATION_VERSION "v0.3.3" +#define APPLICATION_VERSION "v0.3.4" #define APPLICATION_DESCRIPTION "A C99 Discord bot for Korean learning servers." #define APPLICATION_PROJECT_URL "https://github.com/jdeokkim/saerom" diff --git a/src/bot.c b/src/bot.c index 10ed63a..e07c5fa 100644 --- a/src/bot.c +++ b/src/bot.c @@ -193,8 +193,6 @@ uint64_t sr_get_uptime(void) { /* Discord 봇이 대기 중일 때 주기적으로 호출된다. */ static void on_idle(struct discord *client) { if (!(sr_config_get_status_flags() & SR_STATUS_RUNNING)) { - sr_config_set_status_flags(0); - log_info("[SAEROM] Shutting down the bot"); sr_bot_cleanup(); @@ -230,7 +228,7 @@ static void on_ready( { .name = "/info (" APPLICATION_VERSION ")", .type = DISCORD_ACTIVITY_GAME, - }, + } }; timestamp = discord_timestamp(client); @@ -238,7 +236,7 @@ static void on_ready( struct discord_presence_update status = { .activities = &(struct discord_activities) { .size = sizeof(activities) / sizeof(*activities), - .array = activities, + .array = activities }, .status = "online", .afk = false, @@ -297,12 +295,9 @@ static void on_interaction_create( user->discriminator ); - for (int i = 0; i < sizeof(commands) / sizeof(*commands); i++) { - const char *name = commands[i].name; - - if (strncmp(context, name, strlen(name)) == 0) + for (int i = 0; i < sizeof(commands) / sizeof(*commands); i++) + if (strncmp(context, commands[i].name, strlen(commands[i].name)) == 0) commands[i].on_run(client, event); - } break; } diff --git a/src/krdict.c b/src/krdict.c index 2a49069..7f1818a 100644 --- a/src/krdict.c +++ b/src/krdict.c @@ -311,10 +311,7 @@ static void on_message_failure( /* 개인 메시지 전송이 끝났을 때 호출되는 함수. */ static void on_message_complete(struct discord *client, void *data) { - struct discord_interaction *event = data; - - free(event->token); - free(event); + discord_unclaim(client, (struct discord_interaction *) data); } /* 컴포넌트와의 상호 작용 시에 호출되는 함수. */ @@ -341,15 +338,6 @@ static void on_component_interaction( if (result != CCORD_OK) return; discord_channel_cleanup(&ret_channel); - - struct discord_interaction *event_clone = malloc( - sizeof(struct discord_interaction) - ); - - event_clone->id = event->id; - event_clone->token = malloc(strlen(event->token) + 1); - - strcpy(event_clone->token, event->token); discord_create_message( client, @@ -358,7 +346,7 @@ static void on_component_interaction( .embeds = event->message->embeds }, &(struct discord_ret_message) { - .data = event_clone, + .data = (void *) discord_claim(client, event), .cleanup = on_message_complete, .done = on_message_success, .fail = on_message_failure @@ -378,7 +366,9 @@ static void on_response(CURLV_STR res, void *user_data) { log_info( "[SAEROM] Received %ld bytes from \"%s\"", res.len, - request_url_check ? URMS_REQUEST_URL : KRDICT_REQUEST_URL + request_url_check + ? URMS_REQUEST_URL + : KRDICT_REQUEST_URL ); yxml_t *parser = malloc(sizeof(yxml_t) + res.len); diff --git a/src/papago.c b/src/papago.c index 81e4113..1ec4d9b 100644 --- a/src/papago.c +++ b/src/papago.c @@ -125,7 +125,7 @@ void sr_command_papago_run( return; } - char *text = "", *source = "ko", *target = "en"; + char *text = "", *source = "en", *target = "ko"; for (int i = 0; i < event->data->options->size; i++) { char *name = event->data->options->array[i].name; @@ -216,7 +216,7 @@ void sr_command_papago_run( snprintf( buffer, - sizeof(buffer), + sizeof(buffer), "X-Naver-Client-Secret: %s", sr_config_get_papago_client_secret() ); @@ -355,8 +355,6 @@ static void handle_error(struct papago_context *context, const char *code) { else if (streq(code, "N2MT05")) embeds[0].description = "Target language must not be the same as the " "source language."; - else if (streq(code, "N2MT08")) - embeds[0].description = "The length of the `text` parameter is too long."; else embeds[0].description = "An unknown error has occured while processing " "your request."; diff --git a/src/utils.c b/src/utils.c index 026c187..fd5f014 100644 --- a/src/utils.c +++ b/src/utils.c @@ -38,7 +38,7 @@ const char *get_avatar_url(const struct discord_user *user) { snprintf( buffer, MAX_STRING_SIZE, - "https://cdn.discordapp.com/avatars/%"SCNu64"/%s.webp", + "https://cdn.discordapp.com/avatars/%" PRIu64 "/%s.webp", user->id, user->avatar ); @@ -46,7 +46,7 @@ const char *get_avatar_url(const struct discord_user *user) { snprintf( buffer, MAX_STRING_SIZE, - "https://cdn.discordapp.com/embed/avatars/%"SCNu64".png", + "https://cdn.discordapp.com/embed/avatars/%" PRIu64 ".png", strtoul(user->discriminator, NULL, 10) % DISCORD_MAGIC_NUMBER ); } @@ -70,7 +70,7 @@ void *read_input(void *arg) { if (fgets(context, sizeof(context), stdin)) ; - context[strcspn(context, "\r\n")] = 0; + context[strcspn(context, "\r\n")] = '\0'; if (*context == '\0') continue; @@ -101,11 +101,10 @@ size_t utf8len(const char *str) { size_t result = 0; // 첫 번째 바이트만 확인한다. - for (const char *c = str; *c; c++) { + for (const char *c = str; *c != '\0'; c++) { if ((*c & 0xf8) == 0xf0) c += 3; else if ((*c & 0xf0) == 0xe0) c += 2; else if ((*c & 0xe0) == 0xc0) c += 1; - else ; result++; }