mirror of
https://github.com/mii443/ncb-tts-r2.git
synced 2025-12-03 03:08:20 +00:00
add skip command
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
pub mod config;
|
||||
pub mod setup;
|
||||
pub mod skip;
|
||||
pub mod stop;
|
||||
|
||||
90
src/commands/skip.rs
Normal file
90
src/commands/skip.rs
Normal file
@@ -0,0 +1,90 @@
|
||||
use serenity::{
|
||||
model::prelude::{
|
||||
interaction::{application_command::ApplicationCommandInteraction, MessageFlags},
|
||||
UserId,
|
||||
},
|
||||
prelude::Context,
|
||||
};
|
||||
|
||||
use crate::data::TTSData;
|
||||
|
||||
pub async fn skip_command(
|
||||
ctx: &Context,
|
||||
command: &ApplicationCommandInteraction,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
if let None = command.guild_id {
|
||||
command
|
||||
.create_interaction_response(&ctx.http, |f| {
|
||||
f.interaction_response_data(|d| {
|
||||
d.content("このコマンドはサーバーでのみ使用可能です.")
|
||||
.flags(MessageFlags::EPHEMERAL)
|
||||
})
|
||||
})
|
||||
.await?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let guild = command.guild_id.unwrap().to_guild_cached(&ctx.cache);
|
||||
if let None = guild {
|
||||
command
|
||||
.create_interaction_response(&ctx.http, |f| {
|
||||
f.interaction_response_data(|d| {
|
||||
d.content("ギルドキャッシュを取得できませんでした.")
|
||||
.flags(MessageFlags::EPHEMERAL)
|
||||
})
|
||||
})
|
||||
.await?;
|
||||
return Ok(());
|
||||
}
|
||||
let guild = guild.unwrap();
|
||||
|
||||
let channel_id = guild
|
||||
.voice_states
|
||||
.get(&UserId(command.user.id.0))
|
||||
.and_then(|state| state.channel_id);
|
||||
|
||||
if let None = channel_id {
|
||||
command
|
||||
.create_interaction_response(&ctx.http, |f| {
|
||||
f.interaction_response_data(|d| {
|
||||
d.content("ボイスチャンネルに参加してから実行してください.")
|
||||
.flags(MessageFlags::EPHEMERAL)
|
||||
})
|
||||
})
|
||||
.await?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let storage_lock = {
|
||||
let data_read = ctx.data.read().await;
|
||||
data_read
|
||||
.get::<TTSData>()
|
||||
.expect("Cannot get TTSStorage")
|
||||
.clone()
|
||||
};
|
||||
|
||||
{
|
||||
let mut storage = storage_lock.write().await;
|
||||
if !storage.contains_key(&guild.id) {
|
||||
command
|
||||
.create_interaction_response(&ctx.http, |f| {
|
||||
f.interaction_response_data(|d| {
|
||||
d.content("読み上げしていません")
|
||||
.flags(MessageFlags::EPHEMERAL)
|
||||
})
|
||||
})
|
||||
.await?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
storage.get_mut(&guild.id).unwrap().skip(&ctx).await;
|
||||
}
|
||||
|
||||
command
|
||||
.create_interaction_response(&ctx.http, |f| {
|
||||
f.interaction_response_data(|d| d.content("スキップしました"))
|
||||
})
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
use crate::{
|
||||
commands::{config::config_command, setup::setup_command, stop::stop_command},
|
||||
commands::{
|
||||
config::config_command, setup::setup_command, skip::skip_command, stop::stop_command,
|
||||
},
|
||||
data::DatabaseClientData,
|
||||
database::dictionary::Rule,
|
||||
events,
|
||||
@@ -12,7 +14,7 @@ use serenity::{
|
||||
channel::Message,
|
||||
gateway::Ready,
|
||||
prelude::{
|
||||
component::{ActionRowComponent, ButtonStyle, InputText, InputTextStyle},
|
||||
component::{ActionRowComponent, ButtonStyle, InputTextStyle},
|
||||
interaction::{Interaction, InteractionResponseType, MessageFlags},
|
||||
},
|
||||
voice::VoiceState,
|
||||
@@ -38,6 +40,7 @@ impl EventHandler for Handler {
|
||||
"setup" => setup_command(&ctx, &command).await.unwrap(),
|
||||
"stop" => stop_command(&ctx, &command).await.unwrap(),
|
||||
"config" => config_command(&ctx, &command).await.unwrap(),
|
||||
"skip" => skip_command(&ctx, &command).await.unwrap(),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,9 @@ pub async fn ready(ctx: Context, ready: Ready) {
|
||||
})
|
||||
})
|
||||
.create_application_command(|command| command.name("config").description("Config"))
|
||||
.create_application_command(|command| {
|
||||
command.name("skip").description("skip tts message")
|
||||
})
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
@@ -38,4 +38,12 @@ impl TTSInstance {
|
||||
call.enqueue_source(input);
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn skip(&mut self, ctx: &Context) {
|
||||
let manager = songbird::get(&ctx).await.unwrap();
|
||||
let call = manager.get(self.guild).unwrap();
|
||||
let call = call.lock().await;
|
||||
let queue = call.queue();
|
||||
let _ = queue.skip();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user