Port the rest of the commands, rename converted files to mjs

This commit is contained in:
7cc5c4f330d47060 2024-08-20 06:39:00 -04:00
parent b800252588
commit 6063e40efb
Signed by: 7cc5c4f330d47060
SSH key fingerprint: SHA256:e+4tcZut1nBpe10PqjaO+Rvie0Q7W4qIvFzcUw+7riA
35 changed files with 118 additions and 94 deletions

View file

@ -1,10 +1,10 @@
const os = require('os')
const cp = require('child_process')
const { getMessage, formatTime } = require('../util/lang.js')
const fs = require('fs')
const botVersion = require('../util/version.js')
const version = require('../version.json')
const index = require('../index.js')
import * as os from "os"
import { execSync } from "child_process"
import { getMessage, formatTime } from '../util/lang.mjs'
import { readdirSync, readFileSync } from "fs"
import { default as botVersion } from "../util/version.js"
import { default as version } from "../version.json" with { type: "json" }
import { bot } from "../index.mjs"
const aboutBot = function (c) {
c.reply({
@ -59,7 +59,7 @@ const os2 = function (o2, l) {
return `${os.version()}`
case 'android':{
try {
const version = cp.execSync('getprop ro.build.version.release').toString('UTF-8').split('\n')[0]
const version = execSync('getprop ro.build.version.release').toString('UTF-8').split('\n')[0]
return getMessage(l, 'command.about.serverInfo.os.android', [version])
} catch (e) {
return getMessage(l, 'command.about.serverInfo.os.android.noVersion')
@ -67,8 +67,8 @@ const os2 = function (o2, l) {
}
case 'linux':
case 'freebsd':{
if (fs.readdirSync('/etc').includes('os-release')) {
const osrelease = fs.readFileSync('/etc/os-release').toString('UTF-8').split('\n')
if (readdirSync('/etc').includes('os-release')) {
const osrelease = readFileSync('/etc/os-release').toString('UTF-8').split('\n')
const osrelease2 = {}
for (const i in osrelease) {
if (!osrelease[i].includes('=')) continue
@ -173,8 +173,8 @@ const aboutServer = function (c) {
if (process.platform === 'android') {
// Device model
displayInfo('command.about.serverInfo.os.android.model', () => {
const brand = cp.execSync('getprop ro.product.brand').toString('UTF-8').split('\n')[0]
const model = cp.execSync('getprop ro.product.model').toString('UTF-8').split('\n')[0]
const brand = execSync('getprop ro.product.brand').toString('UTF-8').split('\n')[0]
const model = execSync('getprop ro.product.model').toString('UTF-8').split('\n')[0]
return `${brand} ${model}`
})
}
@ -186,8 +186,8 @@ const aboutServer = function (c) {
}
const displayServerList = function (c) {
for (const i in index.bot) {
if (index.bot[i].host.options && index.bot[i].host.options.hidden) continue
for (const i in bot) {
if (bot[i].host.options && bot[i].host.options.hidden) continue
c.reply({
translate: getMessage(c.lang, 'command.about.serverListItem'),
color: c.colors.secondary,
@ -197,7 +197,7 @@ const displayServerList = function (c) {
color: c.colors.primary
},
{
text: `${index.bot[i].host.host}:${index.bot[i].host.port}`,
text: `${bot[i].host.host}:${bot[i].host.port}`,
color: c.colors.primary
}
]
@ -205,7 +205,7 @@ const displayServerList = function (c) {
}
}
module.exports = {
export default {
execute: function (c) {
if (c.args[0] === 'server') {
aboutServer(c)

View file

@ -1,4 +1,4 @@
module.exports = {
export default {
execute: (c) => {
c.bot.ccq.push(c.args.join(' '))
},

View file

@ -1,5 +1,5 @@
const { getMessage } = require('../util/lang.js')
module.exports = {
import { getMessage } from '../util/lang.mjs'
export default {
execute: (c) => {
const subcmd = c.args.splice(0, 1)[0]
switch (subcmd) {

View file

@ -1,5 +1,5 @@
const index = require('../index.js') // Not used in the code, but may be used by users of the command
module.exports = {
import * as index from "../index.mjs" // Not used in the code, but may be used by users of the command
export default {
execute: (c) => {
try {
console.log(eval(c.args.join(' ')))

View file

@ -1,4 +1,4 @@
import { getMessage } from '../util/lang.js'
import { getMessage } from '../util/lang.mjs'
const sortHelp = function sortHelp (c1, c2) {
const level1 = cmds[c1.with[0]].level ? cmds[c1.with[0]].level : 0
@ -6,7 +6,7 @@ const sortHelp = function sortHelp (c1, c2) {
return level1 - level2
}
import { default as cmds } from '../util/commands.js'
import { default as cmds } from '../util/commands.mjs'
const printHelp = (c) => {
const commandList = []

View file

@ -1,4 +1,4 @@
module.exports = {
export default {
execute: (c) => {
c.bot._client.end()
},

View file

@ -1,5 +1,5 @@
import { bot } from '../index.js'
import { getMessage } from '../util/lang.js'
import { bot } from '../index.mjs'
import { getMessage } from '../util/lang.mjs'
export default {
execute: (c) => {
if (c.bot.host && c.bot.host.options.hidden) {

View file

@ -1,4 +1,4 @@
module.exports = {
export default {
execute: (c) => {
c.bot.chat(c.bot.refillCoreCmd)
},

View file

@ -1,4 +1,4 @@
module.exports = {
export default {
execute: (c) => {
process.exit(0)
},

View file

@ -1,6 +1,6 @@
const { languages, getMessage } = require('../util/lang.js')
const fs = require('fs')
module.exports = {
import { languages, getMessage } from '../util/lang.mjs'
import { writeFileSync } from "fs"
export default {
execute: (c) => {
const subcmd = c.args.splice(0, 1)[0]
switch (subcmd) {
@ -64,12 +64,13 @@ module.exports = {
c.prefs[key] = value
// Save to file
fs.writeFileSync(`userPref/${c.uuid}.json`, JSON.stringify(c.prefs))
writeFileSync(`userPref/${c.uuid}.json`, JSON.stringify(c.prefs))
// Delete require cache
for (const i in require.cache) {
/*for (const i in require.cache) {
if (i.endsWith(`${c.uuid}.json`)) delete require.cache[i]
}
}*/
c.reply({
text: getMessage(c.lang, 'command.settings.saved'),
color: c.colors.secondary

View file

@ -1,4 +1,4 @@
module.exports = {
export default {
execute: (c) => {
process.exit(1)
},

View file

@ -1,4 +1,4 @@
module.exports = {
export default {
execute: (c) => {
// Blank template
/*

View file

@ -1,4 +1,4 @@
import { getMessage } from '../util/lang.js'
import { getMessage } from '../util/lang.mjs'
export default {
execute: (c) => {
const reply = function (name, item) {

View file

@ -1,5 +1,5 @@
const { getMessage } = require('../util/lang.js')
module.exports = {
import { getMessage } from '../util/lang.mjs'
export default {
execute: function (c) {
let uuid
if (c.type === 'console') {

View file

@ -1,5 +1,5 @@
const { getMessage } = require('../util/lang.js')
module.exports = {
import { getMessage } from '../util/lang.mjs'
export default {
execute: (c) => {
const permsN = getMessage(c.lang, 'command.help.permsNormal')
const permsT = getMessage(c.lang, 'command.help.permsTrusted')

View file

@ -1,6 +1,6 @@
import * as m from 'minecraft-protocol'
import { default as settings } from './settings.json' with {type: "json"}
import { generateUser } from './util/usergen.js'
import { generateUser } from './util/usergen.mjs'
import EventEmitter from 'node:events'
import * as fs from 'fs'

View file

@ -1,7 +1,7 @@
import { default as settings } from '../settings.json' with {type: "json"}
import { default as parsePlain } from '../util/chatparse_plain.js'
import { default as parseConsole } from '../util/chatparse_console.js'
import { default as parse1204 } from '../util/parseNBT.js'
import { default as parsePlain } from '../util/chatparse_plain.mjs'
import { default as parseConsole } from '../util/chatparse_console.mjs'
import { default as parse1204 } from '../util/parseNBT.mjs'
const messageTypes = [
'',
'chat.type.emote',

View file

@ -1,8 +1,8 @@
import { default as Command } from '../util/Command.js'
import { default as hashcheck } from '../util/hashcheck.js'
import { default as Command } from '../util/Command.mjs'
import { default as hashcheck } from '../util/hashcheck.mjs'
import { default as settings } from '../settings.json' with {type: "json"}
import { getMessage } from '../util/lang.js'
import { default as cmds } from '../util/commands.js'
import { getMessage } from '../util/lang.mjs'
import { default as cmds } from '../util/commands.mjs'
import * as fs from 'fs'
if (!fs.readdirSync('.').includes('userPref')) fs.mkdirSync('userPref')

View file

@ -1,4 +1,4 @@
import { default as uuidToInt } from '../util/uuidtoint.js'
import { default as uuidToInt } from '../util/uuidtoint.mjs'
const cs = {
x: 4,
y: 6,

View file

@ -1,7 +1,7 @@
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'
import { bot } from '../index.mjs'
import { default as ConsoleCommand } from '../util/ConsoleCommand.mjs'
import { default as cmds } from '../util/commands.mjs'
const rl = readln.createInterface({
input: process.stdin,
output: process.stdout,

View file

@ -1,5 +1,5 @@
import { default as parse } from '../util/chatparse_plain.js'
import { default as parseNBT } from '../util/parseNBT.js'
import { default as parse } from '../util/chatparse_plain.mjs'
import { default as parseNBT } from '../util/parseNBT.mjs'
export default {
load: (b) => {
b.players = {}

View file

@ -1,4 +1,4 @@
import { createBot } from "../index.js"
import { createBot } from "../index.mjs"
export default {
load: (b) => {
b._client.on('end', () => {

View file

@ -1,5 +1,5 @@
import { bot } from '../index.js'
import { default as parse } from '../util/chatparse_console.js'
import { bot } from '../index.mjs'
import { default as parse } from './chatparse_console.mjs'
import { default as settings } from '../settings.json' with {type: "json"}
class ConsoleCommand {
constructor (cmd, index2) {

View file

@ -1,5 +1,5 @@
import { default as settings } from '../settings.json' with {type: "json"}
import { default as lang } from './mc_lang.js'
import { default as lang } from './mc_lang.mjs'
import { default as _consoleColors } from './consolecolors.json' with {type: "json"}
let consoleColors

View file

@ -1,4 +1,4 @@
import { default as lang } from './mc_lang.js'
import { default as lang } from './mc_lang.mjs'
const parse = function (_data, l = 0) {
if (l >= 4) {
return ''

View file

@ -1,28 +0,0 @@
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) {
for (const j in cmds[commandName].aliases) {
cmds[cmds[commandName].aliases[j]] = {
execute: cmds[commandName].execute,
alias: commandName,
usage: cmds[commandName].usage,
level: cmds[commandName].level,
hidden: true,
consoleIndex: cmds[commandName].consoleIndex
}
}
}
}
export default cmds

52
util/commands.mjs Normal file
View file

@ -0,0 +1,52 @@
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"
import { default as commandAbout } from "../commands/about.mjs"
import { default as commandCb } from "../commands/cb.mjs"
import { default as commandCloop } from "../commands/cloop.mjs"
import { default as commandEval } from "../commands/eval.mjs"
import { default as commandLogoff } from "../commands/logoff.mjs"
import { default as commandRefill } from "../commands/refill.mjs"
import { default as commandRestart } from "../commands/restart.mjs"
import { default as commandSettings } from "../commands/settings.mjs"
import { default as commandStop } from "../commands/stop.mjs"
import { default as commandTemplate } from "../commands/template.mjs"
import { default as commandTpr } from "../commands/tpr.mjs"
import { default as commandVerify } from "../commands/verify.mjs"
cmds.test = commandTest
cmds.say = commandSay
cmds.netmsg = commandNetmsg
cmds.help = commandHelp
cmds.about = commandAbout
cmds.cb = commandCb
cmds.cloop = commandCloop
cmds.eval = commandEval
cmds.logoff = commandLogoff
cmds.refill = commandRefill
cmds.restart = commandRestart
cmds.settings = commandSettings
cmds.stop = commandStop
cmds.template = commandTemplate
cmds.tpr = commandTpr
cmds.verify = commandVerify
for(const commandName in cmds){
if (cmds[commandName].aliases) {
for (const j in cmds[commandName].aliases) {
cmds[cmds[commandName].aliases[j]] = {
execute: cmds[commandName].execute,
alias: commandName,
usage: cmds[commandName].usage,
level: cmds[commandName].level,
hidden: true,
consoleIndex: cmds[commandName].consoleIndex
}
}
}
}
export default cmds

View file

@ -1,13 +1,12 @@
const version = require('../version.json')
const cp = require('child_process')
import { default as version } from "../version.json" with { type: "json" }
import { execSync } from "child_process"
let botVersion = version.botVersion
let gitCommit
let gitBranch
try {
gitCommit = cp.execSync('git rev-parse --short HEAD').toString('UTF-8').split('\n')[0]
gitBranch = cp.execSync('git rev-parse --abbrev-ref HEAD').toString('UTF-8').split('\n')[0]
gitCommit = execSync('git rev-parse --short HEAD').toString('UTF-8').split('\n')[0]
gitBranch = execSync('git rev-parse --abbrev-ref HEAD').toString('UTF-8').split('\n')[0]
} catch (e) {
gitCommit = false
gitBranch = false
@ -17,4 +16,4 @@ if (gitCommit) {
botVersion += ` (${gitCommit} - ${gitBranch})`
}
module.exports = botVersion
export default botVersion