feat: test-discord-ws.c can be used to test reconnects
#include <assert.h>
#include "discord.h"
+#include "discord-internal.h"
void on_ready(struct discord *client, const struct discord_user *me) {
fprintf(stderr, "\n\nSuccesfully connected to Discord as %s#%s!\n\n",
me->username, me->discriminator);
}
+void on_reconnect(
+ struct discord *client,
+ const struct discord_user *bot,
+ const struct discord_message *msg)
+{
+ if (msg->author->bot)
+ return;
+
+ struct discord_create_message_params params = { .content = "Reconnecting ..." };
+ discord_create_message(client, msg->channel_id, &params, NULL);
+
+ discord_gateway_shutdown(client->gw);
+}
+
int main(int argc, char *argv[])
{
const char *config_file;
@@ -23,6 +38,7 @@ int main(int argc, char *argv[])
assert(NULL != client);
discord_set_on_ready(client, &on_ready);
+ discord_set_on_command(client, "reconnect", &on_reconnect);
discord_run(client);
