mirror of
https://github.com/mii443/ncb-tts-r2.git
synced 2025-08-22 16:15:29 +00:00
add validator
This commit is contained in:
@ -14,6 +14,7 @@ reqwest = { version = "0.11", features = ["json"] }
|
||||
base64 = "0.13"
|
||||
async-trait = "0.1.57"
|
||||
redis = "*"
|
||||
regex = "1"
|
||||
|
||||
[dependencies.uuid]
|
||||
version = "0.8"
|
||||
|
@ -58,7 +58,7 @@ pub async fn stop_command(ctx: &Context, command: &ApplicationCommandInteraction
|
||||
storage.remove(&guild.id);
|
||||
}
|
||||
|
||||
let _handler = manager.leave(guild.id.0).await;
|
||||
let _handler = manager.remove(guild.id.0).await;
|
||||
|
||||
command.create_interaction_response(&ctx.http, |f| {
|
||||
f.interaction_response_data(|d| {
|
||||
|
@ -36,5 +36,21 @@ pub async fn voice_state_update(
|
||||
message
|
||||
}, &ctx).await;
|
||||
}
|
||||
|
||||
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;
|
||||
storage.remove(&guild_id);
|
||||
}
|
||||
|
||||
let manager = songbird::get(&ctx).await.expect("Cannot get songbird client.").clone();
|
||||
|
||||
if voice_move_state == VoiceMoveState::LEAVE {
|
||||
manager.remove(guild_id.0).await.unwrap();
|
||||
}
|
||||
}
|
||||
}
|
@ -11,16 +11,17 @@ use crate::{
|
||||
tts_type::TTSType,
|
||||
gcp_tts::structs::{
|
||||
audio_config::AudioConfig, synthesis_input::SynthesisInput, synthesize_request::SynthesizeRequest
|
||||
}
|
||||
}, validator
|
||||
},
|
||||
};
|
||||
|
||||
#[async_trait]
|
||||
impl TTSMessage for Message {
|
||||
async fn parse(&self, instance: &mut TTSInstance, _: &Context) -> String {
|
||||
let text = validator::remove_url(self.content.clone());
|
||||
let res = if let Some(before_message) = &instance.before_message {
|
||||
if before_message.author.id == self.author.id {
|
||||
self.content.clone()
|
||||
text.clone()
|
||||
} else {
|
||||
let member = self.member.clone();
|
||||
let name = if let Some(member) = member {
|
||||
@ -28,7 +29,7 @@ impl TTSMessage for Message {
|
||||
} else {
|
||||
self.author.name.clone()
|
||||
};
|
||||
format!("{} さんの発言<break time=\"200ms\"/>{}", name, self.content)
|
||||
format!("{} さんの発言<break time=\"200ms\"/>{}", name, text)
|
||||
}
|
||||
} else {
|
||||
let member = self.member.clone();
|
||||
@ -37,7 +38,7 @@ impl TTSMessage for Message {
|
||||
} else {
|
||||
self.author.name.clone()
|
||||
};
|
||||
format!("{} さんの発言<break time=\"200ms\"/>{}", name, self.content)
|
||||
format!("{} さんの発言<break time=\"200ms\"/>{}", name, text)
|
||||
};
|
||||
|
||||
instance.before_message = Some(self.clone());
|
||||
|
@ -4,6 +4,7 @@ pub trait VoiceMoveStateTrait {
|
||||
fn move_state(&self, old: &Option<VoiceState>, target_channel: ChannelId) -> VoiceMoveState;
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub enum VoiceMoveState {
|
||||
JOIN,
|
||||
LEAVE,
|
||||
|
@ -3,3 +3,4 @@ pub mod voicevox;
|
||||
pub mod message;
|
||||
pub mod tts_type;
|
||||
pub mod instance;
|
||||
pub mod validator;
|
6
src/tts/validator.rs
Normal file
6
src/tts/validator.rs
Normal file
@ -0,0 +1,6 @@
|
||||
use regex::Regex;
|
||||
|
||||
pub fn remove_url(text: String) -> String {
|
||||
let url_regex = Regex::new(r"(http://|https://){1}[\w\.\-/:\#\?=\&;%\~\+]+").unwrap();
|
||||
url_regex.replace_all(&text, " URL ").to_string()
|
||||
}
|
Reference in New Issue
Block a user