Skip to content

Commit

Permalink
finaliase badtranslator
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacherr committed Jul 30, 2024
1 parent eaea5d0 commit d95788f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
7 changes: 5 additions & 2 deletions assyst-core/src/bad_translator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use assyst_database::model::badtranslator_channel::BadTranslatorChannel;
use assyst_database::model::badtranslator_messages::BadTranslatorMessages;
use tokio::sync::RwLock;
use twilight_http::error::ErrorType;
use twilight_model::channel::message::AllowedMentions;
use twilight_model::channel::message::{AllowedMentions, MessageType};
use twilight_model::channel::{Message, Webhook};
use twilight_model::id::marker::{ChannelMarker, UserMarker};
use twilight_model::id::Id;
Expand Down Expand Up @@ -192,7 +192,10 @@ impl BadTranslator {
return Ok(());
}

if message.content.is_empty() || message.author.bot {
if message.content.is_empty()
|| message.author.bot
|| ![MessageType::Reply, MessageType::Regular].contains(&message.kind)
{
let _ = assyst.http_client.delete_message(message.channel_id, message.id).await;

return Ok(());
Expand Down
10 changes: 10 additions & 0 deletions assyst-core/src/gateway_handler/event_handlers/message_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ use crate::ThreadSafeAssyst;
/// This function passes the message to the command parser, which then attempts to convert the
/// message to a command for further processing.
pub async fn handle(assyst: ThreadSafeAssyst, MessageCreate(message): MessageCreate) {
if assyst.bad_translator.is_channel(message.channel_id.get()).await && !assyst.bad_translator.is_disabled().await {
match assyst.bad_translator.handle_message(&assyst, Box::new(message)).await {
Err(e) => {
err!("BadTranslator channel execution failed: {e:?}");
},
_ => {},
};
return;
}

let processing_time_start = Instant::now();

match parse_message_into_command(assyst.clone(), &message, processing_time_start, false).await {
Expand Down
8 changes: 6 additions & 2 deletions assyst-core/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,12 @@ async fn main() {
info!("Registering interaction commands");
register_interaction_commands(assyst.clone()).await.unwrap();

info!("Initialising BadTranslator channels");
assyst.init_badtranslator_channels().await;
if !CONFIG.dev.disable_bad_translator_channels {
info!("Initialising BadTranslator channels");
assyst.init_badtranslator_channels().await;
} else {
info!("BadTranslator channels disabled in config.dev.disable_bad_translator_channels, skipping init");
}

let a = assyst.clone();
spawn(async move {
Expand Down

0 comments on commit d95788f

Please sign in to comment.