mirror of
https://github.com/mii443/ncb-tts-r2.git
synced 2025-08-22 16:15:29 +00:00
Add autostart feature
This commit is contained in:
@ -293,6 +293,45 @@ impl EventHandler for Handler {
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
"SET_AUTOSTART_CHANNEL" => {
|
||||
let autostart_channel_id = if message_component.data.values.len() == 0 {
|
||||
None
|
||||
} else {
|
||||
let ch = message_component.data.values[0]
|
||||
.strip_prefix("SET_AUTOSTART_CHANNEL_")
|
||||
.unwrap();
|
||||
Some(u64::from_str_radix(ch, 10).unwrap())
|
||||
};
|
||||
{
|
||||
let data_read = ctx.data.read().await;
|
||||
let database = data_read
|
||||
.get::<DatabaseClientData>()
|
||||
.expect("Cannot get DatabaseClientData")
|
||||
.clone();
|
||||
let mut database = database.lock().await;
|
||||
let mut config = database
|
||||
.get_server_config_or_default(message_component.guild_id.unwrap().0)
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
config.autostart_channel_id = autostart_channel_id;
|
||||
database
|
||||
.set_server_config(message_component.guild_id.unwrap().0, config)
|
||||
.await
|
||||
.unwrap();
|
||||
};
|
||||
|
||||
message_component
|
||||
.create_interaction_response(&ctx.http, |c| {
|
||||
c.kind(InteractionResponseType::UpdateMessage)
|
||||
.interaction_response_data(|d| {
|
||||
d.content("自動参加チャンネルを設定しました。")
|
||||
.components(|f| f)
|
||||
})
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
"TTS_CONFIG_SERVER_SET_AUTOSTART_CHANNEL" => {
|
||||
let config = {
|
||||
let data_read = ctx.data.read().await;
|
||||
@ -308,6 +347,8 @@ impl EventHandler for Handler {
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
let autostart_channel_id = config.autostart_channel_id.unwrap_or(0);
|
||||
|
||||
let channels = message_component
|
||||
.guild_id
|
||||
.unwrap()
|
||||
@ -327,7 +368,7 @@ impl EventHandler for Handler {
|
||||
m.min_values(0)
|
||||
.max_values(1)
|
||||
.disabled(false)
|
||||
.custom_id("AUTOSTART_CHANNEL")
|
||||
.custom_id("SET_AUTOSTART_CHANNEL")
|
||||
.options(|o| {
|
||||
// Create channel list
|
||||
for (id, channel) in channels {
|
||||
@ -344,6 +385,7 @@ impl EventHandler for Handler {
|
||||
)),
|
||||
)
|
||||
.value(format!("SET_AUTOSTART_CHANNEL_{}", id.0))
|
||||
.default_selection(channel.id.0 == autostart_channel_id)
|
||||
});
|
||||
}
|
||||
o
|
||||
|
@ -1,10 +1,10 @@
|
||||
use crate::{
|
||||
data::TTSData,
|
||||
data::{DatabaseClientData, TTSData},
|
||||
implement::{
|
||||
member_name::ReadName,
|
||||
voice_move_state::{VoiceMoveState, VoiceMoveStateTrait},
|
||||
},
|
||||
tts::message::AnnounceMessage,
|
||||
tts::{instance::TTSInstance, message::AnnounceMessage},
|
||||
};
|
||||
use serenity::{model::voice::VoiceState, prelude::Context};
|
||||
|
||||
@ -31,9 +31,46 @@ pub async fn voice_state_update(ctx: Context, old: Option<VoiceState>, new: Voic
|
||||
.clone()
|
||||
};
|
||||
|
||||
let config = {
|
||||
let data_read = ctx.data.read().await;
|
||||
let database = data_read
|
||||
.get::<DatabaseClientData>()
|
||||
.expect("Cannot get DatabaseClientData")
|
||||
.clone();
|
||||
let mut database = database.lock().await;
|
||||
database
|
||||
.get_server_config_or_default(guild_id.0)
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
{
|
||||
let mut storage = storage_lock.write().await;
|
||||
if !storage.contains_key(&guild_id) {
|
||||
if let Some(new_channel) = new.channel_id {
|
||||
if config.autostart_channel_id.unwrap_or(0) == new_channel.0 {
|
||||
let manager = songbird::get(&ctx)
|
||||
.await
|
||||
.expect("Cannot get songbird client.")
|
||||
.clone();
|
||||
storage.insert(
|
||||
guild_id,
|
||||
TTSInstance {
|
||||
before_message: None,
|
||||
guild: guild_id,
|
||||
text_channel: new_channel,
|
||||
voice_channel: new_channel,
|
||||
},
|
||||
);
|
||||
|
||||
let _handler = manager.join(guild_id.0, new_channel.0).await;
|
||||
new_channel.send_message(&ctx.http, |f| f.embed(|e| e.title("読み上げ (Serenity)")
|
||||
.field("クレジット", "```\n四国めたん ずんだもん\n春日部つむぎ 雨晴はう\n波音リツ 玄野武宏\n白上虎太郎 青山龍星\n冥鳴ひまり 九州そら\nモチノ・キョウコ\nナースロボ_タイプT```", false)
|
||||
.field("設定コマンド", "`/config`", false)
|
||||
.field("フィードバック", "https://feedback.mii.codes/", false))).await.unwrap();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user