UNPKG

djs-tickets

Version:

An easy to setup ticket system discord bot for Djs v12/v13, works for unlimited servers

176 lines (175 loc) 9.17 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.close = exports.setup = exports.start = void 0; /** Have to Import Discord/Enmap the old way :( */ var Discord = require('discord.js'); var enmap = require('enmap'); /** Initialise EnMap */ var settings = new enmap({ name: 'settings', autoFetch: true, cloneLevel: 'deep', fetchAll: true, }); var start = function (client /** Doesn't allow me to use Discord.Client*/, MessageEmbed) { if (!client) throw new Error('Client not provided, kindly refer to the documentation!'); if (typeof client !== typeof Discord.Client) throw new Error('Invalid Client provided, kindly refer to the documentation!'); client.on('messageReactionAdd', function (reaction, user, message) { return __awaiter(void 0, void 0, void 0, function () { var ticketid; return __generator(this, function (_a) { switch (_a.label) { case 0: if (!user.partial) return [3 /*break*/, 2]; return [4 /*yield*/, user.fetch()]; case 1: _a.sent(); _a.label = 2; case 2: if (!reaction.partial) return [3 /*break*/, 4]; return [4 /*yield*/, reaction.fetch()]; case 3: _a.sent(); _a.label = 4; case 4: if (!reaction.message.partial) return [3 /*break*/, 6]; return [4 /*yield*/, reaction.message.fetch()]; case 5: _a.sent(); _a.label = 6; case 6: if (user.bot) return [2 /*return*/]; return [4 /*yield*/, settings.get("".concat(reaction.message.guild.id, "-ticket"))]; case 7: ticketid = _a.sent(); if (!ticketid) return [2 /*return*/]; if (reaction.message.id == ticketid && reaction.emoji.name == '🎫') { reaction.users.remove(user); reaction.message.guild.channels .create("ticket-".concat(user.username), { permissionOverwrites: [ { id: user.id, allow: ['SEND_MESSAGES', 'VIEW_CHANNEL'], }, { id: reaction.message.guild.roles.everyone, deny: ['VIEW_CHANNEL'], }, { id: reaction.message.guild.roles.cache.find(function (role) { return role.name === 'Patrol'; }), allow: ['SEND_MESSAGES', 'VIEW_CHANNEL'], }, ], type: 'text', }) .then(function (channel) { return __awaiter(void 0, void 0, void 0, function () { var NewEmbed, embed; return __generator(this, function (_a) { NewEmbed = new Discord.MessageEmbed() .setTitle('Welcome to your ticket!') .setDescription('Support Team will be with you shortly') .setColor('RANDOM'); embed = MessageEmbed ? MessageEmbed : NewEmbed; channel.send({ embeds: [embed] }); return [2 /*return*/]; }); }); }); } return [2 /*return*/]; } }); }); }); }; exports.start = start; var setup = function (MessageObject, ChannelID, Embed) { return __awaiter(void 0, void 0, void 0, function () { var channel, temp_embed, embed, sent; return __generator(this, function (_a) { switch (_a.label) { case 0: if (!MessageObject || !ChannelID) throw new Error('Proper Arguments Not Provided!'); channel = MessageObject.guild.channels.cache.find(function (channel) { return channel.id === ChannelID; }); temp_embed = new Discord.MessageEmbed() .setTitle('Ticket System') .setDescription('React to open a ticket!') .setFooter('Ticket System') .setColor('00ff00'); embed = Embed ? Embed : temp_embed; return [4 /*yield*/, channel.send({ embeds: [embed] })]; case 1: sent = _a.sent(); sent.react('🎫'); settings.set("".concat(MessageObject.guild.id, "-ticket"), sent.id); MessageObject.channel.send('Ticket System Setup Done!'); return [2 /*return*/]; } }); }); }; exports.setup = setup; var close = function (message, transcript) { return __awaiter(void 0, void 0, void 0, function () { var channel; return __generator(this, function (_a) { if (!message || !transcript) throw new Error('Proper Arguments Not Provided!'); if (!message.channel.name.includes('ticket-')) return [2 /*return*/, message.channel.send('You cannot use that here!')]; channel = message.channel; if (transcript === true) { channel.messages.fetch({ limit: 80 }).then(function (messages) { var content = messages.map(function (message) { return message.content && message.content; }).join('\n'); message.author.send("Transcript for your ticket in ".concat(message.guild.name, " Server")); message.author.send({ files: [{ name: 'transcript.txt', attachment: Buffer.from(content) }] }); message.channel.send("I have dmed you transcript if your dms are opened. Deleting channel in 20 seconds. Here is the transcript as well."); message.channel.send({ files: [{ name: 'transcript.txt', attachment: Buffer.from(content) }] }); }); setTimeout(function () { message.channel.delete(); }, 20000); } else { message.channel.delete(); } return [2 /*return*/]; }); }); }; exports.close = close;