Merge pull request 'Unload Global (Remove legacy global load for plugins)' (#2) from unload-global into main

Reviewed-on: 7cc5c4f330d47060/botvX#2
This commit is contained in:
7cc5c4f330d47060 2024-07-29 01:37:38 -04:00
commit b42d4748d3
11 changed files with 71 additions and 105 deletions

View file

@ -19,17 +19,12 @@ const loadplug = (botno) => {
}
botplug.forEach((plug) => {
try {
if (botno !== undefined) {
if (plug.loadBot) {
plug.loadBot(module.exports.bot[botno])
}
} else {
plug.load()
if (plug.load) {
plug.load(module.exports.bot[botno])
}
} catch (e) { console.log(e) }
})
}
loadplug()
const createBot = function createBot (host, oldId) {
if (host.options.disabled) {

View file

@ -12,10 +12,7 @@ const messageTypes = [
''
]
module.exports = {
load: () => {
},
loadBot: (b) => {
load: (b) => {
b._client.on('profileless_chat', (data) => {
if (data.type === 4) {
const json = parse1204(data.message)

View file

@ -1,8 +1,5 @@
module.exports = {
load: () => {
},
loadBot: (b) => {
load: (b) => {
b.cloops = []
b.addCloop = function (command, rate) {
b.cloops.push({

View file

@ -3,17 +3,41 @@ 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 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 sortHelp = function sortHelp (c1, c2) {
const level1 = cmds[c1.with[1]].level ? cmds[c1.with[1]].level : 0
const level2 = cmds[c2.with[1]].level ? cmds[c2.with[1]].level : 0
return level1 - level2
}
module.exports = {
load: () => {
module.exports.loadCMD()
},
loadBot: (b) => {
load: (b) => {
b.prefix = settings.prefix
b.lastCmd = 0
b.runCommand = (name, uuid, text, prefix) => {
@ -154,33 +178,5 @@ module.exports = {
})
}
},
loadCMD: () => {
const bpl = fs.readdirSync('./plugins/commands')
for (const i in bpl) {
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) }
}
},
cmds
}

View file

@ -2,10 +2,7 @@ const uuidToInt = require('../util/uuidtoint.js')
module.exports = {
cs: 4,
cs_v: 6,
load: function () {
},
loadBot: function (b) {
load: function (b) {
b.interval.commandFill = setInterval(() => { if (b.sc_tasks.cc) b.sc_tasks.cc.failed = 1 }, 60000)
b.ccq = []
b.blocknoX = 0

View file

@ -2,7 +2,37 @@ const readln = require('readline')
const index = require('../index.js')
const ConsoleCommand = require('../util/ConsoleCommand.js')
const newercommands = require('./command.js').cmds
let rl
let rl = readln.createInterface({
input: process.stdin,
output: process.stdout,
prompt: '\x1b[0m\x1b[38;5;15m> '
})
rl.on('line', (l) => {
try {
if (newercommands[l.split(' ')[0].toLowerCase()]) {
if (newercommands[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)
}
} else {
const cmd = new ConsoleCommand(tmpcmd.join(' '), +index2)
newercommands[l.split(' ')[0].toLowerCase()].execute(cmd)
}
} else {
const cmd = new ConsoleCommand(l, -2)
newercommands[l.split(' ')[0].toLowerCase()].execute(cmd)
}
}
} catch (e) {
console.log(e)
}
rl.prompt(false)
})
rl.prompt();
function consoleWrite (text) {
readln.cursorTo(process.stdout, 0)
readln.clearLine(process.stdout, 0)
@ -10,40 +40,7 @@ function consoleWrite (text) {
rl.prompt(true)
}
module.exports = {
load: () => {
rl = readln.createInterface({
input: process.stdin,
output: process.stdout,
prompt: '\x1b[0m\x1b[38;5;15m> '
})
rl.on('line', (l) => {
try {
if (newercommands[l.split(' ')[0].toLowerCase()]) {
if (newercommands[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)
}
} else {
const cmd = new ConsoleCommand(tmpcmd.join(' '), +index2)
newercommands[l.split(' ')[0].toLowerCase()].execute(cmd)
}
} else {
const cmd = new ConsoleCommand(l, -2)
newercommands[l.split(' ')[0].toLowerCase()].execute(cmd)
}
}
} catch (e) {
console.log(e)
}
rl.prompt(false)
})
rl.prompt()
},
loadBot: (b) => {
load: (b) => {
b.info = (msg) => {
consoleWrite(`[${b.id}] [info] ${msg}`)
}

View file

@ -1,8 +1,5 @@
module.exports = {
load: () => {
},
loadBot: (b) => {
load: (b) => {
b._client.on('login', () => {
b.interval.chatQueue = setInterval(() => {
if (b.chatqueue.length !== 0) {

View file

@ -1,9 +1,7 @@
const parse = require('../util/chatparse.js')
const parse1204 = require('../util/chatparse_1204.js')
module.exports = {
load: () => {
},
loadBot: (b) => {
load: (b) => {
b.players = {}
b._client.on('player_info', (data) => {
const buffer2 = {}

View file

@ -1,8 +1,6 @@
const index = require('../index.js')
module.exports = {
load: () => {
},
loadBot: (b) => {
load: (b) => {
b._client.on('end', () => {
b.info('bot ' + b.id + ' disconnected')
for (const i in b.interval) {

View file

@ -11,10 +11,7 @@ class SCTask {
}
}
module.exports = {
load: () => {
},
loadBot: (b) => {
load: (b) => {
b.sc_tasks = {}
b.interval.sc = setInterval(() => {
for (const i in b.sc_tasks) {

View file

@ -1,8 +1,5 @@
module.exports = {
load: () => {
},
loadBot: (b) => {
load: (b) => {
}
}