Ingame Verification with Discord Bot#16
Conversation
|
Found a typo. In the verify command i mistyped verify as yerify |
|
|
||
|
|
||
|
|
There was a problem hiding this comment.
There are a few unnecessary newlines here.
| return createHash('sha256').update(string).digest('hex'); | ||
| } | ||
|
|
||
| export function makeid(length) { |
There was a problem hiding this comment.
The type isn't defined, from what I can tell it is meant to be a number.
| @@ -0,0 +1,15 @@ | |||
| const { createHash } = require('crypto'); | |||
|
|
|||
| export function hash(string) { | |||
There was a problem hiding this comment.
No type here either
| 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) |
There was a problem hiding this comment.
This variable isn't being reassigned maybe it could be a const
| switch (type.toLowerCase()){ | ||
| case "minecraft":{ | ||
| let discord = getKeyByValue(usersData,user) | ||
| if (discord == undefined){ |
There was a problem hiding this comment.
This can be compacted to if(!discord) instead of if(discord == undefined) also there's no space in-between the if and {
| 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) { |
There was a problem hiding this comment.
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.
| import { whisperChat } from '../../Utils/IngameChat'; | ||
| export const data = new SlashCommandBuilder() |
There was a problem hiding this comment.
new line in-between pls
| 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}` |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I will probably just change this and...
| 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" }) |
There was a problem hiding this comment.
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
This will resolve #9.
So its the Ingame Verification System.
I will add checking for completed challenges later