Seperate command loader

This commit is contained in:
7cc5c4f330d47060 2024-08-03 03:00:04 -04:00
parent 735ebb1f2c
commit 5bb0c8f00e
No known key found for this signature in database
19 changed files with 46 additions and 45 deletions

View file

@ -1,5 +1,5 @@
const version = require('../../version.json')
const {getMessage} = require('../../util/lang.js')
const version = require('../version.json')
const {getMessage} = require('../util/lang.js')
const cp = require('child_process')
module.exports = {
execute: function (c) {

View file

@ -1,4 +1,4 @@
const {getMessage} = require('../../util/lang.js')
const {getMessage} = require('../util/lang.js')
module.exports = {
execute: (c) => {
const subcmd = c.args.splice(0, 1)[0]

View file

@ -1,4 +1,4 @@
const index = require('../../index.js') // Not used in the code, but may be used by users of the command
const index = require('../index.js') // Not used in the code, but may be used by users of the command
module.exports = {
execute: (c) => {
try {

View file

@ -1,4 +1,4 @@
const { bot } = require('../../index.js')
const { bot } = require('../index.js')
module.exports = {
execute: (c) => {
const json = {

View file

@ -1,7 +1,7 @@
const os = require('os')
const cp = require('child_process')
const version = require('../../version.json')
const {getMessage,formatTime} = require('../../util/lang.js')
const version = require('../version.json')
const {getMessage,formatTime} = require('../util/lang.js')
const fs = require('fs')
const gr = function (l, text, value, color) {
if (!color) color = 'white'

View file

@ -1,4 +1,4 @@
const {getMessage} = require('../../util/lang.js')
const {getMessage} = require('../util/lang.js')
module.exports = {
execute: function (c) {
let uuid

View file

@ -1,35 +1,8 @@
const fs = require('fs')
const Command = require('../util/Command.js')
const hashcheck = require('../util/hashcheck.js')
const settings = require('../settings.json')
const {getMessage} = require('../util/lang.js')
const cmds = Object.create(null)
const bpl = fs.readdirSync('./plugins/commands')
for (const i in bpl) { // Built-in loadCMD
if (!bpl[i].endsWith('.js')) {
continue
}
try {
const commandName = bpl[i].split('.js')[0]
cmds[commandName] = require(`./commands/${bpl[i]}`)
if (cmds[commandName].level === undefined) {
cmds[commandName].level = 0
}
console.log('Loaded command ' + commandName)
if (cmds[commandName].aliases) {
for (const j in cmds[commandName].aliases) {
cmds[cmds[commandName].aliases[j]] = {
execute: cmds[commandName].execute,
desc: 'Alias to ' + commandName,
usage: cmds[commandName].usage,
level: cmds[commandName].level,
hidden: true,
consoleIndex: cmds[commandName].consoleIndex
}
}
}
} catch (e) { console.log(e) }
}
const cmds = require("../util/commands.js")
const sortHelp = function sortHelp (c1, c2) {
const level1 = cmds[c1.with[0]].level ? cmds[c1.with[0]].level : 0
@ -176,6 +149,5 @@ module.exports = {
]
})
}
},
cmds
}
}

View file

@ -1,7 +1,7 @@
const readln = require('readline')
const index = require('../index.js')
const ConsoleCommand = require('../util/ConsoleCommand.js')
const newercommands = require('./command.js').cmds
const cmds = require("../util/commands.js")
const rl = readln.createInterface({
input: process.stdin,
output: process.stdout,
@ -9,22 +9,22 @@ const rl = readln.createInterface({
})
rl.on('line', (l) => {
try {
if (newercommands[l.split(' ')[0].toLowerCase()]) {
if (newercommands[l.split(' ')[0].toLowerCase()].consoleIndex) {
if (cmds[l.split(' ')[0].toLowerCase()]) {
if (cmds[l.split(' ')[0].toLowerCase()].consoleIndex) {
const tmpcmd = l.split(' ')
const index2 = tmpcmd.splice(1, 1)[0]
if (index2 === '*') {
for (let i = 0; i < index.bot.length; i++) {
const cmd = new ConsoleCommand(tmpcmd.join(' '), i)
newercommands[l.split(' ')[0].toLowerCase()].execute(cmd)
cmds[l.split(' ')[0].toLowerCase()].execute(cmd)
}
} else {
const cmd = new ConsoleCommand(tmpcmd.join(' '), +index2)
newercommands[l.split(' ')[0].toLowerCase()].execute(cmd)
cmds[l.split(' ')[0].toLowerCase()].execute(cmd)
}
} else {
const cmd = new ConsoleCommand(l, -2)
newercommands[l.split(' ')[0].toLowerCase()].execute(cmd)
cmds[l.split(' ')[0].toLowerCase()].execute(cmd)
}
}
} catch (e) {

View file

@ -1,6 +1,6 @@
// HOW TO WRITE CLASS JS
const index = require('../index.js')
const { cmds } = require('../plugins/command.js')
const cmds = require('./commands.js')
const parse = require('../util/chatparse_console.js')
const settings = require('../settings.json')
const {getMessage} = require('../util/lang.js')

29
util/commands.js Normal file
View file

@ -0,0 +1,29 @@
const fs = require('fs')
const cmds = Object.create(null)
const bpl = fs.readdirSync('./commands')
for (const i in bpl) { // Built-in loadCMD
if (!bpl[i].endsWith('.js')) {
continue
}
try {
const commandName = bpl[i].split('.js')[0]
cmds[commandName] = require(`../commands/${bpl[i]}`)
if (cmds[commandName].level === undefined) {
cmds[commandName].level = 0
}
console.log('Loaded command ' + commandName)
if (cmds[commandName].aliases) {
for (const j in cmds[commandName].aliases) {
cmds[cmds[commandName].aliases[j]] = {
execute: cmds[commandName].execute,
desc: 'Alias to ' + commandName,
usage: cmds[commandName].usage,
level: cmds[commandName].level,
hidden: true,
consoleIndex: cmds[commandName].consoleIndex
}
}
}
} catch (e) { console.log(e) }
}
module.exports=cmds;