added offline support
This commit is contained in:
parent
ece4aab11b
commit
58d5351d68
3
.gitignore
vendored
3
.gitignore
vendored
@ -7,4 +7,5 @@ server_backup
|
|||||||
old_tests
|
old_tests
|
||||||
nim_bot/src/token.key
|
nim_bot/src/token.key
|
||||||
nim_bot/src/tmp
|
nim_bot/src/tmp
|
||||||
nim_bot/src/bin
|
nim_bot/src/bin
|
||||||
|
server/offline.db
|
@ -104,13 +104,27 @@ proc messageCreate(s: Shard, m: Message) {.event(discord).} =
|
|||||||
of "status":
|
of "status":
|
||||||
let
|
let
|
||||||
db = open("../../server/servers.db", "", "", "")
|
db = open("../../server/servers.db", "", "", "")
|
||||||
server = $db.getAllRows(sql"SELECT host FROM servers").len
|
offdb = open("../../server/offline.db", "", "", "")
|
||||||
|
server = db.getAllRows(sql"SELECT host FROM servers").len
|
||||||
|
offline = offdb.getAllRows(sql"SELECT host FROM servers").len
|
||||||
|
total = server + offline
|
||||||
discard await discord.api.sendMessage(
|
discard await discord.api.sendMessage(
|
||||||
m.channel_id,
|
m.channel_id,
|
||||||
embeds = @[Embed(
|
embeds = @[Embed(
|
||||||
title: some "**Server Database Status**",
|
title: some "**Server Database Status**",
|
||||||
description: some fmt"```{'\n'}{server} total servers{'\n'}```",
|
color: some 0x000066,
|
||||||
color: some 0x000066
|
fields: some @[EmbedField(
|
||||||
|
name: "**Online Servers**",
|
||||||
|
value: fmt"```{$server} online servers```"
|
||||||
|
),
|
||||||
|
EmbedField(
|
||||||
|
name: "**Offline Servers**",
|
||||||
|
value: fmt"```{$offline} offline servers```"
|
||||||
|
),
|
||||||
|
EmbedField(
|
||||||
|
name: "**Total Servers**",
|
||||||
|
value: fmt"```{total} total servers```"
|
||||||
|
)]
|
||||||
)]
|
)]
|
||||||
)
|
)
|
||||||
of "info":
|
of "info":
|
||||||
|
@ -7,7 +7,8 @@ const express = require("express"),
|
|||||||
fs = require("fs"),
|
fs = require("fs"),
|
||||||
config = require("./config.json"),
|
config = require("./config.json"),
|
||||||
app = express(),
|
app = express(),
|
||||||
db = new sqlite3.Database("./servers.db");
|
db = new sqlite3.Database("./servers.db"),
|
||||||
|
offline = new sqlite3.Database("./offline.db");
|
||||||
|
|
||||||
const createWebhook = url => new Discord.Webhook(url).setUsername("TaxenHeimer").setAvatar("https://cdn.discordapp.com/attachments/999167321631363126/999495738943868928/nn.png")
|
const createWebhook = url => new Discord.Webhook(url).setUsername("TaxenHeimer").setAvatar("https://cdn.discordapp.com/attachments/999167321631363126/999495738943868928/nn.png")
|
||||||
const countrify = e => require("./countrycode.json")[e]
|
const countrify = e => require("./countrycode.json")[e]
|
||||||
@ -48,7 +49,10 @@ db.exec(`CREATE TABLE IF NOT EXISTS servers (
|
|||||||
motd text not null,
|
motd text not null,
|
||||||
timestamp text not null
|
timestamp text not null
|
||||||
)`)
|
)`)
|
||||||
|
offline.exec(`CREATE TABLE IF NOT EXISTS servers (
|
||||||
|
host text not null,
|
||||||
|
timestamp text not null
|
||||||
|
)`)
|
||||||
app.post("/server", async (req, res) => {
|
app.post("/server", async (req, res) => {
|
||||||
var Server = req.body.server
|
var Server = req.body.server
|
||||||
if (!Server) return res.send("specify a server")
|
if (!Server) return res.send("specify a server")
|
||||||
@ -56,6 +60,11 @@ app.post("/server", async (req, res) => {
|
|||||||
if (fs.readFileSync(`${__dirname}/ip.txt`).toString().includes(Server)) return
|
if (fs.readFileSync(`${__dirname}/ip.txt`).toString().includes(Server)) return
|
||||||
var Minecraft = await mc.status(Server, 25565, {
|
var Minecraft = await mc.status(Server, 25565, {
|
||||||
enableSRV: true
|
enableSRV: true
|
||||||
|
}).catch(e => {
|
||||||
|
offline.exec(`INSERT INTO servers VALUES (
|
||||||
|
'${Server}',
|
||||||
|
'${new Date().toLocaleDateString("en-US")}'
|
||||||
|
)`)
|
||||||
})
|
})
|
||||||
fs.appendFileSync(`${__dirname}/ip.txt`, `${Server}\n`)
|
fs.appendFileSync(`${__dirname}/ip.txt`, `${Server}\n`)
|
||||||
Minecraft.ip = geoIP.lookup(Server)
|
Minecraft.ip = geoIP.lookup(Server)
|
||||||
|
Loading…
Reference in New Issue
Block a user