#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <assert.h>
void
print_usage(void)
{
printf(
"\n\nThis bot demonstrates how easy it is to create/delete"
" reactions from a message.\n"
"1. Reply to a message with 'reaction.get_users <emoji>' to get all "
"the users who reacted with that particular emoji\n"
"2. Reply to a message with 'reaction.create <emoji>' and the bot "
"will react with that emoji\n"
"3. Reply to a message with 'reaction.delete <emoji>' to delete all "
"reactions with a particular emoji\n"
"4. Reply to a message with 'reaction.delete_all' to delete all "
"reactions\n"
"5. Reply to a message with 'reaction.delete_self <emoji>' to delete "
"your reaction with a particular emoji\n"
"6. Reply to a message with 'reaction.delete_user <user_id> <emoji>' "
"to delete the user reaction with a particular emoji\n"
"\nTYPE ANY KEY TO START BOT\n");
}
void
{
log_info(
"Reaction-Bot succesfully connected to Discord as %s#%s!",
}
void
done_get_users(
struct discord *client,
{
char text[2000];
snprintf(text, sizeof(text), "Nobody reacted with that emoji!");
}
else {
char *cur = text;
char *end = &text[sizeof(text) - 1];
for (
int i = 0; i < users->
size; ++i) {
cur += snprintf(cur, end - cur, "%s (%" PRIu64 ")\n",
if (cur >= end) break;
}
}
}
void
{
char text[256];
snprintf(text, sizeof(text), "Couldn't fetch reactions: %s",
}
void
{
.fail = &fail_get_users,
.keep = event,
};
¶ms, &ret);
}
void
{
NULL);
}
void
{
}
void
{
}
void
{
}
void
{
char emoji_name[256] = "";
sscanf(event->
content,
"%" SCNu64
" %s", &user_id, emoji_name);
emoji_name, NULL);
}
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.
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_delete_own_reaction(struct discord *client, u64snowflake channel_id, u64snowflake message_id, u64snowflake emoji_id, const char emoji_name[], struct discord_ret *ret)
Delete a reaction the current user has made for the message.
CCORDcode discord_delete_user_reaction(struct discord *client, u64snowflake channel_id, u64snowflake message_id, u64snowflake user_id, u64snowflake emoji_id, const char emoji_name[], struct discord_ret *ret)
Deletes another user's reaction.
CCORDcode discord_get_reactions(struct discord *client, u64snowflake channel_id, u64snowflake message_id, u64snowflake emoji_id, const char emoji_name[], struct discord_get_reactions *params, struct discord_ret_users *ret)
Get a list of users that reacted with given emoji.
CCORDcode discord_delete_all_reactions(struct discord *client, u64snowflake channel_id, u64snowflake message_id, struct discord_ret *ret)
Deletes all reactions from message.
CCORDcode discord_create_reaction(struct discord *client, u64snowflake channel_id, u64snowflake message_id, u64snowflake emoji_id, const char emoji_name[], struct discord_ret *ret)
Create a reaction for the message.
CCORDcode discord_delete_all_reactions_for_emoji(struct discord *client, u64snowflake channel_id, u64snowflake message_id, u64snowflake emoji_id, const char emoji_name[], struct discord_ret *ret)
Deletes all the reactions for a given emoji on message.
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.
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
Definition: channel.h:716
int limit
Definition: channel.h:723
Definition: channel.h:195
u64snowflake id
Definition: channel.h:197
struct discord_message * referenced_message
Definition: channel.h:252
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:151
void(* done)(struct discord *client, struct discord_response *resp, const struct discord_users *ret)
Definition: discord-response.h:151
bool bot
Definition: user.h:79
u64snowflake id
Definition: user.h:71
char * username
Definition: user.h:73
char * discriminator
Definition: user.h:75
int size
Definition: user.h:104
struct discord_user * array
Definition: user.h:105
The Discord client handler.
Definition: discord-internal.h:1190