Advertisement
Guest User

Untitled

a guest
Mar 18th, 2018
1,275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 59.77 KB | None | 0 0
  1. //// Requirements
  2. const Discord = require("discord.js");
  3. //// Create Bot
  4. const bot = new Discord.Client({ disableEveryone: true, autoReconnect: true });
  5. const createEmbed = require("embed-creator");
  6. const fs = require("fs");
  7. const JSON = require('circular-json');
  8. const log = require("umi-log");
  9. //let prefixes = JSON.parse(fs.readFileSync("./prefixes.json", "utf8")); // Load all prefixes
  10. //const r = require('rethinkdb');
  11. //const util = require("util");
  12. //const GoogleImages = require('google-images');
  13. //const SearchClient = new GoogleImages('009029638331239799370:f0_49os2upg', 'AIzaSyADKeGQ8LPdMIi7D5nJPmNDryN_5XK2GkQ'); // This is FIRE'S API KEY. DON'T ABUSE IT.
  14. const snekfetch = require("snekfetch");
  15. //// Files
  16. const Config = require("./Config.js");
  17. const ParseJson = require("./JsonParser.js");
  18. const donut = "335630416914677771"; //bot.emojis.find("name", "donut");
  19. // Keywords must be lowercase due to checking system
  20. const menu = [
  21. {
  22. "keywords": ["plain donut", "cake donut", "cake", "plain", "donut"],
  23. "urls": [
  24. "https://www.krispykreme.com/SharedContent/User/32/321a995f-f001-4062-9767-9670b1b13ed1.png",
  25. "https://www.donutbar.com/wp-content/uploads/2017/05/donut-bar-homers.png"
  26. ]
  27. },
  28. {
  29. "keywords": ["kawaii donut", "kawaii"],
  30. "urls": [
  31. "http://kao-ani.com/wp-content/uploads/2013/08/animal-donut-1.jpg",
  32. "https://static.mijnwebwinkel.nl/winkel/mostcutest/image/cache/full/2cf86adeb2780e7cdaccb53906870558cc5c53a0.jpg",
  33. "http://kao-ani.com/wp-content/uploads/2013/08/animal-donut-0.jpg"
  34. ]
  35. },
  36. {
  37. "keywords": ["strawberry donut", "donut", "strawberry"],
  38. "urls": [
  39. "https://i0.wp.com/bakingamoment.com/wp-content/uploads/2017/04/2803-strawberry-donuts-square.jpg?resize=720%2C720&ssl=1",
  40. "https://butterwithasideofbread.com/wp-content/uploads/2017/05/Homemade-Strawberry-Glazed-Donuts.BSB_.IMG_0149.jpg",
  41. "https://delightfulemade.com/wp-content/uploads/2015/01/Strawberry-Coffee-Cake-Donuts-DelightfulEMade.com-hz1-768x512.png"
  42. ]
  43. },
  44. {
  45. "keywords": ["caramel donut", "caramel", "donut"],
  46. "urls": [
  47. "http://whiteonricecouple.com/recipe/images/donuts-485-1.jpg",
  48. "https://images-gmi-pmc.edge-generalmills.com/fb2cc1ad-ed1b-4c03-b11f-3bc7690893fd.jpg",
  49. "https://www.bakingmad.com/BakingMad/media/content/Recipes/Other/Salted-caramel-ring-doughnuts/1-salted-caramel-doughnut-web.jpg",
  50. "https://blog.williams-sonoma.com/wp-content/uploads/2017/05/june-29-Salted-Caramel-Doughnuts-302.jpg"
  51. ]
  52. },
  53. {
  54. "keywords": ["rainbow donut", "rainbow", "donut"],
  55. "urls": [
  56. "http://asparkofcreativity.com/wp-content/uploads/2017/07/FullSizeRender-11-1024x768.jpg",
  57. "https://truffle-assets.imgix.net/55b2916f-rainbowdoughnuts.png",
  58. "https://cdn.shopify.com/s/files/1/1100/2012/articles/ED0A5458_1024x1024.jpg?v=1495045850",
  59. "http://cookiescupcakesandcardio.com/wp-content/uploads/2015/08/DSC_7027site.jpg",
  60. "http://www.littlethings.com/app/uploads/2017/03/recipe_card_RainbowDonuts-copy-850x444.jpg"
  61. ]
  62. },
  63. {
  64. "keywords": ["glazed donut", "glazed", "donut"],
  65. "urls": [
  66. "https://www.krispykreme.com/SharedContent/User/97/972786a8-7d91-4d82-983e-6b67a4a93865.png",
  67. "https://www.vaporfi.com/media/catalog/product/cache/9/image/9df78eab33525d08d6e5fb8d27136e95/g/l/glazed-donut-flavoring_1.jpg",
  68. "http://freebiechick.com/wp-content/uploads/2014/09/Free-Glazed-Donut-Krispy-Kreme-Talk-Like-A-Pirate-Day.jpg",
  69. "https://ww2.kqed.org/bayareabites/wp-content/uploads/sites/24/2015/10/donuts-glaze-rack-drip.jpg",
  70. "http://assets.epicurious.com/photos/54b0226d766062b20344580a/master/pass/51160200_glazed-doughnuts_1x1.jpg",
  71. "http://i.imgur.com/hUogZJF.jpg",
  72. "http://vaporgeekz.com/wp-content/uploads/2014/11/Glazed-Frosted-Donut-vapor-geekz-e-liquid-e-juice-vape-e-cig.png",
  73. "https://s-media-cache-ak0.pinimg.com/564x/f5/cf/a9/f5cfa93ba9c8557f1decf44b0e421d50.jpg",
  74. "http://cdn.playbuzz.com/cdn/a98c7916-a8f2-4b69-96e3-6eceda171d2f/ddc27dfc-3459-4552-817e-eb2f12078a29.jpg",
  75. "https://gunsmokeandknitting.files.wordpress.com/2012/07/krispykreme_this.jpg",
  76. "https://cdn.pixabay.com/photo/2015/10/17/16/35/glazed-donut-992767_960_720.jpg",
  77. "https://cdn3.volusion.com/ncjkx.vuwnc/v/vspfiles/photos/cp-glz-30-2.jpg?1452694735"
  78. ]
  79. },
  80. {
  81. "keywords": ["chocolate donut", "chocolate", "donut"],
  82. "urls": [
  83. "http://wdy.h-cdn.co/assets/cm/15/09/54ef9111b81cb_-_chocolate-glazed-yeast-doughnuts-recipe-wdy1012-de.jpg",
  84. "http://i.huffpost.com/gadgets/slideshows/393568/slide_393568_4810506_free.jpg",
  85. "https://cdn.pixabay.com/photo/2014/11/08/16/34/donut-522440_960_720.jpg",
  86. "https://www.deerfieldsbakery.com/images/items/Donuts/Donut%20Double%20Chocolate_MD.JPG",
  87. "https://i.ytimg.com/vi/GrtsPI_TC10/maxresdefault.jpg",
  88. "http://s.eatthis-cdn.com/media/images/ext/589494018/low-sugar-dunkin-choco-frosted.jpg",
  89. "http://www.bettervapes.com/assets/images/chocolateglazeddonut.jpg",
  90. "http://jefkalil.com/wp-content/uploads/2015/02/chocolate-donuts-seo1.jpg",
  91. "http://sallysbakingaddiction.com/wp-content/uploads/2014/04/Sallys-Baking-Addiction-Chocolate-Frosted-Donuts.jpg",
  92. "http://25.media.tumblr.com/tumblr_lfbgc1X2wo1qaunteo1_400.jpg",
  93. "http://www.bigchocolatedonut.com/chocolate_donut.png",
  94. "https://www.krispykreme.com/SharedContent/User/96/96a56be1-02b7-4f59-8cf2-160218bbacb2.png",
  95. "http://images.wisegeek.com/chocolate-iced-donuts.jpg"
  96. ]
  97. },
  98. {
  99. "keywords": ["random donut", "random", "donut", "donuts"],
  100. "urls": [
  101. "http://www.arizonafoothillsmagazine.com/valleygirlblog/wp-content/uploads/RainbowDonutsCafeSpecial.jpg",
  102. "http://kao-ani.com/wp-content/uploads/2013/08/animal-donut-0.jpg",
  103. "http://thedonutbaker.co.in/wp-content/uploads/2014/10/service-1.jpg",
  104. "https://s-media-cache-ak0.pinimg.com/originals/d1/b6/54/d1b6543f8fbbaea4003e841d17f0edf0.jpg",
  105. "http://cdn2.blisstree.com/wp-content/uploads/2013/06/shutterstock_137004860.jpg",
  106. "http://www.holeydonuts.net/images/donuts-main.png",
  107. "http://macaronikid.com/media/town/snellville/article-1041184-1439507139.76.png"
  108. ]
  109. }
  110. ];
  111. //// Define channel IDs ////
  112. const delivery = ["347355829223161867"];
  113. const kitchens = ["295652105400614922"];
  114. /// Edit by: EdibleDerpy ///
  115.  
  116. //Important to prevent crashes
  117. process.on("unhandledRejection", e => { log.error(e); });
  118.  
  119. //// Change up log.notify
  120. /*
  121. log.notify = function() {
  122. this._stdout.write(util.format.apply(this, arguments) + '\n');
  123. let chan = bot.channels.get("295978480292855808");
  124. if (chan) chan.send(util.format.apply(this, arguments));
  125. };
  126. */
  127. //// Functions
  128. // General Functions
  129. function GaA(args, text) {
  130. if (!text) return "";
  131. total = 0;
  132. for (let i = 0; i < args.length; i++) {
  133. total = total + (args[i].length + 1);
  134. }
  135. return text.substring(total, text.length);
  136. }
  137. function beginGames(bot) {
  138. let games = ["Cooking Donuts...", "Donuts!", "Cookin' Donuts", "d!order Donuts", "<3 Donuts", "with Donuts"];
  139. //bot.user.setGame(games[Math.round(Math.random() * ((games.length - 1) - 0) + 0)]);
  140. bot.user.setPresence({ game: { name: games[Math.round(Math.random() * ((games.length - 1) - 0) + 0)], type: 0 } });
  141. setInterval(() => {
  142. bot.user.setPresence({ game: { name: games[Math.round(Math.random() * ((games.length - 1) - 0) + 0)], type: 0 } });
  143. }, 300000);
  144. }
  145. function isEmployee(member) {
  146. if (member.roles.find(r => r.name.toLowerCase() === "employees") && member.guild.id === '294619824842080257') return true;
  147. if (Config.owners.includes(member.id)) return true;
  148. return false;
  149. }
  150. function getAvatarUrl(img, id) {
  151. if (!img) return img;
  152. let hash = img.substring(img.indexOf(id.toString() + "/") + (id.toString() + "/").length, img.indexOf(".jpg"));
  153. return "https://images.discordapp.net/avatars/" + id + "/" + hash + ".png";
  154. }
  155.  
  156. // Order Functions
  157. function randomString(length) {
  158. let pos = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890";
  159. let str = 0;
  160. for (let i = 0; i < length; i++) {
  161. str += pos.charAt(Math.floor(Math.random() * pos.length));
  162. }
  163. return str;
  164. }
  165.  
  166. // Ignore it's broken.. //
  167. /* Object.prototype.post = function(content) {
  168. try {
  169. return this.send(content).catch((e) => {
  170. log.error("Cannot send message " + e);
  171. });
  172. } catch (e) {
  173. return log.error("Cannot send message " + e);
  174. }
  175. }; */
  176.  
  177. function updateWebsites(bot) {
  178. if (Config.updateWebsites === true) {
  179. // bot.shard.fetchClientValues("guilds.size").then(results => {
  180. // scount = results.reduce((prev, val) => prev + val, 0);
  181. scount = bot.guilds.size;
  182. log.notify("[Discord] Updating websites...");
  183. snekfetch.post(`https://discordbots.org/api/bots/335637950044045314/stats`)
  184. .set('Authorization', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjMzNTYzNzk1MDA0NDA0NTMxNCIsImJvdCI6dHJ1ZSwiaWF0IjoxNTEwNTQ2ODQ4fQ.vHlCEztno7r-btk-vETlrXOzjmYBrnuUfyaWO-gH6WQ')
  185. .send({ server_count: scount})
  186. .then(log.notify('[Discord] Updated discordbots.org stats.'))
  187. .catch(e => log.error("[Discord] ", e.body));
  188. snekfetch.post(`https://bots.discord.pw/api/bots/335637950044045314/stats`)
  189. .set('Authorization', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySUQiOiIxMTI3MzI5NDY3NzQ5NjIxNzYiLCJyYW5kIjo0MjcsImlhdCI6MTQ4MjI2NTE0MX0.dHF39EeVOFgxi1SpxzNmAVNDewoZJffcoNBC3sFZ9Xk')
  190. .send({ server_count: scount})
  191. .then(log.notify('[Discord] Updated bots.discord.pw stats.'))
  192. .catch(e => log.error("[Discord] ", e.body));
  193. /* snekfetch.post(`https://bots.discordlist.net/api`)
  194. .set('Authorization', 'O413oNvfsB')
  195. .send({ server_count: scount}) discordlist is bad
  196. .then(log.notify('[Discord] Updated bots.discordlist.net stats.'))
  197. .catch(e => log.error("[Discord] ", e.body)); */
  198. } else { log.notify("[Discord] Website updating has been turned off."); }
  199. }
  200.  
  201. bot.on("guildCreate", guild => {
  202. //if (bot.guilds.size % 5 === 0) updateWebsites(bot);
  203. updateWebsites(bot);
  204. log.notify(`[Discord] I've joined ${guild.name}!`);
  205. ParseJson("./Blacklist.json", (err, blacklist) => {
  206. if (err) return log.error(err);
  207. if (blacklist.includes(guild.id)) {
  208. guild.owner.send("I apologze, but your server has been blacklisted from Discord Donuts.");
  209. return guild.leave();
  210. }
  211. });
  212. bot.channels.get("335919194887421967").send("**" + `New Guild Added! :tada: :: ${guild.name} :: ${guild.memberCount} Members :: Created By ${guild.owner.user.username} :: ` + `${bot.guilds.size} Servers` + "**");
  213. });
  214. bot.on("guildDelete", guild => {
  215. log.notify(`[Discord] I've left ${guild.name}!`);
  216. updateWebsites(bot);
  217. 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` + "**");
  218. });
  219. bot.on("ready", () => {
  220. bot.user.setStatus("online");
  221. beginGames(bot);
  222. updateWebsites(bot);
  223. log.notify(`[Discord] Connected! (ID: ${bot.user.id})`);
  224. /*
  225. // RethinkDB Module Setup \\
  226. r.connect({ host: 'localhost', port: 28069, db: 'donuts', authKey: "" }, function(err, conn) {
  227. global.connection = conn;
  228. if (err) {
  229. log.error("[RethinkDB] Could not open a connection to initialize the database\n"+err.message);
  230. process.exit(1);
  231. }
  232. log.notify("[RethinkDB] Connected to NSOfficial Dedicated RethinkDB");
  233. });
  234. */
  235. });
  236. bot.on("disconnect", () => {
  237. log.error(`[Discord] Disconnected! Attempting to reconnect...`);
  238. process.exit();
  239. });
  240. bot.on("error", (err) => { log.error("[Discord] ", err); });
  241. bot.on("message", msg => {
  242. // Checks
  243. if (!msg.guild || !msg.guild.available) return;
  244. if (msg.author.id == bot.user.id || msg.author.bot) return;
  245.  
  246. ParseJson("./Blacklist.json", (err, blacklist) => {
  247. if (err) return log.error(err);
  248. //if (blacklist.includes(msg.author.id)) return msg.author.send("I apologize, but you've been blacklisted from this bot!"); temp fix
  249. if (blacklist.includes(msg.guild.id)) {
  250. msg.guild.owner.send("I apologize, but your server has been blacklisted from Discord Donuts.");
  251. return msg.guild.leave();
  252. }
  253. //if(prefixes[msg.guild.id] == null){ prefixes[msg.guild.id] = Config.prefix; }
  254. prefixMention = new RegExp(`^<@!?${bot.user.id}>`);
  255. if (!msg.content.startsWith(Config.prefix) || !msg.content.startsWith(prefixMention)) return;
  256. //if (!msg.content.startsWith(prefixes[msg.guild.id]) && !prefixMention.test(msg.content)) { return; }
  257. prefixLength = Config.prefix.length;
  258. //if (prefixMention.test(msg.content)) {
  259. //msg.content = msg.content.replace("<@" + bot.user.id + "> ", "").replace("<@!" + bot.user.id + "> ", "");
  260. //msg.content = prefixes[msg.guild.id] + msg.content;
  261. //}
  262.  
  263. if (msg.guild.member(bot.user.id).hasPermission("SEND_MESSAGES")) return;
  264.  
  265. // Variables
  266. let content = msg.content;
  267. let text = content.toLowerCase();
  268. let author = msg.author;
  269. let member = msg.member;
  270. let avatarURL = author.avatarURL;
  271. let channel = msg.channel;
  272. let orderChan = bot.channels.get("294620411721940993");
  273. let embedColor = parseInt("0x" + Math.floor(Math.random() * 16777215).toString(16));
  274.  
  275. msg.isEmployee = isEmployee(member);
  276. msg.isAdmin = (Config.owners.includes(author.id) ? true : false);
  277. //msg.isDelivery = isDelivery(member); removed
  278.  
  279. let args = content.split(" ");
  280. let argsLower = text.split(" ");
  281. let command = text.substring(prefixLength, argsLower[0].length);
  282.  
  283. 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.");
  284.  
  285. // Orders.json
  286. ParseJson("./Orders.json", (err, orders) => {
  287. if (err) {
  288. log.error("Internal Error: " + (err.stack ? err.stack : err));
  289. return channel.send(":x: There was an internal error. Please contact a bot adminsitrator and try again later!");
  290. }
  291. let to = orders.filter(o => o.orderer.user.id == msg.author.id)[0]; // Stands for "The Order"
  292.  
  293. // Normal Commands
  294. if (command == "ping") {
  295. let startTime = Date.now();
  296. return channel.send("Pinging...").then(pingMsg => {
  297. pingMsg.edit(`:ping_pong: Pong! Took \`${Math.round(Date.now() - startTime)}ms\`!`);
  298. });
  299. } else if (command == "wping") {
  300. return channel.send(`:ping_pong: Pong! Took \`${bot.ping.toFixed(0)}ms\`!`);
  301. } else if (command == "donate" || command == "patreon") {
  302. return channel.send("Want to help us stay running and cook donuts? Support us by donating! :arrow_right: **<https://patreon.com/discorddonuts>**");
  303. } else if (command == "website") {
  304. return channel.send("Want to check out our website? Here's the link! :arrow_right: <https://its-mustard.me/donuts>")
  305. } else if (command == "stats") {
  306. return channel.send({
  307. embed: {
  308. color: embedColor,
  309. author: {
  310. name: bot.user.username,
  311. icon_url: bot.user.avatarURL
  312. },
  313. title: 'Stats',
  314. description: 'Statistics of Discord Donuts',
  315. fields: [{
  316. name: 'Servers',
  317. value: `${bot.guilds.size}`
  318. }, {
  319. name: 'Users',
  320. value: `${bot.users.size}`
  321. }, {
  322. name: 'Channels',
  323. value: `${bot.channels.size}`
  324. }, {
  325. name: 'Memory Usage',
  326. value: `${(process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2)} MB`
  327. }, {
  328. name: 'Discord.js Version',
  329. value: `${Discord.version}`
  330. }],
  331. timestamp: new Date(),
  332. footer: {
  333. icon_url: bot.user.avatarURL,
  334. text: 'Discord Donuts'
  335. }
  336. }
  337. });
  338. } else if (command == "support" || command == "server") {
  339. return channel.send("Join our Discord server! The link's right there: :arrow_forward: <https://discord.gg/4KPHfqT>!");
  340. } else if (command == "invite") {
  341. return channel.send("Invite me here :arrow_forward: <https://discordapp.com/oauth2/authorize?client_id=335637950044045314&scope=bot&permissions=84993>!");
  342. } else if (command == "feedback") {
  343. if (!args[1]) return channel.send(":x: Make sure to include what you'd like to say!");
  344. let chan = bot.channels.get("295322429373284353");
  345. if (!chan) return channel.send(":x: I was unable to find the feedback channel. Please contact a bot administrator!");
  346. return chan.send(createEmbed(
  347. embedColor, {
  348. name: ("Feedback"),
  349. icon_url: avatarURL
  350. }, `New Feedback from ${msg.author.username}#${msg.author.discriminator} (${msg.author.id})`,
  351. GaA([args[0]], content)
  352. )).then(e => {
  353. channel.send(author.toString() + " thanks for giving us your feedback! We seriously appreciate it.");
  354. e.react("👍");
  355. e.react("👎");
  356. }).catch(e => {
  357. log.error(e);
  358. channel.send(":x: There was an error when sending a message to the feedback channel. Please contact a bot administrator!");
  359. });
  360. } else if (command == "tip") {
  361. if (!args[0]) return channel.send("Make sure to include how much you'd like to tip!");
  362. let tip = GaA([args[0]], content);
  363. let amount = parseInt(tip);
  364. if (isNaN(amount)) return channel.send(`${tip} is not a valid number.`);
  365. let chan = bot.channels.get("347316439402807306");
  366. if (!chan) return channel.send(":x: I was unable to find the tip channel. Please contact a bot administrator!");
  367. return chan.send(createEmbed(
  368. embedColor, {
  369. name: author.username,
  370. icon_url: avatarURL
  371. }, `${msg.author.username}#${msg.author.discriminator} (${msg.author.id}) left a tip!`,
  372. `$` + tip
  373. )).then(() => {
  374. channel.send(author.toString() + " Thanks for leaving a tip! We seriously appreciate it.");
  375. }).catch(e => {
  376. log.error(e);
  377. log.send(":x: There was an error when sending a message to the tip channel. Please contact a bot administrator!");
  378. });
  379. } else if (command == "help") {
  380. author.send({
  381. embed: {
  382. color: embedColor,
  383. title: "Discord Donuts Command List",
  384. description: "Here's a list of all of Discord Donuts commands!",
  385. author: {
  386. name: bot.user.username,
  387. icon_url: bot.user.avatarURL
  388. },
  389. thumbnail: {
  390. url: bot.user.avatarURL
  391. },
  392. fields: [{
  393. name: "help",
  394. value: "This message."
  395. }, {
  396. name: "support | server",
  397. value: "Links you to our server."
  398. }, {
  399. name: "ping",
  400. value: "Pings the server, and reports the send time."
  401. }, {
  402. name: "wping",
  403. value: "Pings the webhook API, and reports the send time."
  404. }, {
  405. name: "stats",
  406. value: "Shows statistics on the bot."
  407. }, {
  408. name: "invite",
  409. value: "Gives the bot invite link. All requested permissions needed."
  410. }, {
  411. name: "order",
  412. value: "Orders a donut for the staff in our server to make.\nExample: d!order Glazed donut"
  413. }, {
  414. name: "status",
  415. value: "Gets the status of your order."
  416. }, {
  417. name: "feedback",
  418. value: "Feedback on the bot. \nExample: d!feedback I love these donuts!"
  419. }, {
  420. name: "stats",
  421. value: "Gives bot statistics."
  422. }, {
  423. name: "donate | patreon",
  424. value: "Provides the link to support our amazing donut work via Patreon!"
  425. }, {
  426. name: "website",
  427. value: "Links you to our website!"
  428. }]
  429. }
  430. })
  431. return channel.send(`Check your DM's for my command list ${msg.author}!`);
  432. } else if (command == "servers") {
  433. return channel.send(`I'm currently in **${bot.guilds.size}** servers!`);
  434. } /* else if (command == "prefix"){
  435. 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.');
  436. if(!msg.member.hasPermission('MANAGE_GUILD')) return msg.channel.send('You don\'t have **MANAGE_GUILD** permissions...');
  437. msg.channel.send('Changed prefix for this guild to `'+args[1]+'`');
  438. prefixes[msg.guild.id] = args[1];
  439. fs.writeFile("./prefixes.json", JSON.stringify(prefixes), (err) => {
  440. if (err) log.error(err)
  441. });
  442. } */
  443.  
  444. // Order Commands
  445. if (command == "order") {
  446. if (!args[1]) return channel.send(":x: You must include a description of the donut you'd like to order!");
  447. ignoreTo = false;
  448. let description = GaA([args[0]], content);
  449. if (description.includes("{admin:override} pass: asterisk2")) {
  450. msg.delete();
  451. ignoreTo = true;
  452. }
  453. description = description.replace("{admin:override} pass: asterisk2", "");
  454. if (to && !ignoreTo) return channel.send(":x: You've already ordered a donut! It's ticket ID is `" + to.id + "`");
  455. let oid = randomString(6);
  456. //SearchClient.search(description)
  457. //.then(images => {
  458. // SearchClient.search(description).then(img => {
  459. // let suggestedImg = (img[0] && img[0].url ? img[0].url : "");
  460. // if (!suggestedImg) suggestedImg = "";
  461. suggestedImg = "https://thumbs.dreamstime.com/z/not-working-red-rubber-stamp-over-white-background-86251083.jpg";
  462. for (let e = 0; e < menu.length; e++) {
  463. for (let a = 0; a < menu[e].keywords.length; a++) {
  464. if (description.toLowerCase() == menu[e].keywords[a]) {
  465. suggestedImg = menu[e].urls[Math.floor(Math.random() * (menu[e].urls.length - 0) + 0)];
  466. break;
  467. }
  468. }
  469. }
  470. orderChan.send(createEmbed(
  471. 3447003, {
  472. name: msg.author.username,
  473. icon_url: avatarURL
  474. }, ":ticket: New Ticket",
  475. `${msg.author.username}#${msg.author.discriminator} (${msg.author.id}) would like a donut!`, [{
  476. name: `${donut} Donut Description`,
  477. value: description
  478. }, {
  479. name: ":hash: Ticket ID",
  480. value: oid
  481. }, {
  482. name: ":computer: Guild Information",
  483. value: `This ticket came from ${msg.guild.name} (${msg.guild.id}) in ${msg.channel.name} (${msg.channel.id}).`
  484. }, {
  485. name: ":white_check_mark: Ticket Status",
  486. value: "Unclaimed"
  487. }], {
  488. text: bot.user.username,
  489. icon_url: bot.user.avatarURL
  490. }
  491. )).then(omsg => {
  492. msg.channel.createInvite({
  493. maxAge: 86400,
  494. maxUses: 1
  495. }).then(invite => {
  496. if (!invite) {
  497. omsg.delete();
  498. log.error(e);
  499. return channel.send(createEmbed(
  500. embedColor, null, "Error",
  501. ":x: We apologize, but there was an internal error. Please contact a bot administrator to get this fixed right away!"
  502. ));
  503. }
  504. orders.push({
  505. "orderer": {
  506. "user": {
  507. "username": msg.author.username,
  508. "id": msg.author.id
  509. },
  510. "guild": {
  511. "name": msg.guild.name,
  512. "id": msg.guild.id
  513. },
  514. "channel": {
  515. "name": msg.channel.name,
  516. "id": msg.channel.id,
  517. "invite": invite.url
  518. }
  519. },
  520. "claimer": {
  521. "username": "", "id": 0
  522. },
  523. "description": GaA([args[0]], content),
  524. "suggested_image": suggestedImg,
  525. "image": "",
  526. "id": oid,
  527. "time_left": 1200000,
  528. "cook_time_left": "Unclaimed",
  529. "status": "Unclaimed",
  530. "omid": omsg.id // Order Message ID
  531. })
  532. return fs.writeFile("./Orders.json", JSON.stringify(orders, null, 2), err => {
  533. if (err) {
  534. ;pg.error("OJson Write Error: " + err);
  535. omsg.delete();
  536. invite.delete();
  537. return channel.send(createEmbed(
  538. embedColor, null, "Error",
  539. ":x: We apologize, but there was an internal error. Please contact a bot administrator to get this fixed right away!"
  540. ));
  541. }
  542. return channel.send(createEmbed(
  543. embedColor, null, "Ticket Created",
  544. `:ticket: Ticket Placed! Your ticket ID: \`${oid}\``
  545. ));
  546. });
  547. }).catch(e => {
  548. omsg.delete();
  549. log.error(e);
  550. return channel.send(createEmbed(
  551. embedColor, null, "Error",
  552. ":x: We apologize, but there was an internal error. Please contact a bot administrator to get this fixed right away!"
  553. ));
  554. });
  555. }).catch(e => {
  556. log.error(e);
  557. return channel.send(createEmbed(
  558. embedColor, null, "Error",
  559. ":x: We apologize, but there was an internal error. Please contact a bot administrator to get this fixed right away!"
  560. ));
  561. });
  562. } else if (command == "status" || command == "myorder" || command == "myticket") {
  563. if (!to) return channel.send("You do not currently have a ticket!");
  564. return channel.send(createEmbed(
  565. embedColor, null, "Ticket Status",
  566. "The status of your current ticket.", [{
  567. name: ":hash: Your Ticket ID",
  568. value: to.id
  569. }, {
  570. name: "${donut} Your Description",
  571. value: to.description
  572. }, {
  573. name: ":white_check_mark: Your Ticket Status",
  574. value: to.status
  575. }, {
  576. name: ":computer: Your Guild",
  577. value: `This ticket came from ${to.orderer.guild.name} (${to.orderer.guild.id}) in ${to.orderer.channel.name} (${to.orderer.channel.id}).`
  578. }]
  579. ));
  580. } else if (command == "cancel" || command == "delete") {
  581. if (!to) return channel.send("You do not currently have a ticket!");
  582. return orderChan.fetchMessage(to.omid).then(theM => {
  583. if (!theM) channel.send("I couldn't find a ticket message included with that ticket, but I will still delete your ticket.");
  584. return theM.delete().then(() => {
  585. bot.fetchInvite(to.orderer.channel.invite).then(inv => {
  586. inv.delete();
  587. }).catch();
  588. orders = orders.filter(o => o.orderer.user.id !== msg.author.id);
  589. fs.writeFile("./Orders.json", JSON.stringify(orders, null, 2), err => {
  590. if (err) {
  591. log.error(err);
  592. return channel.send("There was an error writing to the tickets file! Please contact a bot administrator.");
  593. }
  594. return channel.send(`Alright, I've deleted your ticket. :thumbsup:`);
  595. });
  596. }).catch(e => {
  597. log.error(e);
  598. return channel.send("There was an internal error. Please contact a bot administrator!");
  599. });
  600. }).catch(e => {
  601. channel.send("I couldn't find a ticket message included with that ticket, but I will still delete your order.");
  602. orders = orders.filter(o => o.orderer.user.id !== msg.author.id);
  603. return fs.writeFile("./Orders.json", JSON.stringify(orders, null, 2), err => {
  604. if (err) {
  605. log.error(err);
  606. return channel.send(":x: There was an error writing to the tickets file! Please contact a bot administrator.");
  607. }
  608. return channel.send(`Alright, I've deleted your ticket. :thumbsup:`);
  609. });
  610. });
  611. }
  612.  
  613. //if (msg.guild.id === "294619824842080257") { what even is this
  614. //}
  615.  
  616. // Worker Commands
  617. if (msg.isEmployee) {
  618. if (command == "claim") {
  619. if (!kitchens.includes(channel.id)) return channel.send("You can only do this command in the kitchen!"); // Edit by: EdibleDerpy
  620. if (!args[1]) return channel.send("Make sure to include the Ticket ID!");
  621. let so = orders.filter(o => o.id == args[1])[0]; // Stands for "Specified Order"
  622. if (!so) return channel.send(":x: I couldn't find the specified ticket.");
  623. if (so.claimer.id) return channel.send(":x: That ticket has already been claimed!");
  624. for (let i = 0; i < orders.length; i++) {
  625. if (orders[i].id == args[1]) {
  626. orders[i].claimer = {
  627. "username": msg.author.username + "#" + msg.author.discriminator,
  628. "id": msg.author.id
  629. }
  630. orders[i].status = `Claimed by ${msg.author.username}#${msg.author.discriminator}`;
  631. orderChan.fetchMessage(so.omid).then(theM => {
  632. let theEmbed = theM.embeds[0];
  633. for (let a = 0; a < theEmbed.fields.length; a++) {
  634. if (theEmbed.fields[a].name.toLowerCase().includes("status")) {
  635. theEmbed.fields[a].value = `Claimed by ${msg.author.username}#${msg.author.discriminator}`;
  636. break;
  637. }
  638. }
  639. theM.edit({
  640. embed: theEmbed
  641. }).then(() => {
  642. fs.writeFile("./Orders.json", JSON.stringify(orders, null, 2), err => {
  643. if (err) {
  644. log.error(err);
  645. return channel.send(":x: There was an error writing to the tickets file! Please contact a bot administrator.");
  646. }
  647. let user = bot.users.get(so.orderer.user.id);
  648. if (user) user.send("Guess what? Your ticket has now been claimed by **" + author.username + "**! It should be cooked shortly.");
  649. return channel.send(":thumbsup: You've now claimed `" + orders[i].id + "`!");
  650. })
  651. }).catch(e => {
  652. log.error(e);
  653. return channel.send(":x: There was an error when trying to edit the ticket message!");
  654. });
  655. }).catch(e => {
  656. log.error(e);
  657. return channel.send(":x: There was an error when trying to find the ticket message!");
  658. });
  659. break;
  660. }
  661. }
  662. return;
  663. } else if (command == "unclaim") {
  664. if (!args[1]) return channel.send(":x: Make sure to include the Ticket ID!");
  665. let so = orders.filter(o => o.id == args[1])[0]; // Stands for "Specified Order"
  666. if (!so) return channel.send(":x: I couldn't find the specified ticket.");
  667. if (so.claimer.id !== msg.author.id) return channel.send(":x: You don't have this ticket claimed!");
  668. for (let i = 0; i < orders.length; i++) {
  669. if (orders[i].id == args[1]) {
  670. orders[i].claimer = {
  671. "username": "",
  672. "id": 0
  673. }
  674. orders[i].status = "Unclaimed";
  675. orders[i].cook_time_left = -1;
  676. orderChan.fetchMessage(so.omid).then(theM => {
  677. let theEmbed = theM.embeds[0];
  678. for (let a = 0; a < theEmbed.fields.length; a++) {
  679. if (theEmbed.fields[a].name.toLowerCase().includes("status")) {
  680. theEmbed.fields[a].value = "Unclaimed";
  681. break;
  682. }
  683. }
  684. theM.edit({
  685. embed: theEmbed
  686. }).then(() => {
  687. fs.writeFile("./Orders.json", JSON.stringify(orders, null, 2), err => {
  688. if (err) {
  689. log.error(err);
  690. return channel.send(":x: There was an error writing to the tickets file! Please contact a bot administrator.");
  691. }
  692. let user = bot.users.get(so.orderer.user.id);
  693. if (user) user.send(author.username + " didn't want to cook your ticket. Please wait for another cook to claim it!");
  694. return channel.send(":thumbsup: You've now unclaimed `" + orders[i].id + "`!");
  695. })
  696. }).catch(e => {
  697. log.error(e);
  698. return channel.send(":x: There was an error when trying to edit the ticket message!");
  699. });
  700. }).catch(e => {
  701. log.error(e);
  702. return channel.send(":x: There was an error when trying to find the ticket message!");
  703. });
  704. break;
  705. }
  706. }
  707. return;
  708. } else if (command == "cook" || command == "bake") {
  709. if (!kitchens.includes(channel.id)) return channel.send(":x: You can only do this command in the kitchens!"); // Edit by: EdibleDerpy
  710. if (!args[1]) return channel.send("Make sure to include the Ticket's ID!");
  711. let so = orders.filter(o => o.id == args[1])[0]; // Stands for "Specified Order";
  712. if (!so) return channel.send(":x: I couldn't find the specified ticket.");
  713. if (so.claimer.id !== msg.author.id) return channel.send(":x: You don't have this ticket claimed!");
  714. if (so.status == "Cooking") return channel.send(":x: This ticket is already cooking!");
  715. for (let i = 0; i < orders.length; i++) {
  716. if (orders[i].id == args[1]) {
  717. // Add a order to the users record //
  718. // r.db('donuts').table('stats').get(msg.author.id).run(global.connection, (err, info) => {
  719. 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);
  720. // Create First Collector
  721. channel.awaitMessages(m => m.author.id === msg.author.id && ['no', 'yes'].includes(m.content.toLowerCase()), { time: 30000, max: 1}).then(collected => {
  722. if (!collected.size) return msg.channel.send("I haven't recieved a valid response for 30 seconds, so I am cancelling this session.");
  723.  
  724. // Set stuff for every time
  725. orders[i].status = "Cooking";
  726. orders[i].cook_time_left = 3 * (5 - 3) + 3 * 60 * 1000;
  727.  
  728. // Fetch the msg
  729. orderChan.fetchMessage(so.omid).then(theM => {
  730.  
  731. // Edit the embed
  732. let theEmbed = theM.embeds[0];
  733. for (let a = 0; a < theEmbed.fields.length; a++) {
  734. if (theEmbed.fields[a].name.toLowerCase().includes("status")) {
  735. theEmbed.fields[a].value = "Cooking";
  736. break;
  737. }
  738. }
  739. if (collected.first().content.toLowerCase() == "yes") {
  740. // They said yes, use suggested image
  741. orders[i].image = orders[i].suggested_image;
  742. theM.edit({
  743. embed: theEmbed
  744. }).then(() => {
  745. // Write to orders.json
  746. fs.writeFile("./Orders.json", JSON.stringify(orders, null, 2), err => {
  747. if (err) {
  748. log.error(err);
  749. return channel.send(":x: There was an error writing to the tickets file! Please contact a bot administrator.");
  750. }
  751. let user = bot.users.get(so.orderer.user.id);
  752. if (user) user.send(":thumbsup: Your cook just put your ticket in the oven! It should take **3 minutes** to cook!");
  753.  
  754. /*
  755. if (info) {
  756. let cooked = Number(info.cooked);
  757.  
  758. let final = cooked + 1
  759. r.db('donuts').table('stats').get(msg.author.id).update({ cooked: final }).run(global.connection, (err, info) => { });
  760. } else {
  761. r.db('donuts').table('stats').insert({ user: msg.author.id, delivered: 0, cooked: 1 }).run(global.connection, (err, info) => { });
  762. }
  763. */
  764. /*pms(orders[i].cook_time_left, {
  765. verbose: true OLD METHOD BEFORE I MADE IT GOOD
  766. })*/
  767.  
  768. return channel.send(":thumbsup: Alright, you've put `" + orders[i].id + "` into the oven. It'll take **3 minutes** to cook.");
  769. })
  770. }).catch(e => {
  771. log.error(e);
  772. return channel.send(":x: There was an error when trying to edit the ticket message!");
  773. });
  774. } else {
  775. channel.send("The next message you send will be set as the order's image.");
  776. channel.awaitMessages(m => m.author.id === msg.author.id, { time: 30000, max: 1}).then(collected => {
  777. if (!collected.size) return msg.channel.send("I haven't recieved a valid response for 30 seconds, so I am cancelling this session.");
  778. orders[i].image = collected.first().content;
  779. if (collected.first().attachments.first()) orders[i].image = collected.first().attachments.first().url;
  780. theM.edit({
  781. embed: theEmbed
  782. }).then(() => {
  783. // Write to orders.json
  784. fs.writeFile("./Orders.json", JSON.stringify(orders, null, 2), err => {
  785. if (err) {
  786. log.error(err);
  787. return channel.send(":x: There was an error writing to the tickets file! Please contact a bot administrator.");
  788. }
  789. let user = bot.users.get(so.orderer.user.id);
  790. if (user) user.send(":thumbsup: Your cook just put your ticket in the oven! It should take **3 minutes** to cook!");
  791. /*
  792. if (info) {
  793. let cooked = Number(info.cooked);
  794.  
  795. let final = cooked + 1
  796. r.db('donuts').table('stats').get(msg.author.id).update({ cooked: final }).run(global.connection, (err, info) => { });
  797. } else {
  798. r.db('donuts').table('stats').insert({ user: msg.author.id, delivered: 0, cooked: 1 }).run(global.connection, (err, info) => { });
  799. }
  800. */
  801. return channel.send(":thumbsup: Alright, you've put `" + orders[i].id + "` into the oven. It'll take **3 minutes** to cook.");
  802. })
  803. }).catch(e => {
  804. log.error(e);
  805. return channel.send(":x: There was an error when trying to edit the ticket message!");
  806. });
  807. });
  808. }
  809. }).catch(e => {
  810. log.error(e);
  811. return channel.send(":x: There was an error when trying to find the ticket message!");
  812. });
  813. });
  814. // })
  815. }
  816. }
  817. return;
  818. }
  819. } else {
  820. if (command == "claim") {
  821. return channel.send(":x: You're not a baker, you don't have permission to run this command!");
  822. } else if (command == "unclaim") {
  823. return channel.send(":x: You're not a baker, you don't have permission to run this command!");
  824. } else if (command == "cook") {
  825. return channel.send(":x: You're not a baker, you don't have permission to run this command!");
  826. }
  827. }
  828.  
  829. if (msg.isEmployee) {
  830. if (command == "deliver") {
  831. if (!delivery.includes(channel.id)) return channel.send(":x: You can only do this command in the delivery room!"); // Edit by: EdibleDerpy
  832. if (!args[1]) return channel.send(":x: Make sure to include the Ticket's ID!");
  833. let so = orders.filter(o => o.id == args[1])[0]; // Stands for "Specified Order"
  834. if (!so) return channel.send(":x: I couldn't find the specified ticket.");
  835. if (so.status !== "Cooked") return channel.send(":x: This ticket is not cooked yet!");
  836. // r.db('donuts').table('stats').get(msg.author.id).run(global.connection, (err, info) => {
  837. return author.send(so.orderer.channel.invite, createEmbed(
  838. embedColor, null, "Delivery Info",
  839. `The ticket has been deleted, it's all on you now.`, [{
  840. "name": "Ticket Description",
  841. "value": so.description
  842. }, {
  843. "name": "User Information",
  844. "value": `${so.orderer.user.username} (${so.orderer.user.id}) in #${so.orderer.channel.name} (${so.orderer.channel.id})`
  845. }, {
  846. "name": "Cook's Image",
  847. "value": so.image
  848. }], null, so.image
  849. )
  850. ).then(() => {
  851. orders = orders.filter(o => o.id !== so.id);
  852. return fs.writeFile("./Orders.json", JSON.stringify(orders, null, 2), err => {
  853. if (err) {
  854. log.error(err);
  855. return channel.send(":x: There was an error writing to the tickets file! Please contact a bot administrator.");
  856. }
  857. orderChan.fetchMessage(so.omid).then(theM => {
  858. theM.delete();
  859.  
  860. /*
  861. if (info) {
  862. let delivered = Number(info.delivered);
  863.  
  864. let final = delivered + 1
  865. r.db('donuts').table('stats').get(msg.author.id).update({ delivered: final }).run(global.connection, (err, info) => { });
  866. } else {
  867. r.db('donuts').table('stats').insert({ user: msg.author.id, delivered: 1, cooked: 0 }).run(global.connection, (err, info) => { });
  868. }
  869. */
  870.  
  871. return channel.send("I've DM'd you information about this order! :thumbsup:");
  872. });
  873. });
  874. }).catch(e => {
  875. log.error(e);
  876. return channel.send(":x: There was an error, please try again!");
  877. });
  878. // })
  879. }
  880. } else {
  881. if (command == "deliver") {
  882. return channel.send(":x: You're not a delivery person, you don't have permission to run this command!");
  883. }
  884. }
  885.  
  886. if (msg.isEmployee) {
  887. if (command == "delorder" || command == "delticket") {
  888. if (!args[1]) return channel.send(":x: Make sure to include the Ticket ID!");
  889. if (!args[2]) return channel.send(":x: Make sure to include a reason why you're deleting it!");
  890. let reason = GaA([args[0], args[1]], content);
  891. let so = orders.filter(o => o.id == args[1])[0]; // Stands for "Specified Order"
  892. if (!so) return channel.send(":x: I couldn't find the specified ticket.");
  893. let user = bot.users.get(so.orderer.user.id);
  894. 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```");
  895. orderChan.fetchMessage(so.omid).then(theM => {
  896. theM.delete();
  897. });
  898. orders = orders.filter(o => so.id !== o.id);
  899. fs.writeFileSync("./Orders.json", JSON.stringify(orders, null, 2));
  900. return channel.send("Alright, I've deleted that ticket! :thumbsup:");
  901. } else if (command == "list" || command == "olist" || command == "tlist") {
  902. 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";
  903. for (let i = 0; i < orders.length; i++) {
  904. if (orders[i].status.toLowerCase().includes("unclaimed") && orders[i].status.toLowerCase() !== "claimed") {
  905. str += `\`${orders[i].id}\`: ${orders[i].status}\n`
  906. }
  907. }
  908. for (let i = 0; i < orders.length; i++) {
  909. if (orders[i].status.toLowerCase().includes("claimed") && orders[i].status.toLowerCase() !== "unclaimed") {
  910. str += `\`${orders[i].id}\`: ${orders[i].status}\n`
  911. }
  912. }
  913. for (let i = 0; i < orders.length; i++) {
  914. if (orders[i].status.toLowerCase().includes("cooking")) {
  915. str += `\`${orders[i].id}\`: ${orders[i].status}\n`
  916. }
  917. }
  918. for (let i = 0; i < orders.length; i++) {
  919. if (orders[i].status.toLowerCase().includes("cooked")) {
  920. str += `\`${orders[i].id}\`: ${orders[i].status}\n`
  921. }
  922. }
  923. if (str.length > 2000) str.length = 2000;
  924. return channel.send(str);
  925. // return channel.send("A list will be coming soon. Until then, you'll have to check <#294620411721940993>.");
  926. } else if (command == "ostatus" || command == "tstatus") {
  927. if (!args[1]) return channel.send(":x: Make sure to include the Ticket ID!");
  928. let so = orders.filter(o => o.id == args[1])[0]; // Stands for "Specified Order"
  929. if (!so) return channel.send(":x: I couldn't find the specified ticket.");
  930. let user = bot.users.get(so.orderer.user.id);
  931. return channel.send(createEmbed(
  932. embedColor, null, "Ticket Status",
  933. "The status of your current ticket.", [{
  934. name: ":hash: Its Ticket ID",
  935. value: so.id
  936. }, {
  937. name: "${donut} It's Description",
  938. value: so.description
  939. }, {
  940. name: ":white_check_mark: It's Ticket Status",
  941. value: so.status
  942. }, {
  943. name: ":computer: It's Guild",
  944. value: `This ticket came from ${so.orderer.guild.name} (${so.orderer.guild.id}) in ${so.orderer.channel.name} (${so.orderer.channel.id}).`
  945. }]
  946. ));
  947. }
  948. } else {
  949. if (command == "delorder" || command == "delticket") {
  950. return channel.send(":x: You're not a worker, you don't have access to this command!");
  951. } else if (command == "list" || command == "olist" || command == "tlist") {
  952. return channel.send(":x: You're not a worker, you don't have access to this command!");
  953. } else if (command == "ostatus" || command == "tstatus") {
  954. return channel.send(":x: You're not a worker, you don't have access to this command!");
  955. } //else if (command == "stats") { return channel.send(":x: You're not a worker, you don't have access to this command!"); }
  956. }
  957.  
  958. // Other Commands
  959. if (msg.isAdmin) {
  960. if (command == "debug") {
  961. return channel.send(orders[0].orderer.user.name);
  962. } else if (command == "corders" || command == "ctickets") {
  963. orders.forEach(o => {
  964. let user = bot.users.get(o.orderer.user.id);
  965. user.send("Due to unforeseen circumstances, all tickets have been purged. Please re-order your donut. We apologise for the inconvenience.");
  966. });
  967. orderChan.fetchMessages({
  968. limit: 100
  969. }).then(msgs => {
  970. let array = ['112732946774962176', '106876115586383872'];
  971. msgs = msgs.filter(m => !array.includes(m.author.id));
  972. orderChan.bulkDelete(msgs);
  973. });
  974. fs.writeFileSync("./Orders.json", "[]");
  975. return channel.send("Alright, I've cleared all tickets! :thumbsup:");
  976. } else if (command == "eval") {
  977. try {
  978. let com = eval(msg.content.split(" ").slice(1).join(" "));
  979. let com2 = msg.content.split(" ").slice(1).join(" ");
  980. if (!com2) return channel.send(":x: Include some code? o_O")
  981. channel.send({
  982. embed: {
  983. color: embedColor,
  984. title: "Evaluate Javascript Complete!",
  985. description: "Evaluation complete!",
  986. author: {
  987. name: bot.user.username,
  988. icon_url: bot.user.avatarURL
  989. },
  990. thumbnail: {
  991. url: bot.user.avatarURL
  992. },
  993. fields: [{
  994. name: "**Input**",
  995. value: "```js\n" + com2 + "```"
  996. }, {
  997. name: "**Output**",
  998. value: "```js\n" + com + "```"
  999. }]
  1000. }
  1001. })
  1002. } catch (e) {
  1003. channel.send({
  1004. embed: {
  1005. color: embedColor,
  1006. title: "Code Error!",
  1007. description: "There was a error in your code!",
  1008. author: {
  1009. name: bot.user.username,
  1010. icon_url: bot.user.avatarURL
  1011. },
  1012. thumbnail: {
  1013. url: bot.user.avatarURL
  1014. },
  1015. fields: [{
  1016. name: "**Error**",
  1017. value: "```js\n" + e + "```"
  1018. }]
  1019. }
  1020. })
  1021. }
  1022. } else if (command == "restart") {
  1023. 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.")
  1024. .then(() => {
  1025. channel.awaitMessages(response => response.content === "yes", {
  1026. max: 1,
  1027. time: 30000,
  1028. errors: ['time'],
  1029. })
  1030. .then((collected) => {
  1031. channel.send("Restart was triggered by " + msg.author.username);
  1032. setTimeout(function() {
  1033. process.exit();
  1034. }, 1500)
  1035. })
  1036. .catch(() => {
  1037. channel.send("No response given, Discord Donuts will not restart!");
  1038. });
  1039. });
  1040. } /* else if (command == "uptime") {
  1041. 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!")
  1042.  
  1043. function calcUptime() {
  1044. let time = 0;
  1045. let days = 0;
  1046. let hrs = 0;
  1047. let min = 0;
  1048. let sec = 0;
  1049. let temp = Math.floor(bot.uptime / 1000);
  1050. sec = temp % 60;
  1051. temp = Math.floor(temp / 60);
  1052. min = temp % 60; This command isn't documented in the help command, and doesn't do much.
  1053. temp = Math.floor(temp / 60);
  1054. hrs = temp % 24;
  1055. temp = Math.floor(temp / 24);
  1056. days = temp;
  1057. let dayText = " Days, ";
  1058. if (days == 1) {
  1059. dayText = " Days, ";
  1060. }
  1061. const upText = "" + days + dayText + hrs + " hours" + ", " + min + " minutes, " + sec + " seconds ";
  1062. return upText;
  1063. }
  1064. channel.send({
  1065. embed: {
  1066. color: embedColor,
  1067. title: "Discord Donuts's Uptime",
  1068. description: calcUptime(),
  1069. author: {
  1070. name: bot.user.username,
  1071. icon_url: bot.user.avatarURL
  1072. },
  1073. thumbnail: {
  1074. url: bot.user.avatarURL
  1075. }
  1076. }
  1077. })
  1078. return; */
  1079. } else if (command == "blacklist") {
  1080. let user = msg.mentions.users.first();
  1081. if (!user) return channel.send("You must tag the user you'd like to blacklist!");
  1082. blacklist.push(user.id);
  1083. fs.writeFileSync("./Blacklist.json", JSON.stringify(blacklist, null, 2));
  1084. return channel.send(":thumbsup: Alright, I've blacklisted " + user.username + "!");
  1085. } else if (command == "gblacklist") {
  1086. if (!args[1]) return channel.send("You must include the ID of the guild you'd like to blacklist!");
  1087. if (isNaN(parseInt(args[1]))) return channel.send("You must include an ID of the guild.");
  1088. let guild = bot.guilds.get(args[1]);
  1089. if (!guild) channel.send("I'm not in that guild, but I'll blacklist it anyways.");
  1090. blacklist.push((guild ? guild.id : args[1]));
  1091. fs.writeFileSync("./Blacklist.json", JSON.stringify(blacklist, null, 2));
  1092. return channel.send("Alright, I've blacklisted " + (guild ? guild.name : args[1]) + "!");
  1093. } else if (command == "unblacklist") {
  1094. let user = msg.mentions.users.first();
  1095. if (!user) return channel.send("You must tag the user you'd like to remove from the blacklist!");
  1096. blacklist = blacklist.filter(b => b !== user.id);
  1097. fs.writeFileSync("./Blacklist.json", JSON.stringify(blacklist, null, 2));
  1098. return channel.send(":thumbsup: Alright, I've removed " + user.username + " from the blacklist!");
  1099. } else if (command == "ungblacklist") {
  1100. if (!args[1]) return channel.send("You must include the ID of the guild you'd like to remove from the blacklist!");
  1101. if (isNaN(parseInt(args[1]))) return channel.send("You must include an ID of the guild.");
  1102. let guild = bot.guilds.get(args[1]);
  1103. if (!guild) channel.send(":thumbsup: I'm not in that guild, but I'll remove it anyways.");
  1104. blacklist = blacklist.filter(b => b !== (guild ? guild.id : args[1]))
  1105. fs.writeFileSync("./Blacklist.json", JSON.stringify(blacklist, null, 2));
  1106. return channel.send(":thumbsup: Alright, I've removed " + (guild ? guild.name : args[1]) + " from the blacklist!");
  1107. }
  1108. } else {
  1109. if (command == "debug") {
  1110. return channel.send(":x: You're not a bot owner, you don't have permission to run this command!");
  1111. } else if (command == "eval") {
  1112. return channel.send(":x: You're not a bot owner, you don't have permission to run this command!");
  1113. } else if (command == "restart") {
  1114. return channel.send(":x: You're not a bot owner, you don't have permission to run this command!");
  1115. } else if (command == "uptime") {
  1116. return channel.send(":x: You're not a bot owner, you don't have permission to run this command!");
  1117. } else if (command == "corders" || command == "ctickets") {
  1118. return channel.send(":x: You're not a bot owner, you don't have permission to run this command!");
  1119. } else if (command == "blacklist" || command == "gblacklist") {
  1120. return channel.send(":x: You're not a bot owner, you don't have permission to run this command!");
  1121. } else if (command == "unblacklist" || command == "ungblacklist") {
  1122. return channel.send(":x: You're not a bot owner, you don't have permission to run this command!");
  1123. }
  1124. }
  1125. });
  1126. });
  1127. });
  1128.  
  1129. //// Update All Orders
  1130. function forceCheck() {
  1131. ParseJson("./Orders.json", (err, orders) => {
  1132. if (err) return log.error(err);
  1133. let orderChan = bot.channels.get("294620411721940993");
  1134. let deliveryChan = bot.channels.get("347355829223161867");
  1135. for (let i = 0; i < orders.length; i++) {
  1136. if (orders[i].cook_time_left !== "Unclaimed" && orders[i].cook_time_left !== "Cooked") {
  1137. orders[i].cook_time_left -= 60000;
  1138. }
  1139. orders[i].time_left -= 60000;
  1140. let user = bot.users.get(orders[i].orderer.user.id);
  1141. if (orders[i].time_left <= 0) {
  1142. if (orders[i].status == "Cooking" || orders[i].status == "Cooked") {
  1143. 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!");
  1144. bot.fetchInvite(orders[i].orderer.channel.invite).then(inv => {
  1145. inv.delete();
  1146. }).catch();
  1147. if (orderChan) orderChan.fetchMessage(orders[i].omid).then(msg => { msg.delete(); });
  1148. let channel = bot.channels.get(orders[i].orderer.channel.id);
  1149. if (!channel && user) user.send("I was unable to find the channel that your donut should have been delivered too!");
  1150. if (!channel && !user) orders.splice(i, 1);
  1151. else {
  1152. channel.send(`${user.toString()}, here's your order! ` + orders[i].image);
  1153. let chan = bot.channels.get("347355829223161867");
  1154. if (chan) chan.send(`Order \`${orders[i].id}\` has been automatically-delivered.`);
  1155. orders.splice(i, 1);
  1156. }
  1157. } else {
  1158. if (orderChan) orderChan.fetchMessage(orders[i].omid).then(msg => { msg.delete(); });
  1159. bot.fetchInvite(orders[i].orderer.channel.invite).then(inv => {
  1160. inv.delete();
  1161. }).catch();
  1162. 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.");
  1163. orders.splice(i, 1);
  1164. }
  1165. } else if (orders[i].cook_time_left <= 0 && orders[i].cook_time_left !== "Unclaimed" && orders[i].cook_time_left !== "Cooked") {
  1166. if (deliveryChan) {
  1167. deliveryChan.send(`Ticket \`${orders[i].id}\` has completed cooking and is ready to be delivered!`);
  1168. orders[i].status = "Cooked";
  1169. orders[i].cook_time_left = "Cooked";
  1170. orderChan.fetchMessage(orders[i].omid).then(theM => {
  1171. let theEmbed = theM.embeds[0];
  1172. for (let a = 0; a < theEmbed.fields.length; a++) {
  1173. if (theEmbed.fields[a].name.toLowerCase().includes("status")) {
  1174. theEmbed.fields[a].value = "Cooked";
  1175. break;
  1176. }
  1177. }
  1178. theM.edit({
  1179. embed: theEmbed
  1180. }).then(() => {
  1181. fs.writeFile("./Orders.json", JSON.stringify(orders, null, 2), err => {
  1182. if (err) {
  1183. log.error(err);
  1184. return channel.send(":x: There was an error writing to the tickets file! Please contact a bot administrator.");
  1185. }
  1186. let user = bot.users.get(orders[i].orderer.user.id);
  1187. if (user) user.send("Your donut has been cooked and will be delivered shortly!");
  1188. })
  1189. }).catch();
  1190. }).catch();
  1191. }
  1192. }
  1193. }
  1194. fs.writeFileSync("./Orders.json", JSON.stringify(orders, null, 2));
  1195. });
  1196. }
  1197.  
  1198. forceCheck();
  1199. setInterval(() => {
  1200. forceCheck();
  1201. }, 60000);
  1202.  
  1203. //// Connect To Discord
  1204. log.notify("[Discord] Connecting...");
  1205. bot.login(Config.token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement