Skip to content

Commit

Permalink
Fix wrong format specifiers in get_avatar_url()
Browse files Browse the repository at this point in the history
  • Loading branch information
jdeokkim committed Jul 31, 2022
1 parent c4b6d58 commit 6ab4742
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 34 deletions.
2 changes: 1 addition & 1 deletion include/saerom.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
13 changes: 4 additions & 9 deletions src/bot.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -230,15 +228,15 @@ static void on_ready(
{
.name = "/info (" APPLICATION_VERSION ")",
.type = DISCORD_ACTIVITY_GAME,
},
}
};

timestamp = discord_timestamp(client);

struct discord_presence_update status = {
.activities = &(struct discord_activities) {
.size = sizeof(activities) / sizeof(*activities),
.array = activities,
.array = activities
},
.status = "online",
.afk = false,
Expand Down Expand Up @@ -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;
}
Expand Down
20 changes: 5 additions & 15 deletions src/krdict.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/* 컴포넌트와의 상호 작용 시에 호출되는 함수. */
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions src/papago.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
);
Expand Down Expand Up @@ -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.";
Expand Down
9 changes: 4 additions & 5 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ 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
);
} else {
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
);
}
Expand All @@ -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;

Expand Down Expand Up @@ -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++;
}
Expand Down

0 comments on commit 6ab4742

Please sign in to comment.