...
 
Commits (2)
node_modules/
\ No newline at end of file
.gitignore
node_modules/
world/
logs/
*.json
*.txt
*.properties
*.jar
......@@ -6,6 +6,7 @@ var util = require("./util.js")
var lang = require("./lang.json")
var chalk = require("chalk")
var commands = require("./commands.js")
var cmds = new Map()
......@@ -43,18 +44,21 @@ setInterval(() => {
mc.stdout.on("data", stdout => {
//buffer => string
let data = stdout.toString();
//if data includes "Done" we will set the done bool to true
if(data.includes("Done")) {
util.load(cmds)
console.timeEnd(`startup`)
console.log(`${chalk.blue(lang[config.main.locale][2])}`)
done=true
}
//this code is spaghetti, clean please
if(done) {
if(config.main.debug) console.log(data)
//get the user
let user = data.match(/(?<=\<).+(?=\>)/)
if(!user || !user[0]) return
user[0] = user[0].toLowerCase()
//get chat msg
let chat = data.match(/(?<=\<.+\>\s).+/gi)
......@@ -67,10 +71,11 @@ if(done) {
let wrdarr = chat[0].toLowerCase().split(" ")
if(chat[0].startsWith(config.config.prefix)) {
let com = wrdarr[0].slice(config.config.prefix.length).trim().split(/ +/g);
if(!commands[com]) return mc.stdin.write(`/tellraw ${user[0]} ["",{"text":"command \\""},{"text":"${com}","color":"yellow"},{"text":"\\" does not exist"}]\n`)
if(!cmds.has(com)) return mc.stdin.write(`/tellraw ${user[0]} ["",{"text":"command \\""},{"text":"${com}","color":"yellow"},{"text":"\\" does not exist"}]\n`)
else {
try{
commands[com](wrdarr,user[0],mc,{uin:userinf,excused:config.config.excused},commands)
let _run = cmds.get(com)
_run.run(wrdarr,user[0],mc,{uin:userinf,excused:config.config.excused},commands)
} catch (err) {
let str64 = Buffer.from(String(Math.floor(Math.random() * 2000))).toString("base64")
fs.writeFileSync(`./errorLogs/${str64}.txt`, err)
......
......@@ -3,9 +3,9 @@ version=2
; swe/en
locale=en
; path to mc server .jar
path=notSet
path=E:\kodning\mcUtil\server\server.jar
;enbales debug features
debug=false
debug=true
; time between reload of this ini file
reloadTime=50000
; auto update
......
const https = require('https');
const chalk = require("chalk")
const { exec } = require('child_process');
const fs = require("fs")
exports.load = (_map) => {
let _loadedinf = []
fs.readdirSync("../commands").map(f => {
fs.readdirSync("./commands").map(f => {
try {
//require file
let fr = require(`../commands/${f}`)
let fr = require(`./commands/${f}`)
_loadedinf.push({
name: fr.config.name,
info: fr.config.info,
......@@ -22,23 +24,33 @@ exports.load = (_map) => {
}
/*
This function acs as version control using gitlab as the thingie thing that does the thing!
*/
let vercntrl = `https://gitlab.com/api/v4/projects/12756686/repository/tags`
exports.updates = (conf) => {
try {
//make https request to gitlab api to fetch verion number and shit
https.get(vercntrl, (res) => {
let data = '';
//chunk chunk chunk
res.on('data', (chunk) => {
data += chunk;
});
//do the thing when all data is here
res.on('end', () => {
data = JSON.parse(data)
if(data[0].release.description > conf.version) {
console.log(`${chalk.green(`new update found (${data[0].release.description})`)}`)
if(data[1].release.description > conf.version) {
console.log(`${chalk.green(`new update found (${data[1].release.description})`)}`)
console.log(`- ${data[0].release.description}`)
if(conf.main.aupdate) {
console.log(`auto update: ${chalk.green("true : updating")}`)
exec(`git pull https://gitlab.com/familyfriendly/mcutil.git`)
exec('git pull https://gitlab.com/familyfriendly/mcutil.git',(error,stdout,stderr) => {
console.log(stdout)
});
} else {
console.log(`auto update: ${chalk.red("false : not updating")}`)
}
......@@ -47,6 +59,10 @@ exports.updates = (conf) => {
});
})
} catch(err) {
console.log(`${chalk.red("could not check updates:")} ${err}`)
}
}