Updated dependencies, fixed migrations usage

This commit is contained in:
Benjamin Sherriff
2023-10-03 10:05:14 -04:00
parent e80ad9680a
commit 6c8a7ceefc
16 changed files with 141 additions and 116 deletions

View File

@@ -1,10 +1,12 @@
extern crate diesel;
#[macro_use]
extern crate diesel_migrations;
use std::collections::{HashSet, HashMap};
use std::env;
use std::sync::Arc;
use commands::audio::{create_response, AudioConfig, AudioConfigs};
use diesel::r2d2::{Pool, ConnectionManager};
use diesel::pg::PgConnection;
use dotenv::dotenv;
use log::{error, warn, info};
@@ -18,11 +20,13 @@ use serenity::prelude::*;
use songbird::SerenityInit;
mod commands;
mod database;
mod error_handler;
mod db;
mod messages;
mod schema;
struct Handler {
// Open AI Config
oai: Option<commands::oai::OAI>,
pool: Pool<ConnectionManager<PgConnection>>
oai: Option<commands::oai::OAI>
}
#[async_trait]
@@ -46,7 +50,7 @@ impl EventHandler for Handler {
Err(_) => false
};
if mentioned || bot_in_thread {
commands::oai::generate_response(&ctx, &msg, oai, &self.pool).await;
commands::oai::generate_response(&ctx, &msg, oai).await;
}
}
Err(why) => warn!("Could not check mentions: {:?}", why)
@@ -134,20 +138,18 @@ async fn main() {
Err(why) => panic!("Could not access application info: {:?}", why)
};
let pool = database::establish_connection();
database::run_migrations(&pool);
db::init();
let handler = match env::var("OPENAI_API_KEY") {
Ok(token) => {
info!("Loaded OpenAI token");
Handler {
oai: Some(commands::oai::OAI { client: reqwest::Client::new(), base_url: "https://api.openai.com/v1".to_string(), max_attempts: 5, token , max_context_questions: 15 }),
pool
oai: Some(commands::oai::OAI { client: reqwest::Client::new(), base_url: "https://api.openai.com/v1".to_string(), max_attempts: 5, token , max_context_questions: 15 })
}
}
Err(err) => {
warn!("Could not load OpenAI token: {}", err);
Handler { oai: None, pool }
Handler { oai: None }
}
};