#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <limits.h>
#include <string.h>
#include <assert.h>
void
print_usage(void)
{
printf("\n\nThis bot demonstrates how easy it is to log"
" for certain events.\n"
"1. Type '!last_channel' to check the most recent channel created "
"by you\n"
"\tsee: "
"https://discord.com/developers/docs/resources/"
"audit-log#audit-log-entry-object-audit-log-events\n"
"\nTYPE ANY KEY TO START BOT\n");
}
void
on_ready(
struct discord *client,
const struct discord_ready *event)
{
"Audit-Log-Bot succesfully connected to Discord as %s#%s!",
event->user->username, event->user->discriminator);
}
void
log_on_guild_member_add(
struct discord *client,
const struct discord_guild_member *event)
{
logmod_log(INFO, NULL,
"%s#%s joined guild %" PRIu64,
event->user->username, event->user->discriminator,
event->guild_id);
}
void
log_on_guild_member_update(
struct discord *client,
const struct discord_guild_member_update *event)
{
char nick[128] = "";
if (event->nick && *event->nick)
snprintf(nick, sizeof(nick), " (%s)", event->nick);
logmod_log(INFO, NULL,
"%s#%s%s updated (guild %" PRIu64
")",
event->user->username, event->user->discriminator, nick,
event->guild_id);
}
void
log_on_guild_member_remove(
struct discord *client,
const struct discord_guild_member_remove *event)
{
logmod_log(INFO, NULL,
"%s#%s left guild %" PRIu64, event->user->username,
event->user->discriminator, event->guild_id);
}
void
const struct discord_audit_log *audit_log)
{
const struct discord_message *
event = resp->
keep;
if (!audit_log->audit_log_entries || !audit_log->audit_log_entries->size) {
logmod_log(WARN, NULL,
"No audit log entries found!");
return;
}
struct discord_audit_log_entry *entry =
&audit_log->audit_log_entries->array[0];
char text[1028];
snprintf(text, sizeof(text), "<@!%" PRIu64 "> has created <#%" PRIu64 ">!",
entry->user_id, entry->target_id);
}
void
{
(void)resp;
logmod_log(ERROR, NULL,
"Couldn't retrieve audit log: %s",
}
void
on_audit_channel_create(
struct discord *client,
const struct discord_message *event)
{
if (event->author->bot) return;
.keep = event,
};
.user_id = event->author->id,
.action_type = DISCORD_AUDIT_LOG_CHANNEL_CREATE,
};
}
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_get_guild_audit_log(struct discord *client, u64snowflake guild_id, struct discord_get_guild_audit_log *params, struct discord_ret_audit_log *ret)
Get audit log for a given guild.
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.
struct discord * discord_from_json(const char config_file[])
Creates a Discord Client handle from a config.json file.
const char * discord_strerror(CCORDcode code, struct discord *client)
Return the meaning of CCORDcode.
void discord_add_intents(struct discord *client, uint64_t code)
Subscribe to Discord Events.
void discord_set_on_guild_member_update(struct discord *client, void(*callback)(struct discord *client, const struct discord_guild_member_update *event))
Triggers when a guild member is updated.
void discord_set_on_guild_member_remove(struct discord *client, void(*callback)(struct discord *client, const struct discord_guild_member_remove *event))
Triggers when a guild member is removed.
void discord_set_on_guild_member_add(struct discord *client, void(*callback)(struct discord *client, const struct discord_guild_member *event))
Triggers when a guild member is added.
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 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:78
void(* done)(struct discord *client, struct discord_response *resp, const struct discord_audit_log *ret)
Definition: discord-response.h:78
void(* fail)(struct discord *client, struct discord_response *resp)
Definition: discord-response.h:78
The Discord client handler.
Definition: discord-internal.h:1206