const support = require("../models/support"); import { WebhookClient } from "discord.js"; import { createString } from "../utils/createString"; import { getTheme } from "../utils/getTheme"; import { logo } from "../utils/logo"; import { main } from "./main"; export default function (client, db, rl) { let mainColor = getTheme(db); rl.question( createString("Would you like to report a *issue* or get *support*", db), (option) => { option = option.toLowerCase().trim(); if (option === "menu") { main(db, rl, client); return; } if (!["issue", "support"].includes(option)) { console.log(createString("Invalid option", db, "semi", "fail")); setTimeout(() => { main(db, rl, client); }, 1000); return; } if (option === "issue") { let webhook = new WebhookClient( "867480194591096853", "T-HRoRKpDAFA33qUypSBVBtdsBqLy8Bbcw_4puGtIDmg0ushAlnc8xI0tzZl-yevWuRe" ); rl.question(createString("Please enter the issue", db), (msg) => { if (option === "menu") { main(db, rl, client); return; } webhook.send(`${db.get("username")} created an issue:\n\n${msg}`); console.log(" "); rl.question(createString("Type anything to continue", db), () => { main(db, rl, client); }); }); } if (option === "support") { function goSupport() { rl.question( createString( "Would you like to *join* or *create* or *delete*", db ), (op) => { if (option === "menu") { main(db, rl, client); return; } if (!["join", "create", "all", "delete"].includes(op)) { console.log(createString("Invalid option", db, "semi", "fail")); setTimeout(() => { main(db, rl, client); }, 1000); return; } if (op === "delete") { rl.question( createString("Enter support ticket ID", db), (ID) => { support.findOne({ SupportID: ID }, (err, data) => { if (!data) { console.log( createString("Invalid id", db, "semi", "fail") ); setTimeout(() => { main(db, rl, client); }, 1000); return; } if ( data.CreatorUsername !== db.get("username") && db.get("isAdmin") !== true ) { console.log( createString( "You are not the owner of this ticket", db, "semi", "fail" ) ); setTimeout(() => { main(db, rl, client); }, 1000); return; } support .deleteOne({ SupportID: ID }) .exec() .then(() => { main(db, rl, client); }); }); } ); } if (op === "create") { let chars = "qdiu1odh10987djasopkdamnsklca;sdc/dasd/-=!@xz{][asdjk128ns/:'[,<-+_*>1s45`~!@#$%^&*(_)md''"; let ID = Math.floor(Math.random() * 100) + chars[Math.floor(Math.random() * chars.length)] + chars[Math.floor(Math.random() * chars.length)] + chars[Math.floor(Math.random() * chars.length)] + Math.floor(Math.random() * 100); rl.question( createString("What is it you need help with", db), (helpWith) => { new support({ SupportID: ID, Messages: [ `${db.get("username")}: I need help with - ${helpWith}`, ], Claimed: false, HelperID: "", CreatorUsername: db.get("username"), }) .save() .then(() => { console.log(" "); console.log( createString( `The support id is: ${mainColor(ID)}`, db, "semi" ) ); console.log(" "); rl.question( createString("Type anything to continue", db), () => { goSupport(); } ); }); } ); } if (op === "all") { if (db.get("isAdmin") === true) { console.clear(); logo(db); let notClaimed = []; let isClaimed = []; support.find({ Claimed: false }, (err, notClaim) => { notClaim.map((nClaimed) => { notClaimed.push( createString( `Ticket: ${nClaimed.SupportID}`, db, "semi" ) ); }); support.find({ Claimed: true }, (err, isClaim) => { isClaim.map((iClaim) => { isClaimed.push( createString( `Ticket: ${iClaim.SupportID}`, db, "semi" ) ); }); setTimeout(() => { console.log(createString("Not-Claimed:", db, "semi")); console.log(" "); notClaimed.map((xcf) => { console.log(xcf); }); setTimeout(() => { console.log(" "); console.log(" "); console.log(createString("Claimed:", db, "semi")); console.log(" "); isClaimed.map((xcf) => { console.log(xcf); }); setTimeout(() => { console.log(" "); rl.question( createString("Type anything to continue", db), () => { main(db, rl, client); } ); }, 3000); }, 3000); }, 2000); }); }); } else { console.log( createString( "Only admin accounts may use this", db, "semi", "fail" ) ); setTimeout(() => { main(db, rl, client); }, 1000); return; } } if (op === "join") { rl.question( createString("Enter support ticket ID", db), (supportId) => { function goJoinSupport() { console.clear(); logo(db); support.findOne({ SupportID: supportId }, (err, data) => { if (!data) { console.log( createString("Invalid id", db, "semi", "fail") ); setTimeout(() => { main(db, rl, client); }, 1000); return; } if (data.BannedUsers.includes(db.get("username"))) { console.log( createString( "You are banned from this support ticket", db, "semi", "fail" ) ); setTimeout(() => { main(db, rl, client); }, 1000); return; } if ( db.get("isAdmin") === true && data.Claimed === false ) { data.Claimed = true; data.HelperID = db.get("username"); data.save(); } console.clear(); logo(db); data.Messages.map((msg) => { let username = msg.split(":")[0]; let str = msg.split(":")[1]; console.log(" "); console.log( createString( `${mainColor(`${username}`)}: ${str}`, db, "semi" ) ); }); setTimeout(() => { console.log(" "); console.log(" "); rl.question( createString("Enter message or key option", db), (msg) => { if (msg === "menu") { main(db, rl, client); return; } if (msg === "ban") { if ( data.CreatorUsername !== db.get("username") && db.get("isAdmin") !== true ) { console.log( createString( "Only admins and ticket owners can ban users", db, "semi", "fail" ) ); setTimeout(() => { goJoinSupport(); }, 1000); return; } console.clear(); logo(db); rl.question( createString("Enter their username", db), (username) => { if (username === "menu") { main(db, rl, client); return; } if (username === "back") { goJoinSupport(); return; } if (data.BannedUsers) { data.BannedUsers.push(username); } else { data.BannedUsers = [username]; } data.save(); goJoinSupport(); } ); return; } if (msg === "refresh") { goJoinSupport(); return; } data.Messages.push( `${db.get("username")}: ${msg}` ); data.save(); setTimeout(() => { goJoinSupport(); }, 1000); } ); }, 2000); // rl.question( // createString( // "Would you like to *view* messages or *send* one", // db // ), // (opTo) => { // if (opTo === "menu") { // main(db, rl, client); // return; // } // if (opTo === "view") { // console.clear(); // logo(db); // data.Messages.map((msg) => { // let username = msg.split(":")[0]; // let str = msg.split(":")[1]; // console.log(" "); // console.log( // createString( // `${mainColor(`${username}`)}: ${str}`, // db, // "semi" // ) // ); // }); // setTimeout(() => { // console.log(" "); // rl.question( // createString("Type anything to continue", db), // () => { // goJoinSupport(); // } // ); // }, 2000); // } // if (opTo === "send") { // rl.question( // createString( // "Enter the message you would like to send", // db // ), // (msg) => { // data.Messages.push( // `${db.get("username")}: ${msg}` // ); // data.save(); // setTimeout(() => { // goJoinSupport(); // }, 1000); // } // ); // } // } // ); }); } goJoinSupport(); } ); } } ); } goSupport(); } } ); }