feat: split out all the databse interactions into their own file

This commit is contained in:
silver 2024-10-28 00:59:04 +00:00
parent 79f880daea
commit 41407ecefb
Signed by: silver
GPG key ID: 36F93D61BAD3FD7D
12 changed files with 348 additions and 318 deletions

View file

@ -1,14 +1,15 @@
use serenity::{
builder::CreateApplicationCommand,
client::Context,
model::{
application::interaction::application_command::ApplicationCommandInteraction,
prelude::{command::CommandOptionType, interaction::application_command::CommandDataOptionValue},
},
builder::CreateApplicationCommand,
client::Context,
model::{
application::interaction::application_command::ApplicationCommandInteraction,
prelude::{command::CommandOptionType, interaction::application_command::CommandDataOptionValue},
},
};
use skynet_discord_bot::common::wolves::get_data::get_wolves_cns;
use skynet_discord_bot::{get_server_config, is_admin, set_roles::update_server, DataBase, Servers};
use skynet_discord_bot::{is_admin, set_roles::update_server};
use sqlx::{Error, Pool, Sqlite};
use skynet_discord_bot::common::database::{get_server_config, DataBase, Servers};
pub async fn run(command: &ApplicationCommandInteraction, ctx: &Context) -> String {
// check if user has high enough permisssions

View file

@ -13,8 +13,10 @@ use serenity::{
prelude::{command::CommandOptionType, interaction::application_command::CommandDataOptionValue},
},
};
use skynet_discord_bot::{get_now_iso, random_string, Config, DataBase, Wolves, WolvesVerify};
use skynet_discord_bot::{get_now_iso, random_string, Config};
use sqlx::{Pool, Sqlite};
use skynet_discord_bot::common::database::{DataBase, Wolves, WolvesVerify};
pub mod link {
use super::*;
@ -238,8 +240,9 @@ pub mod verify {
use super::*;
use crate::commands::link_email::link::{db_pending_clear_expired, get_verify_from_db};
use serenity::model::user::User;
use skynet_discord_bot::{get_server_config, ServerMembersWolves, Servers};
use skynet_discord_bot::common::database::get_server_config;
use sqlx::Error;
use skynet_discord_bot::common::database::{ServerMembersWolves, Servers};
pub async fn run(command: &ApplicationCommandInteraction, ctx: &Context) -> String {
let db_lock = {

View file

@ -7,7 +7,7 @@ use serenity::{
},
};
use skynet_discord_bot::DataBase;
use skynet_discord_bot::common::database::DataBase;
use sqlx::{Pool, Sqlite};
pub(crate) mod user {
@ -16,8 +16,9 @@ pub(crate) mod user {
use super::*;
use crate::commands::link_email::link::get_server_member_discord;
use serenity::model::id::UserId;
use skynet_discord_bot::{whitelist_update, Config, Minecraft, Wolves};
use skynet_discord_bot::{whitelist_update, Config};
use sqlx::Error;
use skynet_discord_bot::common::database::{Minecraft, Wolves};
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand {
command.name("link_minecraft").description("Link your minecraft account").create_option(|option| {
@ -122,7 +123,8 @@ pub(crate) mod server {
use sqlx::Error;
// this is to managfe the server side of commands related to minecraft
use super::*;
use skynet_discord_bot::{is_admin, update_server, Config, Minecraft};
use skynet_discord_bot::{is_admin, update_server, Config};
use skynet_discord_bot::common::database::Minecraft;
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand {
command.name("minecraft_add").description("Add a minecraft server").create_option(|option| {
@ -201,7 +203,8 @@ pub(crate) mod server {
use serenity::builder::CreateApplicationCommand;
use serenity::client::Context;
use serenity::model::prelude::application_command::ApplicationCommandInteraction;
use skynet_discord_bot::{get_minecraft_config_server, is_admin, server_information, Config, DataBase};
use skynet_discord_bot::{get_minecraft_config_server, is_admin, server_information, Config};
use skynet_discord_bot::common::database::DataBase;
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand {
command.name("minecraft_list").description("List your minecraft servers")
@ -262,8 +265,9 @@ pub(crate) mod server {
use serenity::model::application::command::CommandOptionType;
use serenity::model::id::GuildId;
use serenity::model::prelude::application_command::{ApplicationCommandInteraction, CommandDataOptionValue};
use skynet_discord_bot::{is_admin, DataBase, Minecraft};
use skynet_discord_bot::is_admin;
use sqlx::{Error, Pool, Sqlite};
use skynet_discord_bot::common::database::{DataBase, Minecraft};
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand {
command.name("minecraft_delete").description("Delete a minecraft server").create_option(|option| {

View file

@ -7,8 +7,9 @@ use serenity::{
},
};
use skynet_discord_bot::{is_admin, DataBase, RoleAdder};
use skynet_discord_bot::is_admin;
use sqlx::{Error, Pool, Sqlite};
use skynet_discord_bot::common::database::{DataBase, RoleAdder};
pub mod edit {
use super::*;
@ -188,7 +189,7 @@ pub mod list {}
pub mod tools {
use serenity::client::Context;
use serenity::model::guild::Member;
use skynet_discord_bot::RoleAdder;
use skynet_discord_bot::common::database::RoleAdder;
use sqlx::{Pool, Sqlite};
pub async fn on_role_change(db: &Pool<Sqlite>, ctx: &Context, mut new_data: Member) {