-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
88 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
mod close_ticket; | ||
mod create_task; | ||
mod task_fixed; | ||
mod thread_archiving; | ||
mod ticket_reopen; | ||
|
||
pub use close_ticket::*; | ||
pub use create_task::*; | ||
pub use task_fixed::*; | ||
pub use thread_archiving::*; | ||
pub use ticket_reopen::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use async_trait::async_trait; | ||
use poise::serenity_prelude::{Context, EditThread, EventHandler, GuildChannel}; | ||
|
||
use crate::{CloseReason, TICKET_FORUM_ID}; | ||
|
||
pub struct ThreadArchivingHandler; | ||
|
||
#[async_trait] | ||
impl EventHandler for ThreadArchivingHandler { | ||
/// Only if the thread has | ||
async fn thread_update(&self, ctx: Context, old: Option<GuildChannel>, new: GuildChannel) { | ||
// If the thread was updated and the archived state changed | ||
let old_archive = old | ||
.and_then(|old| old.thread_metadata) | ||
.map(|meta| meta.archived) | ||
.unwrap_or(false); | ||
let new_archive = new | ||
.thread_metadata | ||
.map(|meta| meta.archived) | ||
.unwrap_or(false); | ||
|
||
if old_archive == new_archive { | ||
return; | ||
} | ||
|
||
// Check that the parent is the ticket forum | ||
let Some(parent) = new.parent_id else { | ||
return; | ||
}; | ||
let parent = match parent.to_channel(&ctx).await { | ||
Ok(parent) => parent, | ||
Err(e) => { | ||
eprintln!("Error getting parent channel: {}", e); | ||
return; | ||
} | ||
}; | ||
|
||
let Some(parent) = parent.guild() else { | ||
return; | ||
}; | ||
|
||
if parent.id != TICKET_FORUM_ID { | ||
return; | ||
} | ||
|
||
let available_tags = parent.available_tags; | ||
let close_tags = available_tags | ||
.iter() | ||
.filter(|tag| CloseReason::is_close_tag(tag)) | ||
.collect::<Vec<_>>(); | ||
|
||
let has_close_tag = new | ||
.applied_tags | ||
.iter() | ||
.any(|tag| close_tags.iter().any(|close_tag| close_tag.id == *tag)); | ||
|
||
if new_archive == has_close_tag { | ||
return; | ||
} | ||
|
||
let mut new = new; | ||
|
||
if let Err(e) = new | ||
.edit_thread(&ctx, EditThread::default().archived(has_close_tag)) | ||
.await | ||
{ | ||
eprintln!("Error editing thread: {}", e); | ||
return; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters