#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
void
print_usage(void)
{
printf("\n\nThis bot demonstrates how to embeds"
" with two different methods.\n"
"1 - Dynamic-approach (type !dynamic): Load the embed from "
"a JSON string.\n"
"2 - Static-approach (type !static): A clean initialization "
"approach "
"using the combination of designated initialization and compound "
"literals.\n"
"\nTYPE ANY KEY TO START BOT\n");
}
#define ICON_URL \
"https://github.com/Cogmasters/concord/blob/master/docs/static/" \
"concord-small.png?raw=true"
#define IMAGE_URL \
"https://github.com/Cogmasters/concord/blob/master/docs/static/" \
"social-preview.png?raw=true"
char JSON[] = "{\n"
" \"title\": \"Concord\",\n"
" \"description\": \"Discord API library\",\n"
" \"url\": \"https://github.com/Cogmasters/concord\",\n"
" \"color\": 3447003,\n"
" \"footer\": {\n"
" \"text\": \"github.com/Cogmasters/concord\",\n"
" \"icon_url\": \"" ICON_URL "\"\n"
" },\n"
" \"image\": {\n"
" \"url\": \"" IMAGE_URL "\"\n"
" },\n"
" \"author\": {\n"
" \"name\": \"Cogmasters\",\n"
" \"url\": \"https://github.com/Cogmasters\"\n"
" },\n"
" \"fields\": [\n"
" {\n"
" \"name\":\"Want to learn more?\", \n"
" \"value\":\"Read our "
"[documentation](https://cogmasters.github.io/concord/)!\"\n"
" },\n"
" {\n"
" \"name\":\"Looking for support?\", \n"
" \"value\":\"Join our server "
"[here](https://discord.gg/Y7Xa6MA82v)!\"\n"
" }\n"
" ]\n"
"}";
void
on_ready(
struct discord *client,
const struct discord_ready *event)
{
"Embed-Bot succesfully connected to Discord as %s#%s!",
event->user->username, event->user->discriminator);
}
void
on_dynamic(
struct discord *client,
const struct discord_message *event)
{
if (event->author->bot) return;
struct discord_embed embed = { 0 };
&embed);
.content = "This is an embed",
.embeds =
&(struct discord_embeds){
.size = 1,
.array = &embed,
},
};
}
void
on_static(
struct discord *client,
const struct discord_message *event)
{
if (event->author->bot) return;
struct discord_embed_field fields[] = {
{
.name = "Want to learn more?",
.value = "Read our "
"[documentation](https://cogmasters.github.io/"
"concord/)!",
},
{
.name = "Looking for support?",
.value = "Join our server "
"[here](https://discord.gg/x4hhGQYu)!",
},
};
struct discord_embed embeds[] = {
{
.title = "Concord",
.description = "Discord API library",
.url = "https://github.com/Cogmasters/concord",
.color = 0x3498DB,
.footer =
&(struct discord_embed_footer){
.text = "github.com/Cogmasters/concord",
.icon_url = ICON_URL,
},
.image =
&(struct discord_embed_image){
.url = IMAGE_URL,
},
.author =
&(struct discord_embed_author){
.name = "Cogmasters",
.url = "https://github.com/Cogmasters",
},
.fields =
&(struct discord_embed_fields){
.size = sizeof(fields) / sizeof *fields,
.array = fields,
},
},
};
.embeds =
&(struct discord_embeds){
.size = sizeof(embeds) / sizeof *embeds,
.array = embeds,
},
};
}
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 && "Couldn't initialize client");
print_usage();
fgetc(stdin);
}
Public functions and datatypes.
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.
void discord_cleanup(struct discord *client)
Free a Discord Client handle.
CCORDcode discord_run(struct discord *client)
Start a connection to the Discord Gateway.
uint64_t discord_timestamp(struct discord *client)
Get the current timestamp (in milliseconds)
struct discord * discord_from_json(const char config_file[])
Creates a Discord Client handle from a config.json file.
#define discord_data_from_json(_symbol, _client, _json, _len, _data)
Parse a JSON string and fill a Discord data type.
Definition: discord.h:608
#define discord_data_cleanup(_client, _data)
Cleanup a Discord data type wrapped into a reflectc_wrap structure.
Definition: discord.h:496
void discord_set_prefix(struct discord *client, const char prefix[])
Set a mandatory prefix before commands.
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.
void discord_set_on_command(struct discord *client, const char *command, void(*callback)(struct discord *client, const struct discord_message *event))
Set command/callback pair.
#define logmod_log
Alias to logmod_nlog for C89 compatibility.
Definition: logmod.h:487
The Discord client handler.
Definition: discord-internal.h:1206