mirror of
https://github.com/Expand-sys/mcbot
synced 2026-03-22 04:27:11 +11:00
beans
This commit is contained in:
parent
b208830519
commit
ab6a9b562b
4 changed files with 48 additions and 9 deletions
BIN
bun.lockb
BIN
bun.lockb
Binary file not shown.
|
|
@ -21,12 +21,12 @@ module.exports = {
|
||||||
host: process.env.MCHOST,
|
host: process.env.MCHOST,
|
||||||
port: process.env.MCHOSTPORT,
|
port: process.env.MCHOSTPORT,
|
||||||
}).then((state) => {
|
}).then((state) => {
|
||||||
//console.log(state);
|
console.log(state);
|
||||||
//console.log(state.players)
|
//console.log(state.players)
|
||||||
sendResponse(interaction, `${JSON.stringify(state)}`)
|
//sendResponse(interaction, `${JSON.stringify(state)}`)
|
||||||
}).catch(async (error) => {
|
}).catch(async (error) => {
|
||||||
console.log("Server is offline " + error);
|
console.log("Server is offline " + error);
|
||||||
sendResponse(interaction, "Server is offline")
|
//sendResponse(interaction, "Server is offline")
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -8,6 +8,25 @@ const dig = require("gamedig")
|
||||||
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const { channelSend } = require('../../utils/utils');
|
const { channelSend } = require('../../utils/utils');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
async function run() {
|
||||||
|
try {
|
||||||
|
// Connect the client to the server (optional starting in v4.7)
|
||||||
|
await dbclient.connect();
|
||||||
|
// Send a ping to confirm a successful connection
|
||||||
|
await dbclient.db("admin").command({ ping: 1 });
|
||||||
|
console.log("Pinged your deployment. You successfully connected to MongoDB!");
|
||||||
|
} finally {
|
||||||
|
// Ensures that the client will close when you finish/error
|
||||||
|
await dbclient.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
run().catch(console.dir);
|
||||||
|
|
||||||
|
count = 0
|
||||||
|
|
||||||
serverofflinefor = 0;
|
serverofflinefor = 0;
|
||||||
let restarted = 0;
|
let restarted = 0;
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
@ -26,14 +45,32 @@ module.exports = {
|
||||||
type: 'minecraft',
|
type: 'minecraft',
|
||||||
host: process.env.MCHOST,
|
host: process.env.MCHOST,
|
||||||
port: process.env.MCHOSTPORT,
|
port: process.env.MCHOSTPORT,
|
||||||
}).then((state) => {
|
}).then(async (state) => {
|
||||||
//console.log(state);
|
//console.log(state);
|
||||||
//console.log(state.players)
|
console.log(state.players)
|
||||||
serverofflinefor = 0;
|
serverofflinefor = 0;
|
||||||
if(restarted == 1){
|
if(restarted == 1){
|
||||||
channelSend("Server back online!")
|
channelSend("Server back online!")
|
||||||
}
|
}
|
||||||
restarted = 0;
|
restarted = 0;
|
||||||
|
count +=1
|
||||||
|
//this will be where i do the tracking logic for how long people have been on the server
|
||||||
|
if(count == 6){
|
||||||
|
await dbclient.connect()
|
||||||
|
//let ping = await dbclient.db("timetracking").command({ ping: 1})
|
||||||
|
//console.log(ping)
|
||||||
|
let collection = await dbclient.db("timetracking").collection("times")
|
||||||
|
for(i = 0; i < state.players.length; i++){
|
||||||
|
const query = { name: `${state.players[i].name}`}
|
||||||
|
const update = { $inc: { time: 1 }}
|
||||||
|
const options = { upsert: true }
|
||||||
|
await collection.findOneAndUpdate(query, update, options)
|
||||||
|
console.log("butts")
|
||||||
|
}
|
||||||
|
await dbclient.close()
|
||||||
|
count = 0
|
||||||
|
}
|
||||||
|
|
||||||
}).catch(async (error) => {
|
}).catch(async (error) => {
|
||||||
console.log("Server is offline " + error);
|
console.log("Server is offline " + error);
|
||||||
serverofflinefor += 10
|
serverofflinefor += 10
|
||||||
|
|
@ -42,10 +79,11 @@ module.exports = {
|
||||||
}
|
}
|
||||||
if(serverofflinefor == 60 && restarted != 1){
|
if(serverofflinefor == 60 && restarted != 1){
|
||||||
channelSend(`Server Offline for 60 seconds Restarting`)
|
channelSend(`Server Offline for 60 seconds Restarting`)
|
||||||
const killer = await spawn("screen", ['-XS', 'minecraft', 'quit'])
|
//this is commented out temporarily to stop the server trying to start on my local machine but has been tested as working
|
||||||
const mc = await spawn("screen", ['-dmS', 'minecraft', '/bin/bash', `${process.env.SERSTARTLOC}/ServerStart.sh`], {
|
//const killer = await spawn("screen", ['-XS', 'minecraft', 'quit'])
|
||||||
cwd: `${process.env.SERSTARTLOC}`
|
//const mc = await spawn("screen", ['-dmS', 'minecraft', '/bin/bash', `${process.env.SERSTARTLOC}/ServerStart.sh`], {
|
||||||
})
|
//cwd: `${process.env.SERSTARTLOC}`
|
||||||
|
//})
|
||||||
restarted = 1
|
restarted = 1
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@
|
||||||
"gamedig": "^4.3.0",
|
"gamedig": "^4.3.0",
|
||||||
"gifencoder": "^2.0.1",
|
"gifencoder": "^2.0.1",
|
||||||
"glob": "^7.2.0",
|
"glob": "^7.2.0",
|
||||||
|
"mongodb": "^6.3.0",
|
||||||
"os": "^0.1.2",
|
"os": "^0.1.2",
|
||||||
"rcon-client": "^4.2.3",
|
"rcon-client": "^4.2.3",
|
||||||
"rss-parser": "^3.12.0",
|
"rss-parser": "^3.12.0",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue