feat: add auto support messages

This commit is contained in:
Ryan Cao 2023-06-05 18:39:33 +08:00
parent cb16991417
commit 97f13e02e4
No known key found for this signature in database

View file

@ -5,6 +5,8 @@ import {
OAuth2Scopes, OAuth2Scopes,
InteractionType, InteractionType,
PermissionFlagsBits, PermissionFlagsBits,
ChannelType,
Events,
} from 'discord.js'; } from 'discord.js';
import { reuploadCommands } from './_reupload'; import { reuploadCommands } from './_reupload';
@ -76,7 +78,7 @@ client.once('ready', async () => {
status: 'online', status: 'online',
}); });
client.on('messageCreate', async (e) => { client.on(Events.MessageCreate, async (e) => {
try { try {
if (e.channel.partial) await e.channel.fetch(); if (e.channel.partial) await e.channel.fetch();
if (e.author.partial) await e.author.fetch(); if (e.author.partial) await e.author.fetch();
@ -98,12 +100,12 @@ client.once('ready', async () => {
} }
await expandDiscordLink(e); await expandDiscordLink(e);
} catch (error) { } catch (error) {
console.error('Unhandled exception on messageCreate', error); console.error('Unhandled exception on MessageCreate', error);
} }
}); });
}); });
client.on('interactionCreate', async (interaction) => { client.on(Events.InteractionCreate, async (interaction) => {
try { try {
if (!interaction.isChatInputCommand()) return; if (!interaction.isChatInputCommand()) return;
@ -130,11 +132,11 @@ client.on('interactionCreate', async (interaction) => {
await roryCommand(interaction); await roryCommand(interaction);
} }
} catch (error) { } catch (error) {
console.error('Unhandled exception on interactionCreate', error); console.error('Unhandled exception on InteractionCreate', error);
} }
}); });
client.on('messageReactionAdd', async (reaction, user) => { client.on(Events.MessageReactionAdd, async (reaction, user) => {
try { try {
if (reaction.partial) { if (reaction.partial) {
try { try {
@ -147,14 +149,45 @@ client.on('messageReactionAdd', async (reaction, user) => {
if ( if (
reaction.message.interaction && reaction.message.interaction &&
reaction.message.interaction?.type === InteractionType.ApplicationCommand && reaction.message.interaction?.type ===
InteractionType.ApplicationCommand &&
reaction.message.interaction?.user === user && reaction.message.interaction?.user === user &&
reaction.emoji.name === '❌' reaction.emoji.name === '❌'
) { ) {
await reaction.message.delete(); await reaction.message.delete();
} }
} catch (error) { } catch (error) {
console.error('Unhandled exception on messageReactionAdd', error); console.error('Unhandled exception on MessageReactionAdd', error);
}
});
client.on(Events.ThreadCreate, async (channel) => {
try {
if (
channel.type === ChannelType.PublicThread &&
channel.parent &&
channel.parent.name === 'support' &&
channel.guild
) {
const pingRole = channel.guild.roles.cache.find(
(r) => r.name === 'Moderators'
);
if (!pingRole) return;
await channel.send({
content: `
<@${channel.ownerId}> We've received your support ticket! Please upload your logs and post the link here if possible. Also, remember not to ping ${pingRole} for support, as they are not support staff!
`.trim(),
allowedMentions: {
repliedUser: true,
roles: [],
users: channel.ownerId ? [channel.ownerId] : [],
},
});
}
} catch (error) {
console.error('Error handling ThreadCreate', error);
} }
}); });