#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 three 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"
"3 - Builder-approach (type !builder): A dynamic and flexible "
"approach that relies on embed builder functions.\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
{
log_info(
"Embed-Bot succesfully connected to Discord as %s#%s!",
}
void
{
.embeds =
.size = 1,
.array = &embed,
},
};
}
void
{
{
.
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)!",
},
};
{
.description = "Discord API library",
.url = "https://github.com/Cogmasters/concord",
.color = 0x3498DB,
.footer =
.text = "github.com/Cogmasters/concord",
.icon_url = ICON_URL,
},
.image =
.url = IMAGE_URL,
},
.author =
.name = "Cogmasters",
.url = "https://github.com/Cogmasters",
},
.fields =
.size = sizeof(fields) / sizeof *fields,
},
},
};
.
size =
sizeof(embeds) /
sizeof *embeds,
},
};
}
void
{
};
NULL);
"https://github.com/Cogmasters", NULL, NULL);
&embed, "Want to learn more?",
"Read our "
"[documentation](https://cogmasters.github.io/concord/)!",
false);
&embed, "Looking for support?",
"Join our server [here](https://discord.gg/x4hhGQYu)!", false);
.array = &embed,
},
};
}
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);
}
CCORDcode ccord_global_init()
Initialize global shared-resources not API-specific.
void ccord_global_cleanup()
Cleanup global shared-resources.
Public functions and datatypes.
size_t discord_embed_from_json(const char buf[], size_t size, struct discord_embed *self)
void discord_embed_cleanup(struct discord_embed *self)
void discord_embed_set_url(struct discord_embed *embed, char format[],...)
Add URL to embed.
void discord_embed_set_footer(struct discord_embed *embed, char text[], char icon_url[], char proxy_icon_url[])
Add footer to embed.
void discord_embed_set_description(struct discord_embed *embed, char format[],...)
Add description to embed.
void discord_embed_set_title(struct discord_embed *embed, char format[],...)
Add title to embed.
void discord_embed_set_author(struct discord_embed *embed, char name[], char url[], char icon_url[], char proxy_icon_url[])
Add author to embed.
void discord_embed_add_field(struct discord_embed *embed, char name[], char value[], bool Inline)
Add field to embed.
void discord_embed_set_image(struct discord_embed *embed, char url[], char proxy_url[], int height, int width)
Add image to embed.
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_config_init(const char config_file[])
Create a Discord Client handle by a config.json file.
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
struct discord_embeds * embeds
Definition: channel.h:689
char * content
Definition: channel.h:685
Definition: channel.h:509
Definition: channel.h:539
char * name
Definition: channel.h:541
Definition: channel.h:548
struct discord_embed_field * array
Definition: channel.h:549
Definition: channel.h:481
Definition: channel.h:397
char * title
Definition: channel.h:399
int color
Definition: channel.h:412
u64unix_ms timestamp
Definition: channel.h:408
Definition: channel.h:441
int size
Definition: channel.h:441
struct discord_embed * array
Definition: channel.h:442
Definition: channel.h:195
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
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