mirror of
https://github.com/nx-bat/discordbot-ng.git
synced 2026-11-11 07:13:37 -05:00
Compare commits
16
Commits
dev-readme
...
5f7ad1921f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5f7ad1921f | ||
|
|
687b647ca8 | ||
|
|
6c7fe40f54 | ||
|
|
71e2d1c088 | ||
|
|
12cdba21b5 | ||
|
|
5a5a82f890 | ||
|
|
f92a650536 | ||
|
|
e87be791eb | ||
|
|
9d2b2e6a9e | ||
|
|
2a96359d8d | ||
|
|
e0aa68874d | ||
|
|
2f14da099d | ||
|
|
8e88b2c83a | ||
|
|
0d2e4403f7 | ||
|
|
f4f0044dc3 | ||
|
|
1d58c9692c |
@@ -1,40 +0,0 @@
|
|||||||
import { ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, ChannelType, Client, MessageFlags, PermissionFlagsBits } from 'discord.js';
|
|
||||||
import { Database } from '../shared/Database';
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'claim-ticket',
|
|
||||||
handler: async function (client: Client, interaction: ButtonInteraction) {
|
|
||||||
const channel = await interaction.channel?.fetch();
|
|
||||||
|
|
||||||
if (!channel || !channel.isThread() || !channel.isSendable() || channel.type != ChannelType.PrivateThread)
|
|
||||||
return interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Oops. Something went wrong.' });
|
|
||||||
|
|
||||||
if (!interaction.memberPermissions) return interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'An error has occurred.' });
|
|
||||||
|
|
||||||
if (!interaction.memberPermissions.has(PermissionFlagsBits.ManageMessages)) return interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'You do not have permission to claim tickets.' });
|
|
||||||
|
|
||||||
const guild = await client.guilds.fetch(interaction.guildId!);
|
|
||||||
|
|
||||||
const settings = await Database.getOrCreateSettings(guild.id);
|
|
||||||
if (!settings.private_help_role_id) return interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Failed to claim ticket.' });
|
|
||||||
|
|
||||||
const closeButton = new ButtonBuilder()
|
|
||||||
.setCustomId('close-ticket')
|
|
||||||
.setLabel('Click here if you no longer need help')
|
|
||||||
.setStyle(ButtonStyle.Danger);
|
|
||||||
|
|
||||||
const unclaimButton = new ButtonBuilder()
|
|
||||||
.setCustomId('unclaim-ticket')
|
|
||||||
.setLabel('Unclaim ticket')
|
|
||||||
.setStyle(ButtonStyle.Primary);
|
|
||||||
|
|
||||||
const row = new ActionRowBuilder<ButtonBuilder>().addComponents(closeButton, unclaimButton);
|
|
||||||
|
|
||||||
await interaction.message.edit({
|
|
||||||
content: `${interaction.message.content}\n\nClaimed by: ${interaction.user}`,
|
|
||||||
components: [row]
|
|
||||||
});
|
|
||||||
|
|
||||||
await interaction.reply({ content: `Ticket claimed by ${interaction.user}.` });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
import { ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, ChannelType, Client, MessageFlags } from 'discord.js';
|
||||||
|
import { Database } from '../shared/Database';
|
||||||
|
import { Button } from '../types';
|
||||||
|
|
||||||
|
class ClaimTicketButton implements Button<Client> {
|
||||||
|
id = 'claim-ticket';
|
||||||
|
|
||||||
|
async execute(context: Client<boolean>, interaction: ButtonInteraction): Promise<void> {
|
||||||
|
if (!interaction.inGuild()) return;
|
||||||
|
await interaction.deferReply({ flags: [MessageFlags.Ephemeral] });
|
||||||
|
|
||||||
|
try {
|
||||||
|
const channel = await context.channels.fetch(interaction.channelId);
|
||||||
|
|
||||||
|
if (!channel) throw new Error("The interaction channel couldn't be fetched.");
|
||||||
|
if (!channel.isThread() || channel.type != ChannelType.PrivateThread) throw new Error('This interaction was not run in a ticket thread.');
|
||||||
|
if (!channel.isSendable()) throw new Error("I don't have permission to send messages in this channel.");
|
||||||
|
|
||||||
|
const settings = await Database.getOrCreateSettings(interaction.guildId);
|
||||||
|
if (!settings.private_help_role_id) throw new Error("`private_help_role_id` hasn't been configured. Please report this error to staff.");
|
||||||
|
|
||||||
|
const guild = await context.guilds.fetch(interaction.guildId);
|
||||||
|
const member = await guild.members.fetch(interaction.user.id);
|
||||||
|
if (!member.roles.cache.has(settings.private_help_role_id)) throw new Error("You don't have permission to claim tickets.");
|
||||||
|
|
||||||
|
const closeButton = new ButtonBuilder()
|
||||||
|
.setCustomId('close-ticket')
|
||||||
|
.setLabel('Click here if you no longer need help')
|
||||||
|
.setStyle(ButtonStyle.Danger);
|
||||||
|
|
||||||
|
const unclaimButton = new ButtonBuilder()
|
||||||
|
.setCustomId('unclaim-ticket')
|
||||||
|
.setLabel('Unclaim ticket')
|
||||||
|
.setStyle(ButtonStyle.Primary);
|
||||||
|
|
||||||
|
const row = new ActionRowBuilder<ButtonBuilder>().addComponents(closeButton, unclaimButton);
|
||||||
|
|
||||||
|
await interaction.message.edit({
|
||||||
|
content: `${interaction.message.content}\n\nClaimed by: ${interaction.user}`,
|
||||||
|
components: [row]
|
||||||
|
});
|
||||||
|
|
||||||
|
await interaction.editReply({ content: `Ticket claimed by ${interaction.user}.` });
|
||||||
|
} catch (error: Error | any) {
|
||||||
|
await interaction.editReply({ content: error.message }).catch(() => {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new ClaimTicketButton();
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
import { ButtonInteraction, Client, MessageFlags, ChannelType, PermissionFlagsBits } from 'discord.js';
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'close-mod-ticket',
|
|
||||||
handler: async function (client: Client, interaction: ButtonInteraction) {
|
|
||||||
await interaction.deferReply({ flags: [MessageFlags.Ephemeral] });
|
|
||||||
const channel = await interaction.channel?.fetch();
|
|
||||||
const guild = await interaction.guild?.fetch();
|
|
||||||
const member = await guild?.members.fetch(interaction.user.id);
|
|
||||||
|
|
||||||
if (!channel || !channel.isThread() || !channel.isSendable() || channel.type != ChannelType.PrivateThread || !member)
|
|
||||||
return interaction.editReply({ content: 'Oops. Something went wrong. Please report this to a staff member.' });
|
|
||||||
|
|
||||||
if (!member.permissions.has(PermissionFlagsBits.KickMembers))
|
|
||||||
return interaction.editReply({ content: 'Only staff members may close mod tickets.' });
|
|
||||||
|
|
||||||
await interaction.message.edit({
|
|
||||||
content: interaction.message.content,
|
|
||||||
components: []
|
|
||||||
});
|
|
||||||
|
|
||||||
await channel.send('This ticket has been closed by staff.');
|
|
||||||
|
|
||||||
await interaction.editReply({ content: 'Ticket closed.' });
|
|
||||||
|
|
||||||
channel.edit({
|
|
||||||
archived: true,
|
|
||||||
locked: true
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
import { ButtonInteraction, Client, MessageFlags, ChannelType } from 'discord.js';
|
|
||||||
import { Database } from '../shared/Database';
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'close-ticket',
|
|
||||||
handler: async function (client: Client, interaction: ButtonInteraction) {
|
|
||||||
const channel = await interaction.channel?.fetch();
|
|
||||||
|
|
||||||
if (!channel || !channel.isThread() || !channel.isSendable() || channel.type != ChannelType.PrivateThread)
|
|
||||||
return interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Oops. Something went wrong. Please report this to a staff member.' });
|
|
||||||
|
|
||||||
await interaction.message.edit({
|
|
||||||
content: interaction.message.content,
|
|
||||||
components: []
|
|
||||||
});
|
|
||||||
|
|
||||||
await Database.closePrivateHelpTicket(channel.id);
|
|
||||||
|
|
||||||
await channel.send(`This ticket has been closed by ${interaction.user}`);
|
|
||||||
|
|
||||||
await interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Ticket closed.' });
|
|
||||||
|
|
||||||
channel.edit({
|
|
||||||
archived: true,
|
|
||||||
locked: true
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import { ButtonInteraction, Client, MessageFlags, ChannelType } from 'discord.js';
|
||||||
|
import { Button } from '../types';
|
||||||
|
|
||||||
|
class CloseModTicketButton implements Button<Client> {
|
||||||
|
id = 'close-mod-ticket';
|
||||||
|
|
||||||
|
async execute(context: Client<boolean>, interaction: ButtonInteraction): Promise<void> {
|
||||||
|
if (!interaction.inGuild()) return;
|
||||||
|
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
|
||||||
|
|
||||||
|
try {
|
||||||
|
const channel = await context.channels.fetch(interaction.channelId);
|
||||||
|
|
||||||
|
if (!channel) throw new Error("The interaction channel couldn't be fetched.");
|
||||||
|
if (!channel.isThread() || channel.type != ChannelType.PrivateThread) throw new Error('This interaction was not run in a ticket thread.');
|
||||||
|
if (!channel.isSendable()) throw new Error("I don't have permission to send messages in this channel.");
|
||||||
|
|
||||||
|
if (!interaction.memberPermissions.has('KickMembers')) throw new Error("You don't have permission to close this ticket.");
|
||||||
|
|
||||||
|
await interaction.message.edit({
|
||||||
|
content: interaction.message.content,
|
||||||
|
components: []
|
||||||
|
});
|
||||||
|
|
||||||
|
await channel.send('This ticket has been closed by staff.');
|
||||||
|
|
||||||
|
await interaction.editReply({ content: 'Ticket closed.' });
|
||||||
|
|
||||||
|
await channel.edit({
|
||||||
|
archived: true,
|
||||||
|
locked: true
|
||||||
|
});
|
||||||
|
} catch (error: Error | any) {
|
||||||
|
await interaction.editReply({ content: error.message }).catch(() => {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new CloseModTicketButton();
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
import { ButtonInteraction, Client, MessageFlags, ChannelType } from 'discord.js';
|
||||||
|
import { Database } from '../shared/Database';
|
||||||
|
import { Button } from '../types';
|
||||||
|
|
||||||
|
class CloseTicketButton implements Button<Client> {
|
||||||
|
id = 'close-ticket';
|
||||||
|
|
||||||
|
async execute(context: Client<boolean>, interaction: ButtonInteraction): Promise<void> {
|
||||||
|
if (!interaction.inGuild()) return;
|
||||||
|
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
|
||||||
|
|
||||||
|
try {
|
||||||
|
const channel = await context.channels.fetch(interaction.channelId);
|
||||||
|
|
||||||
|
if (!channel) throw new Error("The interaction channel couldn't be fetched.");
|
||||||
|
if (!channel.isThread() || channel.type != ChannelType.PrivateThread) throw new Error('This interaction was not run in a ticket thread.');
|
||||||
|
if (!channel.isSendable()) throw new Error("I don't have permission to send messages in this channel.");
|
||||||
|
|
||||||
|
await interaction.message.edit({
|
||||||
|
content: interaction.message.content,
|
||||||
|
components: []
|
||||||
|
});
|
||||||
|
|
||||||
|
await Database.closePrivateHelpTicket(channel.id);
|
||||||
|
|
||||||
|
await channel.send(`This ticket has been closed by ${interaction.user}`);
|
||||||
|
|
||||||
|
await interaction.editReply({ content: 'Ticket closed.' });
|
||||||
|
|
||||||
|
await channel.edit({
|
||||||
|
archived: true,
|
||||||
|
locked: true
|
||||||
|
});
|
||||||
|
} catch (error: Error | any) {
|
||||||
|
await interaction.editReply({ content: error.message }).catch(() => {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new CloseTicketButton();
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
import { ButtonInteraction, Client, MessageFlags } from 'discord.js';
|
|
||||||
import { Database } from '../shared/Database';
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'dev-watch',
|
|
||||||
handler: async function (client: Client, interaction: ButtonInteraction) {
|
|
||||||
try {
|
|
||||||
if (!interaction.guild) throw new Error('This action must be run in a guild.');
|
|
||||||
|
|
||||||
const settings = await Database.getOrCreateSettings(interaction.guild.id);
|
|
||||||
if (!settings.devwatch_role_id) throw new Error('`devwatch_role_id` was not configured. Please configure a role then try again.');
|
|
||||||
|
|
||||||
const member = await interaction.guild.members.fetch(interaction.user.id);
|
|
||||||
if (!member) throw new Error('Unable to retreive the member executing this command.');
|
|
||||||
|
|
||||||
const bot = await interaction.guild.members.fetchMe();
|
|
||||||
const role = await interaction.guild?.roles.fetch(settings.devwatch_role_id);
|
|
||||||
if (!role) throw new Error('The configured `devwatch_role_id` does not exist.');
|
|
||||||
if (role.position > bot.roles.highest.position) throw new Error('The configured `devwatch_role_id` is higher than my highest role.');
|
|
||||||
|
|
||||||
if (member.roles.cache.has(settings.devwatch_role_id)) {
|
|
||||||
await member.roles.remove(settings.devwatch_role_id);
|
|
||||||
await interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Removed role.' });
|
|
||||||
} else {
|
|
||||||
await member.roles.add(settings.devwatch_role_id);
|
|
||||||
await interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Added role.' });
|
|
||||||
}
|
|
||||||
} catch (error: Error | any) {
|
|
||||||
await interaction.reply({ flags: [MessageFlags.Ephemeral], content: error.message });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import { ButtonInteraction, Client, MessageFlags } from 'discord.js';
|
||||||
|
import { Database } from '../shared/Database';
|
||||||
|
import { Button } from '../types';
|
||||||
|
|
||||||
|
class DevWatchButton implements Button<Client> {
|
||||||
|
id = 'dev-watch';
|
||||||
|
|
||||||
|
async execute(context: Client<boolean>, interaction: ButtonInteraction): Promise<void> {
|
||||||
|
if (!interaction.inGuild()) return;
|
||||||
|
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
|
||||||
|
|
||||||
|
try {
|
||||||
|
const settings = await Database.getOrCreateSettings(interaction.guildId);
|
||||||
|
if (!settings.devwatch_role_id) throw new Error('`devwatch_role_id` was not configured. Please configure a role then try again.');
|
||||||
|
|
||||||
|
const guild = await context.guilds.fetch(interaction.guildId);
|
||||||
|
const member = await guild.members.fetch(interaction.user.id);
|
||||||
|
if (!member) throw new Error('Unable to fetch the member executing this command.');
|
||||||
|
|
||||||
|
const bot = await guild.members.fetchMe();
|
||||||
|
const role = await guild.roles.fetch(settings.devwatch_role_id);
|
||||||
|
if (!role) throw new Error('The configured `devwatch_role_id` does not exist.');
|
||||||
|
if (role.position > bot.roles.highest.position) throw new Error('The configured `devwatch_role_id` is higher than my highest role.');
|
||||||
|
|
||||||
|
if (member.roles.cache.has(settings.devwatch_role_id)) {
|
||||||
|
await member.roles.remove(settings.devwatch_role_id);
|
||||||
|
await interaction.editReply({ content: 'Removed role.' });
|
||||||
|
} else {
|
||||||
|
await member.roles.add(settings.devwatch_role_id);
|
||||||
|
await interaction.editReply({ content: 'Added role.' });
|
||||||
|
}
|
||||||
|
} catch (error: Error | any) {
|
||||||
|
await interaction.editReply({ content: error.message }).catch(() => {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new DevWatchButton();
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import claimTicket from './claimTicket';
|
||||||
|
import closeModTicket from './closeModTicket';
|
||||||
|
import closeTicket from './closeTicket';
|
||||||
|
import devWatch from './devWatch';
|
||||||
|
import noteNext from './noteNext';
|
||||||
|
import notePrevious from './notePrevious';
|
||||||
|
import openTicketForReportedMessage from './openTicketForReportedMessage';
|
||||||
|
import privateHelp from './privateHelp';
|
||||||
|
import recordsNext from './recordsNext';
|
||||||
|
import recordsPrevious from './recordsPrevious';
|
||||||
|
import roleButton from './roleButton';
|
||||||
|
import unclaimTicket from './unclaimTicket';
|
||||||
|
|
||||||
|
export default [
|
||||||
|
claimTicket,
|
||||||
|
closeModTicket,
|
||||||
|
closeTicket,
|
||||||
|
devWatch,
|
||||||
|
noteNext,
|
||||||
|
notePrevious,
|
||||||
|
openTicketForReportedMessage,
|
||||||
|
privateHelp,
|
||||||
|
recordsNext,
|
||||||
|
recordsPrevious,
|
||||||
|
roleButton,
|
||||||
|
unclaimTicket
|
||||||
|
];
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
import { ButtonInteraction, Client } from 'discord.js';
|
|
||||||
import { getNoteMessage } from '../utils';
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'note-next',
|
|
||||||
handler: async function (client: Client, interaction: ButtonInteraction, userId: string, page: string) {
|
|
||||||
await interaction.deferUpdate();
|
|
||||||
|
|
||||||
const message = await getNoteMessage(userId, parseInt(page) + 1);
|
|
||||||
|
|
||||||
if (!message) return;
|
|
||||||
|
|
||||||
interaction.editReply(message);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
import { ButtonInteraction, Client} from 'discord.js';
|
|
||||||
import { getNoteMessage } from '../utils';
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'note-previous',
|
|
||||||
handler: async function (client: Client, interaction: ButtonInteraction, userId: string, page: string) {
|
|
||||||
await interaction.deferUpdate();
|
|
||||||
|
|
||||||
const message = await getNoteMessage(userId, parseInt(page) - 1);
|
|
||||||
|
|
||||||
if (!message) return;
|
|
||||||
|
|
||||||
interaction.editReply(message);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import { ButtonInteraction, Client } from 'discord.js';
|
||||||
|
import { Button } from '../types';
|
||||||
|
import { getNoteMessage } from '../utils';
|
||||||
|
|
||||||
|
class NoteNextButton implements Button<Client> {
|
||||||
|
id = 'note-next';
|
||||||
|
|
||||||
|
async execute(context: Client<boolean>, interaction: ButtonInteraction, userId: string, page: string): Promise<void> {
|
||||||
|
await interaction.deferUpdate();
|
||||||
|
|
||||||
|
const message = await getNoteMessage(userId, parseInt(page) + 1);
|
||||||
|
if (!message) return;
|
||||||
|
|
||||||
|
await interaction.editReply(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new NoteNextButton();
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import { ButtonInteraction, Client } from 'discord.js';
|
||||||
|
import { Button } from '../types';
|
||||||
|
import { getNoteMessage } from '../utils';
|
||||||
|
|
||||||
|
class NotePreviousButton implements Button<Client> {
|
||||||
|
id = 'note-previous';
|
||||||
|
|
||||||
|
async execute(context: Client<boolean>, interaction: ButtonInteraction, userId: string, page: string): Promise<void> {
|
||||||
|
await interaction.deferUpdate();
|
||||||
|
|
||||||
|
const message = await getNoteMessage(userId, parseInt(page) - 1);
|
||||||
|
if (!message) return;
|
||||||
|
|
||||||
|
await interaction.editReply(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new NotePreviousButton();
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
import { ButtonInteraction, Client, MessageFlags, MessageMentions } from 'discord.js';
|
|
||||||
import { createPrivateHelpTicketThread } from '../utils';
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'open-ticket-for-reported-message',
|
|
||||||
handler: async function (client: Client, interaction: ButtonInteraction) {
|
|
||||||
const message = await interaction.message.fetch();
|
|
||||||
const guild = await interaction.guild!.fetch();
|
|
||||||
|
|
||||||
const reportEmbed = message.embeds[0]!;
|
|
||||||
|
|
||||||
const regex = new RegExp(MessageMentions.UsersPattern);
|
|
||||||
|
|
||||||
const reportedMessageUrl = reportEmbed.fields[0].value;
|
|
||||||
const reporterId = regex.exec(reportEmbed.fields[2].value)!.groups!.id;
|
|
||||||
const additionalInfo = reportEmbed.fields[3]?.name == 'Additional Information' ? reportEmbed.fields[3].value : '';
|
|
||||||
|
|
||||||
const reporter = await guild.members.fetch(reporterId) ?? await client.users.fetch(reporterId);
|
|
||||||
|
|
||||||
const thread = await createPrivateHelpTicketThread(client, guild, null, `Ticket creted by staff in response to message report: ${message.url}. Reported message: ${reportedMessageUrl}. ${additionalInfo ? `\n\nAdditional information provided in report:\n${additionalInfo.split('\n').map(c => `> ${c}`).join('\n')}` : ''}`, `Ticket: Message Report From ${reporter.displayName}`, [reporterId, interaction.user.id]);
|
|
||||||
|
|
||||||
if (thread) {
|
|
||||||
await interaction.reply({
|
|
||||||
flags: [MessageFlags.Ephemeral],
|
|
||||||
content: `Ticket created: ${thread}`
|
|
||||||
});
|
|
||||||
|
|
||||||
const requestIndex = reportEmbed.fields.findIndex(f => f.name == 'User Requested Private Ticket');
|
|
||||||
if (requestIndex != -1) reportEmbed.fields.splice(requestIndex, 1);
|
|
||||||
|
|
||||||
reportEmbed.fields.push({
|
|
||||||
name: 'Private Help Ticket',
|
|
||||||
value: thread.url,
|
|
||||||
inline: false
|
|
||||||
});
|
|
||||||
|
|
||||||
await message.edit({ embeds: [reportEmbed], components: [] });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
import { ButtonInteraction, Client, MessageFlags, MessageMentions } from 'discord.js';
|
||||||
|
import { Button } from '../types';
|
||||||
|
import { createPrivateHelpTicketThread } from '../utils';
|
||||||
|
|
||||||
|
class OpenTicketForReportedMessageButton implements Button<Client> {
|
||||||
|
id = 'open-ticket-for-reported-message';
|
||||||
|
|
||||||
|
async execute(context: Client<boolean>, interaction: ButtonInteraction): Promise<void> {
|
||||||
|
if (!interaction.inGuild()) return;
|
||||||
|
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
|
||||||
|
|
||||||
|
try {
|
||||||
|
const guild = await context.guilds.fetch(interaction.guildId);
|
||||||
|
const message = await interaction.message.fetch();
|
||||||
|
|
||||||
|
const reportEmbed = message.embeds[0]!;
|
||||||
|
const regex = new RegExp(MessageMentions.UsersPattern);
|
||||||
|
|
||||||
|
const reportedMessageUrl = reportEmbed.fields[0].value;
|
||||||
|
const reporterId = regex.exec(reportEmbed.fields[2].value)!.groups!.id;
|
||||||
|
const additionalInfo = reportEmbed.fields[3]?.name == 'Additional Information' ? reportEmbed.fields[3].value : '';
|
||||||
|
const reporter = await guild.members.fetch(reporterId) ?? await context.users.fetch(reporterId);
|
||||||
|
|
||||||
|
const thread = await createPrivateHelpTicketThread(context, guild, null, `Ticket creted by staff in response to message report: ${message.url}. Reported message: ${reportedMessageUrl}. ${additionalInfo ? `\n\nAdditional information provided in report:\n${additionalInfo.split('\n').map(c => `> ${c}`).join('\n')}` : ''}`, `Ticket: Message Report From ${reporter.displayName}`, [reporterId, interaction.user.id]);
|
||||||
|
if (!thread) throw new Error('An error occured and a thread was not created.');
|
||||||
|
|
||||||
|
await interaction.editReply({ content: `Ticket Created: ${thread}` });
|
||||||
|
|
||||||
|
const requestIndex = reportEmbed.fields.findIndex(f => f.name == 'User Requested Private Ticket');
|
||||||
|
if (requestIndex != -1) reportEmbed.fields.splice(requestIndex, 1);
|
||||||
|
|
||||||
|
reportEmbed.fields.push({
|
||||||
|
name: 'Private Help Ticket',
|
||||||
|
value: thread.url,
|
||||||
|
inline: false
|
||||||
|
});
|
||||||
|
|
||||||
|
await message.edit({ embeds: [reportEmbed], components: [] });
|
||||||
|
} catch (error: Error | any) {
|
||||||
|
await interaction.editReply({ content: error.message }).catch(() => {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new OpenTicketForReportedMessageButton();
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
import { ButtonInteraction, Client, ModalBuilder, TextInputStyle, MessageFlags } from 'discord.js';
|
|
||||||
import { canOpenPrivateHelpTicket, createTextInput } from '../utils';
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'private-help',
|
|
||||||
handler: async function (client: Client, interaction: ButtonInteraction) {
|
|
||||||
if (!(await canOpenPrivateHelpTicket(interaction.user.id)))
|
|
||||||
return interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'You can only have one open ticket at a time that is less than a day old.' });
|
|
||||||
|
|
||||||
const modal = new ModalBuilder()
|
|
||||||
.setCustomId('open-ticket-modal')
|
|
||||||
.setTitle('Get in contact');
|
|
||||||
|
|
||||||
const label = createTextInput('ticket-message', 'What is the reason for your ticket?', null, true, TextInputStyle.Paragraph, 1500, 10);
|
|
||||||
|
|
||||||
modal.addLabelComponents(label);
|
|
||||||
|
|
||||||
await interaction.showModal(modal);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import { ButtonInteraction, Client, ModalBuilder, TextInputStyle, MessageFlags } from 'discord.js';
|
||||||
|
import { Button } from '../types';
|
||||||
|
import { canOpenPrivateHelpTicket, createTextInput } from '../utils';
|
||||||
|
|
||||||
|
class PrivateHelpButton implements Button<Client> {
|
||||||
|
id = 'private-help';
|
||||||
|
|
||||||
|
async execute(context: Client<boolean>, interaction: ButtonInteraction): Promise<void> {
|
||||||
|
try {
|
||||||
|
if (!await canOpenPrivateHelpTicket(interaction.user.id))
|
||||||
|
throw new Error('You can only have one open ticket at a time that is less than a day old.');
|
||||||
|
|
||||||
|
const modal = new ModalBuilder()
|
||||||
|
.setCustomId('open-ticket-modal')
|
||||||
|
.setTitle('Get in contact');
|
||||||
|
|
||||||
|
const label = createTextInput('ticket-message', 'What is the reason for your ticket?', null, true, TextInputStyle.Paragraph, 1500, 10);
|
||||||
|
modal.addLabelComponents(label);
|
||||||
|
|
||||||
|
await interaction.showModal(modal);
|
||||||
|
} catch (error: Error | any) {
|
||||||
|
await interaction.reply({
|
||||||
|
content: error.message,
|
||||||
|
flags: MessageFlags.Ephemeral,
|
||||||
|
}).catch(() => {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new PrivateHelpButton();
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
import { ButtonInteraction, Client } from 'discord.js';
|
|
||||||
import { getRecordMessageFromDiscordId } from '../utils';
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'records-next',
|
|
||||||
handler: async function (client: Client, interaction: ButtonInteraction, userId: string, page: string) {
|
|
||||||
await interaction.deferUpdate();
|
|
||||||
|
|
||||||
const message = await getRecordMessageFromDiscordId(userId, parseInt(page) + 1, interaction.guild!);
|
|
||||||
|
|
||||||
if (!message) return;
|
|
||||||
|
|
||||||
interaction.editReply(message);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
import { ButtonInteraction, Client} from 'discord.js';
|
|
||||||
import { getRecordMessageFromDiscordId } from '../utils';
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'records-previous',
|
|
||||||
handler: async function (client: Client, interaction: ButtonInteraction, userId: string, page: string) {
|
|
||||||
await interaction.deferUpdate();
|
|
||||||
|
|
||||||
const message = await getRecordMessageFromDiscordId(userId, parseInt(page) - 1, interaction.guild!);
|
|
||||||
|
|
||||||
if (!message) return;
|
|
||||||
|
|
||||||
interaction.editReply(message);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import { ButtonInteraction, Client } from 'discord.js';
|
||||||
|
import { Button } from '../types';
|
||||||
|
import { getRecordMessageFromDiscordId } from '../utils';
|
||||||
|
|
||||||
|
class RecordsNextButton implements Button<Client> {
|
||||||
|
id = 'records-next';
|
||||||
|
|
||||||
|
async execute(context: Client<boolean>, interaction: ButtonInteraction, userId: string, page: string): Promise<void> {
|
||||||
|
await interaction.deferUpdate();
|
||||||
|
|
||||||
|
const message = await getRecordMessageFromDiscordId(userId, parseInt(page) + 1, interaction.guild!);
|
||||||
|
if (!message) return;
|
||||||
|
|
||||||
|
await interaction.editReply(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new RecordsNextButton();
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import { ButtonInteraction, Client } from 'discord.js';
|
||||||
|
import { Button } from '../types';
|
||||||
|
import { getRecordMessageFromDiscordId } from '../utils';
|
||||||
|
|
||||||
|
class RecordsPreviousButton implements Button<Client> {
|
||||||
|
id = 'records-previous';
|
||||||
|
|
||||||
|
async execute(context: Client<boolean>, interaction: ButtonInteraction, userId: string, page: string): Promise<void> {
|
||||||
|
await interaction.deferUpdate();
|
||||||
|
|
||||||
|
const message = await getRecordMessageFromDiscordId(userId, parseInt(page) - 1, interaction.guild!);
|
||||||
|
if (!message) return;
|
||||||
|
|
||||||
|
await interaction.editReply(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new RecordsPreviousButton();
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
import { ButtonInteraction, Client, MessageFlags } from 'discord.js';
|
|
||||||
import { Database } from '../shared/Database';
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'role-button',
|
|
||||||
handler: async function (client: Client, interaction: ButtonInteraction) {
|
|
||||||
await interaction.deferReply({ flags: [MessageFlags.Ephemeral] });
|
|
||||||
|
|
||||||
const roleId = await Database.getRoleFromButton(interaction.message.id);
|
|
||||||
|
|
||||||
if (!roleId) await interaction.editReply({ content: 'Could not find role button.' });
|
|
||||||
|
|
||||||
const guild = await interaction.guild?.fetch();
|
|
||||||
const member = await guild?.members.fetch(interaction.user.id);
|
|
||||||
|
|
||||||
if (!member) return interaction.editReply({ content: 'Member not found.' });
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (member.roles.cache.has(roleId!)) {
|
|
||||||
await member.roles.remove(roleId!);
|
|
||||||
interaction.editReply({ content: 'Role removed.' });
|
|
||||||
} else {
|
|
||||||
await member.roles.add(roleId!);
|
|
||||||
interaction.editReply({ content: 'Role added.' });
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e);
|
|
||||||
interaction.editReply({ content: 'Could not add role. Is it higher than mine?' });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import { ButtonInteraction, Client, MessageFlags } from 'discord.js';
|
||||||
|
import { Database } from '../shared/Database';
|
||||||
|
import { Button } from '../types';
|
||||||
|
|
||||||
|
class RoleButtonButton implements Button<Client> {
|
||||||
|
id = 'role-button';
|
||||||
|
|
||||||
|
async execute(context: Client<boolean>, interaction: ButtonInteraction): Promise<void> {
|
||||||
|
if (!interaction.inGuild()) return;
|
||||||
|
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
|
||||||
|
|
||||||
|
try {
|
||||||
|
const roleId = await Database.getRoleFromButton(interaction.message.id);
|
||||||
|
if (!roleId) throw new Error("I couldn't find an associated role ID with this button.");
|
||||||
|
|
||||||
|
const guild = await context.guilds.fetch(interaction.guildId);
|
||||||
|
const member = await guild.members.fetch(interaction.user.id);
|
||||||
|
if (!member) throw new Error('I was unable to fetch you as a member.');
|
||||||
|
|
||||||
|
const bot = await guild.members.fetchMe();
|
||||||
|
const role = await guild.roles.fetch(roleId);
|
||||||
|
if (!role) throw new Error("The configured role for this button doesn't exist.");
|
||||||
|
if (role.position > bot.roles.highest.position) throw new Error(`The configured role (\`${role.name}\`) is higher than my highest role.`);
|
||||||
|
|
||||||
|
if (member.roles.cache.has(roleId)) {
|
||||||
|
await member.roles.remove(roleId);
|
||||||
|
await interaction.editReply({ content: 'Role removed.' });
|
||||||
|
} else {
|
||||||
|
await member.roles.add(roleId);
|
||||||
|
await interaction.editReply({ content: 'Role Added' });
|
||||||
|
}
|
||||||
|
} catch (error: Error | any) {
|
||||||
|
await interaction.editReply({ content: error.message }).catch(() => {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new RoleButtonButton();
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
import { ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, ChannelType, Client, MessageFlags, PermissionFlagsBits } from 'discord.js';
|
|
||||||
import { Database } from '../shared/Database';
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'unclaim-ticket',
|
|
||||||
handler: async function (client: Client, interaction: ButtonInteraction) {
|
|
||||||
const channel = await interaction.channel?.fetch();
|
|
||||||
|
|
||||||
if (!channel || !channel.isThread() || !channel.isSendable() || channel.type != ChannelType.PrivateThread)
|
|
||||||
return interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Oops. Something went wrong.' });
|
|
||||||
|
|
||||||
if (!interaction.memberPermissions) return interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'An error has occurred.' });
|
|
||||||
|
|
||||||
if (!interaction.memberPermissions.has(PermissionFlagsBits.ManageMessages)) return interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'You do not have permission to unclaim this ticket.' });
|
|
||||||
|
|
||||||
if (!interaction.message.content.split('\n').at(-1)!.includes(`<@${interaction.user.id}>`)) return interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'You did not claim this ticket.' });
|
|
||||||
|
|
||||||
const guild = await client.guilds.fetch(interaction.guildId!);
|
|
||||||
|
|
||||||
const settings = await Database.getOrCreateSettings(guild.id);
|
|
||||||
if (!settings.private_help_role_id) return interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Failed to unclaim ticket.' });
|
|
||||||
|
|
||||||
const closeButton = new ButtonBuilder()
|
|
||||||
.setCustomId('close-ticket')
|
|
||||||
.setLabel('Click here if you no longer need help')
|
|
||||||
.setStyle(ButtonStyle.Danger);
|
|
||||||
|
|
||||||
const claimButton = new ButtonBuilder()
|
|
||||||
.setCustomId('claim-ticket')
|
|
||||||
.setLabel('Claim ticket')
|
|
||||||
.setStyle(ButtonStyle.Primary);
|
|
||||||
|
|
||||||
const row = new ActionRowBuilder<ButtonBuilder>().addComponents(closeButton, claimButton);
|
|
||||||
|
|
||||||
await interaction.message.edit({
|
|
||||||
content: interaction.message.content.split('\n').slice(0, -1).join('\n').trim(),
|
|
||||||
components: [row]
|
|
||||||
});
|
|
||||||
|
|
||||||
await interaction.reply({ content: 'Ticket unclaimed.', flags: [MessageFlags.Ephemeral] });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
import { ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, ChannelType, Client, MessageFlags } from 'discord.js';
|
||||||
|
import { Database } from '../shared/Database';
|
||||||
|
import { Button } from '../types';
|
||||||
|
|
||||||
|
class UnclaimTicketButton implements Button<Client> {
|
||||||
|
id = 'unclaim-ticket';
|
||||||
|
|
||||||
|
async execute(context: Client<boolean>, interaction: ButtonInteraction): Promise<void> {
|
||||||
|
if (!interaction.inGuild()) return;
|
||||||
|
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
|
||||||
|
|
||||||
|
try {
|
||||||
|
const channel = await context.channels.fetch(interaction.channelId);
|
||||||
|
|
||||||
|
if (!channel) throw new Error("The interaction channel couldn't be fetched.");
|
||||||
|
if (!channel.isThread() || channel.type != ChannelType.PrivateThread) throw new Error('This interaction was not run in a ticket thread.');
|
||||||
|
if (!channel.isSendable()) throw new Error("I don't have permission to send messages in this channel.");
|
||||||
|
|
||||||
|
const settings = await Database.getOrCreateSettings(interaction.guildId);
|
||||||
|
if (!settings.private_help_role_id) throw new Error("`private_help_role_id` hasn't been configured. Please report this error to staff.");
|
||||||
|
|
||||||
|
const guild = await context.guilds.fetch(interaction.guildId);
|
||||||
|
const member = await guild.members.fetch(interaction.user.id);
|
||||||
|
if (!member.roles.cache.has(settings.private_help_role_id)) throw new Error("You don't have permission to claim tickets.");
|
||||||
|
|
||||||
|
if (!interaction.message.content.split('\n').at(-1)!.includes(`<@${interaction.user.id}>`)) throw new Error('You haven\'t claimed this ticket.');
|
||||||
|
|
||||||
|
const closeButton = new ButtonBuilder()
|
||||||
|
.setCustomId('close-ticket')
|
||||||
|
.setLabel('Click here if you no longer need help')
|
||||||
|
.setStyle(ButtonStyle.Danger);
|
||||||
|
|
||||||
|
const claimButton = new ButtonBuilder()
|
||||||
|
.setCustomId('claim-ticket')
|
||||||
|
.setLabel('Claim ticket')
|
||||||
|
.setStyle(ButtonStyle.Primary);
|
||||||
|
|
||||||
|
const row = new ActionRowBuilder<ButtonBuilder>().addComponents(closeButton, claimButton);
|
||||||
|
|
||||||
|
await interaction.message.edit({
|
||||||
|
content: interaction.message.content.split('\n').slice(0, -1).join('\n').trim(),
|
||||||
|
components: [row]
|
||||||
|
});
|
||||||
|
|
||||||
|
await interaction.editReply({ content: 'Ticket unclaimed.' });
|
||||||
|
} catch (error: Error | any) {
|
||||||
|
await interaction.editReply({ content: error.message }).catch(() => {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new UnclaimTicketButton();
|
||||||
@@ -189,7 +189,7 @@ export default {
|
|||||||
const moderatorChannel = interaction.options.getChannel('moderator-channel');
|
const moderatorChannel = interaction.options.getChannel('moderator-channel');
|
||||||
if (moderatorChannel) {
|
if (moderatorChannel) {
|
||||||
await Database.updateSettings(interaction.guildId, 'moderator_channel_id', moderatorChannel.id);
|
await Database.updateSettings(interaction.guildId, 'moderator_channel_id', moderatorChannel.id);
|
||||||
response.push(`**moderator_channel_id** has been set to": ${moderatorChannel}.`);
|
response.push(`**moderator_channel_id** has been set to: ${moderatorChannel}.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const adminRole = interaction.options.getRole('admin-role');
|
const adminRole = interaction.options.getRole('admin-role');
|
||||||
|
|||||||
+6
-7
@@ -1,4 +1,5 @@
|
|||||||
import { Client, GatewayIntentBits, MessageFlags, Partials } from 'discord.js';
|
import { ButtonInteraction, Client, GatewayIntentBits, MessageFlags, Partials } from 'discord.js';
|
||||||
|
import buttons from './buttons';
|
||||||
import { config } from './config';
|
import { config } from './config';
|
||||||
import events from './events';
|
import events from './events';
|
||||||
import { Database } from './shared/Database';
|
import { Database } from './shared/Database';
|
||||||
@@ -37,7 +38,6 @@ const client = new Client({
|
|||||||
|
|
||||||
const commands: Handler[] = [];
|
const commands: Handler[] = [];
|
||||||
const contextMenus: Handler[] = [];
|
const contextMenus: Handler[] = [];
|
||||||
const buttons: Handler[] = [];
|
|
||||||
const modals: Handler[] = [];
|
const modals: Handler[] = [];
|
||||||
const menus: Handler[] = [];
|
const menus: Handler[] = [];
|
||||||
|
|
||||||
@@ -93,11 +93,12 @@ client.on('interactionCreate', async (interaction) => {
|
|||||||
const id = interaction.customId.split('_')[0];
|
const id = interaction.customId.split('_')[0];
|
||||||
|
|
||||||
for (const button of buttons) {
|
for (const button of buttons) {
|
||||||
if (id == button.name) {
|
if (button.id != id) continue;
|
||||||
button.handler(client, interaction, ...interaction.customId.split('_').slice(1));
|
|
||||||
|
Promise.resolve((button.execute as (context: Client, interaction: ButtonInteraction, ...args: unknown[]) => Promise<void>)(client, interaction, ...interaction.customId.split('_').slice(1))
|
||||||
|
.catch(e => console.error('An error occurred while handling a button interaction: ', e)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else if (interaction.isModalSubmit()) {
|
} else if (interaction.isModalSubmit()) {
|
||||||
// Handle modal submissions.
|
// Handle modal submissions.
|
||||||
const id = interaction.customId.split('_')[0];
|
const id = interaction.customId.split('_')[0];
|
||||||
@@ -126,14 +127,12 @@ client.on('clientReady', async () => {
|
|||||||
|
|
||||||
await loadHandlersFrom('commands', commands);
|
await loadHandlersFrom('commands', commands);
|
||||||
await loadHandlersFrom('context-menus', contextMenus);
|
await loadHandlersFrom('context-menus', contextMenus);
|
||||||
await loadHandlersFrom('buttons', buttons);
|
|
||||||
await loadHandlersFrom('modals', modals);
|
await loadHandlersFrom('modals', modals);
|
||||||
await loadHandlersFrom('menus', menus);
|
await loadHandlersFrom('menus', menus);
|
||||||
|
|
||||||
await refreshCommands(client);
|
await refreshCommands(client);
|
||||||
|
|
||||||
await initIfNecessary(client, commands);
|
await initIfNecessary(client, commands);
|
||||||
await initIfNecessary(client, buttons);
|
|
||||||
await initIfNecessary(client, modals);
|
await initIfNecessary(client, modals);
|
||||||
await initIfNecessary(client, menus);
|
await initIfNecessary(client, menus);
|
||||||
|
|
||||||
|
|||||||
Vendored
+6
@@ -0,0 +1,6 @@
|
|||||||
|
import { ButtonInteraction } from 'discord.js';
|
||||||
|
|
||||||
|
export interface Button<Context> {
|
||||||
|
id: string;
|
||||||
|
execute(context: Context, interaction: ButtonInteraction, ...args: any): Promise<void>;
|
||||||
|
}
|
||||||
Vendored
+1
@@ -1,3 +1,4 @@
|
|||||||
|
export * from './button.d';
|
||||||
export * from './command.d';
|
export * from './command.d';
|
||||||
export * from './database-types.d';
|
export * from './database-types.d';
|
||||||
export * from './event.d';
|
export * from './event.d';
|
||||||
|
|||||||
Reference in New Issue
Block a user