Concord - C Discord API library
A Discord API wrapper library written in C
webhook.c

Demonstrates a couple use cases of the Webhook API

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <assert.h>
#include "discord.h"
#include "log.h"
static void
print_usage(char *prog)
{
fprintf(stderr, "Usage: %s -i webhook-id -t webhook-token\n", prog);
exit(EXIT_FAILURE);
}
int
main(int argc, char *argv[])
{
u64snowflake webhook_id = 0;
char *webhook_token = NULL;
int opt;
while (-1 != (opt = getopt(argc, argv, "i:t:"))) {
switch (opt) {
case 't':
webhook_token = strdup(optarg);
break;
case 'i':
webhook_id = strtoull(optarg, NULL, 10);
break;
default:
print_usage(argv[0]);
break;
}
}
if (!webhook_token || !webhook_id) print_usage(argv[0]);
printf("\n\nThis bot demonstrates how to use webhook endpoints which "
"require no authentication token\n"
"\nTYPE ANY KEY TO START BOT\n");
fgetc(stdin); // wait for input
struct discord *client = discord_init(NULL);
assert(NULL != client && "Couldn't initialize client");
/* Get Webhook */
{
discord_get_webhook_with_token(client, webhook_id, webhook_token,
&ret);
}
/* Execute Webhook */
{
struct discord_ret ret = { .sync = true };
struct discord_execute_webhook params = { .content = "Hello World!" };
discord_execute_webhook(client, webhook_id, webhook_token, &params,
&ret);
}
free(webhook_token);
discord_cleanup(client);
return EXIT_SUCCESS;
}
CCORDcode ccord_global_init()
Initialize global shared-resources not API-specific.
void ccord_global_cleanup()
Cleanup global shared-resources.
#define DISCORD_SYNC_FLAG
flag for enabling sync mode without expecting a datatype return
Definition: discord-response.h:63
Public functions and datatypes.
uint64_t u64snowflake
Snowflake datatype.
Definition: types.h:28
CCORDcode discord_get_webhook_with_token(struct discord *client, u64snowflake webhook_id, const char webhook_token[], struct discord_ret_webhook *ret)
CCORDcode discord_execute_webhook(struct discord *client, u64snowflake webhook_id, const char webhook_token[], struct discord_execute_webhook *params, struct discord_ret *ret)
void discord_cleanup(struct discord *client)
Free a Discord Client handle.
struct discord * discord_init(const char token[])
Create a Discord Client handle by its token.
Definition: webhook.h:111
char * content
Definition: webhook.h:122
Request's return context.
Definition: discord-response.h:162
struct discord_webhook * sync
Definition: discord-response.h:162
Request's return context.
Definition: discord-response.h:54
bool sync
Definition: discord-response.h:59
The Discord client handler.
Definition: discord-internal.h:1182