Skip to content

Commit

Permalink
Add typing for giveawayDeleted event (#340)
Browse files Browse the repository at this point in the history
Co-authored-by: Nico105 <63612668+Nico105@users.noreply.github.com>
  • Loading branch information
reinacchi and Nico105 authored Jul 29, 2021
1 parent e0ee063 commit d0214ae
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
28 changes: 20 additions & 8 deletions src/Manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class GiveawaysManager extends EventEmitter {
end(messageID) {
return new Promise(async (resolve, reject) => {
const giveaway = this.giveaways.find((g) => g.messageID === messageID);
if (!giveaway) return reject('No giveaway found with ID ' + messageID + '.');
if (!giveaway) return reject('No giveaway found with message ID ' + messageID + '.');

giveaway
.end()
Expand Down Expand Up @@ -269,7 +269,7 @@ class GiveawaysManager extends EventEmitter {
return new Promise(async (resolve, reject) => {
options = merge(GiveawayRerollOptions, options);
const giveaway = this.giveaways.find((g) => g.messageID === messageID);
if (!giveaway) return reject('No giveaway found with ID ' + messageID + '.');
if (!giveaway) return reject('No giveaway found with message ID ' + messageID + '.');

giveaway
.reroll(options)
Expand Down Expand Up @@ -330,7 +330,7 @@ class GiveawaysManager extends EventEmitter {
edit(messageID, options = {}) {
return new Promise(async (resolve, reject) => {
const giveaway = this.giveaways.find((g) => g.messageID === messageID);
if (!giveaway) return reject('No giveaway found with ID ' + messageID + '.');
if (!giveaway) return reject('No giveaway found with message ID ' + messageID + '.');
giveaway.edit(options).then(resolve).catch(reject);
});
}
Expand All @@ -339,12 +339,12 @@ class GiveawaysManager extends EventEmitter {
* Deletes a giveaway. It will delete the message and all the giveaway data.
* @param {Discord.Snowflake} messageID The message ID of the giveaway
* @param {boolean} [doNotDeleteMessage=false] Whether the giveaway message shouldn't be deleted
* @returns {Promise<boolean>}
* @returns {Promise<Giveaway>}
*/
delete(messageID, doNotDeleteMessage = false) {
return new Promise(async (resolve, reject) => {
const giveaway = this.giveaways.find((g) => g.messageID === messageID);
if (!giveaway) return reject('No giveaway found with ID ' + messageID + '.');
if (!giveaway) return reject('No giveaway found with message ID ' + messageID + '.');
if (!giveaway.channel && !doNotDeleteMessage) {
return reject('Unable to get the channel of the giveaway with message ID ' + giveaway.messageID + '.');
}
Expand All @@ -356,7 +356,7 @@ class GiveawaysManager extends EventEmitter {
this.giveaways = this.giveaways.filter((g) => g.messageID !== messageID);
await this.deleteGiveaway(messageID);
this.emit('giveawayDeleted', giveaway);
resolve(true);
resolve(giveaway);
});
}

Expand Down Expand Up @@ -568,7 +568,7 @@ class GiveawaysManager extends EventEmitter {
* // This can be used to add features such as a congratulatory message in DM
* manager.on('giveawayEnded', (giveaway, winners) => {
* winners.forEach((member) => {
* member.send('Congratulations, '+member.user.username+', you won: '+giveaway.prize);
* member.send('Congratulations, ' + member.user.username + ', you won: ' + giveaway.prize);
* });
* });
*/
Expand Down Expand Up @@ -629,9 +629,21 @@ class GiveawaysManager extends EventEmitter {
* // This can be used to add features such as a congratulatory message per DM
* manager.on('giveawayRerolled', (giveaway, winners) => {
* winners.forEach((member) => {
* member.send('Congratulations, '+member.user.username+', you won: '+giveaway.prize);
* member.send('Congratulations, ' + member.user.username + ', you won: ' + giveaway.prize);
* });
* });
*/

/**
* Emitted when a giveaway was deleted.
* @event GiveawaysManager#giveawayDeleted
* @param {Giveaway} giveaway The giveaway instance
*
* @example
* // This can be used to add logs
* manager.on('giveawayDeleted', (giveaway) => {
* console.log('Giveaway with message ID ' + giveaway.messageID + ' was deleted.')
* });
*/

module.exports = GiveawaysManager;
3 changes: 2 additions & 1 deletion typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ declare module 'discord-giveaways' {
public options: GiveawaysManagerOptions;
public ready: boolean;

public delete(messageID: Snowflake, doNotDeleteMessage?: boolean): Promise<boolean>;
public delete(messageID: Snowflake, doNotDeleteMessage?: boolean): Promise<Giveaway>;
public deleteGiveaway(messageID: Snowflake): Promise<boolean>;
public edit(messageID: Snowflake, options: GiveawayEditOptions): Promise<Giveaway>;
public end(messageID: Snowflake): Promise<GuildMember[]>;
Expand Down Expand Up @@ -112,6 +112,7 @@ declare module 'discord-giveaways' {
};
}
interface GiveawaysManagerEvents {
giveawayDeleted: [Giveaway];
giveawayEnded: [Giveaway, GuildMember[]];
giveawayRerolled: [Giveaway, GuildMember[]];
giveawayReactionAdded: [Giveaway, GuildMember, MessageReaction];
Expand Down

0 comments on commit d0214ae

Please sign in to comment.