Skip to content

Commit

Permalink
fix: return promises for manager methods
Browse files Browse the repository at this point in the history
Closes #48
  • Loading branch information
Androz2091 committed May 23, 2020
1 parent 06d9c77 commit f10d2bf
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions src/Manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,14 @@ class GiveawaysManager extends EventEmitter {
* manager.end("664900661003157510");
*/
end(messageID) {
let giveawayData = this.giveaways.find(g => g.messageID === messageID);
if (!giveawayData) {
return reject('No giveaway found with ID ' + messageID + '.');
}
let giveaway = new Giveaway(this, giveawayData);
return giveaway.end();
return new Promise(async (resolve, reject) => {
let giveawayData = this.giveaways.find(g => g.messageID === messageID);
if (!giveawayData) {
return reject('No giveaway found with ID ' + messageID + '.');
}
let giveaway = new Giveaway(this, giveawayData);
resolve(await giveaway.end());
});
}

/**
Expand Down Expand Up @@ -172,13 +174,15 @@ class GiveawaysManager extends EventEmitter {
* manager.reroll("664900661003157510");
*/
reroll(messageID, options = {}) {
options = mergeOptions(defaultGiveawayRerollOptions, options);
let giveawayData = this.giveaways.find(g => g.messageID === messageID);
if (!giveawayData) {
return reject('No giveaway found with ID ' + messageID + '.');
}
let giveaway = new Giveaway(this, giveawayData);
return giveaway.reroll(options);
return new Promise(async (resolve, reject) => {
options = mergeOptions(defaultGiveawayRerollOptions, options);
let giveawayData = this.giveaways.find(g => g.messageID === messageID);
if (!giveawayData) {
return reject('No giveaway found with ID ' + messageID + '.');
}
let giveaway = new Giveaway(this, giveawayData);
resolve(await giveaway.reroll(options));
});
}

/**
Expand All @@ -195,12 +199,14 @@ class GiveawaysManager extends EventEmitter {
* });
*/
edit(messageID, options = {}) {
let giveawayData = this.giveaways.find(g => g.messageID === messageID);
if (!giveawayData) {
return reject('No giveaway found with ID ' + messageID + '.');
}
let giveaway = new Giveaway(this, giveawayData);
return giveaway.edit(options);
return new Promise(async (resolve, reject) => {
let giveawayData = this.giveaways.find(g => g.messageID === messageID);
if (!giveawayData) {
return reject('No giveaway found with ID ' + messageID + '.');
}
let giveaway = new Giveaway(this, giveawayData);
resolve(await giveaway.edit(options));
});
}

/**
Expand Down

0 comments on commit f10d2bf

Please sign in to comment.