Working on database for messages
This commit is contained in:
24
src/main.rs
24
src/main.rs
@@ -2,6 +2,8 @@ use std::collections::HashSet;
|
||||
use std::env;
|
||||
|
||||
use commands::audio::create_response;
|
||||
use diesel::r2d2::{Pool, ConnectionManager};
|
||||
use diesel::pg::PgConnection;
|
||||
use dotenv::dotenv;
|
||||
use log::{error, warn, info};
|
||||
use serenity::async_trait;
|
||||
@@ -14,9 +16,12 @@ use serenity::prelude::*;
|
||||
use songbird::SerenityInit;
|
||||
|
||||
mod commands;
|
||||
mod database;
|
||||
|
||||
struct Handler {
|
||||
// Open AI Config
|
||||
oai: Option<commands::oai::OAI>
|
||||
oai: Option<commands::oai::OAI>,
|
||||
pool: Pool<ConnectionManager<PgConnection>>
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -110,28 +115,29 @@ async fn main() {
|
||||
Err(why) => panic!("Could not access application info: {:?}", why)
|
||||
};
|
||||
|
||||
let framework = StandardFramework::new()
|
||||
.configure(|c| c
|
||||
.owners(owners)
|
||||
.prefix("!")
|
||||
);
|
||||
let pool = database::establish_connection();
|
||||
database::run_migrations(&pool);
|
||||
|
||||
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 })
|
||||
oai: Some(commands::oai::OAI { client: reqwest::Client::new(), base_url: "https://api.openai.com/v1".to_string(), max_attempts: 5, token }),
|
||||
pool
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
warn!("Could not load OpenAI token: {}", err);
|
||||
Handler { oai: None }
|
||||
Handler { oai: None, pool }
|
||||
}
|
||||
};
|
||||
|
||||
let mut client = Client::builder(token, intents)
|
||||
.event_handler(handler)
|
||||
.framework(framework)
|
||||
.framework(StandardFramework::new()
|
||||
.configure(|c| c
|
||||
.owners(owners)
|
||||
))
|
||||
.register_songbird()
|
||||
.await
|
||||
.expect("Error creating client");
|
||||
|
||||
Reference in New Issue
Block a user