From eae9b74981beef0039807cb422a06b8924467f44 Mon Sep 17 00:00:00 2001 From: Brett Date: Mon, 26 Feb 2024 10:03:34 -0500 Subject: [PATCH] sql --- include/filemanager.h | 8 ++--- libs/blt | 2 +- src/filemanager.cpp | 2 +- src/main.cpp | 73 +++++++++++++++++++++++++++++++++++++------ 4 files changed, 70 insertions(+), 15 deletions(-) diff --git a/include/filemanager.h b/include/filemanager.h index ffab1d6..50cda11 100644 --- a/include/filemanager.h +++ b/include/filemanager.h @@ -53,7 +53,7 @@ namespace db { private: blt::u64 channelID; - HASHMAP msgs; + blt::hashmap_t msgs; public: explicit channel_fs_manager(blt::u64 channelID): channelID(channelID) {} @@ -64,7 +64,7 @@ namespace db private: std::vector> channels_to_flush; public: - void flush_channels(HASHMAP>& map); + void flush_channels(blt::hashmap_t>& map); }; class guild_fs_manager @@ -73,7 +73,7 @@ namespace db std::string archive_path; std::string path; blt::u64 guildID; - HASHMAP> channels; + blt::hashmap_t> channels; dpp::cluster& bot; channel_flusher flusher; std::fstream f_server_name; @@ -114,7 +114,7 @@ namespace db class fs_manager { private: - HASHMAP> guild_handlers; + blt::hashmap_t> guild_handlers; dpp::cluster& bot; std::string archive_path; int current_day = 0; diff --git a/libs/blt b/libs/blt index 61d46de..9b4d0cc 160000 --- a/libs/blt +++ b/libs/blt @@ -1 +1 @@ -Subproject commit 61d46de5737b09d1eb1a6ef240f2af5e6ef2de71 +Subproject commit 9b4d0cc9a8493c608ab0075ab2c6a2b66061f3be diff --git a/src/filemanager.cpp b/src/filemanager.cpp index f4193ba..7cc6ce8 100644 --- a/src/filemanager.cpp +++ b/src/filemanager.cpp @@ -111,7 +111,7 @@ namespace db return local_day_path; } - void channel_flusher::flush_channels(HASHMAP>& map) + void channel_flusher::flush_channels(blt::hashmap_t>& map) { channels_to_flush.reserve(map.size()); for (auto& v : map) diff --git a/src/main.cpp b/src/main.cpp index ba9de5b..aba7981 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,13 +1,71 @@ #include #include #include +#include #include #include -#include +#include +#include "blt/std/types.h" +struct message_t +{ + blt::u64 messageID; + blt::u64 channelID; + blt::u64 userID; + std::string content; +}; + +struct user_info_t +{ + blt::u64 userID; + blt::u64 changeTime; + std::string username; + std::string global_nickname; + std::string server_name; +}; + +struct channel_info_t +{ + blt::u64 channelID; + blt::u64 changeTime; + std::string channel_name; +}; + +struct message_edits_t +{ + blt::u64 messageID; + blt::u64 channelID; + blt::u64 userID; + std::string new_content; +}; + + +struct db_obj +{ + private: + blt::u64 guildID; + std::string path; + public: + db_obj(blt::u64 guildID, std::string_view path): guildID(guildID), path(path) + {} +}; + +namespace db +{ + void sync_databases() + { + using namespace sqlite_orm; + auto storage = make_storage(":memory:", + make_table("messages", make_column("id", &message_t::userID, primary_key()))); + } +} + +blt::hashmap_t databases; int main(int argc, const char** argv) { + using namespace sqlite_orm; + blt::arg_parse parser; parser.addArgument(blt::arg_builder("-t", "--token").setAction(blt::arg_action_t::STORE).setHelp("The discord bot token").build()); parser.addArgument(blt::arg_builder("-p", "--path").setAction(blt::arg_action_t::STORE).setHelp("Path to store the archive data").build()); @@ -16,12 +74,6 @@ int main(int argc, const char** argv) dpp::cluster bot(args.get("token"), dpp::i_default_intents | dpp::i_message_content | dpp::i_all_intents); - db::fs_manager manager{args.get("path"), bot}; - - bot.start_timer([&manager](auto) { - manager.flush(); - }, 60); - bot.on_message_delete([&bot](const dpp::message_delete_t& event) { }); @@ -31,7 +83,8 @@ int main(int argc, const char** argv) }); bot.on_message_update([&bot](const dpp::message_update_t& event) { - + BLT_INFO("%ld (from user %ld in channel %ld ['%s']) -> '%s'", event.msg.id, event.msg.author.id, event.msg.channel_id, + event.msg.author.username.c_str(), event.msg.content.c_str()); }); bot.on_message_create([&bot](const dpp::message_create_t& event) { @@ -40,7 +93,9 @@ int main(int argc, const char** argv) bot.guild_get(event.msg.guild_id, [](const dpp::confirmation_callback_t& con) { BLT_INFO("Guild name: %s", con.get().name.c_str()); }); - BLT_TRACE("(%s)> %s", event.msg.author.username.c_str(), event.msg.content.c_str()); + + BLT_TRACE("(%s '%s' aka '%s' with mention '%s')> %s", event.msg.author.username.c_str(), event.msg.author.global_name.c_str(), + event.msg.member.get_nickname().c_str(), event.msg.member.get_mention().c_str(), event.msg.content.c_str()); for (const dpp::attachment& attach : event.msg.attachments) { BLT_INFO("\tAttachment: %s", attach.url.c_str());