-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
if ticket author left the thread, archive the thread
- Loading branch information
1 parent
cb96b16
commit aa3ff60
Showing
1 changed file
with
72 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { Collection, MessageEmbed, Snowflake, ThreadMember } from 'discord.js'; | ||
import { channelMention, memberNicknameMention } from '@discordjs/builders'; | ||
import { RowDataPacket } from 'mysql2'; | ||
import { version } from '../../../package.json'; | ||
import { conn } from '../../utils'; | ||
import { Handler, Tables } from '../../types'; | ||
|
||
export const execute: Handler['execute'] = async ( | ||
client, | ||
members: Collection<Snowflake, ThreadMember> | ||
) => { | ||
const first = members.first()!; | ||
const { thread } = first; | ||
const { name, id } = first.thread; | ||
|
||
const ticketUserId = name.split('-').at(-1)!; | ||
const member = members.get(ticketUserId); | ||
|
||
if (!member) return; | ||
|
||
if (name === `ticket-${ticketUserId}`) { | ||
if ( | ||
thread.members.cache.has(client.user!.id) && | ||
!thread.members.cache.has(ticketUserId) | ||
) { | ||
const [rows] = await conn.execute( | ||
'SELECT * FROM TicketingManagers WHERE GuildID = ?', | ||
[thread.guildId] | ||
); | ||
const record = ( | ||
rows as RowDataPacket[] | ||
)[0] as Tables.TicketingManagers | null; | ||
|
||
if (!record) return; | ||
|
||
const user = member.user!; | ||
const embed = new MessageEmbed() | ||
.setColor('YELLOW') | ||
.setAuthor(user.tag, user.displayAvatarURL({ dynamic: true })) | ||
.setTitle('Ticket Archived') | ||
.setDescription( | ||
`${memberNicknameMention(user.id)} left the support ticket!` | ||
) | ||
.setTimestamp() | ||
.setFooter(`Version ${version}`); | ||
|
||
await thread.send({ embeds: [embed] }); | ||
await thread.setArchived(true); | ||
|
||
if (record.LogsChannel !== '0') { | ||
embed.setDescription( | ||
`${memberNicknameMention( | ||
user.id | ||
)} left their ticket! View it at ${channelMention(id)}` | ||
); | ||
embed.addField('Name of Ticket', name); | ||
|
||
const logsChannel = await thread.guild.channels.fetch( | ||
record.LogsChannel | ||
); | ||
|
||
if (!logsChannel?.isText()) return; | ||
if ( | ||
!logsChannel.permissionsFor(thread.guild.me!).has(['SEND_MESSAGES']) | ||
) | ||
return; | ||
|
||
logsChannel.send({ embeds: [embed] }); | ||
} | ||
} | ||
} | ||
}; |