Skip to content
This repository was archived by the owner on Feb 24, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions Commands/general/verify.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { SlashCommandBuilder, EmbedBuilder, ChatInputCommandInteraction, User, Colors } from 'discord.js';
import { DiscordClient } from '../../Utils/DiscordClient';
import fs from 'fs';
import { whisperChat } from '../../Utils/IngameChat';
export const data = new SlashCommandBuilder()
Comment on lines +4 to +5
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new line in-between pls

.setName('verify')
.setDescription('Yerify yourself with the ingame bot')
.addStringOption((o) => o.setName(`code`).setDescription(`Put the code you recieved here.`).setRequired(true))

export function execute(interaction: ChatInputCommandInteraction, client: DiscordClient) {
const code = interaction.options.getString("code") || "null"
let pending = fs.readFileSync(__dirname + "/../../Verification/pendingVerification.json","utf-8");
let done = fs.readFileSync(__dirname + "/../../Verification/doneVerification.json","utf-8");
var pendingData = JSON.parse(pending);
var doneData = JSON.parse(done)
var user = `${interaction.user.username}#${interaction.user.discriminator}`
Comment on lines +12 to +16
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these could be constants except for pendingData but I will talk about a potential solution to that. Additionally instead of making more separate variables you could just do const pending = JSON.parse(fs.readFileSync(__dirname + "/../../Verification/pendingVerification.json", "utf-8")); or if it's too long for your liking you could just make a function in the Utils folder that reads & parses it that way it is shorter.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will probably just change this and...


if (pendingData.hasOwnProperty(code)){
const embed = new EmbedBuilder()
embed.setColor(Colors.Green)
embed.setTitle(`Ok. The account ${user} is now linked to ${pendingData[code]}`)
interaction.reply({
embeds: [embed],
ephemeral: true
})
if (interaction.guild === null){
return
}
// let verifiedRole =interaction.guild.roles.cache.find(r => r.id === client.config.guild.roles.verified)
// if (verifiedRole === undefined){
// console.error("The verfied role doesnt exits or is not defined in the config")
// return
// }
// const usr = interaction.guild?.members.cache.find(m => m.id === interaction.user.username);
// usr?.roles.add(verifiedRole).catch(console.error)

//Ingame Verification Message
const {bot} = client
whisperChat(bot,"Your Verification Process is done. You are now verified as " + user, pendingData[code])

doneData[user] = pendingData[code]
delete pendingData[code]
pendingData = JSON.stringify(pendingData)
doneData = JSON.stringify(doneData)
fs.writeFileSync(__dirname + "/../../Verification/pendingVerification.json",pendingData, { encoding: "utf-8" })
fs.writeFileSync(__dirname + "/../../Verification/doneVerification.json",doneData, { encoding: "utf-8" })
Comment on lines +43 to +46
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if you were to make pendingData and doneData constants a way to make this valid is you could make these seperate variables or just directly pass JSON.stringify(data) as one of the arguments in fs.writeFileSync

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... And this

} else {
const embed = new EmbedBuilder()
embed.setColor(Colors.Red)
embed.setTitle("This code doesnt exist.")
interaction.reply({
embeds: [embed],
ephemeral: true
})
}
}
51 changes: 51 additions & 0 deletions Commands/general/whois.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { SlashCommandBuilder, EmbedBuilder, ChatInputCommandInteraction, User, Colors } from 'discord.js';
import { DiscordClient } from '../../Utils/DiscordClient';
import fs from 'fs';
function getKeyByValue(object, value) {
return Object.keys(object).find(key => object[key] === value);
}
export const data = new SlashCommandBuilder()
.setName('whois')
.setDescription('Lookup a user by their IGN or Discord Name')
.addStringOption((o) => o.setName(`type`).setDescription(`Lookup by minecraft or discord`).setRequired(true).addChoices({name:"Minecraft",value:"minecraft"},{name:"Discord",value:"discord"}))
.addStringOption((o) => o.setName(`user`).setDescription(`If you chose minecraft: IGN; if you chose discord: Username#Discriminator`).setRequired(true))
export function execute(interaction: ChatInputCommandInteraction, client: DiscordClient) {
Comment on lines +1 to +12
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another not so necessary but for readability and good practice, maybe add a new line in-between the imports, the getKeyByValue function, the data export, and the execute function export. Also I think getKeyByValue would be more fit as it's own file in the Utils folder in the future event we may need to use it elsewhere.

const type = interaction.options.getString("type") || "null"
const user = interaction.options.getString("user") || "null"
let users = fs.readFileSync(__dirname + "/../../Verification/doneVerification.json","utf-8");
var usersData = JSON.parse(users)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable isn't being reassigned maybe it could be a const

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No

const embed = new EmbedBuilder()
switch (type.toLowerCase()){
case "minecraft":{
let discord = getKeyByValue(usersData,user)
if (discord == undefined){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be compacted to if(!discord) instead of if(discord == undefined) also there's no space in-between the if and {

embed.setColor(Colors.Red)
embed.setTitle(`The Minecraft Account ${user} has not been verified yet or doesnt exist`)
} else {
embed.setColor(Colors.Green)
embed.setTitle(`The Minecraft Account ${user} is linked to ${discord} on Discord.`)
}
break
}
case "discord":{
if (usersData.hasOwnProperty(user)){
let ingame = usersData[user]
embed.setColor(Colors.Green)
embed.setTitle(`The Account ${user} is linked to ${ingame} Ingame.`)
} else {
embed.setColor(Colors.Red)
embed.setTitle(`The Account ${user} has not been verified yet or doesnt exist`)
}
break
}
default:{
embed.setColor(Colors.Red)
embed.setTitle("Please choose between the minecraft or the discord option when defining the type!")
break
}
Comment on lines +30 to +45
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't a necessary change but to help out with readability for future revisions you can remove the {} in switches and it would still be valid JavaScript

}
interaction.reply({
embeds: [embed],
ephemeral: true
})
}
2 changes: 2 additions & 0 deletions Minecraft/Bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DiscordClient } from '../Utils/DiscordClient';
import { handleChat } from './Chat';
import { PlayerManager } from './PlayerManager';
import { ProfileCache } from './ProfileCache';
import { handleIngameCommands } from './IngameCommands';

