From 989401f0655f69fd7e076169108bf44e42f35109 Mon Sep 17 00:00:00 2001 From: ItsFranklinMyDudes <86197341+ItsFranklinMyDudes@users.noreply.github.com> Date: Mon, 30 Sep 2024 17:10:00 +1000 Subject: [PATCH 1/3] added a description to wordlie --- src/Wordle.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Wordle.js b/src/Wordle.js index 79ceb14..800f0cf 100644 --- a/src/Wordle.js +++ b/src/Wordle.js @@ -14,6 +14,7 @@ module.exports = class Wordle extends events { if (!options.embed) options.embed = {}; if (!options.embed.title) options.embed.title = 'Wordle'; + if (!options.embed.discription) options.embed.discription = 'Send a 5 letter Word in Chat'; if (!options.embed.color) options.embed.color = '#5865F2'; if (!options.customWord) options.customWord = null; @@ -24,6 +25,7 @@ module.exports = class Wordle extends events { if (typeof options.embed !== 'object') throw new TypeError('INVALID_EMBED: embed option must be an object.'); if (typeof options.embed.title !== 'string') throw new TypeError('INVALID_EMBED: embed title must be a string.'); + if (typeof options.embed.discription !== 'string') throw new TypeError('INVALID_EMBED: embed discription must be a string.'); if (typeof options.embed.color !== 'string') throw new TypeError('INVALID_EMBED: embed color must be a string.'); if (typeof options.timeoutTime !== 'number') throw new TypeError('INVALID_TIME: Timeout time option must be a number.'); if (typeof options.winMessage !== 'string') throw new TypeError('INVALID_MESSAGE: Win message option must be a string.'); @@ -62,6 +64,7 @@ module.exports = class Wordle extends events { const embed = new EmbedBuilder() .setColor(this.options.embed.color) .setTitle(this.options.embed.title) + .setDescription(this.option.embed.description) .setImage('attachment://wordle.png') .setFooter({ text: this.message.author.tag, iconURL: this.message.author.displayAvatarURL({ dynamic: true }) }); @@ -95,10 +98,11 @@ module.exports = class Wordle extends events { const embed = new EmbedBuilder() .setColor(this.options.embed.color) .setTitle(this.options.embed.title) + .setDescription(this.option.embed.description) .setImage('attachment://wordle.png') .addFields({ name: 'Game Over', value: GameOverMessage.replace('{word}', this.word) }) .setFooter({ text: this.message.author.tag, iconURL: this.message.author.displayAvatarURL() }); return await msg.edit({ embeds: [embed], files: [await this.getBoardImage()] }); } -} \ No newline at end of file +} From bd891daef92889dd925924e4f38ec15aa8279842 Mon Sep 17 00:00:00 2001 From: ItsFranklinMyDudes <86197341+ItsFranklinMyDudes@users.noreply.github.com> Date: Mon, 30 Sep 2024 17:13:10 +1000 Subject: [PATCH 2/3] fix a typo i made --- src/Wordle.js | 119 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 111 insertions(+), 8 deletions(-) diff --git a/src/Wordle.js b/src/Wordle.js index 800f0cf..ebc3b7e 100644 --- a/src/Wordle.js +++ b/src/Wordle.js @@ -14,18 +14,123 @@ module.exports = class Wordle extends events { if (!options.embed) options.embed = {}; if (!options.embed.title) options.embed.title = 'Wordle'; - if (!options.embed.discription) options.embed.discription = 'Send a 5 letter Word in Chat'; if (!options.embed.color) options.embed.color = '#5865F2'; if (!options.customWord) options.customWord = null; - if (!options.timeoutTime) options.timeoutTime = 60000; + if (!options.timeoutTime) options.timeoutTime = 60000;const { EmbedBuilder, AttachmentBuilder } = require('discord.js'); + const words = require('../utils/words.json'); + const events = require('events'); + + + module.exports = class Wordle extends events { + constructor(options = {}) { + + if (!options.isSlashGame) options.isSlashGame = false; + if (!options.message) throw new TypeError('NO_MESSAGE: No message option was provided.'); + if (typeof options.message !== 'object') throw new TypeError('INVALID_MESSAGE: message option must be an object.'); + if (typeof options.isSlashGame !== 'boolean') throw new TypeError('INVALID_COMMAND_TYPE: isSlashGame option must be a boolean.'); + + + if (!options.embed) options.embed = {}; + if (!options.embed.title) options.embed.title = 'Wordle'; + if (!options.embed.discription) options.embed.discription = 'Send a 5 letter Word in Chat'; + if (!options.embed.color) options.embed.color = '#5865F2'; + + if (!options.customWord) options.customWord = null; + if (!options.timeoutTime) options.timeoutTime = 60000; + if (!options.winMessage) options.winMessage = 'You won! The word was **{word}**.'; + if (!options.loseMessage) options.loseMessage = 'You lost! The word was **{word}**.'; + + + if (typeof options.embed !== 'object') throw new TypeError('INVALID_EMBED: embed option must be an object.'); + if (typeof options.embed.title !== 'string') throw new TypeError('INVALID_EMBED: embed title must be a string.'); + if (typeof options.embed.discription !== 'string') throw new TypeError('INVALID_EMBED: embed discription must be a string.'); + if (typeof options.embed.color !== 'string') throw new TypeError('INVALID_EMBED: embed color must be a string.'); + if (typeof options.timeoutTime !== 'number') throw new TypeError('INVALID_TIME: Timeout time option must be a number.'); + if (typeof options.winMessage !== 'string') throw new TypeError('INVALID_MESSAGE: Win message option must be a string.'); + if (typeof options.loseMessage !== 'string') throw new TypeError('INVALID_MESSAGE: Lose message option must be a string.'); + if (options.customWord && typeof options.customWord !== 'string') throw new TypeError('INVALID_WORD: Custom Word must be a string.'); + if (options.customWord && options.customWord.length !== 5) throw new RangeError('INVALID_WORD: Custom Word must be of 5 letters.'); + + super(); + this.options = options; + this.message = options.message; + this.word = options.customWord; + this.guessed = []; + } + + + async sendMessage(content) { + if (this.options.isSlashGame) return await this.message.editReply(content); + else return await this.message.channel.send(content); + } + + async getBoardImage() { + const guess = this.guessed.length ? '&guessed='+this.guessed.join(',') : ''; + return await new AttachmentBuilder('https://api.aniket091.xyz/wordle?word=' + this.word + guess, { name: 'wordle.png' }); + } + + + async startGame() { + if (this.options.isSlashGame || !this.message.author) { + if (!this.message.deferred) await this.message.deferReply().catch(e => {}); + this.message.author = this.message.user; + this.options.isSlashGame = true; + } + if (!this.word) this.word = words['wordle'][Math.floor(Math.random() * words['wordle'].length)]; + + + const embed = new EmbedBuilder() + .setColor(this.options.embed.color) + .setTitle(this.options.embed.title) + .setDescription(this.options.embed.description) + .setImage('attachment://wordle.png') + .setFooter({ text: this.message.author.tag, iconURL: this.message.author.displayAvatarURL({ dynamic: true }) }); + + const msg = await this.sendMessage({ embeds: [embed], files: [await this.getBoardImage()] }); + const filter = (m) => m.author.id === this.message.author.id && m.content.length === 5; + const collector = this.message.channel.createMessageCollector({ idle: this.options.timeoutTime, filter: filter }); + + + collector.on('collect', async (m) => { + const guess = m.content.toLowerCase(); + if (m.deletable) await m.delete().catch(e => {}); + + this.guessed.push(guess); + if (this.word === guess || this.guessed.length > 5) return collector.stop(); + await msg.edit({ embeds: [embed], files: [await this.getBoardImage()] }); + }) + + + collector.on('end', async (_, reason) => { + if (reason === 'user' || reason === 'idle') return this.gameOver(msg); + }) + } + + + async gameOver(msg) { + const WordleGame = { player: this.message.author, word: this.word, guessed: this.guessed }; + const GameOverMessage = this.guessed.includes(this.word) ? this.options.winMessage : this.options.loseMessage; + this.emit('gameOver', { result: (this.guessed.includes(this.word) ? 'win' : 'lose'), ...WordleGame }); + + + const embed = new EmbedBuilder() + .setColor(this.options.embed.color) + .setTitle(this.options.embed.title) + .setDescription(this.options.embed.description) + .setImage('attachment://wordle.png') + .addFields({ name: 'Game Over', value: GameOverMessage.replace('{word}', this.word) }) + .setFooter({ text: this.message.author.tag, iconURL: this.message.author.displayAvatarURL() }); + + return await msg.edit({ embeds: [embed], files: [await this.getBoardImage()] }); + } + } if (!options.winMessage) options.winMessage = 'You won! The word was **{word}**.'; if (!options.loseMessage) options.loseMessage = 'You lost! The word was **{word}**.'; if (typeof options.embed !== 'object') throw new TypeError('INVALID_EMBED: embed option must be an object.'); if (typeof options.embed.title !== 'string') throw new TypeError('INVALID_EMBED: embed title must be a string.'); - if (typeof options.embed.discription !== 'string') throw new TypeError('INVALID_EMBED: embed discription must be a string.'); if (typeof options.embed.color !== 'string') throw new TypeError('INVALID_EMBED: embed color must be a string.'); if (typeof options.timeoutTime !== 'number') throw new TypeError('INVALID_TIME: Timeout time option must be a number.'); if (typeof options.winMessage !== 'string') throw new TypeError('INVALID_MESSAGE: Win message option must be a string.'); @@ -42,13 +147,13 @@ module.exports = class Wordle extends events { async sendMessage(content) { - if (this.options.isSlashGame) return await this.message.editReply(content); - else return await this.message.channel.send(content); + if (this.options.isSlashGame) return await this.message.editReply(content).catch(e => {}); + else return await this.message.channel.send(content).catch(e => {}); } async getBoardImage() { const guess = this.guessed.length ? '&guessed='+this.guessed.join(',') : ''; - return await new AttachmentBuilder('https://api.aniket091.xyz/wordle?word=' + this.word + guess, { name: 'wordle.png' }); + return await new AttachmentBuilder('https://api.gamecord.xyz/wordle?word=' + this.word + guess, { name: 'wordle.png' }); } @@ -64,7 +169,6 @@ module.exports = class Wordle extends events { const embed = new EmbedBuilder() .setColor(this.options.embed.color) .setTitle(this.options.embed.title) - .setDescription(this.option.embed.description) .setImage('attachment://wordle.png') .setFooter({ text: this.message.author.tag, iconURL: this.message.author.displayAvatarURL({ dynamic: true }) }); @@ -98,7 +202,6 @@ module.exports = class Wordle extends events { const embed = new EmbedBuilder() .setColor(this.options.embed.color) .setTitle(this.options.embed.title) - .setDescription(this.option.embed.description) .setImage('attachment://wordle.png') .addFields({ name: 'Game Over', value: GameOverMessage.replace('{word}', this.word) }) .setFooter({ text: this.message.author.tag, iconURL: this.message.author.displayAvatarURL() }); From ec4e6a57757351f59e25e1e6bab63ea9c802d802 Mon Sep 17 00:00:00 2001 From: ItsFranklinMyDudes <86197341+ItsFranklinMyDudes@users.noreply.github.com> Date: Mon, 30 Sep 2024 17:15:52 +1000 Subject: [PATCH 3/3] fixed description wordle --- src/Wordle.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Wordle.js b/src/Wordle.js index ebc3b7e..243b648 100644 --- a/src/Wordle.js +++ b/src/Wordle.js @@ -169,6 +169,7 @@ module.exports = class Wordle extends events { const embed = new EmbedBuilder() .setColor(this.options.embed.color) .setTitle(this.options.embed.title) + .setDescription(this.options.embed.description) .setImage('attachment://wordle.png') .setFooter({ text: this.message.author.tag, iconURL: this.message.author.displayAvatarURL({ dynamic: true }) }); @@ -202,6 +203,7 @@ module.exports = class Wordle extends events { const embed = new EmbedBuilder() .setColor(this.options.embed.color) .setTitle(this.options.embed.title) + .setDescription(this.options.embed.description) .setImage('attachment://wordle.png') .addFields({ name: 'Game Over', value: GameOverMessage.replace('{word}', this.word) }) .setFooter({ text: this.message.author.tag, iconURL: this.message.author.displayAvatarURL() });