Skip to content

Commit

Permalink
v1.0.0
Browse files Browse the repository at this point in the history
Cleaned up: Removed comments, forgotten console.logs
  • Loading branch information
DarkenLM committed Jan 4, 2022
1 parent 0084a4d commit 91ed136
Show file tree
Hide file tree
Showing 18 changed files with 31 additions and 738 deletions.
12 changes: 0 additions & 12 deletions core/bases/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand All @@ -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:
Expand Down Expand Up @@ -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}'.`)
}

Expand Down
24 changes: 0 additions & 24 deletions core/bases/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
15 changes: 3 additions & 12 deletions core/commands/admin/eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -38,7 +30,7 @@ class command extends Command {
str = str.substring(0, 1800)
str = str + "[...]"
}
message.react("912664654021554176");
message.react("");
message.channel.send({
embeds: [
{
Expand All @@ -56,7 +48,6 @@ class command extends Command {
]
});
} catch (err) {
console.log(err)
message.react("❌");
message.channel.send({
embeds: [
Expand Down
2 changes: 1 addition & 1 deletion core/commands/admin/permtoken.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: <t:${Math.floor( (parseInt(tokenVer.data.iat) + parseInt(tokenVer.data.exp)) / 1000 )}>`}`, '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: <t:${Math.floor( (parseInt(tokenVer.data.iat) + parseInt(tokenVer.data.exp)) / 1000 )}>`}`, 'SUCCESS')], ephemeral: true })
} else {
return interaction.followUp({ embeds: [bot.modules.embed.create(pseudoMessage, `Invalid Permission Token.`, 'ERROR')], ephemeral: true })
}
Expand Down
1 change: 0 additions & 1 deletion core/commands/admin/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class command extends Command {
}

async execute(bot, message, args) {
console.log(args)
let subCommand = args.getSubcommand()

switch (subCommand) {
Expand Down
7 changes: 0 additions & 7 deletions core/commands/admin/reload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion core/commands/info/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 2 additions & 9 deletions core/events/interactionCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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}`)
Expand All @@ -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`,
Expand Down Expand Up @@ -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`,
Expand Down Expand Up @@ -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({
Expand Down
76 changes: 2 additions & 74 deletions core/events/messageCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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`,
Expand Down Expand Up @@ -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`,
Expand Down
15 changes: 1 addition & 14 deletions core/events/ready.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,18 @@ 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({
activities: [presence.activities[Math.floor(Math.random() * presence.activities.length)]],
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)]],
Expand Down
Loading

0 comments on commit 91ed136

Please sign in to comment.