Skip to content

Commit

Permalink
add calculations to counting game
Browse files Browse the repository at this point in the history
  • Loading branch information
CorwinDev committed Sep 12, 2023
1 parent 6a44272 commit fd8450d
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions src/handlers/games/counting.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,28 @@ 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
.on("messageCreate", async (message) => {
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,
Expand Down Expand Up @@ -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;
Expand All @@ -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({
Expand All @@ -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,
Expand All @@ -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
);
Expand Down

0 comments on commit fd8450d

Please sign in to comment.