From 91ed136830777e7199e4365d3630829e7964b6d8 Mon Sep 17 00:00:00 2001 From: DarkenLM Date: Tue, 4 Jan 2022 16:52:54 +0000 Subject: [PATCH] v1.0.0 Cleaned up: Removed comments, forgotten console.logs --- core/bases/command.js | 12 -- core/bases/modules.js | 24 --- core/commands/admin/eval.js | 15 +- core/commands/admin/permtoken.js | 2 +- core/commands/admin/register.js | 1 - core/commands/admin/reload.js | 7 - core/commands/info/help.js | 2 +- core/events/interactionCreate.js | 11 +- core/events/messageCreate.js | 76 +--------- core/events/ready.js | 15 +- core/modules/db.js | 84 ----------- core/modules/generators.js | 58 +------ core/modules/maintest.js | 21 --- core/modules/parsers.js | 250 +------------------------------ core/modules/registerers.js | 109 ++------------ core/modules/verifiers.js | 15 +- core/utils/loader.js | 30 +--- docs/commands.md | 37 ----- 18 files changed, 31 insertions(+), 738 deletions(-) delete mode 100644 core/modules/maintest.js diff --git a/core/bases/command.js b/core/bases/command.js index fbe9632..301ab03 100644 --- a/core/bases/command.js +++ b/core/bases/command.js @@ -40,8 +40,6 @@ class Command { for (let [key, value] of Object.entries(this.command)) { if (this.#defaultCommand.hasOwnProperty(key)) { - //if (typeof(value) !== typeof(this.#defaultCommand[key])) throw new Error(`Invalid type for command metadata property ${key}: '${typeof(value)}' (Expected '${typeof(this.#defaultCommand[key])}')`) - //console.log(key, value) const verifyTypes = function(prop) { switch (prop) { case 'string': @@ -50,7 +48,6 @@ class Command { return true break; case 'array': - //console.log(value) if (!Array.isArray(value)) throw new Error(`Invalid type for command metadata property ${key}: '${typeof(value)}' (Expected 'array')`) break; default: @@ -91,15 +88,6 @@ class Command { break; } } - /*if (["null", "undefined"].includes(typeof(value))) { - switch (key) { - case 'category': { - break; - } - default: - throw new Error(`Required property is undefined: '${key}'.`) - } - }*/ } else throw new Error(`Unexpected property on command definition: '${key}'.`) } diff --git a/core/bases/modules.js b/core/bases/modules.js index 9d32b4c..e9288b3 100644 --- a/core/bases/modules.js +++ b/core/bases/modules.js @@ -7,17 +7,6 @@ class Modules { name: name, description: description || '' } - - // this._attachments = [] - - /*this._helpers = { - isPluginExtension: () => this.declarations.hasOwnProperty("extends"), - clone: () => { - if (this._helpers.isPluginExtension()) { - - } - } - }.bind(this)*/ } async attach(Class) { @@ -65,19 +54,6 @@ class Modules { logger.error(`[MODULE] [${this.declarations.name.toUpperCase()}] [ATTACH] Error while attaching: `, e) return false } - - - - //this[Class.declarations.name] = Class - // this._attachments.push({ - // type: (Class.declarations.name === this.declarations.name) ? "master" : "branch", - // Class - // }) - /*if (Class.declarations.name === this.declarations.name) { - this._attachments.push() - } else { - - }*/ } setBaseClass(baseClass) { diff --git a/core/commands/admin/eval.js b/core/commands/admin/eval.js index ea77955..4dcf65c 100644 --- a/core/commands/admin/eval.js +++ b/core/commands/admin/eval.js @@ -11,16 +11,8 @@ class command extends Command { short: "Manually execute code on the bot's process.", long: "Manually execute code on the bot's process.\n**WARNING:** This command runs arbitrary code. Any changes the code does are ***FINAL***." } - //this.command.category = "" - this.command.arguments = [ - // { - // type: 'STRING', - // name: "code", - // description: "The code to be executed.", - // required: true, - // messageOnly: true - // } - ] + + this.command.arguments = [] this.command.aliases = ["evaluate"] this.command.permlevel = 100 } @@ -38,7 +30,7 @@ class command extends Command { str = str.substring(0, 1800) str = str + "[...]" } - message.react("912664654021554176"); + message.react("✅"); message.channel.send({ embeds: [ { @@ -56,7 +48,6 @@ class command extends Command { ] }); } catch (err) { - console.log(err) message.react("❌"); message.channel.send({ embeds: [ diff --git a/core/commands/admin/permtoken.js b/core/commands/admin/permtoken.js index f82d90b..1e3b174 100644 --- a/core/commands/admin/permtoken.js +++ b/core/commands/admin/permtoken.js @@ -41,7 +41,7 @@ class command extends Command { break; } await dbTable.set(`${interaction.user.id}.global`, obj) - return interaction.followUp({ embeds: [bot.modules.embed.create(pseudoMessage, `Permission Token bound to your account.\n- Token Type: ${tokenVer.data.type}\n${tokenVer.data.type === 'UBOT' ? `- Permission Level: ${tokenVer.data.level}\n- Uses: ${tokenVer.data.uses}` : `- Permission Level: ${tokenVer.data.level}\n- Expiration Date: `}`, 'SUCCESS')], ephemeral: true })//${bot.modules.parsers.formatTime(parseInt(tokenVer.data.iat) + parseInt(tokenVer.data.exp), 'pt', 'LLLL')} + return interaction.followUp({ embeds: [bot.modules.embed.create(pseudoMessage, `Permission Token bound to your account.\n- Token Type: ${tokenVer.data.type}\n${tokenVer.data.type === 'UBOT' ? `- Permission Level: ${tokenVer.data.level}\n- Uses: ${tokenVer.data.uses}` : `- Permission Level: ${tokenVer.data.level}\n- Expiration Date: `}`, 'SUCCESS')], ephemeral: true }) } else { return interaction.followUp({ embeds: [bot.modules.embed.create(pseudoMessage, `Invalid Permission Token.`, 'ERROR')], ephemeral: true }) } diff --git a/core/commands/admin/register.js b/core/commands/admin/register.js index c3a0ca4..7da13c4 100644 --- a/core/commands/admin/register.js +++ b/core/commands/admin/register.js @@ -32,7 +32,6 @@ class command extends Command { } async execute(bot, message, args) { - console.log(args) let subCommand = args.getSubcommand() switch (subCommand) { diff --git a/core/commands/admin/reload.js b/core/commands/admin/reload.js index 233723e..b2558ef 100644 --- a/core/commands/admin/reload.js +++ b/core/commands/admin/reload.js @@ -41,7 +41,6 @@ class command extends Command { } async execute(bot, message, args) { - //console.log(args) let command = args.getSubcommand(), value = args.getString('command_name') || args.getString('category_name'), last = await db.fetch('SYSTEM:last_reload') @@ -108,12 +107,6 @@ class command extends Command { for (let categoryCmd of categoryCmds) { let cmd = categoryCmd[1] - // let file = `../${value.toLowerCase()}/${cmd.command.name}.js` - // delete require.cache[require.resolve(file)]; - // bot.commands.delete(cmd.command.name); - // const pull = require(file); - // bot.commands.set(cmd.command.name, pull); - // reloaded.push(cmd.command.name) for (const [key, value] of bot.aliases.entries()) { if (value === cmd.command.name) bot.aliases.delete(key) } diff --git a/core/commands/info/help.js b/core/commands/info/help.js index eabbff6..3b0c168 100644 --- a/core/commands/info/help.js +++ b/core/commands/info/help.js @@ -8,7 +8,7 @@ class command extends Command { short: "Get the list of commands.", long: "Get the list of commands or information about a specific command." } - //this.command.category = "" + this.command.arguments = [ { type: "STRING", diff --git a/core/events/interactionCreate.js b/core/events/interactionCreate.js index d541f21..0726960 100644 --- a/core/events/interactionCreate.js +++ b/core/events/interactionCreate.js @@ -3,7 +3,6 @@ const path = require('path'); const fs = require("fs"); module.exports = async (bot, interaction) => { - //console.log(interaction) if (!interaction.isCommand()) return; const cmd = bot.commands.get(interaction.commandName); @@ -31,9 +30,6 @@ module.exports = async (bot, interaction) => { let dbTable = await bot.modules.db.tables.get('Tokens') let userToken = await dbTable.get(`${message.author.id}.global`) - //console.log(userToken) - - //console.log('INTERACTION: ', level, isEnabled) if (isEnabled) { if (level >= cmd.command.permlevel) { logger.warn(`[EVENTS] [IC] ${message.author.tag} executed the command ${cmd.command.name}`) @@ -44,11 +40,10 @@ module.exports = async (bot, interaction) => { function genReport() { let reportID = bot.modules.generators.makeID(6) let reportPath = path.join(__dirname, "../../logs/error_reports", `${reportID}.md`) - // console.log(reportPath) + if (fs.existsSync(reportPath)) { genReport() } else { - // console.log(cmd.getFilePath()) let cmdFile = fs.readFileSync(cmd.getFilePath()) let data = [ `# Error Report`, @@ -111,11 +106,10 @@ module.exports = async (bot, interaction) => { function genReport() { let reportID = bot.modules.generators.makeID(6) let reportPath = path.join(__dirname, "../../logs/error_reports", `${reportID}.md`) - // console.log(reportPath) + if (fs.existsSync(reportPath)) { genReport() } else { - // console.log(cmd.getFilePath()) let cmdFile = fs.readFileSync(cmd.getFilePath()) let data = [ `# Error Report`, @@ -170,7 +164,6 @@ module.exports = async (bot, interaction) => { }) } } - //await command.executeInteraction(bot, interaction); } catch (error) { logger.error(`[EVENTS] [IC] Error while running ${interaction.commandName}:`, error); await interaction.followUp({ diff --git a/core/events/messageCreate.js b/core/events/messageCreate.js index 343fef2..5148f4d 100644 --- a/core/events/messageCreate.js +++ b/core/events/messageCreate.js @@ -3,76 +3,6 @@ const db = require("quick.db"); const path = require('path'); const fs = require("fs"); -/*module.exports = async (bot, message) => { - if (message.author.bot) return; - - let prefix = bot.config.messageCommands.prefix; - - if (message.channel.type !== "dm") { - const prefixMention = new RegExp(`^<@!?${bot.user.id}>( |)$`); - if (message.content.match(prefixMention)) { - return message.channel.send({ embeds: [bot.modules.embed.create(message, `I'm {INSERT NAME HERE}, a Multi-tool Discord Bot.\n\nCommand List: \`${prefix}help\``, 'PARTIAL_ERROR', {title: `Hello, ${message.author.username}!`})] }) - } - } - - const _args = message.content.slice(prefix.length).trim().split(/ +/g); - const command = _args.shift().toLowerCase(); - - const level = await bot.modules.verifiers.permLevel(message); - - const cmd = bot.commands.get(command) || bot.commands.get(bot.aliases.get(command)); - - let dbTable = await bot.modules.db.tables.get('Tokens') - let userToken = await dbTable.get(`${message.author.id}.global`) - - if (cmd) { - if (![0, 1].includes(cmd.command.restricted)) { - logger.warn(`[EVENTS] [MESSAGE] ${message.author.tag} attempted to execute the command ${cmd.command.name}, but it was restricted to interaction mode`) - message.reply({ - embeds: [ - bot.modules.embed.create(message, `Please execute this command as a Slash Command.`, "UNAUTHORIZED") - ] - }) - - return; - } - - let isEnabled = await bot.modules.parsers.ecl.get(cmd.command) - if (isEnabled) { - if (level >= cmd.command.permlevel) { - let { validity, argMap } = await bot.modules.parsers.messageArguments(message, _args, cmd.command) - if (validity === true) { - logger.warn(`[EVENTS] [MESSAGE] ${message.author.tag} executed the command ${cmd.command.name}`) - await cmd.execute(bot, message, argMap) - if (userToken?.type == "UBOT") await dbTable.add(`${userID}.global.uses`, 1) - } else { - message.reply({ embeds: [ bot.modules.embed.create(message, `${validity}`, 'UNAUTHORIZED') ] }) - logger.warn(`[EVENTS] [MESSAGE] ${message.author.tag} attempted to execute the command ${cmd.command.name} with invalid arguments: ${validity}`) - } - } else { - logger.warn(`[EVENTS] [MESSAGE] ${message.author.tag} attempted to execute the command ${cmd.command.name} without valid permission`) - message.reply({ embeds: [ bot.modules.embed.create(message, `- Required permission: ${cmd.command.permlevel} (${bot.modules.parsers.permLevels(cmd.command.permlevel)})\n- Current permission: ${level} (${bot.modules.parsers.permLevels(level)})`, 'UNAUTHORIZED') ] }) - } - } else { - if (level >= bot.constants.commands.OVERRIDE_MIN_PERM_LEVEL && level >= cmd.command.permlevel) { - let areArgsValid = await bot.modules.parsers.messageArguments(message, _args, cmd.command) - //console.log(areArgsValid) - if (areArgsValid === true) { - logger.warn(`[EVENTS] [MESSAGE] ${message.author.tag} executed the disabled command ${cmd.command.name}`) - await cmd.execute(bot, message, _args) - if (userToken?.type == "UBOT") await dbTable.add(`${userID}.global.uses`, 1) - } else { - message.reply({ embeds: [ bot.modules.embed.create(message, `${areArgsValid}`, 'UNAUTHORIZED') ] }) - logger.warn(`[EVENTS] [MESSAGE] ${message.author.tag} attempted to execute the disabled command ${cmd.command.name} with invalid arguments: ${areArgsValid}`) - } - } else { - logger.warn(`[EVENTS] [MESSAGE] ${message.author.tag} attempted to execute the disabled command ${cmd.command.name}`) - message.reply({ embeds: [ bot.modules.embed.create(message, `- Required permission: ${bot.constants.commands.OVERRIDE_MIN_PERM_LEVEL > cmd.command.permlevel ? bot.constants.commands.OVERRIDE_MIN_PERM_LEVEL : cmd.command.permlevel} (${bot.modules.parsers.permLevels(bot.constants.commands.OVERRIDE_MIN_PERM_LEVEL > cmd.command.permlevel ? bot.constants.commands.OVERRIDE_MIN_PERM_LEVEL : cmd.command.permlevel)})\n- Current permission: ${level} (${bot.modules.parsers.permLevels(level)})`, 'UNAUTHORIZED') ] }) - } - } - } -};*/ - module.exports = async (bot, message) => { if (message.author.bot) return; @@ -123,11 +53,10 @@ module.exports = async (bot, message) => { function genReport() { let reportID = bot.modules.generators.makeID(6) let reportPath = path.join(__dirname, "../../logs/error_reports", `${reportID}.md`) - // console.log(reportPath) + if (fs.existsSync(reportPath)) { genReport() } else { - // console.log(cmd.getFilePath()) let cmdFile = fs.readFileSync(cmd.getFilePath()) let data = [ `# Error Report`, @@ -210,11 +139,10 @@ module.exports = async (bot, message) => { function genReport() { let reportID = bot.modules.generators.makeID(6) let reportPath = path.join(__dirname, "../../logs/error_reports", `${reportID}.md`) - // console.log(reportPath) + if (fs.existsSync(reportPath)) { genReport() } else { - // console.log(cmd.getFilePath()) let cmdFile = fs.readFileSync(cmd.getFilePath()) let data = [ `# Error Report`, diff --git a/core/events/ready.js b/core/events/ready.js index 4c20483..7791792 100644 --- a/core/events/ready.js +++ b/core/events/ready.js @@ -11,17 +11,11 @@ module.exports = async bot => { else { logger.error(`[LOADER] [INTERACTIONS] Could not load Permissions. Shutting down.`) process.exit(1) - } //logger.warn(`[EVENTS] [READY] Interactions' permissions not registered. Interactions may not work as predicted`) + } function setPresence() { if (bot.config.hasOwnProperty("maintenance") && bot.config.maintenance) { - /*bot.user.setPresence({ - activities: [ - { name: '🚧 MAINTENANCE ONGOING 🚧' } - ], - status: 'idle' - })*/ let presence = bot.config.client.presences.maintenance bot.user.setPresence({ @@ -29,13 +23,6 @@ module.exports = async bot => { status: presence.status }) } else { - /*bot.user.setPresence({ - activities: [ - { name: 'Lost? Go fuck yourself.' }, - { name: 'H' } - ], - status: 'online' - })*/ let presence = bot.config.client.presences.production bot.user.setPresence({ activities: [presence.activities[Math.floor(Math.random() * presence.activities.length)]], diff --git a/core/modules/db.js b/core/modules/db.js index 0b59471..6ede31b 100644 --- a/core/modules/db.js +++ b/core/modules/db.js @@ -13,9 +13,6 @@ const _db = new sqlite("./json.sqlite") const _Module = bot.bases.modules const storage = { tables: {} } class Module extends _Module { - /*#storage = { - tables: {} - }*/ constructor() { super(); this.declarations.name = 'db'; @@ -29,18 +26,8 @@ class Module extends _Module { reset: this._tableReset, fReset: this._forceTableReset } - - /*this.test = { - thisGet: this, - testMethod: this.testMethod - }*/ } - /*testMethod() { - console.log(this.#storage) - return - }*/ - async _tableGet(table) { try { @@ -48,7 +35,6 @@ class Module extends _Module { let _table = new db.table(table) _table.clear = function() { - console.log("I'M HERE BITCH") // Delete all Rows let fetched = _db.prepare(`DELETE FROM ${table.split("--")[0]}`).run(); if(!fetched) return null; @@ -82,7 +68,6 @@ class Module extends _Module { } else { let _table = new db.table(table) _table.clear = function() { - console.log("I'M HERE BITCH 2") // Delete all Rows let fetched = _db.prepare(`DELETE FROM ${table.split("--")[0]}`).run(); if(!fetched) return null; @@ -94,75 +79,6 @@ class Module extends _Module { return true } } - - /*async _tableGet(Table) { - table.prototype.reset = async (table) => { - if (this.#storage.tables[table]) { - await this.#storage.tables[table].clear() - delete this.#storage.tables[table] - return true - } else return null - } - - let _table = new db.table(Table) - this.#storage.tables[table] = _table - ({get: table.prototype.get, fetch: table.prototype.fetch, set: table.prototype.set, add: table.prototype.add, subtract: table.prototype.subtract, push: table.prototype.push, delete: table.prototype.delete, has: table.prototype.has, includes: table.prototype.includes, all: table.prototype.all, fetchAll: table.prototype.fetchAll, type: table.prototype.type} = this.#storage.tables[table]) - /* TABLE METHODS */ - /*this.reset = async (table) => { - if (this.#storage.tables[table]) { - await this.#storage.tables[table].clear() - delete this.#storage.tables[table] - return true - } else return null - } - - try { - if (this.#storage.tables[table]) return this.#storage.tables[table] - - let _table = new db.table(table) - this.#storage.tables[table] = _table - - return this.#storage.tables[table] - } catch(e) { - logger.error(`[DB] [TI] Error while initializing table:`, e) - return false - }* / - }*/ - - /*async #_tableInit(table) { - console.log(this.#storage) - try { - if (this.#storage.tables[table]) return this.#storage.tables[table] - - let _table = new db.table(table) - this.#storage.tables[table] = _table - - return this.#storage.tables[table] - } catch(e) { - logger.error(`[DB] [TI] Error while initializing table:`, e) - return false - } - } - - async #_tableGet(table) { - if (this.#storage.tables[table]) return this.#storage.tables[table] - else return null - } - - async #_tableDelete(table) { - if (this.#storage.tables[table]) { - delete this.#storage.tables[table] - return true - } else return null - } - - async #_tableReset(table) { - if (this.#storage.tables[table]) { - await this.#storage.tables[table].clear() - delete this.#storage.tables[table] - return true - } else return null - }*/ } module.exports = Module \ No newline at end of file diff --git a/core/modules/generators.js b/core/modules/generators.js index dad5a0d..7f8bad4 100644 --- a/core/modules/generators.js +++ b/core/modules/generators.js @@ -45,56 +45,6 @@ class Module extends _Module { * * @returns {string} The permission token */ - /*_permissions_ubot(snowflake, level, uses, command) { - let userRegex = /^(?:<@!?)?(\d{17,21})>?$/gm - let roleRegex = /^(?:<@&)?(\d{17,21})>?$/gm - let sfRegex = /^(\d{17,21})$/gm - - if (!snowflake || (!roleRegex.test(snowflake) && !userRegex.test(snowflake) && !sfRegex.test(snowflake))) { - logger.warn(`[GENERATORS] [PERM] [UBOT] Could not generate Permission Token: SNOWFLAKE is not defined or is not a valid user/mention id.`) - return null; - } - - if (!level) { - logger.warn(`[GENERATORS] [PERM] [UBOT] Could not generate Permission Token: LEVEL is not defined.`) - return null; - } - - let PermissionToken = '' - - let uuid = this.uuid.v4() - let verifiers = uuid.split('-').map(v => v.split("").reverse().join("")) - PermissionToken += `${Buffer.from(uuid).toString('base64')}.` - PermissionToken += `${Buffer.from(`${verifiers[0]}-${snowflake}`).toString('base64')}.` - - let isLevelValid = bot.libraries.permissions ? - bot.libraries.permissions.levels.some(l => l.level === level) : - (bot.temp.permLevels ? bot.temp.permLevels.some(l => l.level === level) : false) - - if (!isLevelValid) { - logger.warn(`[GENERATORS] [PERM] [UBOT] Could not generate Permission Token: LEVEL is invalid.`) - return null; - } - PermissionToken += `${Buffer.from(`${verifiers[1]}-${level}`).toString('base64')}.` - - if (isNaN(uses)) { - logger.warn(`[GENERATORS] [PERM] [UBOT] Could not generate Permission Token: USES is invalid.`) - return null; - } - PermissionToken += `${Buffer.from(`${verifiers[2]}-${uses}`).toString('base64')}` - - if (command) { - if (!bot.commands.has(command)) { - logger.warn(`[GENERATORS] [PERM] [UBOT] Could not generate Permission Token: COMMAND is invalid.`) - return null; - } - - PermissionToken += `.${Buffer.from(`${verifiers[3]}-${command}`).toString('base64')}` - } - - return PermissionToken - }*/ - _permissions_ubot(level, uses, command) { if (!level) { logger.warn(`[GENERATORS] [PERM] [UBOT] Could not generate Permission Token: LEVEL is not defined.`) @@ -139,18 +89,12 @@ class Module extends _Module { count++ PermissionToken += `${Buffer.from(`${verifiers[count]}-${ivParts[parseInt(ordenator)]}`).toString('base64')}.` } - /*let count = 0 - for (let part of ivParts) { - count++ - PermissionToken += `${Buffer.from(`${verifiers[count]}-${part}`).toString('base64')}.` - }*/ PermissionToken += `${Buffer.from(`${order.join("")}-${timestamp.toString()}`).toString('base64')}` - //PermissionToken += `${Buffer.from(`${verifiers[1]}-${level}`).toString('base64')}.` function encrypt(text, key) { const iv = crypto.randomBytes(16); - let cipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(key, 'base64').toString('utf-8'), iv);//Buffer.from(key) + let cipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(key, 'base64').toString('utf-8'), iv); let encrypted = cipher.update(Buffer.from(text, "utf-8")); encrypted = Buffer.concat([encrypted, cipher.final()]); return { iv: iv.toString('hex'), encryptedData: encrypted.toString('hex') }; diff --git a/core/modules/maintest.js b/core/modules/maintest.js deleted file mode 100644 index 11d55c5..0000000 --- a/core/modules/maintest.js +++ /dev/null @@ -1,21 +0,0 @@ -/* -* MODULE -* MODULE_NAME -* By: AUTHOR -* First Version: CREATION_DATE | Last Update: UPDATE_DATE -* Documentation Page: DOCUMENTATION_PAGE -*/ - -const _Module = bot.bases.modules -class Module extends _Module { - constructor() { - super(); - this.declarations.name = "maintest" - } - - getThisShit() { - console.log(this) - } -} - -module.exports = Module \ No newline at end of file diff --git a/core/modules/parsers.js b/core/modules/parsers.js index b9fc127..f1d8f5d 100644 --- a/core/modules/parsers.js +++ b/core/modules/parsers.js @@ -203,19 +203,6 @@ class Module extends _Module { /* Permlevel */ permLevels(level, api) { - /*let permlevels = { - 100: 'Owner', - 99: 'Developer', - 10: 'Admin', - 9: 'Super Moderator', - 8: 'Moderator', - 0: 'User' - }*/ - // console.log(bot.config.permissions.levels) - // console.log(Object.entries(bot.config.permissions.levels)) - // console.log(Object.entries(bot.config.permissions.levels).filter(([key, value]) => value === level)[0]) - // console.log(Object.entries(bot.config.permissions.levels).filter(([key, value]) => value === level)[0][0]) - // console.log(Object.entries(bot.config.permissions.levels).filter(([key, value]) => value === level)[0][0] || (api ? null : 'Not registered')) return Object.entries(bot.config.permissions.levels).filter(([key, value]) => value === level)[0][0] || (api ? null : 'Not registered') } @@ -285,7 +272,6 @@ class Module extends _Module { let obj = { type: 'UBOT', level: variables.l, uses: variables.u } if (variables.c) obj.command = variables.c - //if (variables.u) obj.user = variables.c return { success: true, data: obj } } else { @@ -299,7 +285,6 @@ class Module extends _Module { let obj = { type: 'TOPT', level: variables.l, exp: variables.e, iat: timestamp } if (variables.c) obj.command = variables.c - //if (variables.u) obj.user = variables.c return { success: true, data: obj } } else { @@ -313,192 +298,13 @@ class Module extends _Module { return { error: `Invalid Token` } } } - - //return decrypted } catch (e) { logger.error(`[PARSERS] [PERMTOKEN] Unable to decrypt Token:`, e) return {error: e.message} } - //console.log(uuid_v4, uuid, iv.join(""), encrypted, Buffer.from(decrypted, 'base64').toString('utf-8')) } /* Arguments */ - // arguments(args, command) { - // let storedI = -1, - // isSubCommand = false, - // subCommandFound = false, - // failedArg = null - // function nextArg(args) { - // console.log(storedI) - // storedI++ - // console.log(args) - // if (args[storedI]) return args[storedI] - // else return false - // } - - // function iterateArguments(cmdArgs, args) { - // //console.log('-----') - - // for (let i in cmdArgs) { - // let cmdArg = cmdArgs[i] - // //if (cmdArg.type !== "subCommand") storedI = parseInt(i) - - // //console.log('COMMAND', cmdArg) - // let arg //= args[storedI] - // if (cmdArg.type === "subCommand") { - // if (storedI < 0) storedI++ - // arg = args[storedI] - // console.log('SC_ARG', arg) - // } else { - // arg = nextArg(args) - // console.log('NEXTARG', arg) - // } - // console.log('ARGUMENT', arg) - - // if (!arg) { - // if (cmdArg.required || cmdArg.type === "subCommandGroup") { - // //console.log('req') - // if (cmdArg.type !== "subCommand") return `Missing required argument: ${cmdArg.name}` - // } else { - // continue; - // //console.log('not req') - // } - // } - // /*if (args[i]) { - // arg = args[i] - // console.log(arg) - // } else { - // console.log('No arg') - // if (cmdArg.required) { - // console.log('req') - // if (cmdArg.type !== "subCommand") return `Missing required argument: ${cmdArg.name}` - // } else { - // console.log('not req') - // } - // }*/ - - - // switch (cmdArg.type) { - // case 'subCommandGroup': { - // if (typeof(arg) === 'string') { - // if (arg === cmdArg.name) { - // let newArg = nextArg(args) - // if (newArg) { - // if (typeof(newArg) === 'string') { - // let subCmd = cmdArg.subCommands.filter(c => c.name === newArg)[0] - // if (subCmd) { - // let oldStoredI = storedI - // let newarr = args.slice(storedI + 1) - // //console.log(newarr) - // let res = iterateArguments(subCmd.arguments, newarr) - // if (!res) return false - // else { - // storedI = oldStoredI - // if (typeof(res) === 'string') return res; else continue; - // } - // } else return `Missing required subcommand. Expected one of the following values: ${new Intl.ListFormat('en-US', { style: 'short', type: 'disjunction' }).format(cmdArg.subCommands.map(c => c.name))}` - // } else return `Invalid type for ${cmdArg.name}'s subcommand: '${['undefined', 'null'].includes(typeof(newArg)) ? "none" : typeof(arg)}' (Expected 'string')` - // } else return `Missing required subcommand name for ${cmdArg.name}` - // } else return `Invalid argument name: '${arg}' (Expected '${cmdArg.name}')` - // } else return `Invalid type for argument ${cmdArg.name}: '${['undefined', 'null'].includes(typeof(arg)) ? "none" : typeof(arg)}' (Expected 'string')` - // break; - // } - // case 'subCommand': { - // isSubCommand = true - // failedArg = arg - // //console.log('SUBCOMMAND', cmdArg.name) - // //console.log('ARG', arg) - // if (typeof(arg) === 'string') { - // if (arg === cmdArg.name) { - // subCommandFound = true - // if (cmdArg.arguments) { - // let res = iterateArguments(cmdArg.arguments, args.slice(storedI)) - // if (!res) return false; else { - // if (typeof(res) === 'string') return res; else continue; - // } - // } else return true - // }// else return `Invalid argument name: '${arg}' (Expected '${cmdArg.name}')` - // } else return `Invalid type for argument ${cmdArg.name}: '${['undefined', 'null'].includes(typeof(arg)) ? "none" : typeof(arg)}' (Expected 'string')` - // break; - // } - // case 'string': { - // if (typeof(arg) === 'string') { - // if (command.arguments[storedI].choices.length > 0) { - // if (command.arguments[storedI].choices.some(c => c.value === arg)) continue - // else return `Invalid choice for argument ${cmdArg.name}: '${arg}' (Expected '${new Intl.ListFormat('en-US', { style: 'short', type: 'disjunction' }).format(command.arguments[storedI].choices.map(c => c.value))}')` - // } - // continue - // } else return `Invalid type for argument ${cmdArg.name}: '${['undefined', 'null'].includes(typeof(arg)) ? "none" : typeof(arg)}' (Expected 'string')` - // break; - // } - // case 'integer': { - // if (typeof(arg) === 'number' || !isNaN(arg)) { - // continue - // } else return `Invalid type for argument ${cmdArg.name}: '${['undefined', 'null'].includes(typeof(arg)) ? "none" : typeof(arg)}' (Expected 'integer')` - // break; - // } - // case 'boolean': { - // if (typeof(arg) === 'boolean') { - // continue - // } else return `Invalid type for argument ${cmdArg.name}: '${['undefined', 'null'].includes(typeof(arg)) ? "none" : typeof(arg)}' (Expected 'boolean')` - // break; - // } - // case 'user': { - // if (typeof(arg) === 'string') { - // let userRegex = /^(?:<@!?)?(\d{17,21})>?$/gm - // let sfRegex = /^(\d{17,21})$/gm - - // if (userRegex.test(arg) || sfRegex.test(arg)) { - // continue - // } else return `Invalid argument '${arg}': Not a valid 'userID' or 'userMention'` - // } else return `Invalid type for argument ${cmdArg.name}: '${['undefined', 'null'].includes(typeof(arg)) ? "none" : typeof(arg)}' (Expected 'userID' or 'userMention')` - // break; - // } - // case 'channel': { - // if (typeof(arg) === 'string') { - // let channelRegex = /^(?:<#)?(\d{17,21})>?$/gm - // let sfRegex = /^(\d{17,21})$/gm - - // if (channelRegex.test(arg) || sfRegex.test(arg)) { - // continue - // } else return `Invalid argument '${arg}': Not a valid 'channelID' or 'channelMention'` - // } else return `Invalid type for argument ${cmdArg.name}: '${['undefined', 'null'].includes(typeof(arg)) ? "none" : typeof(arg)}' (Expected 'channelID' or 'channelMention')` - // break; - // } - // case 'role': { - // if (typeof(arg) === 'string') { - // let roleRegex = /^(?:<@&)?(\d{17,21})>?$/gm - // let sfRegex = /^(\d{17,21})$/gm - - // if (roleRegex.test(arg) || sfRegex.test(arg)) { - // continue - // } else return `Invalid argument '${arg}': Not a valid 'roleID' or 'roleMention'` - // } else return `Invalid type for argument ${cmdArg.name}: '${['undefined', 'null'].includes(typeof(arg)) ? "none" : typeof(arg)}' (Expected 'roleID' or 'roleMention')` - // break; - // } - // case 'mentionable': { - // if (typeof(arg) === 'string') { - // let userRegex = /^(?:<@!?)?(\d{17,21})>?$/gm - // let roleRegex = /^(?:<@&)?(\d{17,21})>?$/gm - // let sfRegex = /^(\d{17,21})$/gm - - // if (roleRegex.test(arg) || userRegex.test(arg) || sfRegex.test(arg)) { - // continue - // } else return `Invalid argument '${arg}': Not a valid 'mentionable'` - // } else return `Invalid type for argument ${cmdArg.name}: '${['undefined', 'null'].includes(typeof(arg)) ? "none" : typeof(arg)}' (Expected 'mentionable')` - // break; - // } - // } - // } - - // if (isSubCommand && !subCommandFound) return `No subcommand found with name: \`${failedArg}\`.` - // return true - // } - - // let res = iterateArguments(command.arguments, args) - // return res - // } - async messageArguments(message, Arguments, command) { let _args = {} @@ -516,18 +322,12 @@ class Module extends _Module { } function incrementIndex(index) { - //console.log('increment index', new Error().stack) indexes[index]++; - /*if (indexes[index]) { - indexes[index]++; - }*/ } - let IArg // Index of Current Argument // = indexes[0] + let IArg // Index of Current Argument function peek(args, arg) { - //console.log(index, indexes[index], arg) - //return args[indexes[index]][arg] || null return args[arg] } @@ -548,10 +348,6 @@ class Module extends _Module { let arg = args[IArg] let isRequired = cmdArg.type === "SUB_COMMAND_GROUP" ? true : cmdArg.required - // console.log("CMDARG:", cmdArg) - // console.log("ARGS", args) - // console.log("ARG", arg) - if (indexData[index].hasSubCommandGroup && cmdArg.type !== "SUB_COMMAND_GROUP" && !indexData[index].subCommandGroupFound) return `No SubCommand Group found with name: \`${arg}\`.` if (indexData[index].hasSubCommand && cmdArg.type !== "subCommand" && !indexData[index].subCommandFound) return `1 No SubCommand found with name: \`${arg}\`.` @@ -576,8 +372,6 @@ class Module extends _Module { type: "STRING", value: arg } - // incrementIndex(index) - //continue; } else return `Invalid type for argument \`${cmdArg.name}\`: '${['undefined', 'null'].includes(typeof(arg)) ? "none" : typeof(arg)}' (Expected 'string')` break; } @@ -598,8 +392,6 @@ class Module extends _Module { type: "INTEGER", value: parseInt(arg) } - //incrementIndex(index) - //continue; } else return `Invalid type for argument \`${cmdArg.name}\`: '${['undefined', 'null'].includes(typeof(arg)) ? "none" : typeof(arg)}' (Expected 'integer')` break; } @@ -611,23 +403,16 @@ class Module extends _Module { type: "NUMBER", value: parseFloat(arg) } - //continue; - //incrementIndex(index) + } else return `Invalid type for argument \`${cmdArg.name}\`: '${['undefined', 'null'].includes(typeof(arg)) ? "none" : typeof(arg)}' (Expected 'integer')` break; } case 'BOOLEAN': { - // console.log(arg) - // console.log(typeof(arg), typeof(arg) == "boolean") - // console.log(typeof(arg) == "string", ["true", "false"].includes(arg.toLowerCase()), ( typeof(arg) == "string" && ["true", "false"].includes(arg.toLowerCase()) )) - // console.log(typeof(arg) == "boolean" || ( typeof(arg) == "string" && ["true", "false"].includes(arg.toLowerCase()) )) if (typeof(arg) == "boolean" || ( typeof(arg) == "string" && ["true", "false"].includes(arg.toLowerCase()) ) ) { _args[cmdArg.name] = { type: "BOOLEAN", value: { true: true, false: false }[arg.toLowerCase()] } - //continue; - //incrementIndex(index) } else return `Invalid type for argument \`${cmdArg.name}\`: '${['undefined', 'null'].includes(typeof(arg)) ? "none" : typeof(arg)}' (Expected 'boolean')` break; } @@ -700,13 +485,10 @@ class Module extends _Module { value: arg } if (cmdArg?.subCommands?.length > 0) { - let subCmdArg = peek(args, IArg + 1)//peek(args, index, IArg + 1) - - console.log(args, IArg, subCmdArg) + let subCmdArg = peek(args, IArg + 1) + if (subCmdArg) { - // console.log("SCG CMDARG")//console.log('CMDARG: ', cmdArg) let subCmd = cmdArg.subCommands.find(s => s.name === subCmdArg) - // console.log("SCG SUBCMD")//console.log('SUBCMD: ', subCmd) if (subCmd) { _args[subCmd.name] = { type: "SUB_COMMAND", @@ -714,19 +496,13 @@ class Module extends _Module { } let newArgs = args.slice(0) newArgs.splice(0, IArg + 2) - // console.log(args, IArg, newArgs, Object.keys(indexes).length) let res = await iterateArguments(subCmd.arguments, newArgs, Object.keys(indexes).length) - - // console.log("SCG RES:", res) if (res !== true) { return res; } } else return `SubCommand Group \`${cmdArg.name}\` requires one of the following SubCommands: \`${new Intl.ListFormat('en-US', { style: 'short', type: 'disjunction' }).format(cmdArg.subCommands.map(s => s.name))}\`, but got \`${subCmdArg}\`.` } else return `SubCommand Group \`${cmdArg.name}\` requires one of the following SubCommands: \`${new Intl.ListFormat('en-US', { style: 'short', type: 'disjunction' }).format(cmdArg.subCommands.map(s => s.name))}\`, but got \`none\`.` - //let res = iterateArguments(cmdArg.subCommands, args.slice(0).splice(0, IArg), indexes.length) - - //if (res) return res; } } } else return `Invalid type for argument ${cmdArg.name}: '${['undefined', 'null'].includes(typeof(arg)) ? "none" : typeof(arg)}' (Expected 'string')` @@ -745,16 +521,9 @@ class Module extends _Module { if (cmdArg?.arguments?.length > 0) { let newArgs = args.slice(0) newArgs.splice(0, IArg + 1) - // console.log("SC", args, IArg, newArgs, Object.keys(indexes).length) - // console.log("INDEXDATA", indexData[index]) let res = await iterateArguments(cmdArg.arguments, newArgs, Object.keys(indexes).length) - // console.log("SC RES:", res) - - /*if (res !== true) { - return res; - } else break;*/ return res; } } @@ -766,10 +535,6 @@ class Module extends _Module { if (!indexData[index].hasSubCommand && !indexData[index].hasSubCommandGroup) incrementIndex(index); } - console.log(indexData, index) - console.log(indexData[index]) - - //if (indexData[index].hasSubCommand && !indexData[index].subCommandFound) return `No subcommand found with name: \`${failedArg}\`.` if (indexData[index].hasSubCommandGroup && !indexData[index].subCommandGroupFound) return `No SubCommand Group found with name: \`${args.pop()}\`.` if (indexData[index].hasSubCommand && !indexData[index].subCommandFound) return `No SubCommand found with name: \`${args.pop()}\`.` return true @@ -777,11 +542,7 @@ class Module extends _Module { if (command.arguments.length > 0) { let parsed = await iterateArguments(command.arguments, Arguments, 0) - - //console.log("ARGS:", _args) - let argMap = new bot.constants.classes.ArgumentMap(_args) - //console.log(argMap) return { validity: parsed, @@ -802,8 +563,6 @@ class Module extends _Module { argMap } } - - //return parsed } /* Enabled Command List */ @@ -826,7 +585,6 @@ class Module extends _Module { if (typeof(value) !== 'boolean') return false if (!cat) file[command.category] = {} - //if (!cat || typeof(value) !== 'boolean') return false file[command.category][command.name] = value await db.set('SYSTEM:EnabledCommandList', file) diff --git a/core/modules/registerers.js b/core/modules/registerers.js index 60f40ad..97ef0b2 100644 --- a/core/modules/registerers.js +++ b/core/modules/registerers.js @@ -27,12 +27,7 @@ class Module extends _Module { */ async permLevels() { - let permissions = { - //users: [], - //roles: [], - //levels: [], - //unitary: [] - } + let permissions = {} let origin = bot.config.permissions let _keys = [] @@ -206,7 +201,7 @@ class Module extends _Module { } if (permissions.owners.length == 0) { - let perm = bot.modules.generators.permissions.topt(Object.entries(permissions.levels).sort(([keyA, valueA], [keyB, valueB]) => valueB - valueA)[0][1], '1h')//.ubot(10, 10) + let perm = bot.modules.generators.permissions.topt(Object.entries(permissions.levels).sort(([keyA, valueA], [keyB, valueB]) => valueB - valueA)[0][1], '1h') if (perm) { logger.success(`[TOKEN] Permission Token for LEVEL 10: ${perm}\nUse '/permtoken set '' to activate the Token\nWARNING: DO NOT SEND THIS TOKEN TO ANYONE! THIS TOKEN GRANTS OWNER PERM LEVEL TO ANY USER!`) } else { @@ -218,48 +213,6 @@ class Module extends _Module { bot.config.permissions = permissions delete bot.temp.permLevels return true - - //console.log(bot.constants.keyMap.get(bot.constants['1ca7140650b31d8ecd02a2a64911dc9c06e9c3fd'])) - - /*if (bot.config?.permissions?.levels && (bot.config?.permissions?.users || bot.config?.permissions?.roles || bot.config?.permissions?.unitary)) { - if (typeof(bot.config.permissions) !== "object") { - logger.error(`[REGISTERERS] [PERM] Error while loading permissions: Invalid data type for PERMISSIONS configuration: '${bot.config.permissions}' (expected 'object')`) - return null - } - } else { - logger.warn(`[REGISTERERS] [PERM] No valid PERMISSIONS config found. Using default values.`) - - /*permissions.levels = [ - { level: 100, label: 'Owner' }, - { level: 99, label: 'Developer' }, - { level: 10, label: 'Admin' }, - { level: 9, label: 'Super Moderator' }, - { level: 8, label: 'Moderator' }, - { level: 0, label: 'User' }, - ]* / - - permissions.levels = { - "Owner": 100, - "Developer": 99, - "Admin": 10, - "Super Moderator": 9, - "Moderator": 8, - "User": 0 - } - - bot.temp = { - permLevels: permissions.levels - } - - let perm = bot.modules.generators.permissions.topt(100, '1h')//.ubot(10, 10) - if (perm) { - logger.success(`[TOKEN] Permission Token for LEVEL 10: ${perm}\nUse '/permtoken set '' to activate the Token\nWARNING: DO NOT SEND THIS TOKEN TO ANYONE! THIS TOKEN GRANTS OWNER PERM LEVEL TO ANY USER!`) - } else { - logger.error(`[REGISTERERS] [PERM] Failed to register permissions:`, e) - } - - delete bot.temp.permLevels - }*/ } /** @@ -307,20 +260,6 @@ class Module extends _Module { } catch (e) { logger.error(`[REGISTERERS] [INT] Error while registering interactions:`, e) } - - //logger.info(`[REGISTERERS] [INT] Registering integrations' permissions...`) - - //await this._registerPermissions(commands) - - /*let commands = await bot.aplication.commands.fetch() - const iterator2 = commands[Symbol.iterator](); - for (let iter in iterator2) { - let command = iter[1] - - if (permissions[command.id]) { - - } - }*/ } /** @@ -338,15 +277,12 @@ class Module extends _Module { let commands = bot.commands let interactions = await bot.application.commands.fetch() - //let stop = false let control = { hasInternal: false } const iterator = commands[Symbol.iterator](); for (let iter in iterator) { - //if (stop) return null; - let command = iter[1] let interaction = interactions.filter(i => i.name === command.command.name)[0] @@ -360,62 +296,51 @@ class Module extends _Module { case 'internal': { if (!permission.id || !permission.type || !permission.hasOwnProperty('permission')) { logger.warn(`[REGISTERS] [RP] ${command.command.name} invalid permission error: Missing ID, TYPE or PERMISSION properties.`) - return null;//stop = true - //break; + return null; } if (!bot.modules.parsers.permLevels(permission.level, true)) { logger.warn(`[REGISTERS] [RP] ${command.command.name} has an invalid internal permLevel: ${permission.level}`) - return null;//stop = true - //break; + return null; } control.hasInternal = true break; - /*if (control.hasInternal) { - logger.warn(`[REGISTERS] [RI] ${command.command.name} has more than one internal`) - }*/ } case 'user': { if (!permission.id || !permission.type || !permission.hasOwnProperty('permission')) { logger.warn(`[REGISTERS] [RP] ${command.command.name} invalid permission error: Missing ID, TYPE or PERMISSION properties.`) - return null;//stop = true - //break; + return null; } if (control.hasInternal) { logger.warn(`[REGISTERS] [RP] ${command.command.name} incompatibility error: Cannot add USER permission over INTERNAL.`) - return null;//stop = true - //break; + return null; } let userRegex = /^(?:<@!?)?(\d{17,21})>?$/gm let sfRegex = /^(\d{17,21})$/gm if (!userRegex.test(permission.id) || !sfRegex.test(permission.id)) { logger.warn(`[REGISTERS] [RP] ${command.command.name} has an invalid user id: ${permission.id}`) - return null;//stop = true - //break; + return null; } break; } case 'role': { if (!permission.id || !permission.type || !permission.hasOwnProperty('permission')) { logger.warn(`[REGISTERS] [RP] ${command.command.name} invalid permission error: Missing ID, TYPE or PERMISSION properties.`) - return null;//stop = true - //break; + return null; } if (control.hasInternal) { logger.warn(`[REGISTERS] [RP] ${command.command.name} incompatibility error: Cannot add ROLE permission over INTERNAL.`) - return null;//stop = true - //break; + return null; } let roleRegex = /^(?:<@&)?(\d{17,21})>?$/gm let sfRegex = /^(\d{17,21})$/gm if (!roleRegex.test(permission.id) || !sfRegex.test(permission.id)) { logger.warn(`[REGISTERS] [RP] ${command.command.name} has an invalid role id: ${permission.id}`) - return null;//stop = true - //break; + return null; } break; } @@ -435,21 +360,16 @@ class Module extends _Module { * @returns {null} */ _registerInteraction(Command) { - //console.log('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA') let slashCommand = new SlashCommandBuilder() .setName(Command.name) .setDescription(Command.description.short || 'No description provided.') - //console.log('SCB', slashCommand) - let stop = false function registerArguments(interactionPart, command, types) { - //console.log(arguments) if (command.arguments) { for (let arg of command.arguments) { if (arg?.messageOnly) continue; - //console.log(arg) switch (arg.type) { case 'SUB_COMMAND_GROUP': { if (types?.subCommandGroup) { @@ -462,9 +382,6 @@ class Module extends _Module { .setName(arg.name) .setDescription(arg.description) - /*arg.subCommands.forEach(subCommand => { - registerArguments(group, subCommand, { subCommandGroup: true }) - })*/ registerArguments(group, {arguments: arg.subCommands}, { subCommandGroup: true }) return group @@ -482,10 +399,6 @@ class Module extends _Module { .setName(arg.name) .setDescription(arg.description) - /*for (let subArg of arg.arguments) { - registerArguments(option, subArg, { subCommand: true }) - }*/ - //console.log(arg) registerArguments(option, arg, { subCommand: true }) return option @@ -493,7 +406,6 @@ class Module extends _Module { break; } case 'STRING': { - //console.log('ADDED1', integrationPart) if (arg?.choices?.length > 0) { interactionPart.addStringOption(option => { option @@ -601,7 +513,6 @@ class Module extends _Module { registerArguments(slashCommand, Command) - //console.log(JSON.stringify(slashCommand, null, 4)) if (stop) return false else return slashCommand.toJSON() } diff --git a/core/modules/verifiers.js b/core/modules/verifiers.js index 02cb72c..9f3c65a 100644 --- a/core/modules/verifiers.js +++ b/core/modules/verifiers.js @@ -27,7 +27,6 @@ class Module extends _Module { let tokenStats = bot.modules.parsers.permToken(userToken.token) - //return parseInt(tokenStats.data.level) tempPerm = parseInt(tokenStats.data.level) } @@ -35,12 +34,8 @@ class Module extends _Module { if (tempPerm < level) tempPerm = level } - //if (bot.config?.permissions.overrides && bot.config?.permissions?.overrides[message.author.id]) setOrDropPL(bot.config?.permissions?.overrides[message.author.id])//return bot.config?.permissions?.overrides[message.author.id] if (bot.config.permissions.owners.includes(message.author.id)) setOrDropPL(100)//return 100; if (bot.config.permissions.developers.includes(message.author.id)) setOrDropPL(99)//return 99; - //if (message.member.roles.cache.has(bot.config?.permissions?.roles?.administrator)) setOrDropPL(10)//return 10; - //if (message.member.roles.cache.has(bot.config?.permissions?.roles?.supermod)) setOrDropPL(9)//return 9; - //if (message.member.roles.cache.has(bot.config?.permissions?.roles?.moderator)) setOrDropPL(8)//return 8; if (bot.config.permissions.users[message.author.id]) setOrDropPL(bot.config.permissions.users[message.author.id]) for (let _role of message.member.roles.cache[Symbol.iterator]()) { @@ -51,7 +46,7 @@ class Module extends _Module { if (bot.config.permissions.overrides.users.hasOwnProperty(message.author.id)) tempPerm = bot.config.permissions.overrides.users[message.author.id] - return tempPerm//0 + return tempPerm } catch (e) { logger.error(`[PARSERS] [PERMLEVEL] Error while determining permission level:`, e); logger.error(`[PARSERS] [PERMLEVEL] Defaulting permission to 0.`); @@ -65,16 +60,13 @@ class Module extends _Module { let userToken = await dbTable.get(`${userID}.global`) if (userToken) { let tokenVer = bot.modules.parsers.permToken(userToken.token) - //console.log(tokenVer) switch (tokenVer.data.type) { case 'UBOT': { - //console.log('ubot', userToken.uses < tokenVer.data.uses) if (userToken.uses < tokenVer.data.uses) return { valid: true } else return { valid: false } break; } case 'TOPT': { - //console.log('topt', parseInt(tokenVer.data.iat) + parseInt(tokenVer.data.exp) >= Date.now()) if (parseInt(tokenVer.data.iat) + parseInt(tokenVer.data.exp) >= Date.now()) return { valid: true } else return { valid: false } break; @@ -85,15 +77,11 @@ class Module extends _Module { /* Registry Command Arguments */ async rcArguments(Command) { - //let required = bot.modules.objects.getNested(args, 'required') - //console.log(JSON.stringify(required, null, 2)) return new Promise(async (resolve, reject) => { async function iterateArguments(command, types) { let lastRequired = null - //console.log(command) for (let i in command.arguments) { let arg = command.arguments[i] - //console.log('ARG', arg) switch (arg.type) { case 'SUBCOMMAND_GROUP': { if (types?.subCommandGroup) { @@ -135,7 +123,6 @@ class Module extends _Module { } let res = await iterateArguments(Command) - //console.log(res) resolve(res) }) } diff --git a/core/utils/loader.js b/core/utils/loader.js index ae2da9e..16ff6b1 100644 --- a/core/utils/loader.js +++ b/core/utils/loader.js @@ -28,7 +28,6 @@ class Loader { } logger.success(`[LOADER] [COMMANDS] Successfully loaded Core.`) - //logger.info(`[LOADER] Core loading complete.`) return true } @@ -120,7 +119,7 @@ class Loader { "environment": "dev" } if (fs.existsSync('../../config.json')) { - let config = require('../../config.json')//require('../libraries/config') + let config = require('../../config.json') for (let [key, value] of Object.entries(defaultConfig)) { if (config.hasOwnProperty(key)) { @@ -191,7 +190,6 @@ class Loader { } }) logger.success(`[LOADER] [COMMANDS] Successfully loaded Bases.`) - //logger.info(`[LOADER] [BASES] Bases loaded.`) } catch (e) { logger.error(`[LOADER] [MODULES] Error while loading modules:`, e) } @@ -217,7 +215,7 @@ class Loader { logger.success(`[LOADER] [MODULES] Successfully loaded Core Modules.`) logger.info(`[LOADER] [MODULES] Loading Plugin Modules...`) - let modules = readdirSync(path.join(__dirname, "../../plugins/modules"))//.forEach(async module => { + let modules = readdirSync(path.join(__dirname, "../../plugins/modules")) for (let module of modules) { try { const baseClass = require(path.join(__dirname, "../../plugins/modules", module)) @@ -241,11 +239,9 @@ class Loader { } else { logger.error(`[LOADER] [COMMANDS] Error while loading ${Class.declarations.name}: Invalid structure.`); } - //logger.info(`[LOADER] [MODULES] ${Class.declarations.name} successfuly loaded.`) } catch (e) { logger.error(`[LOADER] [MODULES] Error while loading ${module}:`, e) } - //}) } function loadUnloadedModules() { @@ -279,7 +275,6 @@ class Loader { } catch (e) { logger.error(`[LOADER] [MODULES] Error while loading ${Class.declarations.name}:`, e) } - //}) } if (unloaded.length == 0) return resolve() @@ -319,7 +314,7 @@ class Loader { } async function loadEventTree(Dir) { return new Promise(async (resolve, reject) => { - const evtFiles = await readdir(path.join(__dirname, Dir))//'../events' + const evtFiles = await readdir(path.join(__dirname, Dir)) evtFiles.forEach(evt => { const eventName = evt.split('.')[0] @@ -368,11 +363,10 @@ class Loader { const commands = readdirSync(`${dir}${path.sep}${dirs}${path.sep}`).filter(files => files.endsWith(".js")); for (const file of commands) { logger.info(`[LOADER] [COMMANDS] Loading ${file}...`) - //const pull = require(`${dir}/${dirs}/${file}`); const filePull = require(`${dir}/${dirs}/${file}`); let pull = new filePull() pull._setFilePath(`${dir}${path.sep}${dirs}${path.sep}${file}`) - if (pull.validateStructure()) { //if (pull.command && typeof (pull.command.name) === "string" && typeof (pull.command.category) === "string") { + if (pull.validateStructure()) { if (bot.commands.get(pull.command.name)) return logger.warn(`[LOADER] [COMMANDS] Multiple commands have the same name: ${pull.command.name}.`); bot.commands.set(pull.command.name, pull); logger.success(`[LOADER] [COMMANDS] ${pull.command.name} successfully loaded.`); @@ -380,12 +374,8 @@ class Loader { logger.error(`[LOADER] [COMMANDS] Error while loading ${pull.command.name}: Invalid structure.`); continue; } - /* else { - logger.error(`[LOADER] [COMMANDS] Error while loading ${dir}${dirs}: missing or non-string command.name and/or command.category.`); - continue; - }*/ - if (Array.isArray(pull.command?.aliases)) { //typeof (pull.command?.aliases) === "object" + if (Array.isArray(pull.command?.aliases)) { pull.command.aliases.forEach(alias => { if (bot.aliases.get(alias)) return logger.warn(`[LOADER] [COMMANDS] Multiple commands have the same alias: ${alias}`); bot.aliases.set(alias, pull.command.name); @@ -403,7 +393,6 @@ class Loader { }; } catch (e) { throw `[COMMANDS] Error while loading commands: ${e.message}\n${e.stack}` - //logger.error(`[LOADER] [COMMANDS] Error while loading commands: `, e) } } @@ -430,15 +419,6 @@ class Loader { if (bot.commands) await bot.modules.registerers.interactions() else logger.warn(`[LOADER] [INTERACTIONS] Could not initialize interactions because there is no commands available.`) - // logger.info(`[LOADER] [INTERACTIONS] Registering interactions' permissions...`) - // let permreg = await bot.modules.registerers.permLevels() - - // if (permreg) logger.success(`[LOADER] [INTERACTIONS] Interactions' permissions successfully registered.`) - // else { - // logger.error(`[LOADER] [INTERACTIONS] Could not load Permissions. Shutting down.`) - // process.exit(1) - // } - logger.success(`[LOADER] [COMMANDS] Successfully loaded Interactions.`) } diff --git a/docs/commands.md b/docs/commands.md index e79d07f..4aa82ad 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -4,23 +4,17 @@ padding: 0 5px; background-color: #282828; width: 100%; - /* display: inline; - width: 100%; - height: 100%; */ } .container { width:100%; - /* height:200px; */ } .left { width:auto; - /* height:200px; */ background:#282828; overflow:hidden; } .right { - /* height:200px; */ width:auto; background:transparent; float:left; @@ -32,37 +26,6 @@ All commands should follow this template: - - ```js const Command = bot.bases.commands