-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
2 lines (2 loc) · 3.4 KB
/
index.js
1
2
// Thank you for using ModMail! Copyright (c) 2020 Johnodon.com. All Rights Reserved. Licensed under the MIT license located in the LICENSE file.
const Discord=require("discord.js"),client=new Discord.Client,fetch=require("node-fetch"),{token:token,server_id:server_id,channel_prefix:channel_prefix,modmail_viewing_role_id:modmail_viewing_role_id,status:status,modmail_category_name:modmail_category_name,display_mod_name:display_mod_name}=require("./config.json"),version="1.0.4";console.log("Bot starting... Please wait."),client.once("ready",async()=>{await client.user.setActivity(status,{type:"PLAYING"}),await console.log("Bot has started."),fetch("https://www.johnodon.com/modmail/latest.json").then(e=>e.json()).then(e=>{if(e)return"1.0.4"!=e.version?console.log("Your current modmail version is out of date! Please visit https://github.com/JohnodonCode/modmail and copy the code from the index file into your index file."):console.log("Your current version of modmail is up to date.")})}),client.on("message",async e=>{const t=await client.guilds.cache.get(server_id);if(!e.author.bot)if("dm"!=e.channel.type)if(e.channel.name.startsWith(`${channel_prefix}_`)){const t=e.channel.name.split("_")[2];if("=close"==e.content){await e.channel.delete();const s=(new Discord.MessageEmbed).setTitle("Ticket closed.").setColor("RANDOM").setDescription("To open another ticket, send me a message!");return void await client.users.cache.get(t).send(s)}if(e.content.startsWith("="))return;let s="";s=display_mod_name?e.author.tag:"Anonymous#0000";const n=(new Discord.MessageEmbed).setTitle("Message Received").setColor("RANDOM").setDescription(`**From ${s}**\n${e.content}`);client.users.cache.get(t).send(n);const i=(new Discord.MessageEmbed).setTitle("Message sent.").setColor("RANDOM").setDescription("Sent a message to "+client.users.cache.get(t).username+": "+e.content);await e.channel.send(i)}else;else{if(!t.member(e.author.id))return e.channel.send(`You must be in ${t.name} to use ModMail!`);const s=`${channel_prefix}_${e.author.username.toLowerCase()}_${e.author.id}`.split(" ").join("-");let n=await t.channels.cache.find(e=>e.name==modmail_category_name&&"category"==e.type);n||(n=await t.channels.create(modmail_category_name,{type:"category",permissionOverwrites:[{id:modmail_viewing_role_id,allow:["VIEW_CHANNEL"],allow:["SEND_MESSAGES"]},{id:t.id,deny:["VIEW_CHANNEL"]},{id:client.user.id,allow:["VIEW_CHANNEL"],allow:["SEND_MESSAGES"]}]}));let i=await t.channels.cache.find(e=>e.name==s&&"text"==e.type);if(!i){i=await t.channels.create(s,{type:"text",permissionOverwrites:[{id:modmail_viewing_role_id,allow:["VIEW_CHANNEL"]},{id:t.id,deny:["VIEW_CHANNEL"]},{id:client.user.id,allow:["VIEW_CHANNEL"]}]});const n=(new Discord.MessageEmbed).setTitle("New Ticket").setColor("RANDOM").setDescription("Type a message in this channel to reply. Message starting with `=` are ignored and can be used for staff discussion. Type `=close` to close and delete this channel.");await i.send(n);const o=(new Discord.MessageEmbed).setTitle("New Ticket Opened").setColor("RANDOM").setDescription("You opened a ticket!");await e.channel.send(o)}i&&n&&i.setParent(n.id);const o=(new Discord.MessageEmbed).setTitle("Message Received").setColor("RANDOM").setDescription(e.content);i.send(o);const a=(new Discord.MessageEmbed).setTitle("Message sent.").setColor("RANDOM").setDescription("Sent a message to the moderators: "+e.content);await e.channel.send(a)}}),client.login(token);