mirror of
https://github.com/mii443/ncb-tts-r2.git
synced 2025-08-22 16:15:29 +00:00
WIP: ローカルの変更を保存
This commit is contained in:
@ -98,8 +98,6 @@ impl Database {
|
|||||||
let config = ServerConfig {
|
let config = ServerConfig {
|
||||||
dictionary: Dictionary::new(),
|
dictionary: Dictionary::new(),
|
||||||
autostart_channel_id: None,
|
autostart_channel_id: None,
|
||||||
voice_state_announce: Some(true),
|
|
||||||
read_username: Some(true),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
self.set_server_config(server_id, config).await
|
self.set_server_config(server_id, config).await
|
||||||
|
@ -10,6 +10,4 @@ pub struct DictionaryOnlyServerConfig {
|
|||||||
pub struct ServerConfig {
|
pub struct ServerConfig {
|
||||||
pub dictionary: Dictionary,
|
pub dictionary: Dictionary,
|
||||||
pub autostart_channel_id: Option<u64>,
|
pub autostart_channel_id: Option<u64>,
|
||||||
pub voice_state_announce: Option<bool>,
|
|
||||||
pub read_username: Option<bool>,
|
|
||||||
}
|
}
|
||||||
|
@ -122,93 +122,6 @@ impl EventHandler for Handler {
|
|||||||
}
|
}
|
||||||
if let Some(message_component) = interaction.message_component() {
|
if let Some(message_component) = interaction.message_component() {
|
||||||
match &*message_component.data.custom_id {
|
match &*message_component.data.custom_id {
|
||||||
"TTS_CONFIG_SERVER_SET_VOICE_STATE_ANNOUNCE" => {
|
|
||||||
let data_read = ctx.data.read().await;
|
|
||||||
let mut config = {
|
|
||||||
let database = data_read
|
|
||||||
.get::<DatabaseClientData>()
|
|
||||||
.expect("Cannot get DatabaseClientData")
|
|
||||||
.clone();
|
|
||||||
|
|
||||||
database
|
|
||||||
.get_server_config_or_default(message_component.guild_id.unwrap().get())
|
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
.unwrap()
|
|
||||||
};
|
|
||||||
|
|
||||||
config.voice_state_announce =
|
|
||||||
Some(!config.voice_state_announce.unwrap_or(true));
|
|
||||||
let state = config.voice_state_announce.unwrap_or(true);
|
|
||||||
|
|
||||||
{
|
|
||||||
let database = data_read
|
|
||||||
.get::<DatabaseClientData>()
|
|
||||||
.expect("Cannot get DatabaseClientData")
|
|
||||||
.clone();
|
|
||||||
|
|
||||||
database
|
|
||||||
.set_server_config(message_component.guild_id.unwrap().get(), config)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
message_component
|
|
||||||
.create_response(
|
|
||||||
&ctx.http,
|
|
||||||
CreateInteractionResponse::UpdateMessage(
|
|
||||||
CreateInteractionResponseMessage::new().content(format!(
|
|
||||||
"入退出アナウンス通知を{}へ切り替えました。",
|
|
||||||
if state { "`有効`" } else { "`無効`" }
|
|
||||||
)),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
"TTS_CONFIG_SERVER_SET_READ_USERNAME" => {
|
|
||||||
let data_read = ctx.data.read().await;
|
|
||||||
let mut config = {
|
|
||||||
let database = data_read
|
|
||||||
.get::<DatabaseClientData>()
|
|
||||||
.expect("Cannot get DatabaseClientData")
|
|
||||||
.clone();
|
|
||||||
|
|
||||||
database
|
|
||||||
.get_server_config_or_default(message_component.guild_id.unwrap().get())
|
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
.unwrap()
|
|
||||||
};
|
|
||||||
|
|
||||||
config.read_username = Some(!config.read_username.unwrap_or(true));
|
|
||||||
let state = config.read_username.unwrap_or(true);
|
|
||||||
|
|
||||||
{
|
|
||||||
let database = data_read
|
|
||||||
.get::<DatabaseClientData>()
|
|
||||||
.expect("Cannot get DatabaseClientData")
|
|
||||||
.clone();
|
|
||||||
|
|
||||||
database
|
|
||||||
.set_server_config(message_component.guild_id.unwrap().get(), config)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
message_component
|
|
||||||
.create_response(
|
|
||||||
&ctx.http,
|
|
||||||
CreateInteractionResponse::UpdateMessage(
|
|
||||||
CreateInteractionResponseMessage::new().content(format!(
|
|
||||||
"ユーザー名読み上げを{}へ切り替えました。",
|
|
||||||
if state { "`有効`" } else { "`無効`" }
|
|
||||||
)),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
"TTS_CONFIG_SERVER_REMOVE_DICTIONARY_MENU" => {
|
"TTS_CONFIG_SERVER_REMOVE_DICTIONARY_MENU" => {
|
||||||
let i = usize::from_str_radix(
|
let i = usize::from_str_radix(
|
||||||
&match message_component.data.kind {
|
&match message_component.data.kind {
|
||||||
@ -486,51 +399,14 @@ impl EventHandler for Handler {
|
|||||||
CreateInteractionResponse::UpdateMessage(
|
CreateInteractionResponse::UpdateMessage(
|
||||||
CreateInteractionResponseMessage::new()
|
CreateInteractionResponseMessage::new()
|
||||||
.content("自動参加チャンネル設定")
|
.content("自動参加チャンネル設定")
|
||||||
.components(vec![
|
.components(vec![CreateActionRow::SelectMenu(
|
||||||
CreateActionRow::SelectMenu(
|
CreateSelectMenu::new(
|
||||||
CreateSelectMenu::new(
|
"SET_AUTOSTART_CHANNEL",
|
||||||
"SET_AUTOSTART_CHANNEL",
|
CreateSelectMenuKind::String { options },
|
||||||
CreateSelectMenuKind::String { options },
|
|
||||||
)
|
|
||||||
.min_values(0)
|
|
||||||
.max_values(1),
|
|
||||||
),
|
|
||||||
CreateActionRow::Buttons(vec![CreateButton::new(
|
|
||||||
"TTS_CONFIG_SERVER_BACK",
|
|
||||||
)
|
)
|
||||||
.label("← サーバー設定に戻る")
|
.min_values(0)
|
||||||
.style(ButtonStyle::Secondary)]),
|
.max_values(1),
|
||||||
]),
|
)]),
|
||||||
),
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
"TTS_CONFIG_SERVER_BACK" => {
|
|
||||||
message_component
|
|
||||||
.create_response(
|
|
||||||
&ctx.http,
|
|
||||||
CreateInteractionResponse::UpdateMessage(
|
|
||||||
CreateInteractionResponseMessage::new()
|
|
||||||
.content("サーバー設定")
|
|
||||||
.components(vec![CreateActionRow::Buttons(vec![
|
|
||||||
CreateButton::new("TTS_CONFIG_SERVER_DICTIONARY")
|
|
||||||
.label("辞書管理")
|
|
||||||
.style(ButtonStyle::Primary),
|
|
||||||
CreateButton::new(
|
|
||||||
"TTS_CONFIG_SERVER_SET_AUTOSTART_CHANNEL",
|
|
||||||
)
|
|
||||||
.label("自動参加チャンネル")
|
|
||||||
.style(ButtonStyle::Primary),
|
|
||||||
CreateButton::new(
|
|
||||||
"TTS_CONFIG_SERVER_SET_VOICE_STATE_ANNOUNCE",
|
|
||||||
)
|
|
||||||
.label("入退出アナウンス通知切り替え")
|
|
||||||
.style(ButtonStyle::Primary),
|
|
||||||
CreateButton::new("TTS_CONFIG_SERVER_SET_READ_USERNAME")
|
|
||||||
.label("ユーザー名読み上げ切り替え")
|
|
||||||
.style(ButtonStyle::Primary),
|
|
||||||
])]),
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
@ -544,64 +420,32 @@ impl EventHandler for Handler {
|
|||||||
CreateInteractionResponseMessage::new()
|
CreateInteractionResponseMessage::new()
|
||||||
.content("サーバー設定")
|
.content("サーバー設定")
|
||||||
.components(vec![CreateActionRow::Buttons(vec![
|
.components(vec![CreateActionRow::Buttons(vec![
|
||||||
CreateButton::new("TTS_CONFIG_SERVER_DICTIONARY")
|
CreateButton::new(
|
||||||
.label("辞書管理")
|
"TTS_CONFIG_SERVER_ADD_DICTIONARY_BUTTON",
|
||||||
.style(ButtonStyle::Primary),
|
)
|
||||||
|
.label("辞書を追加")
|
||||||
|
.style(ButtonStyle::Primary),
|
||||||
|
CreateButton::new(
|
||||||
|
"TTS_CONFIG_SERVER_REMOVE_DICTIONARY_BUTTON",
|
||||||
|
)
|
||||||
|
.label("辞書を削除")
|
||||||
|
.style(ButtonStyle::Danger),
|
||||||
|
CreateButton::new(
|
||||||
|
"TTS_CONFIG_SERVER_SHOW_DICTIONARY_BUTTON",
|
||||||
|
)
|
||||||
|
.label("辞書一覧")
|
||||||
|
.style(ButtonStyle::Primary),
|
||||||
CreateButton::new(
|
CreateButton::new(
|
||||||
"TTS_CONFIG_SERVER_SET_AUTOSTART_CHANNEL",
|
"TTS_CONFIG_SERVER_SET_AUTOSTART_CHANNEL",
|
||||||
)
|
)
|
||||||
.label("自動参加チャンネル")
|
.label("自動参加チャンネル")
|
||||||
.style(ButtonStyle::Primary),
|
.style(ButtonStyle::Primary),
|
||||||
CreateButton::new(
|
|
||||||
"TTS_CONFIG_SERVER_SET_VOICE_STATE_ANNOUNCE",
|
|
||||||
)
|
|
||||||
.label("入退出アナウンス通知切り替え")
|
|
||||||
.style(ButtonStyle::Primary),
|
|
||||||
CreateButton::new("TTS_CONFIG_SERVER_SET_READ_USERNAME")
|
|
||||||
.label("ユーザー名読み上げ切り替え")
|
|
||||||
.style(ButtonStyle::Primary),
|
|
||||||
])]),
|
])]),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
"TTS_CONFIG_SERVER_DICTIONARY" => {
|
|
||||||
message_component
|
|
||||||
.create_response(
|
|
||||||
&ctx.http,
|
|
||||||
CreateInteractionResponse::UpdateMessage(
|
|
||||||
CreateInteractionResponseMessage::new()
|
|
||||||
.content("辞書管理")
|
|
||||||
.components(vec![
|
|
||||||
CreateActionRow::Buttons(vec![
|
|
||||||
CreateButton::new(
|
|
||||||
"TTS_CONFIG_SERVER_ADD_DICTIONARY_BUTTON",
|
|
||||||
)
|
|
||||||
.label("辞書を追加")
|
|
||||||
.style(ButtonStyle::Primary),
|
|
||||||
CreateButton::new(
|
|
||||||
"TTS_CONFIG_SERVER_REMOVE_DICTIONARY_BUTTON",
|
|
||||||
)
|
|
||||||
.label("辞書を削除")
|
|
||||||
.style(ButtonStyle::Danger),
|
|
||||||
CreateButton::new(
|
|
||||||
"TTS_CONFIG_SERVER_SHOW_DICTIONARY_BUTTON",
|
|
||||||
)
|
|
||||||
.label("辞書一覧")
|
|
||||||
.style(ButtonStyle::Primary),
|
|
||||||
]),
|
|
||||||
CreateActionRow::Buttons(vec![CreateButton::new(
|
|
||||||
"TTS_CONFIG_SERVER_BACK",
|
|
||||||
)
|
|
||||||
.label("← サーバー設定に戻る")
|
|
||||||
.style(ButtonStyle::Secondary)]),
|
|
||||||
]),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
match message_component.data.kind {
|
match message_component.data.kind {
|
||||||
|
@ -48,10 +48,6 @@ pub async fn voice_state_update(ctx: Context, old: Option<VoiceState>, new: Voic
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
if !config.voice_state_announce.unwrap_or(true) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut storage = storage_lock.write().await;
|
let mut storage = storage_lock.write().await;
|
||||||
if !storage.contains_key(&guild_id) {
|
if !storage.contains_key(&guild_id) {
|
||||||
|
@ -57,11 +57,7 @@ impl TTSMessage for Message {
|
|||||||
} else {
|
} else {
|
||||||
self.author.read_name()
|
self.author.read_name()
|
||||||
};
|
};
|
||||||
if config.read_username.unwrap_or(true) {
|
format!("{}さんの発言<break time=\"200ms\"/>{}", name, text)
|
||||||
format!("{}さんの発言<break time=\"200ms\"/>{}", name, text)
|
|
||||||
} else {
|
|
||||||
format!("{}", text)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let member = self.member.clone();
|
let member = self.member.clone();
|
||||||
@ -75,12 +71,7 @@ impl TTSMessage for Message {
|
|||||||
} else {
|
} else {
|
||||||
self.author.read_name()
|
self.author.read_name()
|
||||||
};
|
};
|
||||||
|
format!("{}さんの発言<break time=\"200ms\"/>{}", name, text)
|
||||||
if config.read_username.unwrap_or(true) {
|
|
||||||
format!("{}さんの発言<break time=\"200ms\"/>{}", name, text)
|
|
||||||
} else {
|
|
||||||
format!("{}", text)
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if self.attachments.len() > 0 {
|
if self.attachments.len() > 0 {
|
||||||
|
Reference in New Issue
Block a user