added offline support

This commit is contained in:
TaxMachine 2022-07-26 16:14:53 -04:00
parent ece4aab11b
commit 58d5351d68
3 changed files with 30 additions and 6 deletions

1
.gitignore vendored
View File

@ -8,3 +8,4 @@ old_tests
nim_bot/src/token.key
nim_bot/src/tmp
nim_bot/src/bin
server/offline.db

View File

@ -104,13 +104,27 @@ proc messageCreate(s: Shard, m: Message) {.event(discord).} =
of "status":
let
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(
m.channel_id,
embeds = @[Embed(
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":

View File

@ -7,7 +7,8 @@ const express = require("express"),
fs = require("fs"),
config = require("./config.json"),
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 countrify = e => require("./countrycode.json")[e]
@ -48,7 +49,10 @@ db.exec(`CREATE TABLE IF NOT EXISTS servers (
motd 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) => {
var Server = req.body.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
var Minecraft = await mc.status(Server, 25565, {
enableSRV: true
}).catch(e => {
offline.exec(`INSERT INTO servers VALUES (
'${Server}',
'${new Date().toLocaleDateString("en-US")}'
)`)
})
fs.appendFileSync(`${__dirname}/ip.txt`, `${Server}\n`)
Minecraft.ip = geoIP.lookup(Server)