Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { config } from '../modules/config/cfg';
- import * as db from '../database/betterKV';
- const role = config.modules.roles;
- const chan = config.modules.channels;
- const group = config.slashCommands;
- const logChannel: string = chan.logging_channel.id;
- const ticketChannel: string = chan.tickets_channel.id;
- const ticketChannelCategory: string = chan.tickets_category.id;
- const adminRoles: Array<string> = [role.ticket_manager.id];
- function intersection(arr1: Array<string>, arr2: Array<string>): number {
- return arr1.filter((value) => arr2.includes(value)).length;
- }
- discord.on(discord.Event.MESSAGE_CREATE, async (message) => {
- if (!(message.channelId == ticketChannel)) return;
- if (message.content.length > 100) {
- await message.delete();
- let msg = await message.reply(
- 'Your ticket name cannot contain more than 100 characters!'
- );
- await setTimeout(() => msg.delete(), 10000);
- }
- let guild = await discord.getGuild();
- let permissions = [
- {
- type: discord.Channel.PermissionOverwriteType.MEMBER,
- id: message.author.id,
- allow: 0x00000400,
- },
- {
- type: discord.Channel.PermissionOverwriteType.ROLE,
- id: guild.id,
- deny: 0x00000400,
- },
- ];
- for (let role of adminRoles)
- permissions.push({
- type: discord.Channel.PermissionOverwriteType.ROLE,
- id: role,
- allow: 0x00000400,
- });
- let channel = (await guild.createChannel({
- name: message.content,
- type: discord.Channel.Type.GUILD_TEXT,
- permissionOverwrites: permissions,
- parentId: ticketChannelCategory,
- })) as discord.GuildTextChannel;
- await channel.sendMessage(
- `${message.member?.toMention()} your ticket has been opened. You may provide further details as a staff member will be with you shortly.`
- );
- await message.delete();
- await db.save(channel.id, [`Log of ticket with topic: ${message.content}`]);
- });
- discord.on(discord.Event.MESSAGE_CREATE, async (message) => {
- if (!(await db.exist(message.channelId))) return;
- db.transact(message.channelId, (val) =>
- (val as Array<string>).concat(
- `${message.author.username}: ${message.content}`
- )
- );
- });
- group.register(
- {
- name: 'close',
- description: 'Closes and archives the ticket, channel, and its history.',
- options: (args) => ({
- channel_id: args.string({
- name: 'channelid',
- description: 'The channel you want to close',
- required: false,
- }),
- }),
- },
- async (message, { channel_id }) => {
- channel_id = channel_id ?? message.channelId;
- if (intersection(message.member.roles, adminRoles) == 0)
- return await message.respondEphemeral(
- 'You lack the permissions to do this'
- );
- if (!(await db.exist(channel_id)))
- return await message.respondEphemeral('This channel id is not a ticket!');
- let logChannelObject: discord.GuildTextChannel | null =
- await discord.getGuildTextChannel(logChannel);
- let ticketChannelObject: discord.GuildTextChannel | null =
- await discord.getGuildTextChannel(channel_id);
- let _logs: Array<string> = (await db.get(channel_id)) as Array<string>;
- let logs: string = _logs.join('\n');
- await ticketChannelObject?.delete();
- await db.del(channel_id);
- logChannelObject?.sendMessage({
- attachments: [
- {
- name: 'log.txt',
- data: new TextEncoder().encode(logs).buffer,
- },
- ],
- });
- }
- );
Add Comment
Please, Sign In to add comment