Skip to content

Commit

Permalink
Hash system to SVEROK command
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasabbe committed Oct 15, 2024
1 parent f92eac8 commit 6d0ab4b
Show file tree
Hide file tree
Showing 10 changed files with 584 additions and 65 deletions.
545 changes: 526 additions & 19 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"license": "ARR",
"devDependencies": {
"@eslint/js": "^9.10.0",
"@types/bcrypt": "^5.0.2",
"@types/ms": "^0.7.34",
"@types/node": "^20.12.13",
"concurrently": "^8.2.2",
Expand All @@ -27,6 +28,7 @@
"typescript-eslint": "^8.5.0"
},
"dependencies": {
"bcrypt": "^5.1.1",
"discord.js": "^14.15.3",
"dotenv": "^16.4.5",
"gamerbot-module": "^1.0.3",
Expand Down
2 changes: 1 addition & 1 deletion setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import fs from 'fs'

fs.writeFile('.env', 'TOKEN=\nGAMERBOT_API_TOKEN=\nCONFIG_ID=\n', () => {
console.log('File created')
})
})
2 changes: 1 addition & 1 deletion src/bot_events/client/ready.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default class ready implements Event {

// Get config data from the API
const config_data = await GamerBotAPIInstance.models.get_config_data(
Number.parseInt(process.env.CONFIG_ID as string),
parseInt(process.env.CONFIG_ID as string),
)

// Register commands and load user reminders
Expand Down
2 changes: 1 addition & 1 deletion src/bot_events/custom_events/remindTimer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export default class remindTimer implements CustomEvent {
reminder.user_id,
)

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const index = user_profile.reminders.findIndex(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(rem: any) =>
rem.message == reminder.message &&
rem.remindTimestamp == reminder.remindTimestamp,
Expand Down
11 changes: 6 additions & 5 deletions src/bot_events/guild/messageCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { updateLevelRoles } from "../../functions/updateLevelRoles";
export default class messageCreate implements Event{
constructor() {}
run_event (client: Client, message:Message) {
if(message.author.bot) return;
if(!message.inGuild()) return;
this.xpCalculation(message);
}
Expand All @@ -25,23 +26,23 @@ export default class messageCreate implements Event{

//returns until time is calculated
if(profile_data.xpTimeoutUntil > message.createdTimestamp) return;

const time_out = 10 * 60 * 1000; // ten mins

//adds timeout
profile_data.xpTimeoutUntil = message.createdTimestamp + time_out;

//Gives xp, if similar word only give 1 xp.
if(profile_data.old_old_messages.length >= 3)
profile_data.old_old_messages.shift();
if(profile_data.old_messages.length >= 3)
profile_data.old_messages.shift();

if(profile_data.old_old_messages.includes(message.content.toLowerCase())){
if(profile_data.old_messages.includes(message.content.toLowerCase())){
profile_data.xp += 1;
}else{
profile_data.xp += 3;
}

profile_data.old_old_messages.push(message.content.toLowerCase());
profile_data.old_messages.push(message.content.toLowerCase());

const lvl_cap = 31;

Expand Down
74 changes: 45 additions & 29 deletions src/bot_interactions/commands/public_command/sverok.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ import {
TextInputStyle,
} from 'discord.js'
import { Command } from '../../../classes/command'
import { GamerBotAPIInstance } from '../../..'
import { PorfileData } from 'gamerbot-module'
import bcrypt from 'bcrypt'

export default class SverokCommand implements Command {
name = 'sverok'
ephemeral = true
description =
'Koppla ditt sverok konto till discord och få en cool sverok roll'
aliases = []
defer = false
defer = true
data = new SlashCommandBuilder()
.setName(this.name)
.setDescription(this.description)
Expand Down Expand Up @@ -64,18 +64,15 @@ export default class SverokCommand implements Command {
button
.awaitModalSubmit({ filter, time: 1000 * 5 * 60 })
.then(async (modal) => {
const email = modal.fields.getTextInputValue('email')
const email = modal.fields.getTextInputValue('email');
const TOKEN = process.env.SVEROK_API_TOKEN

const guild =
await GamerBotAPIInstance.models.get_guild_data(
interaction.guildId as string,
)

if (guild.sverokMails.includes(email))
return interaction.editReply(
'Denna mailadress är redan kopplad till en användare!',
console.log(profileData.hashed_email)
if (profileData.hashed_email != undefined && await this.compare(email, profileData.hashed_email)) {
interaction.editReply(
{content:'Denna mailadress är redan kopplad till en användare!',components:[]},
)
return modal.deferUpdate();
}

fetch(
'https://ebas.sverok.se/apis/confirm_membership.json',
Expand All @@ -99,37 +96,56 @@ export default class SverokCommand implements Command {
.then(async (res) => res.json())
.then(async (data) => {
if (data.response.member_found) {
guild.sverokMails.push(email)
guild.save()
interaction.guild?.members.cache
.get(interaction.user.id)
?.roles.add(sverok_role_id)
button.reply(
profileData.hashed_email = await this.hashEmail(email) as string;
await profileData.save();
modal.reply(
'Ditt sverok konto är nu kopplat till discord och du har fått en sverok roll!',
)
if (
!profileData.exclusiveFrames.includes(
SVEROK_FRAME_ID,
)
) {
profileData.exclusiveFrames.push(
SVEROK_FRAME_ID,
)
profileData.save()
if(interaction.guildId != "813844220694757447"){
interaction.guild?.members.cache
.get(interaction.user.id)
?.roles.add(sverok_role_id)
if (
!profileData.exclusiveFrames.includes(
SVEROK_FRAME_ID,
)
) {
profileData.exclusiveFrames.push(
SVEROK_FRAME_ID,
)
profileData.save()
}
}
} else {
data.reply(
modal.reply(
'Du är inte medlem i sverok föreningen just nu!\nDu kan bli det med denna länk: https://ebas.sverok.se/blimedlem/SGC',
)
}
})
.catch((err) => {
console.log(err)
interaction.editReply(
'Något gick fel när vi försökte koppla ditt konto, försök igen senare!',
{content:'Något gick fel när vi försökte koppla ditt konto, försök igen senare!',components:[]},
)
})
})
})
}
private hashEmail(email:string) {
const salt = 10;
return new Promise((resolve) => {
bcrypt.hash(email,salt, (err, hashedString) => {
if(err) console.log(err);
else resolve(hashedString);
})
})
}
private async compare(email:string,hashedMail:string){
return new Promise((resolve) => {
bcrypt.compare(email,hashedMail,(err, result) => {
if(err) console.log(err);
else resolve(result);
})
})
}
}
7 changes: 0 additions & 7 deletions src/bot_interactions/commands/staff_commands/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export default class EditMessageCommand implements Command {
data = new SlashCommandBuilder()
.setName(this.name)
.setDescription(this.description)
//.addBooleanOption((option) => option.setName("formated").setDescription("Get formated message").setRequired(true))
.addStringOption((option) =>
option
.setName('message_id')
Expand All @@ -37,14 +36,8 @@ export default class EditMessageCommand implements Command {
.value as string
const channel = interaction.options.get('channel', true)
.channel as BaseGuildTextChannel
//const formated = interaction.options.get("formated", true).value as boolean;

const message = await channel.messages.fetch(message_id)
/*
if(formated){
return interaction.editReply("```"+message.content+"```")
}
*/

const modal = new ModalBuilder()
.setTitle('Edit message')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CommandInteraction, SlashCommandBuilder, User } from "discord.js";
import { CommandInteraction, SlashCommandBuilder } from "discord.js";
import { Command } from "../../../classes/command";

export default class giveshrimpsandwich implements Command{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CommandInteraction, EmbedBuilder, GuildChannel, PermissionFlagsBits, SlashCommandBuilder, TextChannel } from "discord.js";
import { CommandInteraction, EmbedBuilder, PermissionFlagsBits, SlashCommandBuilder, TextChannel } from "discord.js";
import { Command } from "../../../classes/command";

export default class maintenance implements Command {
Expand Down

0 comments on commit 6d0ab4b

Please sign in to comment.