diff --git a/plugins/command.js b/plugins/command.js index 4f1abf5..4e92c51 100755 --- a/plugins/command.js +++ b/plugins/command.js @@ -2,6 +2,7 @@ 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'); let cmds=Object.create(null); module.exports={ load:()=>{ @@ -17,6 +18,7 @@ module.exports={ return; } const cmd=text.split(" "); + let lang=settings.defaultLang; let verify=hashcheck(cmd); if(verify>0){ text=cmd.slice(0,cmd.length-1).join(" "); @@ -25,33 +27,33 @@ module.exports={ const command = cmds[cmd[0].toLowerCase()]; if(command.level!==undefined && command.level>verify){ b.tellraw(uuid,{ - text:"You do not have permission to run this command. If you have permission, please make sure you put the command hash at the end, or ran the command through your client's hashing system." + text:getMessage(lang,"command.disallowed.perms") }); b.tellraw(uuid,{ - text:"Your permission level: "+verify + text:getMessage(lang,"command.disallowed.perms.yourLevel",[verify+""]) }); b.tellraw(uuid,{ - text:"Command requires: "+command.level + text:getMessage(lang,"command.disallowed.perms.cmdLevel",[command.level+""]) }); return; } try{ cmds[cmd[0].toLowerCase()].execute(new Command(uuid,name,"nick N/A",text,prefix,b,verify)) } catch(e) { - console.log(e); b.chat("An error occured (check console for more info)") + console.log(e); b.chat(getMessage(lang,"command.error")) } } } - b.printHelp=(uuid,prefix)=>{ + b.printHelp=(uuid,prefix,lang)=>{ let helpCmds=[]; for(const i in cmds){ if(cmds[i].hidden) continue; helpCmds.push(prefix+i) } - b.tellraw(uuid,{"text":"Commands: "+helpCmds.join(" ")}); + b.tellraw(uuid,{"text":getMessage(lang,"command.help.cmdList",[helpCmds.join(" ")])}); } - b.printCmdHelp=(uuid,cmd)=>{ - b.tellraw(uuid,{"text":cmd+cmds[cmd].usage+" - "+cmds[cmd].desc}); + b.printCmdHelp=(uuid,cmd,lang)=>{ + b.tellraw(uuid,{"text":getMessage(lang,"command.help.commandInfo",[cmd,getMessage(lang,`command.${cmd}.usage`),getMessage(lang,"command.${cmd}.desc")])}); } }, loadCMD:()=>{ diff --git a/plugins/commands/about.js b/plugins/commands/about.js index d94744f..dd70aa1 100644 --- a/plugins/commands/about.js +++ b/plugins/commands/about.js @@ -1,12 +1,13 @@ const version = require("../../version.json") const settings = require('../../settings.json') +const getMessage = require('../../util/lang.js') module.exports = { execute: function (c) { - c.reply({text:`${settings.name} - a minecraft bot made by 77c8f4699b732c11 / a5a06d596f15c7db`}); + c.reply({text:getMessage(c.lang,"command.about.author",[settings.name])}); c.reply({text:""}); - c.reply({text:`Version ${version.bot}`}); + c.reply({text:getMessage(c.lang,"command.about.version",[version.bot])}); c.reply({text:""}); - c.reply({text:"To view system information, run the command \"serverinfo\"."}) + c.reply({text:getMessage(c.lang,"command.about.serverinfo")}) }, desc: 'About the bot', usage: '', diff --git a/settings2.json b/settings2.json index 987414d..69c594a 100755 --- a/settings2.json +++ b/settings2.json @@ -2,6 +2,7 @@ "secret":"./settings_s.json", "name": "Minecraft Bot", "version_mc": "1.20.4", + "defaultLang": "en-US", "prefix":[ "ubot:", "\"" diff --git a/util/Command.js b/util/Command.js index 9539630..4406157 100644 --- a/util/Command.js +++ b/util/Command.js @@ -1,7 +1,8 @@ //HOW TO WRITE CLASS JS -const parse = require("../util/chatparse.js") +const parse = require("../util/chatparse.js"); +const settings = require("../settings.json"); class Command{ - constructor (uuid,user,nick,cmd,prefix,bot,verify){ + constructor (uuid,user,nick,cmd,prefix,bot,verify,lang = settings.defaultLang){ this.send = (text,uuid)=>{bot.tellraw(uuid?uuid:"@a",text)}; this.reply = text => bot.tellraw(uuid,text); this.uuid = uuid; @@ -16,6 +17,7 @@ class Command{ this.verify = verify; this.host = bot.host.host; this.port = bot.host.port; + this.lang = lang; } } diff --git a/util/ConsoleCommand.js b/util/ConsoleCommand.js index 878942d..4f068b3 100644 --- a/util/ConsoleCommand.js +++ b/util/ConsoleCommand.js @@ -1,7 +1,8 @@ //HOW TO WRITE CLASS JS const index = require('../index.js') const { cmds } = require('../plugins/command.js'); -const parse = require("../util/chatparse.js") +const parse = require("../util/chatparse.js"); +const settings = require("../settings.json"); class ConsoleCommand{ constructor (cmd,index2){ this.send = ()=>{}; //not needed for console @@ -30,6 +31,7 @@ class ConsoleCommand{ this.verify = 3; this.host = ""; this.port = "3"; // :3 + this.lang = settings.defaultLang; } } diff --git a/util/lang.js b/util/lang.js new file mode 100644 index 0000000..75b7aad --- /dev/null +++ b/util/lang.js @@ -0,0 +1,27 @@ +const fs=require("fs") +let languages={}; +const loadplug = (botno) => { + const bpl = fs.readdirSync('util/lang') + for (const i in bpl) { + if (!bpl[i].endsWith('.json')) { + continue + } + try { + languages[bpl[i].split(".")[0]]=require(`./lang/${bpl[i]}`) + } catch (e) { console.log(e) } + } +} +loadplug() +module.exports = function (l, msg, with2) { + let message=msg.replace(/%%/g, '\ue123'); + if (languages[l][message] !== undefined) { + message = languages[l][message].replace(/%%/g, '\ue123') + } else if (languages["en-US"][message] !== undefined) { + message = languages["en-US"][message].replace(/%%/g, '\ue123') + } + for(i in with2){ + message = message.replace(/%s/, with2[i].replace(/%s/g, '\ue124').replace(/\$s/g, '\ue125')) + message = message.replaceAll(`%${+i+1}$s`, with2[i].replace(/%s/g, '\ue124').replace(/\$s/g, '\ue125')) + } + return message.replace(/\ue123/g, '%').replace(/\ue124/g, '%s').replace(/\ue125/g, '$s') +} diff --git a/util/lang/en-US.json b/util/lang/en-US.json new file mode 100644 index 0000000..2e7813b --- /dev/null +++ b/util/lang/en-US.json @@ -0,0 +1,11 @@ +{ + "command.about.author": "%s - a Minecraft bot made by 77c8f4699b732c11 / a5a06d596f15c7db", + "command.about.version": "Version %s", + "command.about.serverinfo": "To view system information, run the command \"serverinfo\".", + "command.help.cmdList": "Commands: %s", + "command.help.commandInfo": "%s%s - %s", + "command.error": "An error occured (check console for more info)", + "command.disallowed.perms": "You do not have permission to run this command. If you have permission, please make sure you put the command hash at the end, or ran the command through your client's hashing system.", + "command.disallowed.perms.yourLevel": "Your permission level: %s", + "command.disallowed.perms.cmdLevel": "Command requires: %s" +} \ No newline at end of file diff --git a/util/lang/he-IL.json b/util/lang/he-IL.json new file mode 100644 index 0000000..2897985 --- /dev/null +++ b/util/lang/he-IL.json @@ -0,0 +1,5 @@ +{ + "command.about.author": "%s - a Minecwaft bot made by 77c8f4699b732c11 / a5a06d596f15c7db", + "command.about.version": "Vewsion %s", + "command.about.serverinfo": "To view system infowmation, wun the command \"serverinfo\"." +} \ No newline at end of file