Updated dependencies

Updated formatting file
Changed the command line argument system
Updated error checking and matching logic to be easier to work with
Moved groups of functions to more correct modules
Updated the constants.rs file and added a help string for use with the new argument system
Disabled lua for now, the rust side of the bot takes priority
Changed the shutdown handler to be easier to work with
Added shutdown monitor task that gets started after the bot is ready, allowing a graceful shutdown from anywhere in the program, authentication is expected to be handled at the place of calling, not within the shutdown function
Added a basic database interface, SQLite will be implemented first as it is the simplest and most useful to the spiff team
This commit is contained in:
lever1209 2025-02-18 16:46:25 -04:00
commit 578918b22f
Signed by: lever1209
GPG key ID: AD770D25A908AFF4
18 changed files with 1564 additions and 644 deletions

72
src/databases/sqlite.rs Normal file
View file

@ -0,0 +1,72 @@
use std::{
fmt::Debug,
sync::{Arc, Mutex},
};
use sqlite::Connection;
use tracing::{error, info};
use crate::{errors::DatabaseStoredError, CMD_ARGS};
use super::DatabaseAccessor;
struct SQLiteDatabase {
connection: Mutex<Connection>, /*>*/
}
impl SQLiteDatabase {
//fn lock(&self) {
//}
}
impl Debug for SQLiteDatabase {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("SQLiteDatabase")/*.field("connection", &"<SQLiteConnection>")*/.finish()
}
}
impl DatabaseAccessor for SQLiteDatabase {
fn get_db_version(&self) {
todo!()
}
fn check_db_health(&self) {
todo!()
}
fn fix_db_health(&self) {
todo!()
}
fn is_dev(&self, user_id: serenity::all::UserId) -> bool {
todo!()
}
fn set_dev(&self, user_id: serenity::all::UserId) {
todo!()
}
fn store_error(&self, err: &DatabaseStoredError) {
todo!()
}
}
/// # Panics
/// This function will panic if used after the database has already been set
///
/// You should not worry about this as this function only ever gets called once at the start of the program and you are doing something wrong if you need to call this a second time
pub fn create_interface() -> Result<(), Box<dyn std::error::Error>> {
info!("Loading SQLite.");
if let Some(db_path) = CMD_ARGS.dbpath.clone() {
let connection = sqlite::open(&db_path).map_err(|err| format!("Could not open file {db_path:?} with error: {err}"))?;
super::set_db(Box::new(SQLiteDatabase {
connection: /*Arc::new(*/Mutex::new(connection)/*)*/,
}));
Ok(())
} else {
Err("You must provide a path using `dbpath` for sqlite to function!".into())
}
}