#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <assert.h>
void
print_usage(void)
{
printf(
"\n\n(USE WITH CAUTION) This bot demonstrates how easy it is to "
"create/delete channels\n"
"1. Type 'channel.create <channel_name>' anywhere to create a new "
"channel\n"
"2. Type 'channel.rename_this <channel_name>' to rename the current "
"channel\n"
"3. Type 'channel.delete_this' to delete the current channel\n"
"4. Type 'channel.get_invites' to check how many have been created\n"
"5. Type 'channel.create_invite' to create a new invite\n"
"6. Type 'channel.start_thread' to start a new thread (reply to a "
"message if you wish start a thread under it)\n"
"\nTYPE ANY KEY TO START BOT\n");
}
void
{
log_info(
"Channel-Bot succesfully connected to Discord as %s#%s!",
}
void
log_on_channel_create(
struct discord *client,
{
}
void
log_on_channel_update(
struct discord *client,
{
}
void
log_on_channel_delete(
struct discord *client,
{
}
void
log_on_thread_create(
struct discord *client,
{
}
void
log_on_thread_update(
struct discord *client,
{
}
void
log_on_thread_delete(
struct discord *client,
{
}
void
{
.reason = "Shiny new channel",
};
}
void
on_channel_rename_this(
struct discord *client,
{
.reason = "Clicks better",
};
}
void
on_channel_delete_this(
struct discord *client,
{
}
void
done_get_channel_invites(
struct discord *client,
{
return;
}
snprintf(text,
sizeof(text),
"%d invite links created.", invites->
size);
}
void
{
}
void
on_channel_get_invites(
struct discord *client,
{
.
done = &done_get_channel_invites,
.fail = &fail_get_channel_invites,
.keep = event,
};
}
void
done_create_channel_invite(
struct discord *client,
{
char text[256];
snprintf(text,
sizeof(text),
"https://discord.gg/%s", invite->
code);
}
void
fail_create_channel_invite(
struct discord *client,
{
.
content =
"Couldn't create invite",
};
}
void
on_channel_create_invite(
struct discord *client,
{
.
done = &done_create_channel_invite,
.fail = &fail_create_channel_invite,
.keep = event,
};
}
void
done_start_thread(
struct discord *client,
{
char text[1024];
snprintf(text,
sizeof(text),
"Created thread <#%" PRIu64
">",
thread->
id);
}
void
{
char text[1024];
snprintf(text, sizeof(text), "Couldn't create thread: %s",
}
void
on_channel_start_thread(
struct discord *client,
{
.
done = &done_start_thread,
.fail = &fail_start_thread,
.keep = event,
};
};
¶ms, &ret);
}
else {
};
¶ms, &ret);
}
}
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.
@ DISCORD_CHANNEL_GUILD_PUBLIC_THREAD
Definition: channel.h:72
const char * discord_strerror(CCORDcode code, struct discord *client)
Return the meaning of CCORDcode.
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_start_thread_with_message(struct discord *client, u64snowflake channel_id, u64snowflake message_id, struct discord_start_thread_with_message *params, struct discord_ret_channel *ret)
Creates a new thread from an existing message.
CCORDcode discord_start_thread_without_message(struct discord *client, u64snowflake channel_id, struct discord_start_thread_without_message *params, struct discord_ret_channel *ret)
Creates a new thread that is not connected to an existing message.
CCORDcode discord_modify_channel(struct discord *client, u64snowflake channel_id, struct discord_modify_channel *params, struct discord_ret_channel *ret)
Update a channel's settings.
CCORDcode discord_get_channel_invites(struct discord *client, u64snowflake channel_id, struct discord_ret_invites *ret)
Get invites (with invite metadata) for the channel.
CCORDcode discord_delete_channel(struct discord *client, u64snowflake channel_id, struct discord_delete_channel *params, struct discord_ret_channel *ret)
Delete a channel, or close a private message.
CCORDcode discord_create_channel_invite(struct discord *client, u64snowflake channel_id, struct discord_create_channel_invite *params, struct discord_ret_invite *ret)
Create a new invite for the channel.
CCORDcode discord_create_guild_channel(struct discord *client, u64snowflake guild_id, struct discord_create_guild_channel *params, struct discord_ret_channel *ret)
Create a new guild 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_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_on_channel_update(struct discord *client, void(*callback)(struct discord *client, const struct discord_channel *event))
Triggers when a channel is updated.
void discord_set_on_channel_create(struct discord *client, void(*callback)(struct discord *client, const struct discord_channel *event))
Triggers when a channel is created.
void discord_set_prefix(struct discord *client, const char prefix[])
Set a mandatory prefix before commands.
void discord_set_on_channel_delete(struct discord *client, void(*callback)(struct discord *client, const struct discord_channel *event))
Triggers when a channel is deleted.
void discord_set_on_thread_create(struct discord *client, void(*callback)(struct discord *client, const struct discord_channel *event))
Triggers when a thread is created.
void discord_set_on_thread_delete(struct discord *client, void(*callback)(struct discord *client, const struct discord_channel *event))
Triggers when a thread is deleted.
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_thread_update(struct discord *client, void(*callback)(struct discord *client, const struct discord_channel *event))
Triggers when a thread is updated.
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:122
char * name
Definition: channel.h:137
u64snowflake id
Definition: channel.h:124
char * name
Definition: guild.h:534
Definition: channel.h:683
char * content
Definition: channel.h:685
Definition: channel.h:660
char * reason
Definition: channel.h:662
char * code
Definition: invite.h:29
int size
Definition: invite.h:74
u64snowflake message_id
Definition: channel.h:276
Definition: channel.h:195
struct discord_channel * thread
Definition: channel.h:257
u64snowflake guild_id
Definition: channel.h:201
struct discord_user * author
Definition: channel.h:203
u64snowflake channel_id
Definition: channel.h:199
struct discord_message_reference * message_reference
Definition: channel.h:248
Definition: channel.h:587
char * name
Definition: channel.h:591
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:84
void(* done)(struct discord *client, struct discord_response *resp, const struct discord_channel *ret)
Definition: discord-response.h:84
Request's return context.
Definition: discord-response.h:132
void(* done)(struct discord *client, struct discord_response *resp, const struct discord_invite *ret)
Definition: discord-response.h:132
Request's return context.
Definition: discord-response.h:133
void(* done)(struct discord *client, struct discord_response *resp, const struct discord_invites *ret)
Definition: discord-response.h:133
Definition: channel.h:842
char * name
Definition: channel.h:846
Definition: channel.h:859
char * name
Definition: channel.h:863
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:1190