Skip to content

Commit

Permalink
reassign edited message instance to 'this'
Browse files Browse the repository at this point in the history
give devs the 'latest' (reassigned) instance. I think prior to this the reaction cache for rolling could also maybe have been not totally complete (idk how reaction-user fetching influences it exactly)  = now better. ||||| For the record: this is based on test i conducted, since androz had told me the instance would auto update/reassign itself, but that didn't seemed to be the case in my tests. (if smth comes up which changes that conclusion/if theres a problem with the reassigning, lmk)
  • Loading branch information
Nico105 committed Oct 15, 2021
1 parent 929553c commit ad0b1f4
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 40 deletions.
72 changes: 42 additions & 30 deletions src/Giveaway.js
Original file line number Diff line number Diff line change
Expand Up @@ -528,11 +528,13 @@ class Giveaway extends EventEmitter {
if (this.remainingTime <= 0) this.manager.end(this.messageId).catch(() => {});
else {
const embed = this.manager.generateMainEmbed(this);
this.message.edit({
content: this.fillInString(this.messages.giveaway),
embeds: [embed],
allowedMentions: this.allowedMentions
}).catch(() => {});
this.message = await this.message
.edit({
content: this.fillInString(this.messages.giveaway),
embeds: [embed],
allowedMentions: this.allowedMentions
})
.catch(() => {});
}
resolve(this);
});
Expand Down Expand Up @@ -567,11 +569,13 @@ class Giveaway extends EventEmitter {
this.winnerIds = winners.map((w) => w.id);
await this.manager.editGiveaway(this.messageId, this.data);
const embed = this.manager.generateEndEmbed(this, winners);
await this.message.edit({
content: this.fillInString(this.messages.giveawayEnded),
embeds: [embed],
allowedMentions: this.allowedMentions
}).catch(() => {});
this.message = await this.message
.edit({
content: this.fillInString(this.messages.giveawayEnded),
embeds: [embed],
allowedMentions: this.allowedMentions
})
.catch(() => {});

let formattedWinners = winners.map((w) => `<@${w.id}>`).join(', ');
const winMessage = this.fillInString(this.messages.winMessage.content || this.messages.winMessage);
Expand Down Expand Up @@ -639,11 +643,13 @@ class Giveaway extends EventEmitter {
});
}

this.message.edit({
content: this.fillInString(this.messages.giveawayEnded),
embeds: [this.manager.generateNoValidParticipantsEndEmbed(this)],
allowedMentions: this.allowedMentions
}).catch(() => {});
this.message = await this.message
.edit({
content: this.fillInString(this.messages.giveawayEnded),
embeds: [this.manager.generateNoValidParticipantsEndEmbed(this)],
allowedMentions: this.allowedMentions
})
.catch(() => {});
resolve([]);
}
});
Expand Down Expand Up @@ -680,11 +686,13 @@ class Giveaway extends EventEmitter {
this.winnerIds = winners.map((w) => w.id);
await this.manager.editGiveaway(this.messageId, this.data);
const embed = this.manager.generateEndEmbed(this, winners);
await this.message.edit({
content: this.fillInString(this.messages.giveawayEnded),
embeds: [embed],
allowedMentions: this.allowedMentions
}).catch(() => {});
this.message = await this.message
.edit({
content: this.fillInString(this.messages.giveawayEnded),
embeds: [embed],
allowedMentions: this.allowedMentions
})
.catch(() => {});

let formattedWinners = winners.map((w) => `<@${w.id}>`).join(', ');
const congratMessage = this.fillInString(options.messages.congrat.content || options.messages.congrat);
Expand Down Expand Up @@ -789,11 +797,13 @@ class Giveaway extends EventEmitter {

await this.manager.editGiveaway(this.messageId, this.data);
const embed = this.manager.generateMainEmbed(this);
this.message.edit({
content: this.fillInString(this.messages.giveaway),
embeds: [embed],
allowedMentions: this.allowedMentions
}).catch(() => {});
this.message = await this.message
.edit({
content: this.fillInString(this.messages.giveaway),
embeds: [embed],
allowedMentions: this.allowedMentions
})
.catch(() => {});
resolve(this);
});
}
Expand All @@ -819,11 +829,13 @@ class Giveaway extends EventEmitter {

await this.manager.editGiveaway(this.messageId, this.data);
const embed = this.manager.generateMainEmbed(this);
this.message.edit({
content: this.fillInString(this.messages.giveaway),
embeds: [embed],
allowedMentions: this.allowedMentions
}).catch(() => {});
this.message = await this.message
.edit({
content: this.fillInString(this.messages.giveaway),
embeds: [embed],
allowedMentions: this.allowedMentions
})
.catch(() => {});
resolve(this);
});
}
Expand Down
24 changes: 14 additions & 10 deletions src/Manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,11 +521,13 @@ class GiveawaysManager extends EventEmitter {
setTimeout(async () => {
giveaway.message ??= await giveaway.fetchMessage().catch(() => {});
const embed = this.generateMainEmbed(giveaway, true);
giveaway.message?.edit({
content: giveaway.fillInString(giveaway.messages.giveaway),
embeds: [embed],
allowedMentions: giveaway.allowedMentions
}).catch(() => {});
giveaway.message = await giveaway.message
?.edit({
content: giveaway.fillInString(giveaway.messages.giveaway),
embeds: [embed],
allowedMentions: giveaway.allowedMentions
})
.catch(() => {});
}, giveaway.remainingTime - giveaway.lastChance.threshold);
}

Expand All @@ -537,11 +539,13 @@ class GiveawaysManager extends EventEmitter {
const needUpdate = !embedEqual(giveaway.message.embeds[0], updatedEmbed) || giveaway.message.content !== giveaway.fillInString(giveaway.messages.giveaway);

if (needUpdate || this.options.forceUpdateEvery) {
giveaway.message.edit({
content: giveaway.fillInString(giveaway.messages.giveaway),
embeds: [updatedEmbed],
allowedMentions: giveaway.allowedMentions
}).catch(() => {});
giveaway.message = await giveaway.message
.edit({
content: giveaway.fillInString(giveaway.messages.giveaway),
embeds: [updatedEmbed],
allowedMentions: giveaway.allowedMentions
})
.catch(() => {});
}
});
}
Expand Down

0 comments on commit ad0b1f4

Please sign in to comment.