forked from Cogmasters/concord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebhook.c
65 lines (55 loc) · 1.62 KB
/
webhook.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <assert.h>
#include "discord.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
ccord_global_init();
struct discord *client = discord_init(NULL);
assert(NULL != client && "Couldn't initialize client");
/* Get Webhook */
{
struct discord_ret_webhook ret = { .sync = DISCORD_SYNC_FLAG };
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, ¶ms, &ret);
}
free(webhook_token);
discord_cleanup(client);
ccord_global_cleanup();
return EXIT_SUCCESS;
}