Skip to content

Commit

Permalink
prettier fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Nico105 committed Dec 21, 2021
1 parent 9f1a61e commit 6bbdfe4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.validate": ["javascript"],
"eslint.validate": ["javascript"]
}
22 changes: 14 additions & 8 deletions src/Giveaway.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,16 +455,19 @@ class Giveaway extends EventEmitter {
*/
async roll(winnerCount = this.winnerCount) {
if (!this.message) return [];
// Pick the winner

// Find the reaction
const emoji = Discord.Util.resolvePartialEmoji(this.reaction);
const reaction = this.message.reactions.cache.find((r) =>
[r.emoji.name, r.emoji.id].filter(Boolean).includes(emoji?.name ?? emoji?.id)
);
if (!reaction) return [];
const guild = this.message.guild;
// Fetch guild members
if (new Discord.Intents(this.client.options.intents).has(Discord.Intents.FLAGS.GUILD_MEMBERS))

// Fetch all guild members if the intent is available
if (new Discord.Intents(this.client.options.intents).has(Discord.Intents.FLAGS.GUILD_MEMBERS)) {
await guild.members.fetch();
}

// Fetch all reaction users
let userCollection = await reaction.users.fetch().catch(() => {});
Expand Down Expand Up @@ -543,24 +546,27 @@ class Giveaway extends EventEmitter {
if (!this.message) return reject('Unable to fetch message with Id ' + this.messageId + '.');

// Update data
if (options.newMessages && typeof options.newMessages === 'object')
if (options.newMessages && typeof options.newMessages === 'object') {
this.messages = merge(this.messages, options.newMessages);
}
if (typeof options.newThumbnail === 'string') this.thumbnail = options.newThumbnail;
if (typeof options.newPrize === 'string') this.prize = options.newPrize;
if (options.newExtraData) this.extraData = options.newExtraData;

if (Number.isInteger(options.newWinnerCount) && options.newWinnerCount > 0 && !this.isDrop)
if (Number.isInteger(options.newWinnerCount) && options.newWinnerCount > 0 && !this.isDrop) {
this.winnerCount = options.newWinnerCount;
}
if (Number.isFinite(options.addTime) && !this.isDrop) {
this.endAt = this.endAt + options.addTime;
if (this.endTimeout) clearTimeout(this.endTimeout);
this.ensureEndTimeout();
}
if (Number.isFinite(options.setEndTimestamp) && !this.isDrop) this.endAt = options.setEndTimestamp;
if (Array.isArray(options.newBonusEntries) && !this.isDrop)
if (Array.isArray(options.newBonusEntries) && !this.isDrop) {
this.options.bonusEntries = options.newBonusEntries.filter((elem) => typeof elem === 'object');
if (options.newLastChance && typeof options.newLastChance === 'object' && !this.isDrop)
}
if (options.newLastChance && typeof options.newLastChance === 'object' && !this.isDrop) {
this.options.lastChance = merge(this.options.lastChance || {}, options.newLastChance);
}

await this.manager.editGiveaway(this.messageId, this.data);
if (this.remainingTime <= 0) this.manager.end(this.messageId).catch(() => {});
Expand Down
9 changes: 6 additions & 3 deletions src/Manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ class GiveawaysManager extends EventEmitter {
descriptionString(formattedWinners).length > 4096 ||
strings.prize.length + strings.endedAt.length + descriptionString(formattedWinners).length > 6000;
i++
)
) {
formattedWinners = formattedWinners.slice(0, formattedWinners.lastIndexOf(', <@')) + `, ${i} more`;
}

return new Discord.MessageEmbed()
.setTitle(strings.prize)
Expand Down Expand Up @@ -538,8 +539,9 @@ class GiveawaysManager extends EventEmitter {
if (
Number.isFinite(giveaway.pauseOptions.unPauseAfter) &&
Date.now() < giveaway.pauseOptions.unPauseAfter
)
) {
return this.unpause(giveaway.messageId).catch(() => {});
}
}

// Fourth case: giveaway should be ended right now. this case should only happen after a restart
Expand Down Expand Up @@ -627,8 +629,9 @@ class GiveawaysManager extends EventEmitter {
if (packet.t === 'MESSAGE_REACTION_ADD') {
if (giveaway.ended) return this.emit('endedGiveawayReactionAdded', giveaway, member, reaction);
this.emit('giveawayReactionAdded', giveaway, member, reaction);
if (giveaway.isDrop && reaction.count - 1 >= giveaway.winnerCount)
if (giveaway.isDrop && reaction.count - 1 >= giveaway.winnerCount) {
this.end(giveaway.messageId).catch(() => {});
}
} else this.emit('giveawayReactionRemoved', giveaway, member, reaction);
}

Expand Down

0 comments on commit 6bbdfe4

Please sign in to comment.