Port console and help command

This commit is contained in:
7cc5c4f330d47060 2024-08-20 06:04:23 -04:00
parent 8b01388b93
commit b800252588
Signed by: 7cc5c4f330d47060
SSH key fingerprint: SHA256:e+4tcZut1nBpe10PqjaO+Rvie0Q7W4qIvFzcUw+7riA
5 changed files with 18 additions and 50 deletions

View file

@ -1,6 +1,4 @@
const fs = require('fs')
const cmds = Object.create(null)
const { getMessage } = require('../util/lang.js')
import { getMessage } from '../util/lang.js'
const sortHelp = function sortHelp (c1, c2) {
const level1 = cmds[c1.with[0]].level ? cmds[c1.with[0]].level : 0
@ -8,21 +6,7 @@ const sortHelp = function sortHelp (c1, c2) {
return level1 - level2
}
const bpl = fs.readdirSync('./commands')
for (const i in bpl) {
if (!bpl[i].endsWith('.js')) {
continue
}
try {
const commandName = bpl[i].split('.js')[0]
if (commandName !== 'help') {
cmds[commandName] = require(`./${bpl[i]}`)
if (cmds[commandName].level === undefined) {
cmds[commandName].level = 0
}
}
} catch (e) { console.log(e) }
}
import { default as cmds } from '../util/commands.js'
const printHelp = (c) => {
const commandList = []
@ -132,7 +116,7 @@ const printCmdHelp = (c) => {
})
}
module.exports = {
export default {
execute: (c) => {
if (c.args.length > 0) {
printCmdHelp(c)
@ -144,22 +128,3 @@ module.exports = {
'heko' // Parker2991 request
]
}
cmds.help = module.exports // Placed after to ensure that the correct values are added to cmds
if (cmds.help.level === undefined) {
cmds.help.level = 0
}
for (const i in cmds) {
if (cmds[i].aliases) {
for (const j in cmds[i].aliases) {
cmds[cmds[i].aliases[j]] = {
alias: i,
usage: cmds[i].usage,
level: cmds[i].level,
hidden: true,
consoleIndex: cmds[i].consoleIndex
}
}
}
}

View file

@ -16,6 +16,7 @@ import { default as botplug_cmd } from "./plugins/command.mjs"
import { default as botplug_cmdCore } from "./plugins/commandblock.mjs"
import { default as botplug_selfCare } from "./plugins/selfcare.mjs"
import { default as botplug_rejoin } from "./plugins/rejoin.mjs"
import { default as botplug_console } from "./plugins/console.mjs"
botplug.push(botplug_test)
botplug.push(botplug_chat)
@ -25,6 +26,7 @@ botplug.push(botplug_cmd)
botplug.push(botplug_cmdCore)
botplug.push(botplug_selfCare)
botplug.push(botplug_rejoin)
botplug.push(botplug_console)
const bpl = fs.readdirSync('plugins')

View file

@ -1,7 +1,7 @@
const readln = require('readline')
const index = require('../index.js')
const ConsoleCommand = require('../util/ConsoleCommand.js')
const cmds = require('../util/commands.js')
import * as readln from 'readline'
import { bot } from '../index.js'
import { default as ConsoleCommand } from '../util/ConsoleCommand.js'
import { default as cmds } from '../util/commands.js'
const rl = readln.createInterface({
input: process.stdin,
output: process.stdout,
@ -14,7 +14,7 @@ rl.on('line', (l) => {
const tmpcmd = l.split(' ')
const index2 = tmpcmd.splice(1, 1)[0]
if (index2 === '*') {
for (let i = 0; i < index.bot.length; i++) {
for (let i = 0; i < bot.length; i++) {
const cmd = new ConsoleCommand(tmpcmd.join(' '), i)
cmds[l.split(' ')[0].toLowerCase()].execute(cmd)
}
@ -40,7 +40,7 @@ function consoleWrite (text) {
process.stdout.write(text + '\n')
rl.prompt(true)
}
module.exports = {
export default {
load: (b) => {
b.info = (msg) => {
consoleWrite(`[${b.id}] [info] ${msg}`)

View file

@ -1,6 +1,6 @@
const index = require('../index.js')
const parse = require('../util/chatparse_console.js')
const settings = require('../settings.json')
import { bot } from '../index.js'
import { default as parse } from '../util/chatparse_console.js'
import { default as settings } from '../settings.json' with {type: "json"}
class ConsoleCommand {
constructor (cmd, index2) {
this.send = () => {}
@ -12,7 +12,7 @@ class ConsoleCommand {
this.msgType = '_bot_console'
this.prefix = ''
this.bot = index2 >= 0
? index.bot[index2]
? bot[index2]
: {}
this.type = 'console'
this.args = cmd.split(' ').slice(1)
@ -23,5 +23,4 @@ class ConsoleCommand {
this.colors = settings.colors
}
}
module.exports = ConsoleCommand
export default ConsoleCommand

View file

@ -3,10 +3,12 @@ const cmds = Object.create(null)
import { default as commandTest } from "../commands/test.mjs"
import { default as commandSay } from "../commands/say.mjs"
import { default as commandNetmsg } from "../commands/netmsg.mjs"
import { default as commandHelp } from "../commands/help.mjs"
cmds.test = commandTest
cmds.say = commandSay
cmds.netmsg = commandNetmsg
cmds.help = commandHelp
for(const commandName in cmds){
if (cmds[commandName].aliases) {