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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rustmail/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rustmail"
version = "0.1.1"
version = "1.0.3"
edition = "2024"
license = "MIT"

Expand Down
18 changes: 13 additions & 5 deletions rustmail/src/commands/move_thread/common.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::prelude::config::*;
use crate::prelude::db::*;
use serenity::all::{ChannelId, CommandInteraction, Context, EditChannel, GuildId, Message};
use crate::prelude::utils::*;
use serenity::all::{ChannelId, CommandInteraction, Context, EditChannel, GuildChannel, GuildId, Message};
use crate::errors::{ModmailError, ModmailResult};

pub async fn is_in_thread(msg: &Message, pool: &sqlx::SqlitePool) -> bool {
let channel_id = msg.channel_id.to_string();
Expand Down Expand Up @@ -46,21 +48,27 @@ pub async fn move_channel_to_category_by_msg(
ctx: &Context,
msg: &Message,
category_id: ChannelId,
) -> Result<serenity::model::channel::GuildChannel, serenity::Error> {
) -> ModmailResult<GuildChannel> {
let permissions = get_category_permissions_overwrites(ctx, category_id).await?;

msg.channel_id
.edit(&ctx.http, EditChannel::new().category(category_id))
.edit(&ctx.http, EditChannel::new().category(category_id).permissions(permissions))
.await
.map_err(ModmailError::from)
}

pub async fn move_channel_to_category_by_command_option(
ctx: &Context,
command: &CommandInteraction,
category_id: ChannelId,
) -> Result<serenity::model::channel::GuildChannel, serenity::Error> {
) -> ModmailResult<GuildChannel> {
let permissions = get_category_permissions_overwrites(ctx, category_id).await?;

command
.channel_id
.edit(&ctx.http, EditChannel::new().category(category_id))
.edit(&ctx.http, EditChannel::new().category(category_id).permissions(permissions))
.await
.map_err(ModmailError::from)
}

pub fn find_best_match_category(
Expand Down
24 changes: 23 additions & 1 deletion rustmail/src/utils/command/category.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use serenity::all::CommandInteraction;
use serenity::all::{ChannelId, CommandInteraction, PermissionOverwrite};
use serenity::all::{Channel, Context, PermissionOverwriteType, RoleId};
use crate::errors::{CommandError, ModmailError, ModmailResult};

pub async fn get_category_id_from_command(ctx: &Context, command: &CommandInteraction) -> String {
match command.channel_id.to_channel(&ctx.http).await {
Expand Down Expand Up @@ -58,3 +59,24 @@ pub async fn get_required_permissions_channel_from_command(
_ => 0u64,
}
}

pub async fn get_category_permissions_overwrites(
ctx: &Context,
category_id: ChannelId,
) -> ModmailResult<Vec<PermissionOverwrite>> {
let category = match category_id.to_channel(&ctx.http).await {
Ok(channel) => {
channel.category()
}
Err(..) => {
return Err(ModmailError::Command(CommandError::NotInThread()));
}
};

let permissions = match category {
Some(category) => category.permission_overwrites.clone(),
None => return Err(ModmailError::Command(CommandError::NotInThread())),
};

Ok(permissions)
}