Re-implementing the API
This commit is contained in:
@@ -2,7 +2,7 @@ use std::sync::Arc;
|
||||
|
||||
use serenity::all::{CommandInteraction, CommandOptionType, CreateCommand, CreateCommandOption};
|
||||
use serenity::model::prelude::GuildId;
|
||||
use serenity::{prelude::*, async_trait, futures};
|
||||
use serenity::{prelude::*, async_trait};
|
||||
use songbird::input::{Input, YoutubeDl};
|
||||
use songbird::tracks::TrackHandle;
|
||||
use songbird::{Event, EventHandler, Songbird, TrackEvent};
|
||||
@@ -25,7 +25,7 @@ pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
||||
"{} attempted to play a track without a track option",
|
||||
command.user.id.get()
|
||||
);
|
||||
create_message_response(&ctx, &command, format!("Track option is missing"), false).await;
|
||||
create_message_response(&ctx, &command, "Track option is missing".to_string(), false).await;
|
||||
return;
|
||||
}
|
||||
};
|
||||
@@ -53,7 +53,9 @@ pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
||||
// Join the user's voice channel
|
||||
match join_voice_channel(&ctx.cache, &manager, guild_id, &command.user).await {
|
||||
Ok(channel_id) => {
|
||||
log::debug!("<{guild_id}> Play command executed on channel {channel_id} with track: {track_url:?}");
|
||||
log::debug!(
|
||||
"<{guild_id}> Play command executed on channel {channel_id} with track: {track_url:?}"
|
||||
);
|
||||
// Handle the track url
|
||||
match enqueue_track(ctx, manager, guild_id.to_owned(), track_url).await {
|
||||
Ok(items) => {
|
||||
|
||||
@@ -124,7 +124,7 @@ pub async fn generate_response(ctx: &Context, msg: &Message, oai: &OAI) {
|
||||
Err(err) => {
|
||||
log::error!(
|
||||
"<{guild_id}> <{channel_id}> <{author_id}> Could not get response from OpenAI: {}",
|
||||
err.message
|
||||
err.details
|
||||
);
|
||||
"There was an error processing your message. Please try again later.".to_string()
|
||||
}
|
||||
@@ -196,7 +196,7 @@ async fn generate_thread_name(oai: &OAI, s: &str, max_chars: usize) -> String {
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
log::error!("Could not get response from OpenAI: {}", err.message);
|
||||
log::error!("Could not get response from OpenAI: {}", err.details);
|
||||
}
|
||||
};
|
||||
return response;
|
||||
|
||||
@@ -3,6 +3,14 @@ use crate::bot::chat::create_message_response;
|
||||
|
||||
pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
||||
log::debug!("Ping command executed");
|
||||
|
||||
if let Some(guild_id) = command.guild_id {
|
||||
if let Some(guild) = guild_id.to_guild_cached(&ctx.cache) {
|
||||
let owner_id = guild.owner_id;
|
||||
if command.user.id == owner_id {}
|
||||
}
|
||||
}
|
||||
|
||||
create_message_response(&ctx, &command, "pong".to_string(), true).await;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,13 +9,13 @@ use crate::data::guilds::GuildCache;
|
||||
use super::{commands};
|
||||
use super::chat::{create_message_response, create_modal_response};
|
||||
|
||||
pub struct Handler {
|
||||
pub struct BotHandler {
|
||||
// Open AI Config
|
||||
pub oai: Option<OAI>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl EventHandler for Handler {
|
||||
impl EventHandler for BotHandler {
|
||||
async fn message(&self, ctx: Context, msg: Message) {
|
||||
// Ignore bot messages
|
||||
if msg.author.bot {
|
||||
@@ -47,7 +47,8 @@ impl EventHandler for Handler {
|
||||
if let None = GuildCache::get_by_id(guild_id).await.unwrap() {
|
||||
let guild_cache = GuildCache {
|
||||
id: guild_id,
|
||||
bot_id: 1,
|
||||
name: guild.id.name(&ctx.cache),
|
||||
owner_id: None,
|
||||
volume: 100,
|
||||
};
|
||||
guild_cache.insert().await.unwrap();
|
||||
|
||||
@@ -129,7 +129,7 @@ impl OAI {
|
||||
ResponseEvent::ResponseError(error) => {
|
||||
return Err(SirenError {
|
||||
status: 500,
|
||||
message: format!("Error: {}", error.message.unwrap()),
|
||||
details: format!("Error: {}", error.message.unwrap()),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -137,7 +137,7 @@ impl OAI {
|
||||
Err(err) => {
|
||||
return Err(SirenError {
|
||||
status: 500,
|
||||
message: format!("Error: {}", err),
|
||||
details: format!("Error: {}", err),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user