2024-02-26 21:59:25 +13:00
|
|
|
#include <string.h>
|
|
|
|
#include <concord/discord.h>
|
|
|
|
#include <concord/log.h>
|
2024-02-29 22:02:46 +13:00
|
|
|
#include <sqlite3.h>
|
|
|
|
#include <stdlib.h>
|
2024-02-26 21:59:25 +13:00
|
|
|
|
2024-02-29 22:02:46 +13:00
|
|
|
sqlite3* db;
|
|
|
|
|
|
|
|
void on_ready(struct discord *client, const struct discord_ready *msg) {
|
|
|
|
log_info("Logged in as %s!", msg->user->username);
|
2024-02-26 21:59:25 +13:00
|
|
|
}
|
|
|
|
|
2024-02-29 22:02:46 +13:00
|
|
|
void on_message(struct discord *client, const struct discord_message *msg) {
|
2024-02-29 13:18:52 +00:00
|
|
|
log_info("%s", msg->content);
|
|
|
|
if(msg->type == DISCORD_MESSAGE_REPLY && msg->content != NULL) {
|
2024-02-29 22:02:46 +13:00
|
|
|
char buf[1024];
|
2024-02-29 13:18:52 +00:00
|
|
|
sprintf(buf, "INSERT INTO messages(message, reply)"
|
|
|
|
"VALUES('%s', '%s')",
|
|
|
|
msg->referenced_message->content, msg->content);
|
2024-02-29 22:02:46 +13:00
|
|
|
|
|
|
|
char* error;
|
|
|
|
if(sqlite3_exec(db, buf, NULL, NULL, &error)) {
|
|
|
|
log_error(error);
|
|
|
|
}
|
|
|
|
}
|
2024-02-26 21:59:25 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(void) {
|
2024-02-29 22:02:46 +13:00
|
|
|
sqlite3_open("messages.db", &db);
|
|
|
|
|
|
|
|
char* error;
|
|
|
|
if(sqlite3_exec(db,
|
|
|
|
"CREATE TABLE IF NOT EXISTS messages("
|
2024-02-29 13:18:52 +00:00
|
|
|
"id INTEGER PRIMARY KEY AUTOINCREMENT,"
|
2024-02-29 22:02:46 +13:00
|
|
|
"message TEXT NOT NULL,"
|
|
|
|
"reply TEXT NOT NULL"
|
|
|
|
");", NULL, NULL, &error)) {
|
|
|
|
log_error(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct discord *client = discord_config_init("config.json");
|
|
|
|
discord_add_intents(client, DISCORD_GATEWAY_MESSAGE_CONTENT);
|
|
|
|
discord_set_on_ready(client, &on_ready);
|
|
|
|
discord_set_on_message_create(client, &on_message);
|
|
|
|
discord_run(client);
|
2024-02-26 21:59:25 +13:00
|
|
|
}
|