allah
This commit is contained in:
parent
3cae10d39b
commit
05acc96b2e
177
server/index.js
177
server/index.js
@ -1,24 +1,45 @@
|
||||
const express = require('express'),
|
||||
sqlite3 = require('sqlite3'),
|
||||
bodyParser = require('body-parser'),
|
||||
const express = require("express"),
|
||||
sqlite3 = require("sqlite3"),
|
||||
bodyParser = require("body-parser"),
|
||||
mc = require("minecraft-server-util"),
|
||||
Discord = require("discord-webhook-node"),
|
||||
geoIP = require("geoip-lite"),
|
||||
fs = require("fs"),
|
||||
config = require("./config.json"),
|
||||
app = express(),
|
||||
mc = require('minecraft-server-util'),
|
||||
discord = require('discord-webhook-node'),
|
||||
geoip = require('geoip-lite'),
|
||||
fs = require('fs'),
|
||||
config = require('./config.json')
|
||||
var webhook = new discord.Webhook(config.main)
|
||||
.setUsername("TaxenHeimer")
|
||||
.setAvatar("https://cdn.discordapp.com/attachments/999167321631363126/999495738943868928/nn.png")
|
||||
var webhookfronce = new discord.Webhook(config.fronce)
|
||||
.setAvatar("https://cdn.discordapp.com/attachments/999167321631363126/999495738943868928/nn.png")
|
||||
.setUsername("TaxenHeimer")
|
||||
var neithook = new discord.Webhook(config.neit)
|
||||
.setAvatar("https://cdn.discordapp.com/attachments/999167321631363126/999495738943868928/nn.png")
|
||||
.setUsername("TaxenHeimer")
|
||||
app.use(bodyParser.json())
|
||||
app.use(bodyParser.urlencoded({extended: true}))
|
||||
db = new sqlite3.Database('./servers.db')
|
||||
db = new sqlite3.Database("./servers.db");
|
||||
|
||||
const createWebhook = url => new Discord.Webhook(url).setUsername("TaxenHeimer").setAvatar("https://cdn.discordapp.com/attachments/999167321631363126/999495738943868928/nn.png")
|
||||
const countrify = e => require("./contrycode.json")[e]
|
||||
const replaceMOTD = e => e.replace(/'/g, "\\'").replace(/-/g, '\\-')
|
||||
const makeEmbed = (mc, neit) => {
|
||||
var Embed = new Discord.MessageBuilder()
|
||||
.setTitle("TaxenHeimer")
|
||||
.setColor("#00ff00")
|
||||
.addField("**Host**", `\`${mc.Server}\``, true)
|
||||
.addField("**Country**", `\`${countrify(mc.ip.country)}\``)
|
||||
.addField("**Version**", `\`${mc.version.name} (${mc.version.protocol})\``, true)
|
||||
.addField("**Players**", `\`${mc.players.online}/${mc.players.max}\``, true)
|
||||
.addField("**Ping**", `\`${mc.roundTripLatency}ms\``, true)
|
||||
.addField("**Motd**", "```\n" + mc.motd.clean + "\n```")
|
||||
.addField("**Playerlist Sample**", "```\n" + mc.PlayerList + "\n```")
|
||||
.addField("**IP Range**", "```\n" + geoIP.pretty(mc.ip.range[0]) + " - " + geoIP.pretty(mc.ip.range[1]) + "```")
|
||||
.setTimestamp()
|
||||
|
||||
if (neit) Embed.setText("<@390491795655622657>")
|
||||
console.log(Embed)
|
||||
return Embed
|
||||
}
|
||||
var webhooks = [
|
||||
createWebhook(config.main),
|
||||
createWebhook(config.fronce),
|
||||
createWebhook(config.neit)
|
||||
]
|
||||
|
||||
app.use(bodyParser.json()).use(bodyParser.urlencoded({
|
||||
extended: true
|
||||
}))
|
||||
|
||||
db.exec(`CREATE TABLE IF NOT EXISTS servers (
|
||||
host text not null,
|
||||
version text not null,
|
||||
@ -28,87 +49,47 @@ db.exec(`CREATE TABLE IF NOT EXISTS servers (
|
||||
motd text not null,
|
||||
timestamp text not null
|
||||
)`)
|
||||
function countrify(code) {
|
||||
var config = require('./countrycode.json')
|
||||
return config[code]
|
||||
}
|
||||
app.post('/server', async(req, res) => {
|
||||
var server = req.body.server
|
||||
if (!server) return res.send("specify a server")
|
||||
var ipfile = fs.readFileSync(`${__dirname}/ip.txt`, 'utf8')
|
||||
if (ipfile.includes(server)) return;
|
||||
|
||||
app.post("/server", async (req, res) => {
|
||||
var Server = req.body.server
|
||||
if (!Server) return res.send("specify a server")
|
||||
res.send("allah")
|
||||
mc.status(server, 25565, {enableSRV: true}).then(res => {
|
||||
var playerlist = ""
|
||||
if (res.players.sample != null) {
|
||||
res.players.sample.forEach(e => playerlist += `${e.name}::${e.id}\n`)
|
||||
} else {
|
||||
playerlist += "No players"
|
||||
}
|
||||
var ip = geoip.lookup(server)
|
||||
if (res.motd.clean.includes("'")) var cleanmotd = res.motd.clean.replace(/'/g, "\\'")
|
||||
else cleanmotd = res.motd.clean
|
||||
if (res.motd.clean.includes('-')) var cleanmotd = res.motd.clean.replace(/-/g, '\\-')
|
||||
else cleanmotd = res.motd.clean
|
||||
db.exec(`INSERT INTO servers VALUES (
|
||||
'${server}:25565',
|
||||
'${res.version.name}',
|
||||
'${res.players.online}/${res.players.max}',
|
||||
'${playerlist}',
|
||||
'${res.roundTripLatency}ms',
|
||||
'${cleanmotd}',
|
||||
'${(new Date()).toLocaleDateString('en-US')}'
|
||||
)`)
|
||||
if (ip.country === "FR") {
|
||||
const embed = new discord.MessageBuilder()
|
||||
.setTitle("TaxenHeimer")
|
||||
.setColor("#00ff00")
|
||||
.addField("**Host**", `\`${server}:25565\``, true)
|
||||
.addField("**Country**", `\`${countrify(ip.country)}\``)
|
||||
.addField("**Version**", `\`${res.version.name} (${res.version.protocol})\``, true)
|
||||
.addField("**Players**", `\`${res.players.online}/${res.players.max}\``, true)
|
||||
.addField("**Ping**", `\`${res.roundTripLatency}ms\``, true)
|
||||
.addField("**Motd**", "```\n"+res.motd.clean+"\n```")
|
||||
.addField("**Playerlist Sample**", "```\n"+playerlist+"\n```")
|
||||
.addField("**IP Range**", "```\n" + geoip.pretty(ip.range[0]) + " - " + geoip.pretty(ip.range[1]) + "```")
|
||||
.setTimestamp()
|
||||
webhookfronce.send(embed)
|
||||
}
|
||||
if (res.version.name.includes("1.17")) {
|
||||
const embed = new discord.MessageBuilder()
|
||||
.setText("<@390491795655622657>")
|
||||
.setTitle("TaxenHeimer")
|
||||
.setColor("#00ff00")
|
||||
.addField("**Host**", `\`${server}:25565\``, true)
|
||||
.addField("**Country**", `\`${countrify(ip.country)}\``)
|
||||
.addField("**Version**", `\`${res.version.name} (${res.version.protocol})\``, true)
|
||||
.addField("**Players**", `\`${res.players.online}/${res.players.max}\``, true)
|
||||
.addField("**Ping**", `\`${res.roundTripLatency}ms\``, true)
|
||||
.addField("**Motd**", "```\n"+res.motd.clean+"\n```")
|
||||
.addField("**Playerlist Sample**", "```\n"+playerlist+"\n```")
|
||||
.addField("**IP Range**", "```\n" + geoip.pretty(ip.range[0]) + " - " + geoip.pretty(ip.range[1]) + "```")
|
||||
.setTimestamp()
|
||||
neithook.send(embed)
|
||||
}
|
||||
const embed = new discord.MessageBuilder()
|
||||
.setTitle("TaxenHeimer")
|
||||
.setColor("#00ff00")
|
||||
.addField("**Host**", `\`${server}:25565\``, true)
|
||||
.addField("**Country**", `\`${countrify(ip.country)}\``)
|
||||
.addField("**Version**", `\`${res.version.name} (${res.version.protocol})\``, true)
|
||||
.addField("**Players**", `\`${res.players.online}/${res.players.max}\``, true)
|
||||
.addField("**Ping**", `\`${res.roundTripLatency}ms\``, true)
|
||||
.addField("**Motd**", "```\n"+res.motd.clean+"\n```")
|
||||
.addField("**Playerlist Sample**", "```\n"+playerlist+"\n```")
|
||||
.addField("**IP Range**", "```\n" + geoip.pretty(ip.range[0]) + " - " + geoip.pretty(ip.range[1]) + "```")
|
||||
.setTimestamp()
|
||||
webhook.send(embed)
|
||||
fs.appendFileSync(`${server}\n`)
|
||||
}).catch(e => {})
|
||||
if (fs.readFileSync(`${__dirname}/ip.txt`).toString().includes(Server)) return
|
||||
var Minecraft = await mc.status(Server, 25565, {
|
||||
enableSRV: true
|
||||
})
|
||||
Minecraft.ip = geoIP.lookup(Server)
|
||||
Minecraft.Server = `${Server}:25565`
|
||||
var cleanMOTD = replaceMOTD(Minecraft.motd.clean)
|
||||
Minecraft.PlayerList = ""
|
||||
Minecraft.players.sample ? Minecraft.players.sample.forEach(e => Minecraft.PlayerList += `${e.name}::${e.id}\n`) : Minecraft.PlayerList = "No Players"
|
||||
db.exec(`INSERT INTO servers VALUES (
|
||||
'${Minecraft.Server}',
|
||||
'${Minecraft.version.name}',
|
||||
'${Minecraft.players.online}/${Minecraft.players.max}',
|
||||
'${Minecraft.PlayerList}',
|
||||
'${Minecraft.roundTripLatency}ms',
|
||||
'${cleanMOTD}',
|
||||
'${new Date().toLocaleDateString('en-US')}'
|
||||
)`)
|
||||
switch (Minecraft.ip.country) {
|
||||
default: break;
|
||||
case "FR":
|
||||
webhooks[1].send(makeEmbed(Minecraft))
|
||||
break
|
||||
}
|
||||
switch(true) {
|
||||
case Minecraft.version.name.includes("1.17"):
|
||||
webhooks[2].send(makeEmbed(Minecraft, "neit"))
|
||||
break;
|
||||
default:
|
||||
webhooks[0].send(makeEmbed(Minecraft))
|
||||
break
|
||||
}
|
||||
})
|
||||
app.listen(9000, () => {
|
||||
console.clear()
|
||||
console.log("server ready")
|
||||
})
|
||||
process.on("unhandledRejection", callback => {})
|
||||
process.on("uncaughtException", callback => {})
|
||||
//process.on("unhandledRejection", callback => console.log(callback))
|
||||
//process.on("uncaughtException", callback => console.log(callback))
|
Loading…
Reference in New Issue
Block a user