#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <assert.h>
void
print_usage(void)
{
printf(
"\n\n This bot demonstrates how easy it is to create/delete emojis\n"
"1. Type 'emoji.list' to get a list of server emojis (in no "
"particular order)\n"
"2. Type 'emoji.get <emoji_id>' to get the selected emoji\n"
"\nTYPE ANY KEY TO START BOT\n");
}
void
{
log_info(
"Emoji-Bot succesfully connected to Discord as %s#%s!",
}
void
done_list_guild_emojis(
struct discord *client,
{
char text[2000] = "";
return;
}
char *cur = text;
char *end = &text[sizeof(text) - 1];
char *prev;
for (
int i = 0; i < emojis->
size; ++i) {
prev = cur;
cur += snprintf(cur, end - cur, "<%s:%s:%" PRIu64 ">(%" PRIu64 ")\n",
if (cur >= end) {
*prev = '\0';
cur = text;
--i;
continue;
}
}
}
void
{
char text[256];
snprintf(text, sizeof(text), "Couldn't fetch guild emojis: %s",
}
void
on_list_guild_emojis(
struct discord *client,
{
.
done = &done_list_guild_emojis,
.fail = &fail_list_guild_emojis,
.keep = event,
};
}
void
done_get_guild_emoji(
struct discord *client,
{
snprintf(text, sizeof(text), "Here you go: <%s:%s:%" PRIu64 ">",
}
void
{
char text[256];
snprintf(text, sizeof(text), "Unknown emoji: %s",
}
void
{
sscanf(event->
content,
"%" SCNu64, &emoji_id);
if (!emoji_id) return;
.
done = &done_get_guild_emoji,
.fail = &fail_get_guild_emoji,
.keep = event,
};
}
int
main(int argc, char *argv[])
{
const char *config_file;
if (argc > 1)
config_file = argv[1];
else
config_file = "../config.json";
assert(NULL != client && "Could not initialize client");
print_usage();
fgetc(stdin);
}
CCORDcode ccord_global_init()
Initialize global shared-resources not API-specific.
void ccord_global_cleanup()
Cleanup global shared-resources.
Public functions and datatypes.
const char * discord_strerror(CCORDcode code, struct discord *client)
Return the meaning of CCORDcode.
uint64_t u64snowflake
Snowflake datatype.
Definition: types.h:28
CCORDcode discord_create_message(struct discord *client, u64snowflake channel_id, struct discord_create_message *params, struct discord_ret_message *ret)
Post a message to a guild text or DM channel.
CCORDcode discord_list_guild_emojis(struct discord *client, u64snowflake guild_id, struct discord_ret_emojis *ret)
Get emojis of a given guild.
CCORDcode discord_get_guild_emoji(struct discord *client, u64snowflake guild_id, u64snowflake emoji_id, struct discord_ret_emoji *ret)
Get a specific emoji from a guild.
void discord_cleanup(struct discord *client)
Free a Discord Client handle.
CCORDcode discord_run(struct discord *client)
Start a connection to the Discord Gateway.
struct discord * discord_config_init(const char config_file[])
Create a Discord Client handle by a config.json file.
#define DISCORD_MAX_MESSAGE_LEN
Definition: discord.h:64
void discord_set_prefix(struct discord *client, const char prefix[])
Set a mandatory prefix before commands.
void discord_set_on_command(struct discord *client, char *command, void(*callback)(struct discord *client, const struct discord_message *event))
Set command/callback pair.
void discord_set_on_ready(struct discord *client, void(*callback)(struct discord *client, const struct discord_ready *event))
Triggers when the client session is ready.
#define log_info(...)
Definition: log.h:52
Definition: channel.h:683
char * content
Definition: channel.h:685
u64snowflake id
Definition: emoji.h:25
char * name
Definition: emoji.h:27
bool animated
Definition: emoji.h:41
struct discord_emoji * array
Definition: emoji.h:48
int size
Definition: emoji.h:47
Definition: channel.h:195
u64snowflake guild_id
Definition: channel.h:201
char * content
Definition: channel.h:207
struct discord_user * author
Definition: channel.h:203
u64snowflake channel_id
Definition: channel.h:199
Definition: gateway.h:332
struct discord_user * user
Definition: gateway.h:336
The response for the completed request.
Definition: discord-response.h:12
const void * keep
Definition: discord-response.h:16
CCORDcode code
Definition: discord-response.h:18
Request's return context.
Definition: discord-response.h:95
void(* done)(struct discord *client, struct discord_response *resp, const struct discord_emoji *ret)
Definition: discord-response.h:95
Request's return context.
Definition: discord-response.h:96
void(* done)(struct discord *client, struct discord_response *resp, const struct discord_emojis *ret)
Definition: discord-response.h:96
bool bot
Definition: user.h:79
char * username
Definition: user.h:73
char * discriminator
Definition: user.h:75
The Discord client handler.
Definition: discord-internal.h:1182