Skip to content

Commit

Permalink
Allow toggling text-in-voice functionality
Browse files Browse the repository at this point in the history
Closes #97
  • Loading branch information
GnomedDev committed Sep 4, 2024
1 parent 230bea0 commit 9e5cb22
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
9 changes: 9 additions & 0 deletions tts_commands/src/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ pub async fn settings(ctx: Context<'_>) -> CommandResult {
let guild_mode: &str = guild_mode.into();
let to_translate = guild_row.to_translate();
let require_voice = guild_row.require_voice();
let text_in_voice = guild_row.text_in_voice();
let audience_ignore = guild_row.audience_ignore();
let role_mention = required_role.as_deref().unwrap_or(none_str);
let voice_mode = user_mode.map(|m| m.into()).unwrap_or(none_str);
Expand Down Expand Up @@ -170,6 +171,7 @@ pub async fn settings(ctx: Context<'_>) -> CommandResult {
{sep2} Ignore audience messages: `{audience_ignore}`
{sep2} Require users in voice channel: `{require_voice}`
{sep2} Required prefix for TTS: `{required_prefix}`
{sep2} Read from Text in Voice channels: `{text_in_voice}`
**{sep2} Default Server Voice Mode: `{guild_mode}`**
**{sep2} Default Server Voice: `{default_voice}`**
Expand Down Expand Up @@ -530,6 +532,12 @@ create_bool_command!(
"audience_ignore",
aliases("audienceignore", "ignore_audience", "ignoreaudience"),
);
create_bool_command!(
"Makes the bot read messages from text-in-voice channels",
text_in_voice,
"text_in_voice",
aliases(),
);
create_bool_command!(
"Makes the bot translate all TTS messages to the same language",
translation,
Expand Down Expand Up @@ -1337,6 +1345,7 @@ pub fn commands() -> [Command; 5] {
require_voice(),
required_prefix(),
command_prefix(),
text_in_voice(),
owner::block(),
owner::bot_ban(),
owner::gtts_disabled(),
Expand Down
4 changes: 4 additions & 0 deletions tts_core/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ pub async fn run_checks(
if guild_row.channel != Some(message.channel_id) {
// "Text in Voice" works by just sending messages in voice channels, so checking for it just takes
// checking if the message's channel_id is the author's voice channel_id
if !guild_row.text_in_voice() {
return Ok(None);
}

let guild = require!(message.guild(&ctx.cache), Ok(None));
let author_vc = guild
.voice_states
Expand Down
3 changes: 3 additions & 0 deletions tts_core/src/database_models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub struct GuildRowRaw {
pub bot_ignore: bool,
pub to_translate: bool,
pub require_voice: bool,
pub text_in_voice: bool,
pub audience_ignore: bool,
pub msg_length: i16,
pub repeated_chars: i16,
Expand All @@ -57,6 +58,7 @@ pub struct GuildRow {
pub bot_ignore: bool,
pub to_translate: bool,
pub require_voice: bool,
pub text_in_voice: bool,
pub audience_ignore: bool,
pub msg_length: u16,
pub repeated_chars: Option<NonZeroU8>,
Expand Down Expand Up @@ -103,6 +105,7 @@ impl Compact for GuildRowRaw {
.set_bot_ignore(self.bot_ignore)
.set_to_translate(self.to_translate)
.set_require_voice(self.require_voice)
.set_text_in_voice(self.text_in_voice)
.set_audience_ignore(self.audience_ignore)
}
}
Expand Down
3 changes: 2 additions & 1 deletion tts_migrations/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ async fn _run(
ADD COLUMN IF NOT EXISTS premium_user bigint,
ADD COLUMN IF NOT EXISTS require_voice bool DEFAULT True,
ADD COLUMN IF NOT EXISTS required_role bigint,
ADD COLUMN IF NOT EXISTS required_prefix varchar(6);
ADD COLUMN IF NOT EXISTS required_prefix varchar(6),
ADD COLUMN IF NOT EXISTS text_in_voice bool DEFAULT True;
ALTER TABLE user_voice
ADD COLUMN IF NOT EXISTS speaking_rate real;
Expand Down

0 comments on commit 9e5cb22

Please sign in to comment.