This commit is contained in:
TaxMachine 2022-07-26 01:05:12 -04:00
parent b67230d13c
commit 5927e767aa
7 changed files with 135 additions and 2 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@ nimscan/bin
.vscode
server_backup
old_tests
nim_bot/token.key

13
nim_bot/nim_bot.nimble Normal file
View File

@ -0,0 +1,13 @@
# Package
version = "0.1.0"
author = "TaxMachine"
description = "A new awesome nimble package"
license = "MIT"
srcDir = "src"
bin = @["nim_bot"]
# Dependencies
requires "nim >= 1.6.6"

2
nim_bot/src/config.nims Normal file
View File

@ -0,0 +1,2 @@
switch("d", "ssl")
switch("d", "release")

BIN
nim_bot/src/nim_bot Executable file

Binary file not shown.

116
nim_bot/src/nim_bot.nim Normal file
View File

@ -0,0 +1,116 @@
import asyncdispatch, json, options, dimscord, strutils, harpoon, os, db_sqlite
from uri import parseUri
discard os.execShellCmd("clear")
let
keyfile = readFile("token.key")
discord = newDiscordClient(keyfile)
prefix = "$"
proc onReady(s: Shard, r: Ready) {.event(discord).} =
echo "Login on " & $r.user
proc messageCreate(s: Shard, m: Message) {.event(discord).} =
if m.author.bot: return
if not m.content.startsWith(prefix): return
let
args = m.content.toLowerAscii().substr(prefix.len).split(" ")
argument = m.content.split(" ")
case args[0]:
of "help":
discard await discord.api.sendMessage(
m.channel_id,
embeds = @[Embed(
title: some "TaxenHeimer Bot",
fields: some @[EmbedField(
name: "**$help**",
value: "`Displays this menu`",
inline: some true
),
EmbedField(
name: "**$namemc**",
value: "`Displays informations about a minecraft account`",
inline: some true
)],
color: some 0x000066
)]
)
of "namemc":
if (argument.len < 2):
discard await discord.api.sendMessage(m.channel_id, "User not found")
else:
let
url = "https://api.ashcon.app/mojang/v2/user/" & argument[1]
data = getJson(parseUri(url))
if (data{"code"}.getInt == 404):
discard await discord.api.sendMessage(m.channel_id, "User not found")
else:
var
uuid = data["uuid"].getStr
renderurl = "https://crafatar.com/avatars/" & uuid
bodyurl = "https://crafatar.com/renders/body/" & uuid
username = data["username"].getStr
date = data{"created_at"}.getStr
usernamehistory = data["username_history"]
hist = ""
if (usernamehistory.len > 0):
for names in usernamehistory:
if (names{"changed_at"}.isNil):
hist.add(names["username"].getStr & " : " & "Original\n")
else:
var
cdate = names{"changed_at"}.getStr.split("T")
pdate = cdate[1].split(".")[0] & " " & cdate[0]
hist.add(names["username"].getStr & " : " & pdate & "\n")
else:
hist.add("No Name History")
discard await discord.api.sendMessage(
m.channel_id,
embeds = @[Embed(
title: some "Namemc Lookup",
fields: some @[EmbedField(
name: "**username**",
value: "```\n" & username & "\n```",
inline: some true
),
EmbedField(
name: "**UUID**",
value: "```\n" & uuid & "\n```",
inline: some true
),
EmbedField(
name: "**Creation Date(Might not be given)**",
value: "```\n" & date & "\n```",
inline: some true
),
EmbedField(
name: "**Name History**",
value: "```fix\n" & hist & "\n```",
inline: some false
)
],
thumbnail: some EmbedThumbnail(
url: some renderurl
),
image: some EmbedImage(
url: some bodyurl
),
color: some 0x000066
)]
)
of "status":
let
db = open("../../server/servers.db", "", "", "")
server = db.getAllRows(sql"SELECT host FROM servers").len.intToStr
discard await discord.api.sendMessage(
m.channel_id,
embeds = @[Embed(
title: some "**Server Database Status**",
fields: some @[EmbedField(
name: "**Total Server Count**",
value: "`" & server & "`",
inline: some false
)],
color: some 0x000066
)]
)
waitFor discord.startSession()

1
nim_bot/src/token.key Normal file
View File

@ -0,0 +1 @@
MTAwMTE4NDM3Njc2OTQ4Mjg2Mw.GLkB_i.w-hAvgUGOVfGq1GI4xFaWuh91PM2SFqRCCZ7As

View File

@ -67,7 +67,7 @@ app.post("/server", async (req, res) => {
'${Minecraft.Server}',
'${Minecraft.version.name}',
'${Minecraft.players.online}/${Minecraft.players.max}',
'${Minecraft.PlayerList}',
'${Minecraft.PlayerList.replace(/\n/g, "\\n")}',
'${Minecraft.roundTripLatency}ms',
'${cleanMOTD}',
'${new Date().toLocaleDateString('en-US')}'