Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions rustmail/src/commands/close/slash_command/close.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,35 @@ impl RegistrableCommand for CloseCommand {
.await?;
let _ = delete_scheduled_closure(&thread.id, db_pool).await;

if config.bot.enable_logs {
if let Some(logs_channel_id) = config.bot.logs_channel_id {
let base_url = config
.bot
.redirect_url
.trim_end_matches("/api/auth/callback")
.trim_end_matches('/');

let panel_url = format!("{}/panel/tickets/{}", base_url, thread.id);

let mut params = HashMap::new();
params.insert("username".to_string(), thread.user_name.clone());
params.insert("user_id".to_string(), thread.user_id.to_string());
params.insert("panel_url".to_string(), panel_url);

let _ = MessageBuilder::system_message(&ctx, &config)
.translated_content(
"logs.ticket_closed",
Some(&params),
Some(command.user.id),
command.guild_id.map(|g| g.get()),
)
.await
.to_channel(serenity::all::ChannelId::new(logs_channel_id))
.send(true)
.await;
}
}

let _ = command.channel_id.delete(&ctx.http).await?;

Ok(())
Expand Down
29 changes: 29 additions & 0 deletions rustmail/src/commands/close/text_command/close.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,35 @@ pub async fn close(
.await?;
let _ = delete_scheduled_closure(&thread.id, db_pool).await;

if config.bot.enable_logs {
if let Some(logs_channel_id) = config.bot.logs_channel_id {
let base_url = config
.bot
.redirect_url
.trim_end_matches("/api/auth/callback")
.trim_end_matches('/');

let panel_url = format!("{}/panel/tickets/{}", base_url, thread.id);

let mut params = HashMap::new();
params.insert("username".to_string(), thread.user_name.clone());
params.insert("user_id".to_string(), thread.user_id.to_string());
params.insert("panel_url".to_string(), panel_url);

let _ = MessageBuilder::system_message(&ctx, config)
.translated_content(
"logs.ticket_closed",
Some(&params),
Some(msg.author.id),
msg.guild_id.map(|g| g.get()),
)
.await
.to_channel(serenity::all::ChannelId::new(logs_channel_id))
.send(true)
.await;
}
}

let _ = msg.channel_id.delete(&ctx.http).await?;

Ok(())
Expand Down
38 changes: 38 additions & 0 deletions rustmail/src/commands/force_close/slash_command/force_close.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::prelude::db::*;
use crate::prelude::errors::*;
use crate::prelude::handlers::*;
use crate::prelude::i18n::*;
use crate::prelude::utils::*;
use serenity::FutureExt;
use serenity::all::{CommandInteraction, Context, CreateCommand, ResolvedOption};
use std::sync::Arc;
Expand Down Expand Up @@ -82,11 +83,48 @@ impl RegistrableCommand for ForceCloseCommand {
}
}

let thread = get_thread_by_channel_id(&command.channel_id.to_string(), db_pool).await;

match is_orphaned_thread_channel(command.channel_id, db_pool).await {
Ok(res) => {
if !res {
return Err(ModmailError::Thread(ThreadError::UserStillInServer));
}

if let Some(thread_info) = thread {
if config.bot.enable_logs {
if let Some(logs_channel_id) = config.bot.logs_channel_id {
let base_url = config
.bot
.redirect_url
.trim_end_matches("/api/auth/callback")
.trim_end_matches('/');

let panel_url =
format!("{}/panel/tickets/{}", base_url, thread_info.id);

let mut params = std::collections::HashMap::new();
params
.insert("username".to_string(), thread_info.user_name.clone());
params
.insert("user_id".to_string(), thread_info.user_id.to_string());
params.insert("panel_url".to_string(), panel_url);

let _ = MessageBuilder::system_message(&ctx, &config)
.translated_content(
"logs.ticket_closed",
Some(&params),
Some(command.user.id),
command.guild_id.map(|g| g.get()),
)
.await
.to_channel(serenity::all::ChannelId::new(logs_channel_id))
.send(true)
.await;
}
}
}

delete_channel(&ctx, command.channel_id).await
}
Err(..) => Err(ModmailError::Database(DatabaseError::QueryFailed(
Expand Down
35 changes: 35 additions & 0 deletions rustmail/src/commands/force_close/text_command/force_close.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::prelude::config::*;
use crate::prelude::db::*;
use crate::prelude::errors::*;
use crate::prelude::handlers::*;
use crate::prelude::utils::*;
use serenity::all::{Context, Message};
use std::sync::Arc;

Expand All @@ -26,11 +27,45 @@ pub async fn force_close(
};
}

let thread = get_thread_by_channel_id(&msg.channel_id.to_string(), db_pool).await;

match is_orphaned_thread_channel(msg.channel_id, db_pool).await {
Ok(res) => {
if !res {
return Err(ModmailError::Thread(ThreadError::UserStillInServer));
}

if let Some(thread_info) = thread {
if config.bot.enable_logs {
if let Some(logs_channel_id) = config.bot.logs_channel_id {
let base_url = config
.bot
.redirect_url
.trim_end_matches("/api/auth/callback")
.trim_end_matches('/');

let panel_url = format!("{}/panel/tickets/{}", base_url, thread_info.id);

let mut params = std::collections::HashMap::new();
params.insert("username".to_string(), thread_info.user_name.clone());
params.insert("user_id".to_string(), thread_info.user_id.to_string());
params.insert("panel_url".to_string(), panel_url);

let _ = MessageBuilder::system_message(&ctx, config)
.translated_content(
"logs.ticket_closed",
Some(&params),
Some(msg.author.id),
msg.guild_id.map(|g| g.get()),
)
.await
.to_channel(serenity::all::ChannelId::new(logs_channel_id))
.send(true)
.await;
}
}
}

delete_channel(&ctx, msg.channel_id).await
}
Err(..) => Err(ModmailError::Database(DatabaseError::QueryFailed(
Expand Down
4 changes: 4 additions & 0 deletions rustmail/src/i18n/language/en.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,10 @@ pub fn load_english_messages(dict: &mut ErrorDictionary) {
"close.silent_closing".to_string(),
DictionaryMessage::new("This ticket will be closed silently in {time}."),
);
dict.messages.insert(
"logs.ticket_closed".to_string(),
DictionaryMessage::new("Ticket closed for user **{username}** (ID: {user_id})\n[View log on panel]({panel_url})"),
);
dict.messages.insert(
"feature.not_implemented".to_string(),
DictionaryMessage::new("This feature is not yet implemented."),
Expand Down
4 changes: 4 additions & 0 deletions rustmail/src/i18n/language/fr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,10 @@ pub fn load_french_messages(dict: &mut ErrorDictionary) {
"close.silent_closing".to_string(),
DictionaryMessage::new("Ce ticket sera fermé silencieusement dans {time}."),
);
dict.messages.insert(
"logs.ticket_closed".to_string(),
DictionaryMessage::new("Ticket fermé pour l'utilisateur **{username}** (ID: {user_id})\n[Voir le log sur le panel]({panel_url})"),
);
dict.messages.insert(
"feature.not_implemented".to_string(),
DictionaryMessage::new("Cette feature n'est pas encore implémentée."),
Expand Down
55 changes: 55 additions & 0 deletions rustmail/src/modules/scheduled_closures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,36 @@ pub fn schedule_one(ctx: &Context, config: &Config, thread_id: String, close_at:
)
.await;
let _ = delete_scheduled_closure(&thread_id, pool).await;

if config_clone.bot.enable_logs {
if let Some(logs_channel_id) = config_clone.bot.logs_channel_id {
let base_url = config_clone
.bot
.redirect_url
.trim_end_matches("/api/auth/callback")
.trim_end_matches('/');

let panel_url = format!("{}/panel/tickets/{}", base_url, thread.id);

let mut params = std::collections::HashMap::new();
params.insert("username".to_string(), thread.user_name.clone());
params.insert("user_id".to_string(), thread.user_id.to_string());
params.insert("panel_url".to_string(), panel_url);

let _ = MessageBuilder::system_message(&ctx_clone, &config_clone)
.translated_content(
"logs.ticket_closed",
Some(&params),
None,
None,
)
.await
.to_channel(ChannelId::new(logs_channel_id))
.send(true)
.await;
}
}

if !current.silent {
let _ = MessageBuilder::system_message(&ctx_clone, &config_clone)
.content(&config_clone.bot.close_message)
Expand Down Expand Up @@ -85,6 +115,31 @@ pub async fn hydrate_scheduled_closures(ctx: &Context, config: &Config) {
)
.await;
let _ = delete_scheduled_closure(&thread.id, pool).await;

if config.bot.enable_logs {
if let Some(logs_channel_id) = config.bot.logs_channel_id {
let base_url = config
.bot
.redirect_url
.trim_end_matches("/api/auth/callback")
.trim_end_matches('/');

let panel_url = format!("{}/panel/tickets/{}", base_url, thread.id);

let mut params = std::collections::HashMap::new();
params.insert("username".to_string(), thread.user_name.clone());
params.insert("user_id".to_string(), thread.user_id.to_string());
params.insert("panel_url".to_string(), panel_url);

let _ = MessageBuilder::system_message(ctx, config)
.translated_content("logs.ticket_closed", Some(&params), None, None)
.await
.to_channel(ChannelId::new(logs_channel_id))
.send(true)
.await;
}
}

if !sc.silent {
let _ = MessageBuilder::system_message(ctx, config)
.content(&config.bot.close_message)
Expand Down