Skip to content

Commit

Permalink
Fix /krd breaking formatted strings in some cases
Browse files Browse the repository at this point in the history
  • Loading branch information
jdeokkim committed Jul 24, 2022
1 parent 1b224c1 commit c19e067
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ A C99 Discord bot for Korean learning servers.

- GCC version 9.4.0+
- GNU Make version 4.1+
- CMake version 3.22.0+
- CMake version 3.10.0+
- Git version 2.17.1+
- libcurl4 version 7.58.0+ (with OpenSSL flavor)

Expand Down
2 changes: 1 addition & 1 deletion include/saerom.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/* | 매크로 정의... | */

#define APPLICATION_NAME "jdeokkim/saerom"
#define APPLICATION_VERSION "v0.1.0"
#define APPLICATION_VERSION "v0.1.1"
#define APPLICATION_DESCRIPTION "A C99 Discord bot for Korean learning servers."
#define APPLICATION_PROJECT_URL "https://github.com/jdeokkim/saerom"
#define APPLICATION_ID 986954825176596498
Expand Down
19 changes: 16 additions & 3 deletions src/krdict.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct krdict_context {
u64snowflake id;
char *token;
} event;
bool translated;
};

/* `krdict` 모듈 명령어의 개별 검색 결과를 나타내는 구조체. */
Expand Down Expand Up @@ -173,6 +174,7 @@ void run_krdict_command(
context->client = client;
context->event.id = event->id;
context->event.token = malloc(strlen(event->token) + 1);
context->translated = string_equals(translated, "true");

strcpy(context->event.token, event->token);

Expand Down Expand Up @@ -450,15 +452,25 @@ static void on_response(CURLV_STR res, void *user_data) {
strcat(buffer, item.entry);
} else if (string_equals(elem, "sense_order")) {
order = atoi(content);
} else if (string_equals(elem, "definition")) {
if (context->translated) break;

if (order >= KRDICT_MAX_ORDER_COUNT) break;
len = strlen(buffer);

snprintf(
buffer + len,
sizeof(buffer) - len,
"**%d. %s**\n- ",
order,
item.word
);

len = strlen(buffer);

snprintf(
buffer + len,
sizeof(buffer) - len,
"**%s. ",
"%s\n\n",
content
);
} else if (string_equals(elem, "trans_word")) {
Expand All @@ -469,7 +481,8 @@ static void on_response(CURLV_STR res, void *user_data) {
snprintf(
buffer + len,
sizeof(buffer) - len,
"%s**\n- ",
"**%d. %s**\n- ",
order,
content
);
} else if (string_equals(elem, "trans_dfn")) {
Expand Down
6 changes: 3 additions & 3 deletions src/papago.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void run_papago_command(

snprintf(
buffer,
DISCORD_MAX_MESSAGE_LEN,
sizeof(buffer),
"source=%s&target=%s&text=%s",
source,
target,
Expand All @@ -165,7 +165,7 @@ void run_papago_command(

snprintf(
buffer,
DISCORD_MAX_MESSAGE_LEN,
sizeof(buffer),
"X-Naver-Client-Id: %s",
config->papago.client_id
);
Expand All @@ -174,7 +174,7 @@ void run_papago_command(

snprintf(
buffer,
DISCORD_MAX_MESSAGE_LEN,
sizeof(buffer),
"X-Naver-Client-Secret: %s",
config->papago.client_secret
);
Expand Down

0 comments on commit c19e067

Please sign in to comment.