-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
107 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod config; | ||
pub mod setup; | ||
pub mod skip; | ||
pub mod stop; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters