Skip to content

Commit

Permalink
fix - "this" wasn't accessable in bonus function
Browse files Browse the repository at this point in the history
  • Loading branch information
Nico105 committed Dec 20, 2021
1 parent 7668b34 commit 385fbc0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 4 additions & 5 deletions src/Giveaway.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,18 +403,18 @@ class Giveaway extends EventEmitter {

/**
* @param {Discord.User} user The user to check.
* @returns {Promise<number|boolean>} The highest bonus entries the user should get or false.
* @returns {Promise<number>} The highest bonus entries the user should get.
*/
async checkBonusEntries(user) {
const member = await this.message.guild.members.fetch(user.id).catch(() => {});
const entries = [];
const entries = [0];
const cumulativeEntries = [];

if (this.bonusEntries.length) {
for (const obj of this.bonusEntries) {
if (typeof obj.bonus === 'function') {
try {
const result = await obj.bonus(member);
const result = await obj.bonus.apply(this, [member]);
if (Number.isInteger(result) && result > 0) {
if (obj.cumulative) cumulativeEntries.push(result);
else entries.push(result);
Expand All @@ -427,8 +427,7 @@ class Giveaway extends EventEmitter {
}

if (cumulativeEntries.length) entries.push(cumulativeEntries.reduce((a, b) => a + b));
if (entries.length) return Math.max.apply(Math, entries);
return false;
return Math.max(...entries);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,12 @@ declare module 'discord-giveaways' {
private ensureEndTimeout(): void;
private fillInString(string: string): string | null;
private fillInString(embed: MessageEmbed | MessageEmbedOptions): MessageEmbed | null;
private checkWinnerEntry(user: User): Promise<boolean>;
public exemptMembers(member: GuildMember): Promise<boolean>;
public checkBonusEntries(user: User): Promise<number>;
public fetchMessage(): Promise<Message>;
public edit(options: GiveawayEditOptions): Promise<Giveaway>;
public end(noWinnerMessage?: string | MessageObject): Promise<GuildMember[]>;
public fetchMessage(): Promise<Message>;
public reroll(options?: GiveawayRerollOptions): Promise<GuildMember[]>;
public roll(winnerCount?: number): Promise<GuildMember[]>;
public pause(options?: PauseOptions): Promise<Giveaway>;
Expand Down

0 comments on commit 385fbc0

Please sign in to comment.