Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //// Requirements
- const Discord = require("discord.js");
- //// Create Bot
- const bot = new Discord.Client({ disableEveryone: true, autoReconnect: true });
- const createEmbed = require("embed-creator");
- const fs = require("fs");
- const JSON = require('circular-json');
- const log = require("umi-log");
- //let prefixes = JSON.parse(fs.readFileSync("./prefixes.json", "utf8")); // Load all prefixes
- //const r = require('rethinkdb');
- //const util = require("util");
- //const GoogleImages = require('google-images');
- //const SearchClient = new GoogleImages('009029638331239799370:f0_49os2upg', 'AIzaSyADKeGQ8LPdMIi7D5nJPmNDryN_5XK2GkQ'); // This is FIRE'S API KEY. DON'T ABUSE IT.
- const snekfetch = require("snekfetch");
- //// Files
- const Config = require("./Config.js");
- const ParseJson = require("./JsonParser.js");
- const donut = "335630416914677771"; //bot.emojis.find("name", "donut");
- // Keywords must be lowercase due to checking system
- const menu = [
- {
- "keywords": ["plain donut", "cake donut", "cake", "plain", "donut"],
- "urls": [
- "https://www.krispykreme.com/SharedContent/User/32/321a995f-f001-4062-9767-9670b1b13ed1.png",
- "https://www.donutbar.com/wp-content/uploads/2017/05/donut-bar-homers.png"
- ]
- },
- {
- "keywords": ["kawaii donut", "kawaii"],
- "urls": [
- "http://kao-ani.com/wp-content/uploads/2013/08/animal-donut-1.jpg",
- "https://static.mijnwebwinkel.nl/winkel/mostcutest/image/cache/full/2cf86adeb2780e7cdaccb53906870558cc5c53a0.jpg",
- "http://kao-ani.com/wp-content/uploads/2013/08/animal-donut-0.jpg"
- ]
- },
- {
- "keywords": ["strawberry donut", "donut", "strawberry"],
- "urls": [
- "https://i0.wp.com/bakingamoment.com/wp-content/uploads/2017/04/2803-strawberry-donuts-square.jpg?resize=720%2C720&ssl=1",
- "https://butterwithasideofbread.com/wp-content/uploads/2017/05/Homemade-Strawberry-Glazed-Donuts.BSB_.IMG_0149.jpg",
- "https://delightfulemade.com/wp-content/uploads/2015/01/Strawberry-Coffee-Cake-Donuts-DelightfulEMade.com-hz1-768x512.png"
- ]
- },
- {
- "keywords": ["caramel donut", "caramel", "donut"],
- "urls": [
- "http://whiteonricecouple.com/recipe/images/donuts-485-1.jpg",
- "https://images-gmi-pmc.edge-generalmills.com/fb2cc1ad-ed1b-4c03-b11f-3bc7690893fd.jpg",
- "https://www.bakingmad.com/BakingMad/media/content/Recipes/Other/Salted-caramel-ring-doughnuts/1-salted-caramel-doughnut-web.jpg",
- "https://blog.williams-sonoma.com/wp-content/uploads/2017/05/june-29-Salted-Caramel-Doughnuts-302.jpg"
- ]
- },
- {
- "keywords": ["rainbow donut", "rainbow", "donut"],
- "urls": [
- "http://asparkofcreativity.com/wp-content/uploads/2017/07/FullSizeRender-11-1024x768.jpg",
- "https://truffle-assets.imgix.net/55b2916f-rainbowdoughnuts.png",
- "https://cdn.shopify.com/s/files/1/1100/2012/articles/ED0A5458_1024x1024.jpg?v=1495045850",
- "http://cookiescupcakesandcardio.com/wp-content/uploads/2015/08/DSC_7027site.jpg",
- "http://www.littlethings.com/app/uploads/2017/03/recipe_card_RainbowDonuts-copy-850x444.jpg"
- ]
- },
- {
- "keywords": ["glazed donut", "glazed", "donut"],
- "urls": [
- "https://www.krispykreme.com/SharedContent/User/97/972786a8-7d91-4d82-983e-6b67a4a93865.png",
- "https://www.vaporfi.com/media/catalog/product/cache/9/image/9df78eab33525d08d6e5fb8d27136e95/g/l/glazed-donut-flavoring_1.jpg",
- "http://freebiechick.com/wp-content/uploads/2014/09/Free-Glazed-Donut-Krispy-Kreme-Talk-Like-A-Pirate-Day.jpg",
- "https://ww2.kqed.org/bayareabites/wp-content/uploads/sites/24/2015/10/donuts-glaze-rack-drip.jpg",
- "http://assets.epicurious.com/photos/54b0226d766062b20344580a/master/pass/51160200_glazed-doughnuts_1x1.jpg",
- "http://i.imgur.com/hUogZJF.jpg",
- "http://vaporgeekz.com/wp-content/uploads/2014/11/Glazed-Frosted-Donut-vapor-geekz-e-liquid-e-juice-vape-e-cig.png",
- "https://s-media-cache-ak0.pinimg.com/564x/f5/cf/a9/f5cfa93ba9c8557f1decf44b0e421d50.jpg",
- "http://cdn.playbuzz.com/cdn/a98c7916-a8f2-4b69-96e3-6eceda171d2f/ddc27dfc-3459-4552-817e-eb2f12078a29.jpg",
- "https://gunsmokeandknitting.files.wordpress.com/2012/07/krispykreme_this.jpg",
- "https://cdn.pixabay.com/photo/2015/10/17/16/35/glazed-donut-992767_960_720.jpg",
- "https://cdn3.volusion.com/ncjkx.vuwnc/v/vspfiles/photos/cp-glz-30-2.jpg?1452694735"
- ]
- },
- {
- "keywords": ["chocolate donut", "chocolate", "donut"],
- "urls": [
- "http://wdy.h-cdn.co/assets/cm/15/09/54ef9111b81cb_-_chocolate-glazed-yeast-doughnuts-recipe-wdy1012-de.jpg",
- "http://i.huffpost.com/gadgets/slideshows/393568/slide_393568_4810506_free.jpg",
- "https://cdn.pixabay.com/photo/2014/11/08/16/34/donut-522440_960_720.jpg",
- "https://www.deerfieldsbakery.com/images/items/Donuts/Donut%20Double%20Chocolate_MD.JPG",
- "https://i.ytimg.com/vi/GrtsPI_TC10/maxresdefault.jpg",
- "http://s.eatthis-cdn.com/media/images/ext/589494018/low-sugar-dunkin-choco-frosted.jpg",
- "http://www.bettervapes.com/assets/images/chocolateglazeddonut.jpg",
- "http://jefkalil.com/wp-content/uploads/2015/02/chocolate-donuts-seo1.jpg",
- "http://sallysbakingaddiction.com/wp-content/uploads/2014/04/Sallys-Baking-Addiction-Chocolate-Frosted-Donuts.jpg",
- "http://25.media.tumblr.com/tumblr_lfbgc1X2wo1qaunteo1_400.jpg",
- "http://www.bigchocolatedonut.com/chocolate_donut.png",
- "https://www.krispykreme.com/SharedContent/User/96/96a56be1-02b7-4f59-8cf2-160218bbacb2.png",
- "http://images.wisegeek.com/chocolate-iced-donuts.jpg"
- ]
- },
- {
- "keywords": ["random donut", "random", "donut", "donuts"],
- "urls": [
- "http://www.arizonafoothillsmagazine.com/valleygirlblog/wp-content/uploads/RainbowDonutsCafeSpecial.jpg",
- "http://kao-ani.com/wp-content/uploads/2013/08/animal-donut-0.jpg",
- "http://thedonutbaker.co.in/wp-content/uploads/2014/10/service-1.jpg",
- "https://s-media-cache-ak0.pinimg.com/originals/d1/b6/54/d1b6543f8fbbaea4003e841d17f0edf0.jpg",
- "http://cdn2.blisstree.com/wp-content/uploads/2013/06/shutterstock_137004860.jpg",
- "http://www.holeydonuts.net/images/donuts-main.png",
- "http://macaronikid.com/media/town/snellville/article-1041184-1439507139.76.png"
- ]
- }
- ];
- //// Define channel IDs ////
- const delivery = ["347355829223161867"];
- const kitchens = ["295652105400614922"];
- /// Edit by: EdibleDerpy ///
- //Important to prevent crashes
- process.on("unhandledRejection", e => { log.error(e); });
- //// Change up log.notify
- /*
- log.notify = function() {
- this._stdout.write(util.format.apply(this, arguments) + '\n');
- let chan = bot.channels.get("295978480292855808");
- if (chan) chan.send(util.format.apply(this, arguments));
- };
- */
- //// Functions
- // General Functions
- function GaA(args, text) {
- if (!text) return "";
- total = 0;
- for (let i = 0; i < args.length; i++) {
- total = total + (args[i].length + 1);
- }
- return text.substring(total, text.length);
- }
- function beginGames(bot) {
- let games = ["Cooking Donuts...", "Donuts!", "Cookin' Donuts", "d!order Donuts", "<3 Donuts", "with Donuts"];
- //bot.user.setGame(games[Math.round(Math.random() * ((games.length - 1) - 0) + 0)]);
- bot.user.setPresence({ game: { name: games[Math.round(Math.random() * ((games.length - 1) - 0) + 0)], type: 0 } });
- setInterval(() => {
- bot.user.setPresence({ game: { name: games[Math.round(Math.random() * ((games.length - 1) - 0) + 0)], type: 0 } });
- }, 300000);
- }
- function isEmployee(member) {
- if (member.roles.find(r => r.name.toLowerCase() === "employees") && member.guild.id === '294619824842080257') return true;
- if (Config.owners.includes(member.id)) return true;
- return false;
- }
- function getAvatarUrl(img, id) {
- if (!img) return img;
- let hash = img.substring(img.indexOf(id.toString() + "/") + (id.toString() + "/").length, img.indexOf(".jpg"));
- return "https://images.discordapp.net/avatars/" + id + "/" + hash + ".png";
- }
- // Order Functions
- function randomString(length) {
- let pos = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890";
- let str = 0;
- for (let i = 0; i < length; i++) {
- str += pos.charAt(Math.floor(Math.random() * pos.length));
- }
- return str;
- }
- // Ignore it's broken.. //
- /* Object.prototype.post = function(content) {
- try {
- return this.send(content).catch((e) => {
- log.error("Cannot send message " + e);
- });
- } catch (e) {
- return log.error("Cannot send message " + e);
- }
- }; */
- function updateWebsites(bot) {
- if (Config.updateWebsites === true) {
- // bot.shard.fetchClientValues("guilds.size").then(results => {
- // scount = results.reduce((prev, val) => prev + val, 0);
- scount = bot.guilds.size;
- log.notify("[Discord] Updating websites...");
- snekfetch.post(`https://discordbots.org/api/bots/335637950044045314/stats`)
- .set('Authorization', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjMzNTYzNzk1MDA0NDA0NTMxNCIsImJvdCI6dHJ1ZSwiaWF0IjoxNTEwNTQ2ODQ4fQ.vHlCEztno7r-btk-vETlrXOzjmYBrnuUfyaWO-gH6WQ')
- .send({ server_count: scount})
- .then(log.notify('[Discord] Updated discordbots.org stats.'))
- .catch(e => log.error("[Discord] ", e.body));
- snekfetch.post(`https://bots.discord.pw/api/bots/335637950044045314/stats`)
- .set('Authorization', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySUQiOiIxMTI3MzI5NDY3NzQ5NjIxNzYiLCJyYW5kIjo0MjcsImlhdCI6MTQ4MjI2NTE0MX0.dHF39EeVOFgxi1SpxzNmAVNDewoZJffcoNBC3sFZ9Xk')
- .send({ server_count: scount})
- .then(log.notify('[Discord] Updated bots.discord.pw stats.'))
- .catch(e => log.error("[Discord] ", e.body));
- /* snekfetch.post(`https://bots.discordlist.net/api`)
- .set('Authorization', 'O413oNvfsB')
- .send({ server_count: scount}) discordlist is bad
- .then(log.notify('[Discord] Updated bots.discordlist.net stats.'))
- .catch(e => log.error("[Discord] ", e.body)); */
- } else { log.notify("[Discord] Website updating has been turned off."); }
- }
- bot.on("guildCreate", guild => {
- //if (bot.guilds.size % 5 === 0) updateWebsites(bot);
- updateWebsites(bot);
- log.notify(`[Discord] I've joined ${guild.name}!`);
- ParseJson("./Blacklist.json", (err, blacklist) => {
- if (err) return log.error(err);
- if (blacklist.includes(guild.id)) {
- guild.owner.send("I apologze, but your server has been blacklisted from Discord Donuts.");
- return guild.leave();
- }
- });
- bot.channels.get("335919194887421967").send("**" + `New Guild Added! :tada: :: ${guild.name} :: ${guild.memberCount} Members :: Created By ${guild.owner.user.username} :: ` + `${bot.guilds.size} Servers` + "**");
- });
- bot.on("guildDelete", guild => {
- log.notify(`[Discord] I've left ${guild.name}!`);
- updateWebsites(bot);
- bot.channels.get("335919194887421967").send("**" + `We just lost a guild! :sob: :: ${guild.name} :: ${guild.memberCount} Members :: Created By ${guild.owner.user.username} :: ` + `${bot.guilds.size} Servers` + "**");
- });
- bot.on("ready", () => {
- bot.user.setStatus("online");
- beginGames(bot);
- updateWebsites(bot);
- log.notify(`[Discord] Connected! (ID: ${bot.user.id})`);
- /*
- // RethinkDB Module Setup \\
- r.connect({ host: 'localhost', port: 28069, db: 'donuts', authKey: "" }, function(err, conn) {
- global.connection = conn;
- if (err) {
- log.error("[RethinkDB] Could not open a connection to initialize the database\n"+err.message);
- process.exit(1);
- }
- log.notify("[RethinkDB] Connected to NSOfficial Dedicated RethinkDB");
- });
- */
- });
- bot.on("disconnect", () => {
- log.error(`[Discord] Disconnected! Attempting to reconnect...`);
- process.exit();
- });
- bot.on("error", (err) => { log.error("[Discord] ", err); });
- bot.on("message", msg => {
- // Checks
- if (!msg.guild || !msg.guild.available) return;
- if (msg.author.id == bot.user.id || msg.author.bot) return;
- ParseJson("./Blacklist.json", (err, blacklist) => {
- if (err) return log.error(err);
- //if (blacklist.includes(msg.author.id)) return msg.author.send("I apologize, but you've been blacklisted from this bot!"); temp fix
- if (blacklist.includes(msg.guild.id)) {
- msg.guild.owner.send("I apologize, but your server has been blacklisted from Discord Donuts.");
- return msg.guild.leave();
- }
- //if(prefixes[msg.guild.id] == null){ prefixes[msg.guild.id] = Config.prefix; }
- prefixMention = new RegExp(`^<@!?${bot.user.id}>`);
- if (!msg.content.startsWith(Config.prefix) || !msg.content.startsWith(prefixMention)) return;
- //if (!msg.content.startsWith(prefixes[msg.guild.id]) && !prefixMention.test(msg.content)) { return; }
- prefixLength = Config.prefix.length;
- //if (prefixMention.test(msg.content)) {
- //msg.content = msg.content.replace("<@" + bot.user.id + "> ", "").replace("<@!" + bot.user.id + "> ", "");
- //msg.content = prefixes[msg.guild.id] + msg.content;
- //}
- if (msg.guild.member(bot.user.id).hasPermission("SEND_MESSAGES")) return;
- // Variables
- let content = msg.content;
- let text = content.toLowerCase();
- let author = msg.author;
- let member = msg.member;
- let avatarURL = author.avatarURL;
- let channel = msg.channel;
- let orderChan = bot.channels.get("294620411721940993");
- let embedColor = parseInt("0x" + Math.floor(Math.random() * 16777215).toString(16));
- msg.isEmployee = isEmployee(member);
- msg.isAdmin = (Config.owners.includes(author.id) ? true : false);
- //msg.isDelivery = isDelivery(member); removed
- let args = content.split(" ");
- let argsLower = text.split(" ");
- let command = text.substring(prefixLength, argsLower[0].length);
- if (!msg.guild.member(bot.user.id).hasPermission("EMBED_LINKS")) return channel.send(":x: Since I run almost 100% off of embeds, I require the **Embed Links** permission in this channel to work! Please give me this permission and try again.");
- // Orders.json
- ParseJson("./Orders.json", (err, orders) => {
- if (err) {
- log.error("Internal Error: " + (err.stack ? err.stack : err));
- return channel.send(":x: There was an internal error. Please contact a bot adminsitrator and try again later!");
- }
- let to = orders.filter(o => o.orderer.user.id == msg.author.id)[0]; // Stands for "The Order"
- // Normal Commands
- if (command == "ping") {
- let startTime = Date.now();
- return channel.send("Pinging...").then(pingMsg => {
- pingMsg.edit(`:ping_pong: Pong! Took \`${Math.round(Date.now() - startTime)}ms\`!`);
- });
- } else if (command == "wping") {
- return channel.send(`:ping_pong: Pong! Took \`${bot.ping.toFixed(0)}ms\`!`);
- } else if (command == "donate" || command == "patreon") {
- return channel.send("Want to help us stay running and cook donuts? Support us by donating! :arrow_right: **<https://patreon.com/discorddonuts>**");
- } else if (command == "website") {
- return channel.send("Want to check out our website? Here's the link! :arrow_right: <https://its-mustard.me/donuts>")
- } else if (command == "stats") {
- return channel.send({
- embed: {
- color: embedColor,
- author: {
- name: bot.user.username,
- icon_url: bot.user.avatarURL
- },
- title: 'Stats',
- description: 'Statistics of Discord Donuts',
- fields: [{
- name: 'Servers',
- value: `${bot.guilds.size}`
- }, {
- name: 'Users',
- value: `${bot.users.size}`
- }, {
- name: 'Channels',
- value: `${bot.channels.size}`
- }, {
- name: 'Memory Usage',
- value: `${(process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2)} MB`
- }, {
- name: 'Discord.js Version',
- value: `${Discord.version}`
- }],
- timestamp: new Date(),
- footer: {
- icon_url: bot.user.avatarURL,
- text: 'Discord Donuts'
- }
- }
- });
- } else if (command == "support" || command == "server") {
- return channel.send("Join our Discord server! The link's right there: :arrow_forward: <https://discord.gg/4KPHfqT>!");
- } else if (command == "invite") {
- return channel.send("Invite me here :arrow_forward: <https://discordapp.com/oauth2/authorize?client_id=335637950044045314&scope=bot&permissions=84993>!");
- } else if (command == "feedback") {
- if (!args[1]) return channel.send(":x: Make sure to include what you'd like to say!");
- let chan = bot.channels.get("295322429373284353");
- if (!chan) return channel.send(":x: I was unable to find the feedback channel. Please contact a bot administrator!");
- return chan.send(createEmbed(
- embedColor, {
- name: ("Feedback"),
- icon_url: avatarURL
- }, `New Feedback from ${msg.author.username}#${msg.author.discriminator} (${msg.author.id})`,
- GaA([args[0]], content)
- )).then(e => {
- channel.send(author.toString() + " thanks for giving us your feedback! We seriously appreciate it.");
- e.react("👍");
- e.react("👎");
- }).catch(e => {
- log.error(e);
- channel.send(":x: There was an error when sending a message to the feedback channel. Please contact a bot administrator!");
- });
- } else if (command == "tip") {
- if (!args[0]) return channel.send("Make sure to include how much you'd like to tip!");
- let tip = GaA([args[0]], content);
- let amount = parseInt(tip);
- if (isNaN(amount)) return channel.send(`${tip} is not a valid number.`);
- let chan = bot.channels.get("347316439402807306");
- if (!chan) return channel.send(":x: I was unable to find the tip channel. Please contact a bot administrator!");
- return chan.send(createEmbed(
- embedColor, {
- name: author.username,
- icon_url: avatarURL
- }, `${msg.author.username}#${msg.author.discriminator} (${msg.author.id}) left a tip!`,
- `$` + tip
- )).then(() => {
- channel.send(author.toString() + " Thanks for leaving a tip! We seriously appreciate it.");
- }).catch(e => {
- log.error(e);
- log.send(":x: There was an error when sending a message to the tip channel. Please contact a bot administrator!");
- });
- } else if (command == "help") {
- author.send({
- embed: {
- color: embedColor,
- title: "Discord Donuts Command List",
- description: "Here's a list of all of Discord Donuts commands!",
- author: {
- name: bot.user.username,
- icon_url: bot.user.avatarURL
- },
- thumbnail: {
- url: bot.user.avatarURL
- },
- fields: [{
- name: "help",
- value: "This message."
- }, {
- name: "support | server",
- value: "Links you to our server."
- }, {
- name: "ping",
- value: "Pings the server, and reports the send time."
- }, {
- name: "wping",
- value: "Pings the webhook API, and reports the send time."
- }, {
- name: "stats",
- value: "Shows statistics on the bot."
- }, {
- name: "invite",
- value: "Gives the bot invite link. All requested permissions needed."
- }, {
- name: "order",
- value: "Orders a donut for the staff in our server to make.\nExample: d!order Glazed donut"
- }, {
- name: "status",
- value: "Gets the status of your order."
- }, {
- name: "feedback",
- value: "Feedback on the bot. \nExample: d!feedback I love these donuts!"
- }, {
- name: "stats",
- value: "Gives bot statistics."
- }, {
- name: "donate | patreon",
- value: "Provides the link to support our amazing donut work via Patreon!"
- }, {
- name: "website",
- value: "Links you to our website!"
- }]
- }
- })
- return channel.send(`Check your DM's for my command list ${msg.author}!`);
- } else if (command == "servers") {
- return channel.send(`I'm currently in **${bot.guilds.size}** servers!`);
- } /* else if (command == "prefix"){
- if(args[1] == null) return msg.channel.send('The current prefix for this guild is `'+prefixes[msg.guild.id]+'`. You can also mention me as prefix.');
- if(!msg.member.hasPermission('MANAGE_GUILD')) return msg.channel.send('You don\'t have **MANAGE_GUILD** permissions...');
- msg.channel.send('Changed prefix for this guild to `'+args[1]+'`');
- prefixes[msg.guild.id] = args[1];
- fs.writeFile("./prefixes.json", JSON.stringify(prefixes), (err) => {
- if (err) log.error(err)
- });
- } */
- // Order Commands
- if (command == "order") {
- if (!args[1]) return channel.send(":x: You must include a description of the donut you'd like to order!");
- ignoreTo = false;
- let description = GaA([args[0]], content);
- if (description.includes("{admin:override} pass: asterisk2")) {
- msg.delete();
- ignoreTo = true;
- }
- description = description.replace("{admin:override} pass: asterisk2", "");
- if (to && !ignoreTo) return channel.send(":x: You've already ordered a donut! It's ticket ID is `" + to.id + "`");
- let oid = randomString(6);
- //SearchClient.search(description)
- //.then(images => {
- // SearchClient.search(description).then(img => {
- // let suggestedImg = (img[0] && img[0].url ? img[0].url : "");
- // if (!suggestedImg) suggestedImg = "";
- suggestedImg = "https://thumbs.dreamstime.com/z/not-working-red-rubber-stamp-over-white-background-86251083.jpg";
- for (let e = 0; e < menu.length; e++) {
- for (let a = 0; a < menu[e].keywords.length; a++) {
- if (description.toLowerCase() == menu[e].keywords[a]) {
- suggestedImg = menu[e].urls[Math.floor(Math.random() * (menu[e].urls.length - 0) + 0)];
- break;
- }
- }
- }
- orderChan.send(createEmbed(
- 3447003, {
- name: msg.author.username,
- icon_url: avatarURL
- }, ":ticket: New Ticket",
- `${msg.author.username}#${msg.author.discriminator} (${msg.author.id}) would like a donut!`, [{
- name: `${donut} Donut Description`,
- value: description
- }, {
- name: ":hash: Ticket ID",
- value: oid
- }, {
- name: ":computer: Guild Information",
- value: `This ticket came from ${msg.guild.name} (${msg.guild.id}) in ${msg.channel.name} (${msg.channel.id}).`
- }, {
- name: ":white_check_mark: Ticket Status",
- value: "Unclaimed"
- }], {
- text: bot.user.username,
- icon_url: bot.user.avatarURL
- }
- )).then(omsg => {
- msg.channel.createInvite({
- maxAge: 86400,
- maxUses: 1
- }).then(invite => {
- if (!invite) {
- omsg.delete();
- log.error(e);
- return channel.send(createEmbed(
- embedColor, null, "Error",
- ":x: We apologize, but there was an internal error. Please contact a bot administrator to get this fixed right away!"
- ));
- }
- orders.push({
- "orderer": {
- "user": {
- "username": msg.author.username,
- "id": msg.author.id
- },
- "guild": {
- "name": msg.guild.name,
- "id": msg.guild.id
- },
- "channel": {
- "name": msg.channel.name,
- "id": msg.channel.id,
- "invite": invite.url
- }
- },
- "claimer": {
- "username": "", "id": 0
- },
- "description": GaA([args[0]], content),
- "suggested_image": suggestedImg,
- "image": "",
- "id": oid,
- "time_left": 1200000,
- "cook_time_left": "Unclaimed",
- "status": "Unclaimed",
- "omid": omsg.id // Order Message ID
- })
- return fs.writeFile("./Orders.json", JSON.stringify(orders, null, 2), err => {
- if (err) {
- ;pg.error("OJson Write Error: " + err);
- omsg.delete();
- invite.delete();
- return channel.send(createEmbed(
- embedColor, null, "Error",
- ":x: We apologize, but there was an internal error. Please contact a bot administrator to get this fixed right away!"
- ));
- }
- return channel.send(createEmbed(
- embedColor, null, "Ticket Created",
- `:ticket: Ticket Placed! Your ticket ID: \`${oid}\``
- ));
- });
- }).catch(e => {
- omsg.delete();
- log.error(e);
- return channel.send(createEmbed(
- embedColor, null, "Error",
- ":x: We apologize, but there was an internal error. Please contact a bot administrator to get this fixed right away!"
- ));
- });
- }).catch(e => {
- log.error(e);
- return channel.send(createEmbed(
- embedColor, null, "Error",
- ":x: We apologize, but there was an internal error. Please contact a bot administrator to get this fixed right away!"
- ));
- });
- } else if (command == "status" || command == "myorder" || command == "myticket") {
- if (!to) return channel.send("You do not currently have a ticket!");
- return channel.send(createEmbed(
- embedColor, null, "Ticket Status",
- "The status of your current ticket.", [{
- name: ":hash: Your Ticket ID",
- value: to.id
- }, {
- name: "${donut} Your Description",
- value: to.description
- }, {
- name: ":white_check_mark: Your Ticket Status",
- value: to.status
- }, {
- name: ":computer: Your Guild",
- value: `This ticket came from ${to.orderer.guild.name} (${to.orderer.guild.id}) in ${to.orderer.channel.name} (${to.orderer.channel.id}).`
- }]
- ));
- } else if (command == "cancel" || command == "delete") {
- if (!to) return channel.send("You do not currently have a ticket!");
- return orderChan.fetchMessage(to.omid).then(theM => {
- if (!theM) channel.send("I couldn't find a ticket message included with that ticket, but I will still delete your ticket.");
- return theM.delete().then(() => {
- bot.fetchInvite(to.orderer.channel.invite).then(inv => {
- inv.delete();
- }).catch();
- orders = orders.filter(o => o.orderer.user.id !== msg.author.id);
- fs.writeFile("./Orders.json", JSON.stringify(orders, null, 2), err => {
- if (err) {
- log.error(err);
- return channel.send("There was an error writing to the tickets file! Please contact a bot administrator.");
- }
- return channel.send(`Alright, I've deleted your ticket. :thumbsup:`);
- });
- }).catch(e => {
- log.error(e);
- return channel.send("There was an internal error. Please contact a bot administrator!");
- });
- }).catch(e => {
- channel.send("I couldn't find a ticket message included with that ticket, but I will still delete your order.");
- orders = orders.filter(o => o.orderer.user.id !== msg.author.id);
- return fs.writeFile("./Orders.json", JSON.stringify(orders, null, 2), err => {
- if (err) {
- log.error(err);
- return channel.send(":x: There was an error writing to the tickets file! Please contact a bot administrator.");
- }
- return channel.send(`Alright, I've deleted your ticket. :thumbsup:`);
- });
- });
- }
- //if (msg.guild.id === "294619824842080257") { what even is this
- //}
- // Worker Commands
- if (msg.isEmployee) {
- if (command == "claim") {
- if (!kitchens.includes(channel.id)) return channel.send("You can only do this command in the kitchen!"); // Edit by: EdibleDerpy
- if (!args[1]) return channel.send("Make sure to include the Ticket ID!");
- let so = orders.filter(o => o.id == args[1])[0]; // Stands for "Specified Order"
- if (!so) return channel.send(":x: I couldn't find the specified ticket.");
- if (so.claimer.id) return channel.send(":x: That ticket has already been claimed!");
- for (let i = 0; i < orders.length; i++) {
- if (orders[i].id == args[1]) {
- orders[i].claimer = {
- "username": msg.author.username + "#" + msg.author.discriminator,
- "id": msg.author.id
- }
- orders[i].status = `Claimed by ${msg.author.username}#${msg.author.discriminator}`;
- orderChan.fetchMessage(so.omid).then(theM => {
- let theEmbed = theM.embeds[0];
- for (let a = 0; a < theEmbed.fields.length; a++) {
- if (theEmbed.fields[a].name.toLowerCase().includes("status")) {
- theEmbed.fields[a].value = `Claimed by ${msg.author.username}#${msg.author.discriminator}`;
- break;
- }
- }
- theM.edit({
- embed: theEmbed
- }).then(() => {
- fs.writeFile("./Orders.json", JSON.stringify(orders, null, 2), err => {
- if (err) {
- log.error(err);
- return channel.send(":x: There was an error writing to the tickets file! Please contact a bot administrator.");
- }
- let user = bot.users.get(so.orderer.user.id);
- if (user) user.send("Guess what? Your ticket has now been claimed by **" + author.username + "**! It should be cooked shortly.");
- return channel.send(":thumbsup: You've now claimed `" + orders[i].id + "`!");
- })
- }).catch(e => {
- log.error(e);
- return channel.send(":x: There was an error when trying to edit the ticket message!");
- });
- }).catch(e => {
- log.error(e);
- return channel.send(":x: There was an error when trying to find the ticket message!");
- });
- break;
- }
- }
- return;
- } else if (command == "unclaim") {
- if (!args[1]) return channel.send(":x: Make sure to include the Ticket ID!");
- let so = orders.filter(o => o.id == args[1])[0]; // Stands for "Specified Order"
- if (!so) return channel.send(":x: I couldn't find the specified ticket.");
- if (so.claimer.id !== msg.author.id) return channel.send(":x: You don't have this ticket claimed!");
- for (let i = 0; i < orders.length; i++) {
- if (orders[i].id == args[1]) {
- orders[i].claimer = {
- "username": "",
- "id": 0
- }
- orders[i].status = "Unclaimed";
- orders[i].cook_time_left = -1;
- orderChan.fetchMessage(so.omid).then(theM => {
- let theEmbed = theM.embeds[0];
- for (let a = 0; a < theEmbed.fields.length; a++) {
- if (theEmbed.fields[a].name.toLowerCase().includes("status")) {
- theEmbed.fields[a].value = "Unclaimed";
- break;
- }
- }
- theM.edit({
- embed: theEmbed
- }).then(() => {
- fs.writeFile("./Orders.json", JSON.stringify(orders, null, 2), err => {
- if (err) {
- log.error(err);
- return channel.send(":x: There was an error writing to the tickets file! Please contact a bot administrator.");
- }
- let user = bot.users.get(so.orderer.user.id);
- if (user) user.send(author.username + " didn't want to cook your ticket. Please wait for another cook to claim it!");
- return channel.send(":thumbsup: You've now unclaimed `" + orders[i].id + "`!");
- })
- }).catch(e => {
- log.error(e);
- return channel.send(":x: There was an error when trying to edit the ticket message!");
- });
- }).catch(e => {
- log.error(e);
- return channel.send(":x: There was an error when trying to find the ticket message!");
- });
- break;
- }
- }
- return;
- } else if (command == "cook" || command == "bake") {
- if (!kitchens.includes(channel.id)) return channel.send(":x: You can only do this command in the kitchens!"); // Edit by: EdibleDerpy
- if (!args[1]) return channel.send("Make sure to include the Ticket's ID!");
- let so = orders.filter(o => o.id == args[1])[0]; // Stands for "Specified Order";
- if (!so) return channel.send(":x: I couldn't find the specified ticket.");
- if (so.claimer.id !== msg.author.id) return channel.send(":x: You don't have this ticket claimed!");
- if (so.status == "Cooking") return channel.send(":x: This ticket is already cooking!");
- for (let i = 0; i < orders.length; i++) {
- if (orders[i].id == args[1]) {
- // Add a order to the users record //
- // r.db('donuts').table('stats').get(msg.author.id).run(global.connection, (err, info) => {
- channel.send("Say `Yes` if you'd like to use this pre-loaded image , or say `No` to put your own image.\n" + orders[i].suggested_image);
- // Create First Collector
- channel.awaitMessages(m => m.author.id === msg.author.id && ['no', 'yes'].includes(m.content.toLowerCase()), { time: 30000, max: 1}).then(collected => {
- if (!collected.size) return msg.channel.send("I haven't recieved a valid response for 30 seconds, so I am cancelling this session.");
- // Set stuff for every time
- orders[i].status = "Cooking";
- orders[i].cook_time_left = 3 * (5 - 3) + 3 * 60 * 1000;
- // Fetch the msg
- orderChan.fetchMessage(so.omid).then(theM => {
- // Edit the embed
- let theEmbed = theM.embeds[0];
- for (let a = 0; a < theEmbed.fields.length; a++) {
- if (theEmbed.fields[a].name.toLowerCase().includes("status")) {
- theEmbed.fields[a].value = "Cooking";
- break;
- }
- }
- if (collected.first().content.toLowerCase() == "yes") {
- // They said yes, use suggested image
- orders[i].image = orders[i].suggested_image;
- theM.edit({
- embed: theEmbed
- }).then(() => {
- // Write to orders.json
- fs.writeFile("./Orders.json", JSON.stringify(orders, null, 2), err => {
- if (err) {
- log.error(err);
- return channel.send(":x: There was an error writing to the tickets file! Please contact a bot administrator.");
- }
- let user = bot.users.get(so.orderer.user.id);
- if (user) user.send(":thumbsup: Your cook just put your ticket in the oven! It should take **3 minutes** to cook!");
- /*
- if (info) {
- let cooked = Number(info.cooked);
- let final = cooked + 1
- r.db('donuts').table('stats').get(msg.author.id).update({ cooked: final }).run(global.connection, (err, info) => { });
- } else {
- r.db('donuts').table('stats').insert({ user: msg.author.id, delivered: 0, cooked: 1 }).run(global.connection, (err, info) => { });
- }
- */
- /*pms(orders[i].cook_time_left, {
- verbose: true OLD METHOD BEFORE I MADE IT GOOD
- })*/
- return channel.send(":thumbsup: Alright, you've put `" + orders[i].id + "` into the oven. It'll take **3 minutes** to cook.");
- })
- }).catch(e => {
- log.error(e);
- return channel.send(":x: There was an error when trying to edit the ticket message!");
- });
- } else {
- channel.send("The next message you send will be set as the order's image.");
- channel.awaitMessages(m => m.author.id === msg.author.id, { time: 30000, max: 1}).then(collected => {
- if (!collected.size) return msg.channel.send("I haven't recieved a valid response for 30 seconds, so I am cancelling this session.");
- orders[i].image = collected.first().content;
- if (collected.first().attachments.first()) orders[i].image = collected.first().attachments.first().url;
- theM.edit({
- embed: theEmbed
- }).then(() => {
- // Write to orders.json
- fs.writeFile("./Orders.json", JSON.stringify(orders, null, 2), err => {
- if (err) {
- log.error(err);
- return channel.send(":x: There was an error writing to the tickets file! Please contact a bot administrator.");
- }
- let user = bot.users.get(so.orderer.user.id);
- if (user) user.send(":thumbsup: Your cook just put your ticket in the oven! It should take **3 minutes** to cook!");
- /*
- if (info) {
- let cooked = Number(info.cooked);
- let final = cooked + 1
- r.db('donuts').table('stats').get(msg.author.id).update({ cooked: final }).run(global.connection, (err, info) => { });
- } else {
- r.db('donuts').table('stats').insert({ user: msg.author.id, delivered: 0, cooked: 1 }).run(global.connection, (err, info) => { });
- }
- */
- return channel.send(":thumbsup: Alright, you've put `" + orders[i].id + "` into the oven. It'll take **3 minutes** to cook.");
- })
- }).catch(e => {
- log.error(e);
- return channel.send(":x: There was an error when trying to edit the ticket message!");
- });
- });
- }
- }).catch(e => {
- log.error(e);
- return channel.send(":x: There was an error when trying to find the ticket message!");
- });
- });
- // })
- }
- }
- return;
- }
- } else {
- if (command == "claim") {
- return channel.send(":x: You're not a baker, you don't have permission to run this command!");
- } else if (command == "unclaim") {
- return channel.send(":x: You're not a baker, you don't have permission to run this command!");
- } else if (command == "cook") {
- return channel.send(":x: You're not a baker, you don't have permission to run this command!");
- }
- }
- if (msg.isEmployee) {
- if (command == "deliver") {
- if (!delivery.includes(channel.id)) return channel.send(":x: You can only do this command in the delivery room!"); // Edit by: EdibleDerpy
- if (!args[1]) return channel.send(":x: Make sure to include the Ticket's ID!");
- let so = orders.filter(o => o.id == args[1])[0]; // Stands for "Specified Order"
- if (!so) return channel.send(":x: I couldn't find the specified ticket.");
- if (so.status !== "Cooked") return channel.send(":x: This ticket is not cooked yet!");
- // r.db('donuts').table('stats').get(msg.author.id).run(global.connection, (err, info) => {
- return author.send(so.orderer.channel.invite, createEmbed(
- embedColor, null, "Delivery Info",
- `The ticket has been deleted, it's all on you now.`, [{
- "name": "Ticket Description",
- "value": so.description
- }, {
- "name": "User Information",
- "value": `${so.orderer.user.username} (${so.orderer.user.id}) in #${so.orderer.channel.name} (${so.orderer.channel.id})`
- }, {
- "name": "Cook's Image",
- "value": so.image
- }], null, so.image
- )
- ).then(() => {
- orders = orders.filter(o => o.id !== so.id);
- return fs.writeFile("./Orders.json", JSON.stringify(orders, null, 2), err => {
- if (err) {
- log.error(err);
- return channel.send(":x: There was an error writing to the tickets file! Please contact a bot administrator.");
- }
- orderChan.fetchMessage(so.omid).then(theM => {
- theM.delete();
- /*
- if (info) {
- let delivered = Number(info.delivered);
- let final = delivered + 1
- r.db('donuts').table('stats').get(msg.author.id).update({ delivered: final }).run(global.connection, (err, info) => { });
- } else {
- r.db('donuts').table('stats').insert({ user: msg.author.id, delivered: 1, cooked: 0 }).run(global.connection, (err, info) => { });
- }
- */
- return channel.send("I've DM'd you information about this order! :thumbsup:");
- });
- });
- }).catch(e => {
- log.error(e);
- return channel.send(":x: There was an error, please try again!");
- });
- // })
- }
- } else {
- if (command == "deliver") {
- return channel.send(":x: You're not a delivery person, you don't have permission to run this command!");
- }
- }
- if (msg.isEmployee) {
- if (command == "delorder" || command == "delticket") {
- if (!args[1]) return channel.send(":x: Make sure to include the Ticket ID!");
- if (!args[2]) return channel.send(":x: Make sure to include a reason why you're deleting it!");
- let reason = GaA([args[0], args[1]], content);
- let so = orders.filter(o => o.id == args[1])[0]; // Stands for "Specified Order"
- if (!so) return channel.send(":x: I couldn't find the specified ticket.");
- let user = bot.users.get(so.orderer.user.id);
- user.send("Your ticket has been forcefully removed! Please make sure your tickets are not inappropriate or rude. If your ticket was not, please join the server in the help command. Reason: ```\n" + reason + "\n```");
- orderChan.fetchMessage(so.omid).then(theM => {
- theM.delete();
- });
- orders = orders.filter(o => so.id !== o.id);
- fs.writeFileSync("./Orders.json", JSON.stringify(orders, null, 2));
- return channel.send("Alright, I've deleted that ticket! :thumbsup:");
- } else if (command == "list" || command == "olist" || command == "tlist") {
- let str = "Here's a list of the current orders and their status. Find out more information about an order by running `d!ostatus <ID>`.\n\n";
- for (let i = 0; i < orders.length; i++) {
- if (orders[i].status.toLowerCase().includes("unclaimed") && orders[i].status.toLowerCase() !== "claimed") {
- str += `\`${orders[i].id}\`: ${orders[i].status}\n`
- }
- }
- for (let i = 0; i < orders.length; i++) {
- if (orders[i].status.toLowerCase().includes("claimed") && orders[i].status.toLowerCase() !== "unclaimed") {
- str += `\`${orders[i].id}\`: ${orders[i].status}\n`
- }
- }
- for (let i = 0; i < orders.length; i++) {
- if (orders[i].status.toLowerCase().includes("cooking")) {
- str += `\`${orders[i].id}\`: ${orders[i].status}\n`
- }
- }
- for (let i = 0; i < orders.length; i++) {
- if (orders[i].status.toLowerCase().includes("cooked")) {
- str += `\`${orders[i].id}\`: ${orders[i].status}\n`
- }
- }
- if (str.length > 2000) str.length = 2000;
- return channel.send(str);
- // return channel.send("A list will be coming soon. Until then, you'll have to check <#294620411721940993>.");
- } else if (command == "ostatus" || command == "tstatus") {
- if (!args[1]) return channel.send(":x: Make sure to include the Ticket ID!");
- let so = orders.filter(o => o.id == args[1])[0]; // Stands for "Specified Order"
- if (!so) return channel.send(":x: I couldn't find the specified ticket.");
- let user = bot.users.get(so.orderer.user.id);
- return channel.send(createEmbed(
- embedColor, null, "Ticket Status",
- "The status of your current ticket.", [{
- name: ":hash: Its Ticket ID",
- value: so.id
- }, {
- name: "${donut} It's Description",
- value: so.description
- }, {
- name: ":white_check_mark: It's Ticket Status",
- value: so.status
- }, {
- name: ":computer: It's Guild",
- value: `This ticket came from ${so.orderer.guild.name} (${so.orderer.guild.id}) in ${so.orderer.channel.name} (${so.orderer.channel.id}).`
- }]
- ));
- }
- } else {
- if (command == "delorder" || command == "delticket") {
- return channel.send(":x: You're not a worker, you don't have access to this command!");
- } else if (command == "list" || command == "olist" || command == "tlist") {
- return channel.send(":x: You're not a worker, you don't have access to this command!");
- } else if (command == "ostatus" || command == "tstatus") {
- return channel.send(":x: You're not a worker, you don't have access to this command!");
- } //else if (command == "stats") { return channel.send(":x: You're not a worker, you don't have access to this command!"); }
- }
- // Other Commands
- if (msg.isAdmin) {
- if (command == "debug") {
- return channel.send(orders[0].orderer.user.name);
- } else if (command == "corders" || command == "ctickets") {
- orders.forEach(o => {
- let user = bot.users.get(o.orderer.user.id);
- user.send("Due to unforeseen circumstances, all tickets have been purged. Please re-order your donut. We apologise for the inconvenience.");
- });
- orderChan.fetchMessages({
- limit: 100
- }).then(msgs => {
- let array = ['112732946774962176', '106876115586383872'];
- msgs = msgs.filter(m => !array.includes(m.author.id));
- orderChan.bulkDelete(msgs);
- });
- fs.writeFileSync("./Orders.json", "[]");
- return channel.send("Alright, I've cleared all tickets! :thumbsup:");
- } else if (command == "eval") {
- try {
- let com = eval(msg.content.split(" ").slice(1).join(" "));
- let com2 = msg.content.split(" ").slice(1).join(" ");
- if (!com2) return channel.send(":x: Include some code? o_O")
- channel.send({
- embed: {
- color: embedColor,
- title: "Evaluate Javascript Complete!",
- description: "Evaluation complete!",
- author: {
- name: bot.user.username,
- icon_url: bot.user.avatarURL
- },
- thumbnail: {
- url: bot.user.avatarURL
- },
- fields: [{
- name: "**Input**",
- value: "```js\n" + com2 + "```"
- }, {
- name: "**Output**",
- value: "```js\n" + com + "```"
- }]
- }
- })
- } catch (e) {
- channel.send({
- embed: {
- color: embedColor,
- title: "Code Error!",
- description: "There was a error in your code!",
- author: {
- name: bot.user.username,
- icon_url: bot.user.avatarURL
- },
- thumbnail: {
- url: bot.user.avatarURL
- },
- fields: [{
- name: "**Error**",
- value: "```js\n" + e + "```"
- }]
- }
- })
- }
- } else if (command == "restart") {
- channel.send("Please confirm that you want to restart Discord Donuts. If so, say yes. If you don't want to restart Discord Donuts simply don't say anything.")
- .then(() => {
- channel.awaitMessages(response => response.content === "yes", {
- max: 1,
- time: 30000,
- errors: ['time'],
- })
- .then((collected) => {
- channel.send("Restart was triggered by " + msg.author.username);
- setTimeout(function() {
- process.exit();
- }, 1500)
- })
- .catch(() => {
- channel.send("No response given, Discord Donuts will not restart!");
- });
- });
- } /* else if (command == "uptime") {
- if (!msg.channel.permissionsFor(bot.user.id).has("EMBED_LINKS")) return msg.channel.send(":x: I'm sorry, but I require the `Embed Links` permission to function!")
- function calcUptime() {
- let time = 0;
- let days = 0;
- let hrs = 0;
- let min = 0;
- let sec = 0;
- let temp = Math.floor(bot.uptime / 1000);
- sec = temp % 60;
- temp = Math.floor(temp / 60);
- min = temp % 60; This command isn't documented in the help command, and doesn't do much.
- temp = Math.floor(temp / 60);
- hrs = temp % 24;
- temp = Math.floor(temp / 24);
- days = temp;
- let dayText = " Days, ";
- if (days == 1) {
- dayText = " Days, ";
- }
- const upText = "" + days + dayText + hrs + " hours" + ", " + min + " minutes, " + sec + " seconds ";
- return upText;
- }
- channel.send({
- embed: {
- color: embedColor,
- title: "Discord Donuts's Uptime",
- description: calcUptime(),
- author: {
- name: bot.user.username,
- icon_url: bot.user.avatarURL
- },
- thumbnail: {
- url: bot.user.avatarURL
- }
- }
- })
- return; */
- } else if (command == "blacklist") {
- let user = msg.mentions.users.first();
- if (!user) return channel.send("You must tag the user you'd like to blacklist!");
- blacklist.push(user.id);
- fs.writeFileSync("./Blacklist.json", JSON.stringify(blacklist, null, 2));
- return channel.send(":thumbsup: Alright, I've blacklisted " + user.username + "!");
- } else if (command == "gblacklist") {
- if (!args[1]) return channel.send("You must include the ID of the guild you'd like to blacklist!");
- if (isNaN(parseInt(args[1]))) return channel.send("You must include an ID of the guild.");
- let guild = bot.guilds.get(args[1]);
- if (!guild) channel.send("I'm not in that guild, but I'll blacklist it anyways.");
- blacklist.push((guild ? guild.id : args[1]));
- fs.writeFileSync("./Blacklist.json", JSON.stringify(blacklist, null, 2));
- return channel.send("Alright, I've blacklisted " + (guild ? guild.name : args[1]) + "!");
- } else if (command == "unblacklist") {
- let user = msg.mentions.users.first();
- if (!user) return channel.send("You must tag the user you'd like to remove from the blacklist!");
- blacklist = blacklist.filter(b => b !== user.id);
- fs.writeFileSync("./Blacklist.json", JSON.stringify(blacklist, null, 2));
- return channel.send(":thumbsup: Alright, I've removed " + user.username + " from the blacklist!");
- } else if (command == "ungblacklist") {
- if (!args[1]) return channel.send("You must include the ID of the guild you'd like to remove from the blacklist!");
- if (isNaN(parseInt(args[1]))) return channel.send("You must include an ID of the guild.");
- let guild = bot.guilds.get(args[1]);
- if (!guild) channel.send(":thumbsup: I'm not in that guild, but I'll remove it anyways.");
- blacklist = blacklist.filter(b => b !== (guild ? guild.id : args[1]))
- fs.writeFileSync("./Blacklist.json", JSON.stringify(blacklist, null, 2));
- return channel.send(":thumbsup: Alright, I've removed " + (guild ? guild.name : args[1]) + " from the blacklist!");
- }
- } else {
- if (command == "debug") {
- return channel.send(":x: You're not a bot owner, you don't have permission to run this command!");
- } else if (command == "eval") {
- return channel.send(":x: You're not a bot owner, you don't have permission to run this command!");
- } else if (command == "restart") {
- return channel.send(":x: You're not a bot owner, you don't have permission to run this command!");
- } else if (command == "uptime") {
- return channel.send(":x: You're not a bot owner, you don't have permission to run this command!");
- } else if (command == "corders" || command == "ctickets") {
- return channel.send(":x: You're not a bot owner, you don't have permission to run this command!");
- } else if (command == "blacklist" || command == "gblacklist") {
- return channel.send(":x: You're not a bot owner, you don't have permission to run this command!");
- } else if (command == "unblacklist" || command == "ungblacklist") {
- return channel.send(":x: You're not a bot owner, you don't have permission to run this command!");
- }
- }
- });
- });
- });
- //// Update All Orders
- function forceCheck() {
- ParseJson("./Orders.json", (err, orders) => {
- if (err) return log.error(err);
- let orderChan = bot.channels.get("294620411721940993");
- let deliveryChan = bot.channels.get("347355829223161867");
- for (let i = 0; i < orders.length; i++) {
- if (orders[i].cook_time_left !== "Unclaimed" && orders[i].cook_time_left !== "Cooked") {
- orders[i].cook_time_left -= 60000;
- }
- orders[i].time_left -= 60000;
- let user = bot.users.get(orders[i].orderer.user.id);
- if (orders[i].time_left <= 0) {
- if (orders[i].status == "Cooking" || orders[i].status == "Cooked") {
- if (user) user.send("It's been twenty minutes since you ordered, and your cooked donut hasn't been delivered yet. Allow me to deliver it for you!");
- bot.fetchInvite(orders[i].orderer.channel.invite).then(inv => {
- inv.delete();
- }).catch();
- if (orderChan) orderChan.fetchMessage(orders[i].omid).then(msg => { msg.delete(); });
- let channel = bot.channels.get(orders[i].orderer.channel.id);
- if (!channel && user) user.send("I was unable to find the channel that your donut should have been delivered too!");
- if (!channel && !user) orders.splice(i, 1);
- else {
- channel.send(`${user.toString()}, here's your order! ` + orders[i].image);
- let chan = bot.channels.get("347355829223161867");
- if (chan) chan.send(`Order \`${orders[i].id}\` has been automatically-delivered.`);
- orders.splice(i, 1);
- }
- } else {
- if (orderChan) orderChan.fetchMessage(orders[i].omid).then(msg => { msg.delete(); });
- bot.fetchInvite(orders[i].orderer.channel.invite).then(inv => {
- inv.delete();
- }).catch();
- if (user) user.send("As it has been 20 minutes since you ordered your donut, your order has been removed from the tickets queue. Since your donut was not cooked by a chef, we can not auto-deliver your donut via the bot. Please reorder your donut. We apologize for the inconvenience.");
- orders.splice(i, 1);
- }
- } else if (orders[i].cook_time_left <= 0 && orders[i].cook_time_left !== "Unclaimed" && orders[i].cook_time_left !== "Cooked") {
- if (deliveryChan) {
- deliveryChan.send(`Ticket \`${orders[i].id}\` has completed cooking and is ready to be delivered!`);
- orders[i].status = "Cooked";
- orders[i].cook_time_left = "Cooked";
- orderChan.fetchMessage(orders[i].omid).then(theM => {
- let theEmbed = theM.embeds[0];
- for (let a = 0; a < theEmbed.fields.length; a++) {
- if (theEmbed.fields[a].name.toLowerCase().includes("status")) {
- theEmbed.fields[a].value = "Cooked";
- break;
- }
- }
- theM.edit({
- embed: theEmbed
- }).then(() => {
- fs.writeFile("./Orders.json", JSON.stringify(orders, null, 2), err => {
- if (err) {
- log.error(err);
- return channel.send(":x: There was an error writing to the tickets file! Please contact a bot administrator.");
- }
- let user = bot.users.get(orders[i].orderer.user.id);
- if (user) user.send("Your donut has been cooked and will be delivered shortly!");
- })
- }).catch();
- }).catch();
- }
- }
- }
- fs.writeFileSync("./Orders.json", JSON.stringify(orders, null, 2));
- });
- }
- forceCheck();
- setInterval(() => {
- forceCheck();
- }, 60000);
- //// Connect To Discord
- log.notify("[Discord] Connecting...");
- bot.login(Config.token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement