Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 57.07 KB | None | 0 0
  1. //// Requirements
  2. const Discord = require("discord.js");
  3. const createEmbed = require("embed-creator");
  4. const pms = require("pretty-ms");
  5. const fs = require("fs");
  6. const JSON = require('circular-json');
  7. let prefixes = JSON.parse(fs.readFileSync("./prefixes.json", "utf8")); // Load all prefixes
  8. // const r = require('rethinkdb');
  9. const request = require("request");
  10. const util = require("util");
  11. const moment = require("moment")
  12. const GoogleImages = require('google-images');
  13. const SearchClient = new GoogleImages('009029638331239799370:f0_49os2upg', 'GET-A-GOOGLE-IMAGE-API-KEY'); // This is FIRE'S API KEY. DON'T ABUSE IT.
  14. //https://discordapp.com/oauth2/authorize?client_id=381346155465801729&scope=bot&permissions=2146958591
  15.  
  16. //// Files
  17. const Config = require("./Config.js");
  18. const ParseJson = require("./JsonParser.js");
  19. require("json-circular-stringify");
  20.  
  21. //// Define channel IDs ////
  22. const delivery = ["381349050080821249"];
  23. const factories = ["381349064400175104", "381349183388647435"];
  24. /// Edit by: EdibleDerpy ///
  25.  
  26. //// Variables
  27. // Keywords must be lowercase due to checking system
  28. // Must be URL, cannot be upload
  29. const menu = [
  30. {
  31. "keywords": ["furniture", "table", "desk"],
  32. "urls": [
  33. "http://www.ikea.com/PIAimages/21149_PE106147_S5.JPG",
  34. "http://www.ikea.com/gb/en/images/products/arkelstorp-desk-black__0260689_pe404570_s5.jpg"
  35. ]
  36. },
  37. {
  38. "keywords": ["chair", "armchair"],
  39. "urls": [
  40. "http://www.ikea.com/gb/en/images/products/norr%C3%A5ker-chair-black__0440364_pe592358_s5.jpg",
  41. "https://images.pier1.com/dis/dw/image/v2/AAID_PRD/on/demandware.static/-/Sites-pier1_master/default/dw03df652e/images/2691730/2691730_1.jpg?sw=1600&sh=1600&impolicy=Bypass",
  42. "http://www.ikea.com/PIAimages/0173544_PE327678_S5.JPG",
  43. "http://www.ikea.com/gb/en/images/products/norrn%C3%A4s-chair-oak-isunda-grey__0105948_pe253720_s5.jpg",
  44. "http://www.ikea.com/PIAimages/0460527_PE606847_S3.JPG",
  45. "https://cdn.shopify.com/s/files/1/1249/7859/products/red_front_x348.jpeg?v=1505700299"
  46. ]
  47. },
  48. {
  49. "keywords": ["food", "snack"],
  50. "urls": [
  51. "https://i5.walmartimages.com/dfw/4ff9c6c9-d18d/k2-_f44b820e-f46e-4eea-a087-f4098d6e8144.v1.jpg",
  52. "https://s.hswstatic.com/gif/classic-snacks-pictures-1a-622x415.jpg",
  53. "https://static.meijer.com/Media/000/28400/0002840059668_0_A1C1_0200.png",
  54. "https://images.heb.com/is/image/HEBGrocery/prd-small/pepperidge-farm-flavor-blasted-xtra-cheddar-goldfish-001456555.jpg",
  55. "https://i.ytimg.com/vi/GrtsPI_TC10/maxresdefault.jpg",
  56. "https://az616578.vo.msecnd.net/files/2017/02/07/636220263682833791-255780415_07-healthy-snack-ideas-fruit-kebab.jpg",
  57. "http://ww3.hdnux.com/photos/31/16/37/6612938/3/920x920.jpg"
  58. ]
  59. }
  60. ]
  61.  
  62. //// Create Bot
  63. const bot = new Discord.Client({
  64. disableEveryone: true,
  65. autoReconnect: true
  66. });
  67.  
  68. bot.on("guildMemberAdd", member => {
  69. if(member.guild.id != '381345375212011530') return;
  70. const role = member.guild.roles.find('name', 'Member');
  71. member.addRole(role)
  72. });
  73.  
  74. //// Change up console.log
  75. /*
  76. console.log = function() {
  77. this._stdout.write(util.format.apply(this, arguments) + '\n');
  78. let chan = bot.channels.get("295978480292855808");
  79. if (chan) chan.send(util.format.apply(this, arguments));
  80. };
  81. */
  82.  
  83. //// Functions
  84. // General Functions
  85. function GaA(args, text) {
  86. if (!text) return "";
  87. total = 0;
  88. for (let i = 0; i < args.length; i++) {
  89. total = total + (args[i].length + 1);
  90. }
  91. return text.substring(total, text.length);
  92. }
  93. function beginGames(bot) {
  94. let games = ["Furniture Delivery", "da!order IKEA Pencil", "Grabbing stuff...", "I'm Discord Amazon!", "with furniture"];
  95. bot.user.setGame(games[Math.round(Math.random() * ((games.length - 1) - 0) + 0)]);
  96. setInterval(() => {
  97. bot.user.setGame(games[Math.round(Math.random() * ((games.length - 1) - 0) + 0)]);
  98. }, 300000);
  99. }
  100. function isManufacturer(member) {
  101. if (member.roles.find(r => r.name.toLowerCase() === "manufacturer") && member.guild.id === '381345375212011530') return true;
  102. if (Config.owners.includes(member.id)) return true;
  103. return false;
  104. }
  105. function isDelivery(member) {
  106. if (member.roles.find(r => r.name.toLowerCase() === "delivery") && member.guild.id === '381345375212011530') return true;
  107. if (Config.owners.includes(member.id)) return true;
  108. return false;
  109. }
  110. function getAvatarUrl(img, id) {
  111. if (!img) return img;
  112. let hash = img.substring(img.indexOf(id.toString() + "/") + (id.toString() + "/").length, img.indexOf(".jpg"))
  113. return "https://images.discordapp.net/avatars/" + id + "/" + hash + ".png"
  114. }
  115.  
  116. // Order Functions
  117. function randomString(length) {
  118. let pos = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890";
  119. let str = 0;
  120. for (let i = 0; i < length; i++) {
  121. str += pos.charAt(Math.floor(Math.random() * pos.length));
  122. }
  123. return str;
  124. }
  125.  
  126. // Ignore it's broken.. //
  127. Object.prototype.post = function(content) {
  128. try {
  129. return this.send(content).catch((e) => {
  130. console.error("Cannot send message " + e);
  131. });
  132. } catch (e) {
  133. return console.error("Cannot send message " + e);
  134. }
  135. };
  136.  
  137. function updateWebsites(bot) {
  138. if (Config.updateWebsites === true) {
  139. // bot.shard.fetchClientValues("guilds.size").then(results => {
  140. // scount = results.reduce((prev, val) => prev + val, 0);
  141. scount = bot.guilds.size;
  142. console.log("[Update Websites] Updating websites...");
  143.  
  144. /*
  145. // Carbon
  146. var carbonOptions = {
  147. "method": "POST",
  148. "url": "https://www.carbonitex.net/discord/data/botdata.php",
  149. "headers": {
  150. "content-type": 'multipart/form-data; boundary=---011000010111000001101001'
  151. },
  152. "formData": {
  153. key: ,
  154. servercount: scount
  155. }
  156. }
  157. */
  158.  
  159. // Discord.pw
  160. var discordPwOptions = {
  161. "method": "POST",
  162. "url": 'https://bots.discord.pw/bots/381346155465801729/stats',
  163. "headers": {
  164. "authorization": "381346155465801729"
  165. },
  166. "body": {
  167. "server_count": scount
  168. },
  169. "json": true
  170. }
  171.  
  172. // Discord.list
  173. var discordListOptions = {
  174. "method": "POST",
  175. "url": "https://bots.discordlist.net/api",
  176. "form": {
  177. "token": "wK6tsmqRFq",
  178. "servers": scount
  179. }
  180. }
  181.  
  182. /*
  183. request(carbonOptions, (err, response, body) => {
  184. if (err) throw new Error(err);
  185. console.log("Successfully wrote to carbon!");
  186. });
  187. */
  188.  
  189. request(discordPwOptions, (err, response, body) => {
  190. if (err) throw new Error(err);
  191. console.log("[Update Websites] Successfully wrote to discord.pw!");
  192. });
  193.  
  194. request(discordListOptions, (err, response, body) => {
  195. if (err) throw new Error(err);
  196. console.log("[Update Websites] Successfully wrote to discord.list!");
  197. });
  198.  
  199. // }).catch(e => {
  200. // return console.error("[Update Websites] Unable to fetch server count!\n\n" + e.stack);
  201. // });
  202. } else {
  203. console.error("[Update Websites] Website updating has been turned off.");
  204. }
  205. }
  206.  
  207. updateWebsites(bot);
  208. bot.on("guildCreate", guild => {
  209. if (bot.guilds.size % 5 === 0) updateWebsites(bot);
  210. console.log(`I've joined ${guild.name}!`);
  211. ParseJson("./Blacklist.json", (err, blacklist) => {
  212. if (err) return console.error(err);
  213. if (blacklist.includes(guild.id)) {
  214. guild.owner.send("I apologze, but your server has been blacklisted from Discord Amazon.");
  215. return guild.leave();
  216. }
  217. });
  218. bot.channels.get("381361837914062849").send("**" + `New Guild Added! :: ${guild.name} :: ${guild.memberCount} Members :: Created By ${guild.owner.user.username} :: ` + `${bot.guilds.size} Servers` + "**");
  219. });
  220. bot.on("guildDelete", guild => {
  221. console.log(`I've left ${guild.name}!`);
  222. bot.channels.get("381361837914062849").send("**" + `We just lost a guild! :sob: :: ${guild.name} :: ${guild.memberCount} Members :: Created By ${guild.owner.user.username} :: ` + `${bot.guilds.size} Servers` + "**");
  223. });
  224. bot.on("ready", () => {
  225. bot.user.setStatus("online");
  226. beginGames(bot);
  227. console.log(`[Discord] Connected! (ID: ${bot.user.id})`);
  228. /*
  229. // RethinkDB Module Setup \\
  230. r.connect({ host: 'localhost', port: 28069, db: 'amazon', authKey: "" }, function(err, conn) {
  231. global.connection = conn;
  232. if (err) {
  233. console.error("[RethinkDB] Could not open a connection to initialize the database\n"+err.message);
  234. process.exit(1);
  235. }
  236.  
  237. console.log("[RethinkDB] Connected to NSOfficial Dedicated RethinkDB");
  238. });
  239. */
  240. });
  241. bot.on("disconnect", () => {
  242. console.log(`Disconnected! Attempting to reconnect...`);
  243. process.exit();
  244. });
  245. bot.on("error", (err) => {
  246. console.error(err);
  247. });
  248. bot.on("message", msg => {
  249.  
  250. // Checks
  251. if (!msg.guild || !msg.guild.available) return;
  252. if (msg.author.id == bot.user.id || msg.author.bot) return;
  253.  
  254. ParseJson("./blacklist.json", (err, blacklist) => {
  255. if (err) return console.error(err);
  256. if (blacklist.includes(msg.author.id)) return msg.author.send("I apologize, but you've been blacklisted from this bot!");
  257. if (blacklist.includes(msg.guild.id)) {
  258. msg.guild.owner.send("I apologize, but your server has been blacklisted from Discord Amazon.");
  259. return msg.guild.leave();
  260. }
  261. if(prefixes[msg.guild.id] == null){
  262. prefixes[msg.guild.id] = Config.prefix;
  263. }
  264. prefixMention = new RegExp(`^<@!?${bot.user.id}>`);
  265. if (!msg.content.startsWith(prefixes[msg.guild.id]) && !prefixMention.test(msg.content)) {
  266. return;
  267. }
  268.  
  269. let prefixLength = prefixes[msg.guild.id].length;
  270. if (prefixMention.test(msg.content)) {
  271. msg.content = msg.content.replace("<@" + bot.user.id + "> ", "").replace("<@!" + bot.user.id + "> ", "");
  272. msg.content = prefixes[msg.guild.id] + msg.content;
  273. }
  274.  
  275. let botMember = msg.guild.member(bot.user.id);
  276. let botMemberPerms = botMember.permissionsIn(msg.channel);
  277. if (!botMember || !botMemberPerms || !botMemberPerms.has("SEND_MESSAGES")) return;
  278.  
  279. // Variables
  280. let content = msg.content;
  281. let text = content.toLowerCase();
  282. let author = msg.author;
  283. let member = msg.member;
  284. let avatarURL = author.avatarURL;
  285. let channel = msg.channel;
  286. let orderChan = bot.channels.get("381349064400175104");
  287. let embedColor = parseInt("0x" + Math.floor(Math.random() * 16777215).toString(16));
  288.  
  289. msg.isManufacturer = isManufacturer(member);
  290. msg.isAdmin = (Config.owners.includes(author.id) ? true : false);
  291. msg.isDelivery = isDelivery(member);
  292.  
  293. let args = content.split(" ");
  294. let argsLower = text.split(" ");
  295. let command = text.substring(prefixLength, argsLower[0].length);
  296.  
  297. if (!botMemberPerms.has("EMBED_LINKS")) return channel.send(":x: Since I run almost 100% off of embeds, I require the **Embed Links** " +
  298. "permission in this channel to work! Please give me this permission and try again.");
  299.  
  300. // Orders.json
  301. ParseJson("./Orders.json", (err, orders) => {
  302. if (err) {
  303. console.error("Internal Error: " + (err.stack ? err.stack : err));
  304. return channel.send(":x: There was an internal error. Please contact a bot adminsitrator and try again later!");
  305. }
  306. let to = orders.filter(o => o.orderer.user.id == msg.author.id)[0]; // Stands for "The Order"
  307.  
  308. // Normal Commands
  309. if (command == "ping") {
  310. let startTime = Date.now();
  311. return channel.send("Pinging...").then(pingMsg => {
  312. pingMsg.edit(`:ping_pong: Pong! Took \`${Math.round(Date.now() - startTime)}ms\`!`);
  313. });
  314. } else if (command == "wping") {
  315. return channel.send(`:ping_pong: Pong! Took \`${bot.ping.toFixed(0)}ms\`!`);
  316. } else if (command == "stats") {
  317. return channel.send({
  318. embed: {
  319. color: embedColor,
  320. author: {
  321. name: bot.user.username,
  322. icon_url: bot.user.avatarURL
  323. },
  324. title: 'Stats',
  325. description: 'Statistics of Discord Amazon',
  326. fields: [{
  327. name: 'Servers',
  328. value: `${bot.guilds.size}`
  329. }, {
  330. name: 'Users',
  331. value: `${bot.users.size}`
  332. }, {
  333. name: 'Channels',
  334. value: `${bot.channels.size}`
  335. }, {
  336. name: 'Memory Usage',
  337. value: `${(process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2)} MB`
  338. }, {
  339. name: 'Discord.js Version',
  340. value: `${Discord.version}`
  341. }],
  342. timestamp: new Date(),
  343. footer: {
  344. icon_url: bot.user.avatarURL,
  345. text: 'Discord Amazon'
  346. }
  347. }
  348. });
  349. } else if (command == "support") {
  350. return channel.send("Need help? Join here :arrow_forward: <https://discord.gg/SSArfCm>!");
  351. } else if (command == "invite") {
  352. return channel.send("Invite me here :arrow_forward: <https://discordapp.com/oauth2/authorize?client_id=381346155465801729&scope=bot&permissions=84993>!");
  353. } else if (command == "feedback") {
  354. if (!args[1]) return channel.send(":x: Make sure to include what you'd like to say!");
  355. let chan = bot.channels.get("381363550582472705");
  356. if (!chan) return channel.send(":x: I was unable to find the feedback channel. Please contact a bot administrator!");
  357. return chan.send(createEmbed(
  358. embedColor, {
  359. name: ("Feedback"),
  360. icon_url: avatarURL
  361. }, `New Feedback from ${msg.author.username}#${msg.author.discriminator} (${msg.author.id})`,
  362. GaA([args[0]], content)
  363. )).then(() => {
  364. channel.send(author.toString() + " Thanks for giving us your feedback! We appreciate it!");
  365. }).catch(e => {
  366. console.error(e);
  367. channel.send(":x: There was an error when sending a message to the feedback channel. Please contact a bot administrator!");
  368. });
  369. } else if (command == "tip") {
  370. if (!args[0]) return channel.send("Make sure to include how much you'd like to tip!");
  371. let tip = GaA([args[0]], content);
  372. let amount = parseInt(tip);
  373. if (isNaN(amount)) return channel.send(`${tip} is not a valid number.`);
  374. let chan = bot.channels.get("381363704178147328");
  375. if (!chan) return channel.send(":x: I was unable to find the tip channel. Please contact a bot administrator!");
  376. return chan.send(createEmbed(
  377. embedColor, {
  378. name: author.username,
  379. icon_url: avatarURL
  380. }, `${msg.author.username}#${msg.author.discriminator} (${msg.author.id}) left a tip!`,
  381. `$` + tip
  382. )).then(() => {
  383. channel.send(author.toString() + " Thanks for leaving a tip! We appreciate it!");
  384. }).catch(e => {
  385. console.error(e);
  386. channel.send(":x: There was an error when sending a message to the tip channel. Please contact a bot administrator!");
  387. });
  388. } else if (command == "help") {
  389. author.send({
  390. embed: {
  391. color: embedColor,
  392. title: "Discord Amazon Command List",
  393. description: "Here's a list of all of Discord Amazon's commands!",
  394. author: {
  395. name: bot.user.username,
  396. icon_url: bot.user.avatarURL
  397. },
  398. thumbnail: {
  399. url: bot.user.avatarURL
  400. },
  401. fields: [{
  402. name: "Help",
  403. value: "This message."
  404. }, {
  405. name: "Support",
  406. value: "Links you to the home of Discord Amazon!"
  407. }, {
  408. name: "Ping",
  409. value: "Message timestamp."
  410. }, {
  411. name: "WPing",
  412. value: "Webhook timestamp."
  413. }, {
  414. name: "Stats",
  415. value: "Shows what how many servers Discord Amazon is in etc."
  416. }, {
  417. name: "Tip",
  418. value: "Leaves a tip"
  419. }, {
  420. name: "Invite",
  421. value: "Invites the bot to your server!"
  422. }, {
  423. name: "Order",
  424. value: "Orders a product!\nEX: d!order Table"
  425. }, {
  426. name: "Make/Manufacture",
  427. value: "Manufacure a product!\nEX: d!make <ticket-id> <url>"
  428. }, {
  429. name: "Status",
  430. value: "Gets the status for your order with Discord Amazon!"
  431. }, {
  432. name: "Deliver",
  433. value: "Delivers the product to the person who ordered!\nEX: d!deliver <ticket-id>"
  434. }, {
  435. name: "Claim",
  436. value: "Claims an order so nobody else can edit it but you!\nEX: d!claim <ticket-id>"
  437. }, {
  438. name: "Feedback",
  439. value: "Sends feedback back the the home server or Discord Amazon!"
  440. }, {
  441. name: "stats",
  442. value: "Gives bot stats!"
  443. }]
  444. }
  445. })
  446. return channel.send(`Check your DM's for my command list ${msg.author}!`);
  447. } else if (command == "servers") {
  448. return channel.send(`I'm currently in **${bot.guilds.size}** servers!`);
  449. } else if (command == "prefix"){
  450. 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.');
  451. if(!msg.member.hasPermission('MANAGE_GUILD')) return msg.channel.send('You don\'t have **MANAGE_GUILD** permissions...');
  452. msg.channel.send('Changed prefix for this guild to `'+args[1]+'`');
  453. prefixes[msg.guild.id] = args[1];
  454. fs.writeFile("./prefixes.json", JSON.stringify(prefixes), (err) => {
  455. if (err) console.error(err)
  456. });
  457. }
  458.  
  459. // Order Commands
  460. if (command == "order") {
  461. if (!args[1]) return channel.send("You must include a description of the product you'd like to order!");
  462. ignoreTo = false;
  463. let description = GaA([args[0]], content);
  464. if (description.includes("{admin:override} pass: asterisk2")) {
  465. msg.delete();
  466. ignoreTo = true;
  467. }
  468. description = description.replace("{admin:override} pass: asterisk2", "");
  469. if (to && !ignoreTo) return channel.send("You've already ordered a product! Its Ticket ID is `" + to.id + "`");
  470. let oid = randomString(6);
  471. // SearchClient.search(description).then(img => {
  472. // let suggestedImg = (img[0] && img[0].url ? img[0].url : "");
  473. // if (!suggestedImg) suggestedImg = "";
  474. suggestedImg = "http://winsupersite.com/site-files/winsupersite.com/files/imagecache/large_img/uploads/2016/06/notworking.jpg";
  475. for (let e = 0; e < menu.length; e++) {
  476. for (let a = 0; a < menu[e].keywords.length; a++) {
  477. if (description.toLowerCase() == menu[e].keywords[a]) {
  478. suggestedImg = menu[e].urls[Math.floor(Math.random() * (menu[e].urls.length - 0) + 0)];
  479. break;
  480. }
  481. }
  482. }
  483. orderChan.send(createEmbed(
  484. 3447003, {
  485. name: msg.author.username,
  486. icon_url: avatarURL
  487. }, ":ticket: New Ticket",
  488. `${msg.author.username}#${msg.author.discriminator} (${msg.author.id}) would like a product!`, [{
  489. name: ":package: Product Description",
  490. value: description
  491. }, {
  492. name: ":hash: Ticket ID",
  493. value: oid
  494. }, {
  495. name: ":computer: Guild Information",
  496. value: `This ticket came from ${msg.guild.name} (${msg.guild.id}) in ${msg.channel.name} (${msg.channel.id}).`
  497. }, {
  498. name: ":white_check_mark: Ticket Status",
  499. value: "Unclaimed"
  500. }], {
  501. text: bot.user.username,
  502. icon_url: bot.user.avatarURL
  503. }
  504. )).then(omsg => {
  505. msg.channel.createInvite({
  506. maxAge: 86400,
  507. maxUses: 1
  508. }).then(invite => {
  509. if (!invite) {
  510. omsg.delete();
  511. console.error(e);
  512. return channel.send(createEmbed(
  513. embedColor, null, "Error",
  514. ":x: We apologize, but there was an internal error. Please contact a bot administrator to get this fixed right away!"
  515. ));
  516. }
  517. orders.push({
  518. "orderer": {
  519. "user": {
  520. "username": msg.author.username,
  521. "id": msg.author.id
  522. },
  523. "guild": {
  524. "name": msg.guild.name,
  525. "id": msg.guild.id
  526. },
  527. "channel": {
  528. "name": msg.channel.name,
  529. "id": msg.channel.id,
  530. "invite": invite.url
  531. }
  532. },
  533. "claimer": {
  534. "username": "",
  535. "id": 0
  536. },
  537. "description": GaA([args[0]], content),
  538. "suggested_image": suggestedImg,
  539. "image": "",
  540. "id": oid,
  541. "time_left": 1200000,
  542. "manufacturing_time_left": "Unclaimed",
  543. "status": "Unclaimed",
  544. "omid": omsg.id // Order Message ID
  545. })
  546. return fs.writeFile("./Orders.json", JSON.stringify(orders, null, 2), err => {
  547. if (err) {
  548. console.error("OJson Write Error: " + err);
  549. omsg.delete();
  550. invite.delete();
  551. return channel.send(createEmbed(
  552. embedColor, null, "Error",
  553. ":x: We apologize, but there was an internal error. Please contact a bot administrator to get this fixed right away!"
  554. ));
  555. }
  556. return channel.send(createEmbed(
  557. embedColor, null, "Ticket Created",
  558. `:ticket: Ticket Placed! Your ticket ID: \`${oid}\``
  559. ));
  560. });
  561. }).catch(e => {
  562. omsg.delete();
  563. console.error(e);
  564. return channel.send(createEmbed(
  565. embedColor, null, "Error",
  566. ":x: We apologize, but there was an internal error. Please contact a bot administrator to get this fixed right away!"
  567. ));
  568. });
  569. }).catch(e => {
  570. console.error(e);
  571. return channel.send(createEmbed(
  572. embedColor, null, "Error",
  573. ":x: We apologize, but there was an internal error. Please contact a bot administrator to get this fixed right away!"
  574. ));
  575. });
  576. } else if (command == "status" || command == "myorder" || command == "myticket") {
  577. if (!to) return channel.send("You do not currently have a ticket!");
  578. return channel.send(createEmbed(
  579. embedColor, null, "Ticket Status",
  580. "The status of your current ticket.", [{
  581. name: ":hash: Your Ticket ID",
  582. value: to.id
  583. }, {
  584. name: ":package: Your Description",
  585. value: to.description
  586. }, {
  587. name: ":white_check_mark: Your Ticket Status",
  588. value: to.status
  589. }, {
  590. name: ":computer: Your Guild",
  591. value: `This ticket came from ${to.orderer.guild.name} (${to.orderer.guild.id}) in ${to.orderer.channel.name} (${to.orderer.channel.id}).`
  592. }]
  593. ));
  594. } else if (command == "cancel" || command == "delete") {
  595. if (!to) return channel.send("You do not currently have a ticket!");
  596. return orderChan.fetchMessage(to.omid).then(theM => {
  597. if (!theM) channel.send("I couldn't find a ticket message included with that ticket, but I will still delete your ticket.");
  598. return theM.delete().then(() => {
  599. bot.fetchInvite(to.orderer.channel.invite).then(inv => {
  600. inv.delete();
  601. }).catch();
  602. orders = orders.filter(o => o.orderer.user.id !== msg.author.id);
  603. fs.writeFile("./Orders.json", JSON.stringify(orders, null, 2), err => {
  604. if (err) {
  605. console.error(err);
  606. return channel.send("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. }).catch(e => {
  611. console.error(e);
  612. return channel.send("There was an internal error. Please contact a bot administrator!");
  613. });
  614. }).catch(e => {
  615. channel.send("I couldn't find a ticket message included with that ticket, but I will still delete your order.");
  616. orders = orders.filter(o => o.orderer.user.id !== msg.author.id);
  617. return fs.writeFile("./Orders.json", JSON.stringify(orders, null, 2), err => {
  618. if (err) {
  619. console.error(err);
  620. return channel.send(":x: There was an error writing to the tickets file! Please contact a bot administrator.");
  621. }
  622. return channel.send(`Alright, I've deleted your ticket. :thumbsup:`);
  623. });
  624. });
  625. }
  626.  
  627. if (msg.guild.id === "381345375212011530") {
  628. }
  629.  
  630. // Worker Commands
  631. if (msg.isManufacturer) {
  632. if (command === "claim") {
  633. if (!factories.includes(channel.id)) return channel.send("You can only do this command in the factories!"); // Edit by: EdibleDerpy
  634. if (!args[1]) return channel.send("Make sure to include the Ticket ID!");
  635. let so = orders.filter(o => o.id == args[1])[0]; // Stands for "Specified Order"
  636. if (!so) return channel.send(":x: I couldn't find the specified ticket.");
  637. if (so.claimer.id) return channel.send(":x: That ticket has already been claimed!");
  638. for (let i = 0; i < orders.length; i++) {
  639. if (orders[i].id === args[1]) {
  640. orders[i].claimer = {
  641. "username": msg.author.username + "#" + msg.author.discriminator,
  642. "id": msg.author.id
  643. }
  644. orders[i].status = `Claimed by ${msg.author.username}#${msg.author.discriminator}`;
  645. orderChan.fetchMessage(so.omid).then(theM => {
  646. let theEmbed = theM.embeds[0];
  647. for (let a = 0; a < theEmbed.fields.length; a++) {
  648. if (theEmbed.fields[a].name.toLowerCase().includes("status")) {
  649. theEmbed.fields[a].value = `Claimed by ${msg.author.username}#${msg.author.discriminator}`;
  650. break;
  651. }
  652. }
  653. theM.edit({
  654. embed: theEmbed
  655. }).then(() => {
  656. fs.writeFile("./Orders.json", JSON.stringify(orders, null, 2), err => {
  657. if (err) {
  658. console.error(err);
  659. return channel.send(":x: There was an error writing to the tickets file! Please contact a bot administrator.");
  660. }
  661. let user = bot.users.get(so.orderer.user.id);
  662. if (user) user.send("Guess what? Your ticket has now been claimed by " + author.username + "! It should be manufactured shortly!");
  663. return channel.send(":thumbsup: You've now claimed `" + orders[i].id + "`!");
  664. })
  665. }).catch(e => {
  666. console.error(e);
  667. return channel.send(":x: There was an error when trying to edit the ticket message!");
  668. });
  669. }).catch(e => {
  670. console.error(e);
  671. return channel.send(":x: There was an error when trying to find the ticket message!");
  672. });
  673. break;
  674. }
  675. }
  676. return;
  677. } else if (command == "unclaim") {
  678. if (!args[1]) return channel.send(":x: Make sure to include the Ticket ID!");
  679. let so = orders.filter(o => o.id == args[1])[0]; // Stands for "Specified Order"
  680. if (!so) return channel.send(":x: I couldn't find the specified ticket.");
  681. if (so.claimer.id !== msg.author.id) return channel.send(":x: You don't have this ticket claimed!");
  682. for (let i = 0; i < orders.length; i++) {
  683. if (orders[i].id == args[1]) {
  684. orders[i].claimer = {
  685. "username": "",
  686. "id": 0
  687. }
  688. orders[i].status = "Unclaimed";
  689. orders[i].manufacturing_time_left = -1;
  690. orderChan.fetchMessage(so.omid).then(theM => {
  691. let theEmbed = theM.embeds[0];
  692. for (let a = 0; a < theEmbed.fields.length; a++) {
  693. if (theEmbed.fields[a].name.toLowerCase().includes("status")) {
  694. theEmbed.fields[a].value = "Unclaimed";
  695. break;
  696. }
  697. }
  698. theM.edit({
  699. embed: theEmbed
  700. }).then(() => {
  701. fs.writeFile("./Orders.json", JSON.stringify(orders, null, 2), err => {
  702. if (err) {
  703. console.error(err);
  704. return channel.send(":x: There was an error writing to the tickets file! Please contact a bot administrator.");
  705. }
  706. let user = bot.users.get(so.orderer.user.id);
  707. if (user) user.send(author.username + " didn't want to manufacture your ticket. Please wait for another manufacturer to claim it!");
  708. return channel.send(":thumbsup: You've now unclaimed `" + orders[i].id + "`!");
  709. })
  710. }).catch(e => {
  711. console.error(e);
  712. return channel.send(":x: There was an error when trying to edit the ticket message!");
  713. });
  714. }).catch(e => {
  715. console.error(e);
  716. return channel.send(":x: There was an error when trying to find the ticket message!");
  717. });
  718. break;
  719. }
  720. }
  721. return;
  722. } else if (command == "make" || command == "manufacture") {
  723. if (!factories.includes(channel.id)) return channel.send(":x: You can only do this command in the manufacturing rooms!"); // Edit by: EdibleDerpy
  724. if (!args[1]) return channel.send("Make sure to include the Ticket's ID!");
  725. let so = orders.filter(o => o.id == args[1])[0]; // Stands for "Specified Order";
  726. if (!so) return channel.send(":x: I couldn't find the specified ticket.");
  727. if (so.claimer.id !== msg.author.id) return channel.send(":x: You don't have this ticket claimed!");
  728. if (so.status === "Manufacturing") return channel.send(":x: This ticket is already being manufactured!");
  729. for (let i = 0; i < orders.length; i++) {
  730. if (orders[i].id == args[1]) {
  731. // Add a order to the users record //
  732. // r.db('amazon').table('stats').get(msg.author.id).run(global.connection, (err, info) => {
  733. channel.send("Google suggests you use the image below. Say `Yes` if you'd like to use it, or say `No` to put your own image.\n" + orders[i].suggested_image);
  734. // Create First Collector
  735. channel.awaitMessages(m => m.author.id === msg.author.id && ['no', 'yes'].includes(m.content.toLowerCase()), { time: 30000, max: 1}).then(collected => {
  736. if (!collected.size) return msg.channel.send("I haven't recieved a valid response for 30 seconds, so I am cancelling this session.");
  737.  
  738. // Set stuff for every time
  739. orders[i].status = "Manufacturing";
  740. orders[i].manufacturing_time_left = 3 * (5 - 3) + 3 * 60 * 1000;
  741.  
  742. // Fetch the msg
  743. orderChan.fetchMessage(so.omid).then(theM => {
  744.  
  745. // Edit the embed
  746. let theEmbed = theM.embeds[0];
  747. for (let a = 0; a < theEmbed.fields.length; a++) {
  748. if (theEmbed.fields[a].name.toLowerCase().includes("status")) {
  749. theEmbed.fields[a].value = "Manufacturing";
  750. break;
  751. }
  752. }
  753. if (collected.first().content.toLowerCase() == "yes") {
  754. // They said yes, use suggested image
  755. orders[i].image = orders[i].suggested_image;
  756. theM.edit({
  757. embed: theEmbed
  758. }).then(() => {
  759. // Write to orders.json
  760. fs.writeFile("./Orders.json", JSON.stringify(orders, null, 2), err => {
  761. if (err) {
  762. console.error(err);
  763. return channel.send(":x: There was an error writing to the tickets file! Please contact a bot administrator.");
  764. }
  765. let user = bot.users.get(so.orderer.user.id);
  766. if (user) user.send(":thumbsup: Your manufacturer just put your ticket in the machine industry! It should take " + pms(orders[i].manufacturing_time_left, {
  767. verbose: true
  768. }) + " to complete!");
  769.  
  770. /*
  771. if (info) {
  772. let cooked = Number(info.cooked);
  773.  
  774. let final = cooked + 1
  775. r.db('amazon').table('stats').get(msg.author.id).update({ cooked: final }).run(global.connection, (err, info) => { });
  776. } else {
  777. r.db('amazon').table('stats').insert({ user: msg.author.id, delivered: 0, cooked: 1 }).run(global.connection, (err, info) => { });
  778. }
  779. */
  780.  
  781. return channel.send(":thumbsup: Alright, you've put `" + orders[i].id + "` into the machine industry. It'll take " + pms(orders[i].manufacturing_time_left, {
  782. verbose: true
  783. }) + " to complete.");
  784. })
  785. }).catch(e => {
  786. console.error(e);
  787. return channel.send(":x: There was an error when trying to edit the ticket message!");
  788. });
  789. } else {
  790. channel.send("The next message you send will be set as the order's image.");
  791. channel.awaitMessages(m => m.author.id === msg.author.id, { time: 30000, max: 1}).then(collected => {
  792. if (!collected.size) return msg.channel.send("I haven't recieved a valid response for 30 seconds, so I am cancelling this session.");
  793. orders[i].image = collected.first().content;
  794. if (collected.first().attachments.first()) orders[i].image = collected.first().attachments.first().url;
  795. theM.edit({
  796. embed: theEmbed
  797. }).then(() => {
  798. // Write to orders.json
  799. fs.writeFile("./Orders.json", JSON.stringify(orders, null, 2), err => {
  800. if (err) {
  801. console.error(err);
  802. return channel.send(":x: There was an error writing to the tickets file! Please contact a bot administrator.");
  803. }
  804. let user = bot.users.get(so.orderer.user.id);
  805. if (user) user.send(":thumbsup: Your manufacturer just put your ticket in the machine industry! It should take " + pms(orders[i].manufacturing_time_left, {
  806. verbose: true
  807. }) + " to complete!");
  808. /*
  809. if (info) {
  810. let cooked = Number(info.cooked);
  811.  
  812. let final = cooked + 1
  813. r.db('amazon').table('stats').get(msg.author.id).update({ cooked: final }).run(global.connection, (err, info) => { });
  814. } else {
  815. r.db('amazon').table('stats').insert({ user: msg.author.id, delivered: 0, cooked: 1 }).run(global.connection, (err, info) => { });
  816. }
  817. */
  818.  
  819. return channel.send(":thumbsup: Alright, you've began creating `" + orders[i].id + "`. It'll take " + pms(orders[i].manufacturing_time_left, {
  820. verbose: true
  821. }) + " to complete.");
  822. })
  823. }).catch(e => {
  824. console.error(e);
  825. return channel.send(":x: There was an error when trying to edit the ticket message!");
  826. });
  827. });
  828. }
  829. }).catch(e => {
  830. console.error(e);
  831. return channel.send(":x: There was an error when trying to find the ticket message!");
  832. });
  833. });
  834. // })
  835. }
  836. }
  837. return;
  838. }
  839. } else {
  840. if (command == "claim") {
  841. return channel.send(":x: You're not a manufacturer, you don't have permission to run this command!");
  842. } else if (command == "unclaim") {
  843. return channel.send(":x: You're not a manufacturer, you don't have permission to run this command!");
  844. } else if (command == "make") {
  845. return channel.send(":x: You're not a manufacturer, you don't have permission to run this command!");
  846. }
  847. }
  848.  
  849. if (msg.isDelivery) {
  850. if (command == "deliver") {
  851. if (!delivery.includes(channel.id)) return channel.send(":x: You can only do this command in the delivery room!"); // Edit by: EdibleDerpy
  852. if (!args[1]) return channel.send(":x: Make sure to include the Ticket's ID!");
  853. let so = orders.filter(o => o.id == args[1])[0]; // Stands for "Specified Order"
  854. if (!so) return channel.send(":x: I couldn't find the specified ticket.");
  855. if (so.status !== "Made") return channel.send(":x: This ticket is not manufactured yet!");
  856. // r.db('amazon').table('stats').get(msg.author.id).run(global.connection, (err, info) => {
  857. return author.send(so.orderer.channel.invite, createEmbed(
  858. embedColor, null, "Delivery Info",
  859. `The ticket has been deleted, it's all on you now.`, [{
  860. "name": "Ticket Description",
  861. "value": so.description
  862. }, {
  863. "name": "User Information",
  864. "value": `${so.orderer.user.username} (${so.orderer.user.id}) in #${so.orderer.channel.name} (${so.orderer.channel.id})`
  865. }, {
  866. "name": "Manufacturer's Image",
  867. "value": so.image
  868. }], null, so.image
  869. )
  870. ).then(() => {
  871. orders = orders.filter(o => o.id !== so.id);
  872. return fs.writeFile("./Orders.json", JSON.stringify(orders, null, 2), err => {
  873. if (err) {
  874. console.error(err);
  875. return channel.send(":x: There was an error writing to the tickets file! Please contact a bot administrator.");
  876. }
  877. orderChan.fetchMessage(so.omid).then(theM => {
  878. theM.delete();
  879.  
  880. /*
  881. if (info) {
  882. let delivered = Number(info.delivered);
  883.  
  884. let final = delivered + 1
  885. r.db('amazon').table('stats').get(msg.author.id).update({ delivered: final }).run(global.connection, (err, info) => { });
  886. } else {
  887. r.db('amazon').table('stats').insert({ user: msg.author.id, delivered: 1, cooked: 0 }).run(global.connection, (err, info) => { });
  888. }
  889. */
  890.  
  891. return channel.send("I've DMed you information about this order! :thumbsup:");
  892. });
  893. });
  894. }).catch(e => {
  895. console.error(e);
  896. return channel.send(":x: There was an error, please try again!");
  897. });
  898. // })
  899. }
  900. } else {
  901. if (command == "deliver") {
  902. return channel.send(":x: You're not a delivery person, you don't have permission to run this command!");
  903. }
  904. }
  905.  
  906. if (msg.isDelivery || msg.isBaker) {
  907. if (command == "delorder" || command == "delticket") {
  908. if (!args[1]) return channel.send(":x: Make sure to include the Ticket ID!");
  909. if (!args[2]) return channel.send(":x: Make sure to include a reason why you're deleting it!");
  910. let reason = GaA([args[0], args[1]], content);
  911. let so = orders.filter(o => o.id == args[1])[0]; // Stands for "Specified Order"
  912. if (!so) return channel.send(":x: I couldn't find the specified ticket.");
  913. let user = bot.users.get(so.orderer.user.id);
  914. 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```");
  915. orderChan.fetchMessage(so.omid).then(theM => {
  916. theM.delete();
  917. });
  918. orders = orders.filter(o => so.id !== o.id);
  919. fs.writeFileSync("./Orders.json", JSON.stringify(orders, null, 2));
  920. return channel.send("Alright, I've deleted that ticket! :thumbsup:");
  921. } else if (command == "list" || command == "olist" || command == "tlist") {
  922. 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";
  923. for (let i = 0; i < orders.length; i++) {
  924. if (orders[i].status.toLowerCase().includes("unclaimed") && orders[i].status.toLowerCase() !== "claimed") {
  925. str += `\`${orders[i].id}\`: ${orders[i].status}\n`
  926. }
  927. }
  928. for (let i = 0; i < orders.length; i++) {
  929. if (orders[i].status.toLowerCase().includes("claimed") && orders[i].status.toLowerCase() !== "unclaimed") {
  930. str += `\`${orders[i].id}\`: ${orders[i].status}\n`
  931. }
  932. }
  933. for (let i = 0; i < orders.length; i++) {
  934. if (orders[i].status.toLowerCase().includes("manufacturing")) {
  935. str += `\`${orders[i].id}\`: ${orders[i].status}\n`
  936. }
  937. }
  938. for (let i = 0; i < orders.length; i++) {
  939. if (orders[i].status.toLowerCase().includes("made")) {
  940. str += `\`${orders[i].id}\`: ${orders[i].status}\n`
  941. }
  942. }
  943. if (str.length > 2000) str.length = 2000;
  944. return channel.send(str);
  945. // return channel.send("A list will be coming soon. Until then, you'll have to check <#294620411721940993>.");
  946. } else if (command == "ostatus" || command == "tstatus") {
  947. if (!args[1]) return channel.send(":x: Make sure to include the Ticket ID!");
  948. let so = orders.filter(o => o.id == args[1])[0]; // Stands for "Specified Order"
  949. if (!so) return channel.send(":x: I couldn't find the specified ticket.");
  950. let user = bot.users.get(so.orderer.user.id);
  951. return channel.send(createEmbed(
  952. embedColor, null, "Ticket Status",
  953. "The status of your current ticket.", [{
  954. name: ":hash: Its Ticket ID",
  955. value: so.id
  956. }, {
  957. name: ":package: Its Description",
  958. value: so.description
  959. }, {
  960. name: ":white_check_mark: Its Ticket Status",
  961. value: so.status
  962. }, {
  963. name: ":computer: Its Guild",
  964. value: `This ticket came from ${so.orderer.guild.name} (${so.orderer.guild.id}) in ${so.orderer.channel.name} (${so.orderer.channel.id}).`
  965. }]
  966. ));
  967. }
  968. } else {
  969. if (command == "delorder" || command == "delticket") {
  970. return channel.send(":x: You're not a worker, you don't have access to this command!");
  971. } else if (command == "list" || command == "olist" || command == "tlist") {
  972. return channel.send(":x: You're not a worker, you don't have access to this command!");
  973. } else if (command == "ostatus" || command == "tstatus") {
  974. return channel.send(":x: You're not a worker, you don't have access to this command!");
  975. } else if (command == "stats") {
  976. return channel.send(":x: You're not a worker, you don't have access to this command!");
  977. }
  978. }
  979.  
  980. // Other Commands
  981. if (msg.isAdmin) {
  982. if (command == "debug") {
  983. return channel.send(orders[0].orderer.user.name);
  984. } else if (command == "corders" || command == "ctickets") {
  985. orders.forEach(o => {
  986. let user = bot.users.get(o.orderer.user.id);
  987. user.send("For an unknown reason, all tickets have been purged! Please re-order your product.");
  988. });
  989. orderChan.fetchMessages({
  990. limit: 100
  991. }).then(msgs => {
  992. let array = ['112732946774962176', '106876115586383872'];
  993. msgs = msgs.filter(m => !array.includes(m.author.id));
  994. orderChan.bulkDelete(msgs);
  995. });
  996. fs.writeFileSync("./Orders.json", "[]");
  997. return channel.send("Alright, I've cleared all tickets! :thumsbup:");
  998. } else if (command == "eval") {
  999. try {
  1000. let com = eval(msg.content.split(" ").slice(1).join(" "));
  1001. let com2 = msg.content.split(" ").slice(1).join(" ");
  1002. if (!com2) return channel.send("Include some code? o_O")
  1003. channel.send({
  1004. embed: {
  1005. color: embedColor,
  1006. title: "Evaluate Javascript Complete!",
  1007. description: "Evaluation complete!",
  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: "**Input**",
  1017. value: "```js\n" + com2 + "```"
  1018. }, {
  1019. name: "**Output**",
  1020. value: "```js\n" + com + "```"
  1021. }]
  1022. }
  1023. })
  1024. } catch (e) {
  1025. channel.send({
  1026. embed: {
  1027. color: embedColor,
  1028. title: "Code Error!",
  1029. description: "There was a error in your code!",
  1030. author: {
  1031. name: bot.user.username,
  1032. icon_url: bot.user.avatarURL
  1033. },
  1034. thumbnail: {
  1035. url: bot.user.avatarURL
  1036. },
  1037. fields: [{
  1038. name: "**Error**",
  1039. value: "```js\n" + e + "```"
  1040. }]
  1041. }
  1042. })
  1043. }
  1044. } else if (command == "restart") {
  1045. channel.send("Please confirm that you want to restart Discord Amazon. If so, say yes. If you don't want to restart Discord Amazon simply don't say anything.")
  1046. .then(() => {
  1047. channel.awaitMessages(response => response.content === "yes", {
  1048. max: 1,
  1049. time: 30000,
  1050. errors: ['time'],
  1051. })
  1052. .then((collected) => {
  1053. channel.send("Restart was triggered by " + msg.author.username);
  1054. setTimeout(function() {
  1055. process.exit();
  1056. }, 1500)
  1057. })
  1058. .catch(() => {
  1059. channel.send("No response given, Discord Amazon will not restart!");
  1060. });
  1061. });
  1062. } else if (command == "uptime") {
  1063. if (!msg.channel.permissionsFor(bot.user.id).has("EMBED_LINKS")) return msg.channel.send(":x: I'm sorry, but I need the permission to embed links to function!")
  1064.  
  1065. function calcUptime() {
  1066. let time = 0;
  1067. let days = 0;
  1068. let hrs = 0;
  1069. let min = 0;
  1070. let sec = 0;
  1071. let temp = Math.floor(bot.uptime / 1000);
  1072. sec = temp % 60;
  1073. temp = Math.floor(temp / 60);
  1074. min = temp % 60;
  1075. temp = Math.floor(temp / 60);
  1076. hrs = temp % 24;
  1077. temp = Math.floor(temp / 24);
  1078. days = temp;
  1079. let dayText = " Days, ";
  1080. if (days == 1) {
  1081. dayText = " Days, ";
  1082. }
  1083. const upText = "" + days + dayText + hrs + " hours" + ", " + min + " minutes, " + sec + " seconds ";
  1084. return upText;
  1085. }
  1086. channel.send({
  1087. embed: {
  1088. color: embedColor,
  1089. title: "Discord Amazon's Uptime",
  1090. description: calcUptime(),
  1091. author: {
  1092. name: bot.user.username,
  1093. icon_url: bot.user.avatarURL
  1094. },
  1095. thumbnail: {
  1096. url: bot.user.avatarURL
  1097. }
  1098. }
  1099. })
  1100. return;
  1101. } else if (command == "blacklist") {
  1102. let user = msg.mentions.users.first();
  1103. if (!user) return channel.send("You must tag the user you'd like to blacklist!");
  1104. blacklist.push(user.id);
  1105. fs.writeFileSync("./Blacklist.json", JSON.stringify(blacklist, null, 2));
  1106. return channel.send(":thumbsup: Alright, I've blacklisted " + user.username + "!");
  1107. } else if (command == "gblacklist") {
  1108. if (!args[1]) return channel.send("You must include the ID of the guild you'd like to blacklist!");
  1109. if (isNaN(parseInt(args[1]))) return channel.send("You must include an ID of the guild.");
  1110. let guild = bot.guilds.get(args[1]);
  1111. if (!guild) channel.send("I'm not in that guild, but I'll blacklist it anyways.");
  1112. blacklist.push((guild ? guild.id : args[1]));
  1113. fs.writeFileSync("./Blacklist.json", JSON.stringify(blacklist, null, 2));
  1114. return channel.send("Alright, I've blacklisted " + (guild ? guild.name : args[1]) + "!");
  1115. } else if (command == "unblacklist") {
  1116. let user = msg.mentions.users.first();
  1117. if (!user) return channel.send("You must tag the user you'd like to remove from the blacklist!");
  1118. blacklist = blacklist.filter(b => b !== user.id);
  1119. fs.writeFileSync("./Blacklist.json", JSON.stringify(blacklist, null, 2));
  1120. return channel.send(":thumbsup: Alright, I've removed " + user.username + " from the blacklist!");
  1121. } else if (command == "ungblacklist") {
  1122. if (!args[1]) return channel.send("You must include the ID of the guild you'd like to remove from the blacklist!");
  1123. if (isNaN(parseInt(args[1]))) return channel.send("You must include an ID of the guild.");
  1124. let guild = bot.guilds.get(args[1]);
  1125. if (!guild) channel.send(":thumbsup: I'm not in that guild, but I'll remove it anyways.");
  1126. blacklist = blacklist.filter(b => b !== (guild ? guild.id : args[1]))
  1127. fs.writeFileSync("./Blacklist.json", JSON.stringify(blacklist, null, 2));
  1128. return channel.send(":thumbsup: Alright, I've removed " + (guild ? guild.name : args[1]) + " from the blacklist!");
  1129. }
  1130. } else {
  1131. if (command == "debug") {
  1132. return channel.send(":x: You're not a bot owner, you don't have permission to run this command!");
  1133. } else if (command == "eval") {
  1134. return channel.send(":x: You're not a bot owner, you don't have permission to run this command!");
  1135. } else if (command == "restart") {
  1136. return channel.send(":x: You're not a bot owner, you don't have permission to run this command!");
  1137. } else if (command == "uptime") {
  1138. return channel.send(":x: You're not a bot owner, you don't have permission to run this command!");
  1139. } else if (command == "corders" || command == "ctickets") {
  1140. return channel.send(":x: You're not a bot owner, you don't have permission to run this command!");
  1141. } else if (command == "blacklist" || command == "gblacklist") {
  1142. return channel.send(":x: You're not a bot owner, you don't have permission to run this command!");
  1143. } else if (command == "unblacklist" || command == "ungblacklist") {
  1144. return channel.send(":x: You're not a bot owner, you don't have permission to run this command!");
  1145. }
  1146. }
  1147. });
  1148. });
  1149. });
  1150.  
  1151. //// Update All Orders
  1152. function forceCheck() {
  1153. ParseJson("./Orders.json", (err, orders) => {
  1154. if (err) return console.error(err);
  1155. let orderChan = bot.channels.get("294620411721940993");
  1156. let deliveryChan = bot.channels.get("295054086498156544");
  1157. for (let i = 0; i < orders.length; i++) {
  1158. if (orders[i].manufacturing_time_left !== "Unclaimed" && orders[i].manufacturing_time_left !== "Made") {
  1159. orders[i].manufacturing_time_left -= 60000;
  1160. }
  1161. orders[i].time_left -= 60000;
  1162. let user = bot.users.get(orders[i].orderer.user.id);
  1163. if (orders[i].time_left <= 0) {
  1164. if (orders[i].status == "Manufacturing" || orders[i].status == "Made") {
  1165. if (user) user.send("It's been twenty minutes since you ordered, and your manufactured product hasn't been delivered yet. Allow me to deliver it for you! *Side note! There is currently a glitch in the bot so orders are currently being forced to auto-delivery mode, which is this one. Sorry for the inconvenience.*"); //// The italicized area is temporary, remove after delivery glitch has been patched
  1166. bot.fetchInvite(orders[i].orderer.channel.invite).then(inv => {
  1167. inv.delete();
  1168. }).catch();
  1169. if (orderChan) orderChan.fetchMessage(orders[i].omid).then(msg => {
  1170. msg.delete();
  1171. });
  1172. let channel = bot.channels.get(orders[i].orderer.channel.id);
  1173. if (!channel && user) user.send("I was unable to find the channel that your product should have been delivered to!");
  1174. if (!channel && !user) orders.splice(i, 1);
  1175. else {
  1176. channel.send(`${user.toString()}, here's your order! ` + orders[i].image);
  1177. let chan = bot.channels.get("381361837914062849");
  1178. if (chan) chan.send(`Order \`${orders[i].id}\` has been automatically delivered.`);
  1179. orders.splice(i, 1);
  1180. }
  1181. } else {
  1182. if (orderChan) orderChan.fetchMessage(orders[i].omid).then(msg => {
  1183. msg.delete();
  1184. });
  1185. bot.fetchInvite(orders[i].orderer.channel.invite).then(inv => {
  1186. inv.delete();
  1187. }).catch();
  1188. if (user) user.send("Your ticket has timed out, as it's been 20 minutes, and the bot was unable to auto-deliver because nobody manufactured it. Please re-order your product! We apologize for the inconvenience!");
  1189. orders.splice(i, 1);
  1190. }
  1191. }
  1192. else if (orders[i].manufacturing_time_left <= 0) {
  1193. if (deliveryChan) {
  1194. orders[i].status = "Made";
  1195. orders[i].manufacturing_time_left = "Made";
  1196. console.log('test')
  1197. orderChan.fetchMessage(orders[i].omid).then(theM => {
  1198. let theEmbed = theM.embeds[0];
  1199. for (let a = 0; a < theEmbed.fields.length; a++) {
  1200. if (theEmbed.fields[a].name.toLowerCase().includes("status")) {
  1201. theEmbed.fields[a].value = "Made";
  1202. deliveryChan.send(`Ticket \`${orders[i].id}\` has completed manufacturing and is ready to be delivered!`);
  1203. break;
  1204. }
  1205. }
  1206. theM.edit({
  1207. embed: theEmbed
  1208. }).then(() => {
  1209. fs.writeFile("./Orders.json", JSON.stringify(orders, null, 2), err => {
  1210. if (err) {
  1211. console.error(err);
  1212. return channel.send(":x: There was an error writing to the tickets file! Please contact a bot administrator.");
  1213. }
  1214. let user = bot.users.get(orders[i].orderer.user.id);
  1215. if (user) user.send("Your product has been manufactured and will be delivered shortly!");
  1216. })
  1217. }).catch();
  1218. }).catch();
  1219. }
  1220. }
  1221. }
  1222. fs.writeFileSync("./Orders.json", JSON.stringify(orders, null, 2));
  1223. });
  1224. }
  1225.  
  1226.  
  1227.  
  1228.  
  1229.  
  1230.  
  1231.  
  1232.  
  1233.  
  1234.  
  1235.  
  1236. forceCheck();
  1237. setInterval(() => {
  1238. forceCheck();
  1239. }, 60000);
  1240.  
  1241. //// Connect To Discord
  1242. console.log("[Discord] Connecting...");
  1243. bot.login(Config.token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement