From fd8450dc91298b691df0f9c173e6575568e92c48 Mon Sep 17 00:00:00 2001 From: Corwin Date: Tue, 12 Sep 2023 09:29:54 +0200 Subject: [PATCH] add calculations to counting game --- src/handlers/games/counting.js | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/handlers/games/counting.js b/src/handlers/games/counting.js index 35fbf92..d646c32 100644 --- a/src/handlers/games/counting.js +++ b/src/handlers/games/counting.js @@ -2,6 +2,7 @@ const Discord = require("discord.js"); const countSchema = require("../../database/models/countChannel"); const count = require("../../database/models/count"); +const math = require('mathjs'); module.exports = async (client) => { client @@ -9,11 +10,20 @@ module.exports = async (client) => { if (message.author.bot || message.channel.type === Discord.ChannelType.DM) return; if ( - isNaN(message.content) || message.attachments.size > 0 || message.type == Discord.MessageType.ChannelPinnedMessage ) return; + var content = message.content.toLowerCase(); + if(isNaN(content)) { + try { + const result = math.evaluate(content); + content = result; + } catch (error) { + return; + } + + } const data = await countSchema.findOne({ Guild: message.guild.id, @@ -42,7 +52,7 @@ module.exports = async (client) => { console.log(error); } } else { - if (message.content == countData.Count) { + if (content == countData.Count) { message.react(client.emotes.normal.check); countData.User = message.author.id; countData.Count += 1; @@ -68,7 +78,7 @@ module.exports = async (client) => { } } } else if (data) { - if (message.content == 1) { + if (content == 1) { message.react(client.emotes.normal.check); new count({ @@ -86,7 +96,18 @@ module.exports = async (client) => { client .on("messageDelete", async (message) => { try { - if (isNaN(message.content) || message.author.bot) return; + if (message.author.bot) return; + + var content = message.content.toLowerCase(); + if(isNaN(content)) { + try { + const result = math.evaluate(content); + content = result; + } catch (error) { + return; + } + + } const data = await countSchema.findOne({ Guild: message.guild.id, @@ -96,10 +117,10 @@ module.exports = async (client) => { if (data && countData) { let lastCount = countData.Count - 1; - if (message.content == lastCount) { + if (content == lastCount) { client.simpleEmbed( { - desc: `**${message.author.tag}**: ${message.content}`, + desc: `**${message.author.tag}**: ${content}`, }, message.channel );