mirror of
https://github.com/mii443/ncb-tts-r2.git
synced 2025-08-22 16:15:29 +00:00
TTS Channel mode feature
This commit is contained in:
@ -70,7 +70,7 @@ pub async fn setup_command(
|
||||
.clone()
|
||||
};
|
||||
|
||||
let thread_id = {
|
||||
let text_channel_id = {
|
||||
let mut storage = storage_lock.write().await;
|
||||
if storage.contains_key(&guild.id) {
|
||||
command
|
||||
@ -84,40 +84,59 @@ pub async fn setup_command(
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let text_channel_id = {
|
||||
if let Some(mode) = command.data.options.get(0) {
|
||||
let mode = mode.clone();
|
||||
let value = mode.value.unwrap();
|
||||
let value = value.as_str().unwrap();
|
||||
match value {
|
||||
"TEXT_CHANNEL" => command.channel_id,
|
||||
"NEW_THREAD" => {
|
||||
let message = command
|
||||
.channel_id
|
||||
.send_message(&ctx.http, |f| f.content("TTS thread"))
|
||||
.await
|
||||
.unwrap();
|
||||
let thread_id = command
|
||||
command
|
||||
.channel_id
|
||||
.create_public_thread(&ctx.http, message, |f| {
|
||||
f.name("TTS").auto_archive_duration(60)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
.unwrap()
|
||||
.id
|
||||
}
|
||||
"VOICE_CHANNEL" => channel_id,
|
||||
_ => channel_id,
|
||||
}
|
||||
} else {
|
||||
channel_id
|
||||
}
|
||||
};
|
||||
|
||||
storage.insert(
|
||||
guild.id,
|
||||
TTSInstance {
|
||||
before_message: None,
|
||||
guild: guild.id,
|
||||
text_channel: thread_id.id,
|
||||
text_channel: text_channel_id,
|
||||
voice_channel: channel_id,
|
||||
},
|
||||
);
|
||||
|
||||
thread_id
|
||||
text_channel_id
|
||||
};
|
||||
|
||||
let _handler = manager.join(guild.id.0, channel_id.0).await;
|
||||
command
|
||||
.create_interaction_response(&ctx.http, |f| {
|
||||
f.interaction_response_data(|d| d.content("."))
|
||||
f.interaction_response_data(|d| {
|
||||
d.content(format!("TTS Channel: <#{}>", text_channel_id))
|
||||
})
|
||||
})
|
||||
.await?;
|
||||
|
||||
thread_id.send_message(&ctx.http, |f| f.embed(|e| e.title("読み上げ (Serenity)")
|
||||
text_channel_id.send_message(&ctx.http, |f| f.embed(|e| e.title("読み上げ (Serenity)")
|
||||
.field("クレジット", "```\n四国めたん ずんだもん\n春日部つむぎ 雨晴はう\n波音リツ 玄野武宏\n白上虎太郎 青山龍星\n冥鳴ひまり 九州そら\nモチノ・キョウコ```", false)
|
||||
.field("設定コマンド", "`/config`", false)
|
||||
)).await?;
|
||||
|
@ -68,7 +68,7 @@ pub async fn stop_command(
|
||||
.clone()
|
||||
};
|
||||
|
||||
let thread_id = {
|
||||
let text_channel_id = {
|
||||
let mut storage = storage_lock.write().await;
|
||||
if !storage.contains_key(&guild.id) {
|
||||
command
|
||||
@ -82,11 +82,11 @@ pub async fn stop_command(
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let thread_id = storage.get(&guild.id).unwrap().text_channel;
|
||||
let text_channel_id = storage.get(&guild.id).unwrap().text_channel;
|
||||
|
||||
storage.remove(&guild.id);
|
||||
|
||||
thread_id
|
||||
text_channel_id
|
||||
};
|
||||
|
||||
let _handler = manager.remove(guild.id.0).await;
|
||||
@ -97,10 +97,9 @@ pub async fn stop_command(
|
||||
})
|
||||
.await?;
|
||||
|
||||
thread_id
|
||||
let _ = text_channel_id
|
||||
.edit_thread(&ctx.http, |f| f.archived(true))
|
||||
.await
|
||||
.unwrap();
|
||||
.await;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
use serenity::{
|
||||
model::prelude::{command::Command, Ready},
|
||||
model::prelude::{command::Command, CommandId, Ready},
|
||||
prelude::Context,
|
||||
};
|
||||
|
||||
@ -9,7 +9,19 @@ pub async fn ready(ctx: Context, ready: Ready) {
|
||||
let _ = Command::set_global_application_commands(&ctx.http, |commands| {
|
||||
commands
|
||||
.create_application_command(|command| command.name("stop").description("Stop tts"))
|
||||
.create_application_command(|command| command.name("setup").description("Setup tts"))
|
||||
.create_application_command(|command| {
|
||||
command
|
||||
.name("setup")
|
||||
.description("Setup tts")
|
||||
.create_option(|o| {
|
||||
o.name("Channel Mode")
|
||||
.description("TTS channel")
|
||||
.add_string_choice("Text Channel", "TEXT_CHANNEL")
|
||||
.add_string_choice("New Thread", "NEW_THREAD")
|
||||
.add_string_choice("Voice Channel", "VOICE_CHANNEL")
|
||||
.required(false)
|
||||
})
|
||||
})
|
||||
.create_application_command(|command| command.name("config").description("Config"))
|
||||
})
|
||||
.await;
|
||||
|
@ -66,13 +66,12 @@ pub async fn voice_state_update(ctx: Context, old: Option<VoiceState>, new: Voic
|
||||
}
|
||||
|
||||
if del_flag {
|
||||
storage
|
||||
let _ = storage
|
||||
.get(&guild_id)
|
||||
.unwrap()
|
||||
.text_channel
|
||||
.edit_thread(&ctx.http, |f| f.archived(true))
|
||||
.await
|
||||
.unwrap();
|
||||
.await;
|
||||
storage.remove(&guild_id);
|
||||
|
||||
let manager = songbird::get(&ctx)
|
||||
|
Reference in New Issue
Block a user