Fixed play command

This commit is contained in:
2024-09-05 11:01:08 -04:00
parent fce4a0a4a2
commit bce363db7e
23 changed files with 410 additions and 552 deletions

View File

@@ -5,18 +5,24 @@ extern crate diesel_migrations;
use std::env;
use std::collections::HashSet;
use std::sync::Arc;
use serenity::client::Cache;
use serenity::framework::StandardFramework;
use serenity::http::Http;
use serenity::prelude::*;
use songbird::{SerenityInit, Songbird};
use reqwest::Client as HttpClient;
use crate::bot::handler::Handler;
mod bot;
mod dnd;
mod error;
mod storage;
pub struct HttpKey;
impl TypeMapKey for HttpKey {
type Value = HttpClient;
}
#[tokio::main]
async fn main() {
dotenv::dotenv().ok();
@@ -27,25 +33,25 @@ async fn main() {
let intents: GatewayIntents = GatewayIntents::all();
let http: Http = Http::new(&token);
let (owners, _bot_id) = match http.get_current_application_info().await {
let (_owners, _bot_id) = match http.get_current_application_info().await {
Ok(info) => {
let mut owners: HashSet<serenity::model::id::UserId> = HashSet::new();
if let Some(team) = info.team {
owners.insert(team.owner_user_id);
} else {
owners.insert(info.owner.id);
owners.insert(info.owner.unwrap().id);
}
match http.get_current_user().await {
Ok(bot) => (owners, bot.id),
Err(why) => panic!("Could not access the bot id: {:?}", why),
Err(why) => panic!("Could not access the bot id: {why:?}"),
}
}
Err(why) => panic!("Could not access application info: {:?}", why),
Err(why) => panic!("Could not access application info: {why:?}"),
};
let handler = match env::var("OPENAI_API_KEY") {
Ok(token) => {
log::info!("Loaded OpenAI token");
log::info!("OpenAI functionality enabled");
let default_model = env::var("OPENAI_API_MODEL").unwrap_or("gpt-3.5-turbo".to_string());
Handler {
oai: Some(bot::oai::OAI {
@@ -61,7 +67,8 @@ async fn main() {
}
}
Err(err) => {
log::warn!("Could not load OpenAI token: {}", err);
log::trace!("No OPENAI_API_KEY found: {err}");
log::warn!("OpenAI functionality disabled");
Handler { oai: None }
}
};
@@ -70,8 +77,9 @@ async fn main() {
let mut client = Client::builder(token, intents)
.event_handler(handler)
.framework(StandardFramework::new().configure(|c| c.owners(owners)))
// .framework(StandardFramework::new().configure(|c| c.owners(owners)))
.register_songbird_with(Arc::clone(&songbird))
.type_map_insert::<HttpKey>(HttpClient::new())
.await
.expect("Error creating client");
@@ -81,11 +89,4 @@ async fn main() {
if let Err(why) = client.start_autosharded().await {
log::error!("Client error: {why:?}");
}
}
pub struct AppState {
pub http: Arc<Http>,
pub cache: Arc<Cache>,
pub songbird: Arc<Songbird>,
}