forked from Cogmasters/concord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathping-pong.c
64 lines (51 loc) · 1.53 KB
/
ping-pong.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
#include <stdio.h>
#include <stdlib.h>
#include "discord.h"
#include "log.h"
void
print_usage(void)
{
printf("\n\nThis bot demonstrates a simple ping-pong response.\n"
"1. Type 'pong' in chat\n"
"2. Type 'ping' in chat\n"
"\nTYPE ANY KEY TO START BOT\n");
}
void
on_ready(struct discord *client, const struct discord_ready *event)
{
log_info("PingPong-Bot succesfully connected to Discord as %s#%s!",
event->user->username, event->user->discriminator);
}
void
on_ping(struct discord *client, const struct discord_message *event)
{
if (event->author->bot) return;
struct discord_create_message params = { .content = "pong" };
discord_create_message(client, event->channel_id, ¶ms, NULL);
}
void
on_pong(struct discord *client, const struct discord_message *event)
{
if (event->author->bot) return;
struct discord_create_message params = { .content = "ping" };
discord_create_message(client, event->channel_id, ¶ms, NULL);
}
int
main(int argc, char *argv[])
{
const char *config_file;
if (argc > 1)
config_file = argv[1];
else
config_file = "../config.json";
ccord_global_init();
struct discord *client = discord_config_init(config_file);
discord_set_on_ready(client, &on_ready);
discord_set_on_command(client, "ping", &on_ping);
discord_set_on_command(client, "pong", &on_pong);
print_usage();
fgetc(stdin); // wait for input
discord_run(client);
discord_cleanup(client);
ccord_global_cleanup();
}