Fixed play command
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
use log::{warn, info, error};
|
||||
use serenity::all::Interaction;
|
||||
use serenity::async_trait;
|
||||
use serenity::model::application::interaction::Interaction;
|
||||
use serenity::model::gateway::Ready;
|
||||
use serenity::model::channel::Message;
|
||||
use serenity::prelude::*;
|
||||
|
||||
use super::guilds::GuildCache;
|
||||
use super::{commands, oai};
|
||||
use super::commands::audio::create_response;
|
||||
|
||||
@@ -28,7 +29,7 @@ impl EventHandler for Handler {
|
||||
Ok(t) => {
|
||||
match t
|
||||
.iter()
|
||||
.find(|t| t.user_id.unwrap().0 == ctx.cache.current_user_id().0)
|
||||
.find(|t| t.user_id == ctx.cache.current_user().id)
|
||||
{
|
||||
Some(_) => true,
|
||||
None => false,
|
||||
@@ -48,8 +49,10 @@ impl EventHandler for Handler {
|
||||
}
|
||||
|
||||
async fn interaction_create(&self, ctx: Context, interaction: Interaction) {
|
||||
if let Interaction::ApplicationCommand(command) = interaction {
|
||||
if let Interaction::Command(command) = interaction {
|
||||
log::trace!("Received command interaction: {command:#?}");
|
||||
match command.data.name.as_str() {
|
||||
// Match commands without returns
|
||||
"roll" => commands::roll::run(&ctx, &command).await,
|
||||
"play" => commands::audio::play::run(&ctx, &command).await,
|
||||
"stop" => commands::audio::stop::run(&ctx, &command).await,
|
||||
@@ -59,6 +62,7 @@ impl EventHandler for Handler {
|
||||
"volume" => commands::audio::volume::run(&ctx, &command).await,
|
||||
_ => {
|
||||
let content: String = match command.data.name.as_str() {
|
||||
// Match commands with string returns
|
||||
"ping" => commands::ping::run(&command.data.options),
|
||||
_ => "Unknown command".to_string(),
|
||||
};
|
||||
@@ -76,57 +80,34 @@ impl EventHandler for Handler {
|
||||
warn!("No ready guilds found");
|
||||
}
|
||||
for guild in ready.guilds {
|
||||
// Check if guild exists in database
|
||||
let guild_id = guild.id.get() as i64;
|
||||
if let Err(why) = GuildCache::get(guild_id) {
|
||||
let guild_cache = GuildCache {
|
||||
id: guild_id,
|
||||
bot_id: 1,
|
||||
volume: 100
|
||||
};
|
||||
guild_cache.insert();
|
||||
}
|
||||
let commands = guild
|
||||
.id
|
||||
.set_application_commands(&ctx.http, |commands| {
|
||||
commands
|
||||
.create_application_command(
|
||||
|command: &mut serenity::builder::CreateApplicationCommand| {
|
||||
commands::ping::register(command)
|
||||
},
|
||||
)
|
||||
.create_application_command(
|
||||
|command: &mut serenity::builder::CreateApplicationCommand| {
|
||||
commands::roll::register(command)
|
||||
},
|
||||
)
|
||||
.create_application_command(
|
||||
|command: &mut serenity::builder::CreateApplicationCommand| {
|
||||
commands::audio::play::register(command)
|
||||
},
|
||||
)
|
||||
.create_application_command(
|
||||
|command: &mut serenity::builder::CreateApplicationCommand| {
|
||||
commands::audio::stop::register(command)
|
||||
},
|
||||
)
|
||||
.create_application_command(
|
||||
|command: &mut serenity::builder::CreateApplicationCommand| {
|
||||
commands::audio::pause::register(command)
|
||||
},
|
||||
)
|
||||
.create_application_command(
|
||||
|command: &mut serenity::builder::CreateApplicationCommand| {
|
||||
commands::audio::resume::register(command)
|
||||
},
|
||||
)
|
||||
.create_application_command(
|
||||
|command: &mut serenity::builder::CreateApplicationCommand| {
|
||||
commands::audio::skip::register(command)
|
||||
},
|
||||
)
|
||||
.create_application_command(
|
||||
|command: &mut serenity::builder::CreateApplicationCommand| {
|
||||
commands::audio::volume::register(command)
|
||||
},
|
||||
)
|
||||
})
|
||||
.set_commands(&ctx.http, vec![
|
||||
commands::ping::register(),
|
||||
commands::roll::register(),
|
||||
commands::audio::play::register(),
|
||||
commands::audio::stop::register(),
|
||||
commands::audio::pause::register(),
|
||||
commands::audio::resume::register(),
|
||||
commands::audio::skip::register(),
|
||||
commands::audio::volume::register(),
|
||||
])
|
||||
.await;
|
||||
match commands {
|
||||
Ok(c) => info!("Registered {} commands for guild {}", c.len(), guild.id.0),
|
||||
Ok(c) => info!("Registered {} commands for guild {}", c.len(), guild.id.get()),
|
||||
Err(why) => error!(
|
||||
"Could not register commands for guild {}: {:?}",
|
||||
guild.id.0, why
|
||||
guild.id.get(), why
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user