diff --git a/Commands/Private/stats.js b/Commands/Private/stats.js index 69d08a10..9825c645 100644 --- a/Commands/Private/stats.js +++ b/Commands/Private/stats.js @@ -1,5 +1,5 @@ -const { MessageEmbed } = require("discord.js"); -const os = require("os"); +import { MessageEmbed } from "discord.js"; +import * as os from ("os"); module.exports = async(client, msg, suffix) => { const DTS = config.dtsEmoji; diff --git a/Commands/Public/block.js b/Commands/Public/block.js index 0745452b..20e2dfc5 100644 --- a/Commands/Public/block.js +++ b/Commands/Public/block.js @@ -1,5 +1,3 @@ -import embeds from "../../configuration/embeds"; - module.exports = async(client, msg, suffix) => { if (!suffix) return msg.channel.send({ embed: { color: config.colors.info, title: "Command usage", description: "To (un)block a number: >block [number]" } }); diff --git a/Commands/Public/call.js b/Commands/Public/call.js index 5b21813e..b84ee4fa 100644 --- a/Commands/Public/call.js +++ b/Commands/Public/call.js @@ -1,5 +1,4 @@ import { v4 as uuidv4 } from "uuid"; -import embeds from "../../configuration/embeds"; module.exports = async(client, msg, suffix, rcall) => { let csCall; diff --git a/Commands/Public/coinflip.js b/Commands/Public/coinflip.js index f11322f8..2e60f00f 100644 --- a/Commands/Public/coinflip.js +++ b/Commands/Public/coinflip.js @@ -1,34 +1,33 @@ // @ts-check module.exports = async(client, msg, suffix) => { - if (!suffix || !["heads", "tails"].includes(suffix.split(" ")[0].toLowerCase())) return msg.channel.send({ embed: { color: config.colors.info, description: "Are you confident in your guessing skills? Then ~~waste~~ win some money with coinflip!\nUsage: `>coinflip [heads|tails] [amount]`" } }); + if (!suffix || !["heads", "tails"].includes(suffix.split(" ")[0].toLowerCase())) return msg.channel.send({ embed: { color: config.colors.info, description: "Are you confident in your guessing skills? Then ~~waste~~ win some money with coinflip!\nUsage: `>coinflip [heads|tails] [amount]`" } }); - const type = suffix.split(" ")[0].toLowerCase() === "heads" ? 0 : 1; - let bet = parseInt(suffix.split(" ")[1]); + const type = suffix.split(" ")[0].toLowerCase() === "heads" ? 0 : 1; + let bet = parseInt(suffix.split(" ")[1]); - if (!bet || bet < 5) { - msg.channel.send({ embed: { color: config.colors.info, description: "We're not playing for free, I've set your bet to <:DTS:668551813317787659>5" } }); - bet = 5; - } else if (bet > 250) { - msg.channel.send("Hoho, you may be rich but the maximum betting amount is <:DTS:668551813317787659>250. I've lowered it for you."); - bet = 250; - } + if (!bet || bet < 5) { + msg.channel.send({ embed: { color: config.colors.info, description: "We're not playing for free, I've set your bet to <:DTS:668551813317787659>5" } }); + bet = 5; + } else if (bet > 250) { + msg.channel.send("Hoho, you may be rich but the maximum betting amount is <:DTS:668551813317787659>250. I've lowered it for you."); + bet = 250; + } - const account = await msg.author.account(); - if (!account.balance || account.balance < bet) msg.channel.send({ embed: { color: config.colors.error, description: "You can't bet with money you don't even have." } }); + const account = await msg.author.account(); + if (!account.balance || account.balance < bet) msg.channel.send({ embed: { color: config.colors.error, description: "You can't bet with money you don't even have." } }); - const side = Math.random() < .5 ? 0 : 1; - const color = config.colors.lottery; + const side = Math.random() < 0.5 ? 0 : 1; + const color = config.colors.lottery; - return msg.channel.send({ embed: { color, description: "Flipping the coin..." } }).then(async(m) => { - const balance = account.balance + Math.ceil(((side === type ? .85 : -1) * bet)); - await r.table("Accounts").get(msg.author.id).update({ balance }); - const title = `Landed on ${side === 0 ? "heads" : "tails"}` - const description = type === side ? - `Congratulations! You've won <:DTS:668551813317787659>${Math.ceil(bet * .85)}` - : `Thanks for your credits, I'll be ~~gambling~~ spending them well!`; - - setTimeout(() => { - m.edit({ embed: { title, description, color } }); - }, 2500); - }); + return msg.channel.send({ embed: { color, description: "Flipping the coin..." } }).then(async(m) => { + const balance = account.balance + Math.ceil((side === type ? 0.85 : -1) * bet); + await r.table("Accounts").get(msg.author.id).update({ balance }); + const title = `Landed on ${side === 0 ? "heads" : "tails"}`; + const description = type === side ? + `Congratulations! You've won <:DTS:668551813317787659>${Math.ceil(bet * 0.85)}` : + `Thanks for your credits, I'll be ~~gambling~~ spending them well!`; + setTimeout(() => { + m.edit({ embed: { title, description, color } }); + }, 2500); + }); }; diff --git a/Commands/Public/contacts.js b/Commands/Public/contacts.js index 868e545c..2f8056a2 100644 --- a/Commands/Public/contacts.js +++ b/Commands/Public/contacts.js @@ -1,5 +1,4 @@ import { MessageEmbed } from "discord.js"; -import embeds from "../../configuration/embeds"; module.exports = async(client, msg) => { const myNumber = await msg.channel.number; @@ -70,7 +69,7 @@ module.exports = async(client, msg) => { let getNumber = async bad => { if (!perm) { msg.author.busy = false; - return msg.channel.send({ embed: { color: config.colors.error, title: "Insufficient permission", description: "You need manage server permission to do this." } }); + return msg.channel.send({ embed: embeds.requiresManageGuild }); } if (contacts.length >= 10) msg.channel.send({ embed: { color: config.colors.error, title: "Too many contacts", description: "We currently do not allow more than 9 contacts." } }); @@ -170,7 +169,7 @@ module.exports = async(client, msg) => { // check for perm & if the contact is legit if (!perm) { msg.author.busy = false; - return msg.channel.send({ embed: { color: config.colors.error, title: "Insufficient perms", description: "You need the Manage Server permission to do this." } }); + return msg.channel.send({ embed: embeds.requiresManageGuild }); } omsg = await msg.channel.send({ embed: { @@ -239,7 +238,7 @@ module.exports = async(client, msg) => { if (/delete/i.test(collected.first().content.split(" ")[0])) { msg.author.busy = false; // check for perm & if the contact is legit - if (!perm) return msg.channel.send({ embed: { color: config.colors.error, title: "Insufficient permission", description: "You need manage server permission to do this." } }); + if (!perm) return msg.channel.send({ embed: embeds.requiresManageGuild }); // Delete the contact's entry contacts.splice(contacts.indexOf(contact), 1); diff --git a/Commands/Public/mailbox.js b/Commands/Public/mailbox.js index d5037d25..28ddd724 100644 --- a/Commands/Public/mailbox.js +++ b/Commands/Public/mailbox.js @@ -1,5 +1,4 @@ import { MessageEmbed } from "discord.js"; -import embeds from "../../configuration/embeds.js"; module.exports = async(client, msg, suffix) => { // get the number @@ -97,7 +96,7 @@ module.exports = async(client, msg, suffix) => { } }); } else if (suffix.split(" ")[0].toLowerCase() == "delete") { // deleting mailbox - if (!perm) return msg.channel.send({ embed: { color: config.colors.error, title: "Permission error", description: "You need the manage guild permission for this." } }); + if (!perm) return msg.channel.send({ embed: embeds.requiresManageGuild }); omsg = await msg.channel.send({ embed: { color: config.colors.info, title: "Confirmation", description: "Are you sure you want to delete your mailbox? Stored messages will become **unretrievable**.\nType **yes** to confirm, **no** to cancel." } }); collector = await msg.channel.awaitMessages( diff --git a/Commands/Public/mention.js b/Commands/Public/mention.js index fdfcf032..c8f12f54 100644 --- a/Commands/Public/mention.js +++ b/Commands/Public/mention.js @@ -1,5 +1,3 @@ -import embeds from "../../configuration/embeds"; - module.exports = async(client, msg, suffix) => { let perms = msg.guild ? msg.guild.members.cache.get(msg.author.id).hasPermission("MANAGE_MESSAGES") : msg.author.support; diff --git a/Commands/Public/message.js b/Commands/Public/message.js index 65cea3e3..a0ddcd9e 100644 --- a/Commands/Public/message.js +++ b/Commands/Public/message.js @@ -1,5 +1,4 @@ import * as randomstring from "randomstring"; -import embeds from "../../configuration/embeds"; module.exports = async(client, msg, suffix) => { let time = Date.now(); diff --git a/Commands/Public/promote.js b/Commands/Public/promote.js index e9980e12..2a49a92e 100644 --- a/Commands/Public/promote.js +++ b/Commands/Public/promote.js @@ -1,5 +1,4 @@ import { MessageEmbed } from "discord.js"; -import embeds from "../../configuration/embeds"; module.exports = async(client, msg) => { /* diff --git a/Commands/Public/rcall.js b/Commands/Public/rcall.js index 4a91dd19..9e388d95 100644 --- a/Commands/Public/rcall.js +++ b/Commands/Public/rcall.js @@ -1,5 +1,3 @@ -import embeds from "../../configuration/embeds"; - module.exports = async(client, msg) => { let fromNumber = await msg.channel.number; if (!fromNumber) return msg.channel.send({ embed: embeds.noNumber }); diff --git a/Commands/Public/update.js b/Commands/Public/update.js index 56b715ce..88046a1c 100644 --- a/Commands/Public/update.js +++ b/Commands/Public/update.js @@ -20,7 +20,7 @@ module.exports = async(client, msg, suffix) => { const newPerms = await require("../../internals/modules").updatePerms(member); return msg.channel.send({ embed: { author: { name: member.user.tag, icon_url: member.user.displayAvatarURL() }, description: `\`\`\`js\n${require("util").inspect(newPerms)}\`\`\`` } }); } - + let resstr = ""; const permsArr = suffix.match(/[+-]\w*/g) || []; permsArr.push("end"); diff --git a/Commands/Public/upgrade.js b/Commands/Public/upgrade.js index dba2fac4..b2e2fbd9 100644 --- a/Commands/Public/upgrade.js +++ b/Commands/Public/upgrade.js @@ -1,8 +1,8 @@ // @ts-check -const { MessageEmbed } = require("discord.js"); +import { MessageEmbed } from "discord.js"; -module.exports = async(client, msg, suffix) => { +module.exports = async(client, msg) => { // Get their details let number = await msg.channel.number; let vipExpiry = number ? number.vip ? new Date(number.vip.expiry) : null : null; diff --git a/Commands/Public/wizard.js b/Commands/Public/wizard.js index 21d97844..bc9dfb3c 100644 --- a/Commands/Public/wizard.js +++ b/Commands/Public/wizard.js @@ -12,7 +12,7 @@ module.exports = async(client, msg) => { let perm = msg.channel.type === "dm" ? true : await msg.guild.members.cache.get(msg.author.id).hasPermission("MANAGE_GUILD"); if (!perm) perm = msg.author.support; - if (!perm) return msg.channel.send({ embed: { color: config.colors.error, title: "Permission error", description: "You need to have `manage guild` permission to run this command." } }); + if (!perm) return msg.channel.send({ embed: embeds.requiresManageGuild }); let prefix = msg.channel.type == "dm" ? "0900" : `030${client.shard.id + 1}`; msg.author.busy = true; diff --git a/Commands/Support/cinfo.js b/Commands/Support/cinfo.js index 3267241a..d7b1e500 100644 --- a/Commands/Support/cinfo.js +++ b/Commands/Support/cinfo.js @@ -1,4 +1,5 @@ -const { MessageEmbed } = require("discord.js"); +import { MessageEmbed } from "discord.js"; + module.exports = async(client, msg, suffix) => { let call = await r.table("OldCalls").get(suffix); if (!call) call = await r.table("Calls").get(suffix); diff --git a/Commands/Support/identify.js b/Commands/Support/identify.js index 01fd9b54..991051bc 100644 --- a/Commands/Support/identify.js +++ b/Commands/Support/identify.js @@ -1,4 +1,5 @@ -const { MessageEmbed } = require("discord.js"); +import { MessageEmbed } from "discord.js"; + module.exports = async(client, msg, suffix) => { let callID = suffix.split(" ")[0]; let msgID = suffix.split(" ")[1]; diff --git a/Commands/Support/minfo.js b/Commands/Support/minfo.js index adad14b3..55a12ac0 100644 --- a/Commands/Support/minfo.js +++ b/Commands/Support/minfo.js @@ -1,4 +1,4 @@ -const { MessageEmbed } = require("discord.js"); +import { MessageEmbed } from "discord.js"; module.exports = async(client, msg, suffix) => { let number = suffix.split(" ")[0]; diff --git a/Commands/Support/ninfo.js b/Commands/Support/ninfo.js index 8e7e1ef1..fab84aca 100644 --- a/Commands/Support/ninfo.js +++ b/Commands/Support/ninfo.js @@ -1,4 +1,4 @@ -const { MessageEmbed } = require("discord.js"); +import { MessageEmbed } from "discord.js"; const reaction = "💡"; diff --git a/Commands/Support/uinfo.js b/Commands/Support/uinfo.js index 649768b6..0162b029 100644 --- a/Commands/Support/uinfo.js +++ b/Commands/Support/uinfo.js @@ -1,4 +1,4 @@ -const { MessageEmbed } = require("discord.js"); +import { MessageEmbed } from "discord.js"; const reaction = "💡"; diff --git a/Configuration/embeds.js b/Configuration/embeds.js index 7739e4d0..49faf681 100644 --- a/Configuration/embeds.js +++ b/Configuration/embeds.js @@ -1,4 +1,5 @@ /* eslint-disable no-inline-comments */ + // This file contains a series of commonly-used embed objects. module.exports = { // Registry error: no number @@ -8,4 +9,11 @@ module.exports = { description: "This channel doesn't have a number assigned. Use >wizard to set one up, then try this command again.", footer: `If you have any questions, please join our support server (${config.guildInvite}) or, in a channel with a number, \`>call *611\`.`, }, + // Perm error: user doesn't have Manage Guild + requiresManageGuid: { + color: config.colors.error, + title: "Insufficient permissions", + description: "This command requires the `Manage Guild` (also known as the `Manage Server`) permission. Ask an admin to run this command.", + footer: `If you have any questions, or if you think you have the Manage Guild permission, please join our support server (${config.guildInvite}) or \`>call *611\`.`, + }, }; diff --git a/DTel.js b/DTel.js index 90f25114..12750cd9 100644 --- a/DTel.js +++ b/DTel.js @@ -6,7 +6,7 @@ import { createLogger, format, transports } from "winston"; const DailyRotateFile = require("winston-daily-rotate-file"); const config = global.config = require("./configuration/config.js"); const aliases = global.aliases = require("./configuration/aliases.js"); - +const embeds = global.embeds = require ("./configuration/embeds.js"); module.exports = class extends require("kurasuta").BaseCluster { launch() { const client = global.client = this.client; diff --git a/Database/init.js b/Database/init.js index 7b0d6a88..a1e8e589 100644 --- a/Database/init.js +++ b/Database/init.js @@ -1,4 +1,4 @@ -const { db } = require("../configuration/auth.js"); +import { db } from "../configuration/auth.js"; const Cache = require("../internals/Cache.js"); diff --git a/Events/ready.js b/Events/ready.js index 77372231..7c2eba62 100644 --- a/Events/ready.js +++ b/Events/ready.js @@ -1,4 +1,4 @@ -const { updatePerms, perms } = require("../internals/modules"); +import { updatePerms, perms } from "../internals/modules"; module.exports = async() => { await client.shard.broadcastEval(`this.done = true`); diff --git a/Internals/callHandler.js b/Internals/callHandler.js index 34a30d79..437158bd 100644 --- a/Internals/callHandler.js +++ b/Internals/callHandler.js @@ -1,4 +1,4 @@ -const { MessageEmbed } = require("discord.js"); +import { MessageEmbed } from "discord.js"; module.exports = async(cmd, msg, suffix, call) => { let embed = null, @@ -56,8 +56,8 @@ module.exports = async(cmd, msg, suffix, call) => { await r.table("Calls").get(call.id).update({ connectionLost: true }); let amt = 0; - - const lostInterval = setInterval(async () => { + + const lostInterval = setInterval(async() => { try { await client.api.channels(toSend.channel).get(); @@ -82,7 +82,7 @@ module.exports = async(cmd, msg, suffix, call) => { return client.delete(toSend.number, { force: false, log: true, origin: "callHandler" }); } } - }, 1e4) + }, 1e4); } // send the msg