export function handleMinecraft(client: DiscordClient) {
if (!client.config['in-game-bot'].enabled) return; // Returns if there is no bot config
Expand Down Expand Up @@ -37,6 +38,7 @@ export function handleMinecraft(client: DiscordClient) {
client.bot.on('connect', () => {
console.log(`Connected to Server...`);
handleChat(client);
handleIngameCommands(client);
}); // Sends log message when the bot connects to the server
}

Expand Down
29 changes: 29 additions & 0 deletions Minecraft/IngameCommands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { DiscordClient } from '../Utils/DiscordClient';
import { makeid } from "../Utils/Hashing"
import { whisperChat } from "../Utils/IngameChat"
import fs from 'fs';
export function handleIngameCommands(client: DiscordClient) {
const { bot } = client;
bot.on("player_chat", data =>{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There doesn't appear to be a space between => and {

var message = String(data.plainMessage);
if (message.includes("?verify")){
var username = JSON.parse(data.networkName).text
var code = makeid(10)
Comment on lines +8 to +11
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These variables won't be reassigned, they can be constants.

whisperChat(bot,"Your verification code is " + code + ". Use the /verify command in the discord to complete the verification.","Techfox")
verification(username,code)
}

})
}


function verification(username:string,hash:string){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no spacing in the function parameters and the {

let datajson = fs.readFileSync(__dirname + "/../Verification/pendingVerification.json","utf-8");
let data = JSON.parse(datajson);
data[hash] = username
data = JSON.stringify(data)
fs.writeFileSync(__dirname + "/../Verification/pendingVerification.json",data, { encoding: "utf-8" })
}



Comment on lines +27 to +29
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few unnecessary newlines here.

2 changes: 1 addition & 1 deletion Utils/Config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type Config = {
},
roles: {
rwx: string,
rw: string
rw: string,
}
},
"in-game-bot": {
Expand Down
15 changes: 15 additions & 0 deletions Utils/Hashing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const { createHash } = require('crypto');

export function hash(string) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No type here either

return createHash('sha256').update(string).digest('hex');
}

export function makeid(length) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type isn't defined, from what I can tell it is meant to be a number.

var result = '';
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var charactersLength = characters.length;
for ( var i = 0; i < length; i++ ) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
30 changes: 30 additions & 0 deletions Utils/IngameChat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { MinecraftClient } from "./MinecraftClient";

export function writeChat(bot: MinecraftClient,message:String){
bot.write('chat_message', {
message: message,
timestamp: BigInt(Date.now()),
salt: 0,
signature: Buffer.alloc(0),
signedPreview: false,
previousMessages: [],
lastMessage: null
});


}
export function whisperChat(bot: MinecraftClient,message:String,user:String){
const command = `tell ${user} ${message}`
bot.write('chat_command', {
command: command,
timestamp: BigInt(Date.now()),
salt: 0,
argumentSignatures: [
{argumentName:"targets",signature:Buffer.alloc(0)},
{argumentName:"message",signature:Buffer.alloc(0)}
],
signedPreview: false,
previousMessages: [],
lastMessage: null
});
}
1 change: 1 addition & 0 deletions Verification/doneVerification.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions Verification/pendingVerification.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}