Skip to content

Commit

Permalink
🐛 save storage through setting undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
Nico105 committed Jun 7, 2021
1 parent 302cfbd commit 375099d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 32 deletions.
12 changes: 6 additions & 6 deletions src/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ exports.defaultManagerOptions = {
* The reroll method options
* @typedef GiveawayRerollOptions
*
* @property {number?} [winnerCount=this.winnerCount] The number of winners to pick
* @property {number} [winnerCount=this.winnerCount] The number of winners to pick
* @property {Object} [messages] The messages used in this method
* @property {string} [messages.congrat=':tada: New winner(s): {winners}! Congratulations, you won **{prize}**!\n{messageURL}'] The message used if there are winners
* @property {string} [messages.error='No valid participations, no new winner(s) can be chosen!'] The message used if no winner can be choosen
Expand Down Expand Up @@ -181,21 +181,21 @@ exports.GiveawayEditOptions = {};
* @property {number} startAt The start date of the giveaway
* @property {number} endAt The end date of the giveaway
* @property {number} winnerCount The number of winners of the giveaway
* @property {Discord.Snowflake[]} winnerIDs winnerIDs The winner IDs of the giveaway after it ended
* @property {GiveawayMessages} messages The giveaway messages
* @property {boolean} ended Whether the giveaway is ended
* @property {string} prize The prize of the giveaway
* @property {Discord.Snowflake} channelID The ID of the channel
* @property {Discord.Snowflake} guildID The ID of the guild
* @property {Discord.Snowflake?} [messageID] The ID of the message
* @property {boolean} [ended] Whether the giveaway is ended
* @property {Discord.Snowflake[]} [winnerIDs] winnerIDs The winner IDs of the giveaway after it ended
* @property {Discord.Snowflake} [messageID] The ID of the message
* @property {Discord.EmojiIdentifierResolvable} [reaction] The reaction of the giveaway
* @property {boolean} [botsCanWin] Whether the bots can win the giveaway
* @property {Discord.PermissionResolvable[]} [exemptPermissions] Members with any of these permissions won't be able to win the giveaway
* @property {string?} [exemptMembers] Filter function to exempt members from winning the giveaway
* @property {string} [exemptMembers] Filter function to exempt members from winning the giveaway
* @property {string} [bonusEntries] The array of BonusEntry objects for the giveaway
* @property {Discord.ColorResolvable} [embedColor] The color of the giveaway embed
* @property {Discord.ColorResolvable} [embedColorEnd] The color of the giveaway ended when it's ended
* @property {string?} [hostedBy] Mention of user who hosts the giveaway
* @property {string} [hostedBy] Mention of user who hosts the giveaway
* @property {any} [extraData] The extra data value for this giveaway
* @property {LastChanceOptions} [lastChance] The last chance system options
*/
Expand Down
14 changes: 7 additions & 7 deletions src/Giveaway.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Giveaway extends EventEmitter {
* Whether the giveaway is ended
* @type {Boolean}
*/
this.ended = options.ended;
this.ended = options.ended || false;
/**
* The channel ID of the giveaway
* @type {Discord.Snowflake}
Expand All @@ -76,7 +76,7 @@ class Giveaway extends EventEmitter {
* The winner IDs for this giveaway after it ended
* @type {Array<string>}
*/
this.winnerIDs = options.winnerIDs;
this.winnerIDs = options.winnerIDs || [];
/**
* The mention of the user who hosts this giveaway
* @type {string?}
Expand Down Expand Up @@ -176,7 +176,7 @@ class Giveaway extends EventEmitter {
* @type {LastChanceOptions}
*/
get lastChance() {
return (this.options.lastChance && typeof this.options.lastChance === 'object') ? merge(this.manager.options.default.lastChance, this.options.lastChance) : this.manager.options.default.lastChance;
return merge(this.manager.options.default.lastChance, this.options.lastChance);
}

/**
Expand Down Expand Up @@ -291,7 +291,7 @@ class Giveaway extends EventEmitter {
guildID: this.guildID,
startAt: this.startAt,
endAt: this.endAt,
ended: this.ended,
ended: this.ended || undefined,
winnerCount: this.winnerCount,
prize: this.prize,
messages: this.messages,
Expand All @@ -300,10 +300,10 @@ class Giveaway extends EventEmitter {
embedColorEnd: this.options.embedColorEnd,
botsCanWin: this.options.botsCanWin,
exemptPermissions: this.options.exemptPermissions,
exemptMembers: (!this.options.exemptMembers || typeof this.options.exemptMembers === 'string') ? this.options.exemptMembers : serialize(this.options.exemptMembers),
bonusEntries: typeof this.options.bonusEntries === 'string' ? this.options.bonusEntries : serialize(this.options.bonusEntries),
exemptMembers: (!this.options.exemptMembers || typeof this.options.exemptMembers === 'string') ? (this.options.exemptMembers || undefined) : serialize(this.options.exemptMembers),
bonusEntries: typeof this.options.bonusEntries === 'string' ? (this.options.bonusEntries || undefined) : serialize(this.options.bonusEntries),
reaction: this.options.reaction,
winnerIDs: this.winnerIDs,
winnerIDs: this.winnerIDs.length ? this.winnerIDs : undefined,
extraData: this.extraData,
lastChance: this.options.lastChance
};
Expand Down
18 changes: 8 additions & 10 deletions src/Manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,22 +203,20 @@ class GiveawaysManager extends EventEmitter {
startAt: Date.now(),
endAt: Date.now() + options.time,
winnerCount: options.winnerCount,
winnerIDs: [],
channelID: channel.id,
guildID: channel.guild.id,
ended: false,
prize: options.prize,
hostedBy: options.hostedBy ? options.hostedBy.toString() : null,
hostedBy: options.hostedBy ? options.hostedBy.toString() : undefined,
messages: options.messages,
reaction: options.reaction,
botsCanWin: options.botsCanWin,
exemptPermissions: Array.isArray(options.exemptPermissions) ? options.exemptPermissions : [],
reaction: options.reaction || undefined,
botsCanWin: typeof options.botsCanWin === 'boolean' ? options.botsCanWin : undefined,
exemptPermissions: Array.isArray(options.exemptPermissions) ? options.exemptPermissions : undefined,
exemptMembers: options.exemptMembers,
bonusEntries: Array.isArray(options.bonusEntries) ? options.bonusEntries.filter((elem) => typeof elem === 'object') : [],
embedColor: options.embedColor,
embedColorEnd: options.embedColorEnd,
bonusEntries: Array.isArray(options.bonusEntries) ? options.bonusEntries.filter((elem) => typeof elem === 'object') : undefined,
embedColor: options.embedColor || undefined,
embedColorEnd: options.embedColorEnd || undefined,
extraData: options.extraData,
lastChance: options.lastChance
lastChance: (options.lastChance && typeof options.lastChance === 'object') ? options.lastChance : undefined
});
const embed = this.generateMainEmbed(giveaway);
const message = await channel.send(giveaway.messages.giveaway, { embed });
Expand Down
18 changes: 9 additions & 9 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ declare module 'discord-giveaways' {
default?: GiveawayStartOptions;
}
interface GiveawayStartOptions {
time?: number;
winnerCount?: number;
prize?: string;
time: number;
winnerCount: number;
prize: string;
hostedBy?: User;
botsCanWin?: boolean;
exemptPermissions?: PermissionResolvable[];
Expand All @@ -70,7 +70,7 @@ declare module 'discord-giveaways' {
embedColor?: ColorResolvable;
embedColorEnd?: ColorResolvable;
reaction?: EmojiIdentifierResolvable;
messages?: Partial<GiveawaysMessages>;
messages?: GiveawaysMessages;
extraData?: any;
lastChance?: LastChanceOptions;
}
Expand Down Expand Up @@ -108,10 +108,10 @@ declare module 'discord-giveaways' {
public endAt: number;
public ended: boolean;
public guildID: Snowflake;
public hostedBy: User | null;
public hostedBy?: User;
public manager: GiveawaysManager;
public message: Message | null;
public messageID: Snowflake | null;
public messageID?: Snowflake;
public messages: GiveawaysMessages;
public options: GiveawayData;
public prize: string;
Expand Down Expand Up @@ -141,7 +141,7 @@ declare module 'discord-giveaways' {
public edit(options: GiveawayEditOptions): Promise<Giveaway>;
public end(): Promise<GuildMember[]>;
public fetchMessage(): Promise<Message>;
public reroll(options: GiveawayRerollOptions): Promise<GuildMember[]>;
public reroll(options?: GiveawayRerollOptions): Promise<GuildMember[]>;
public roll(winnerCount?: number): Promise<GuildMember[]>;
}
interface GiveawayEditOptions {
Expand All @@ -164,12 +164,12 @@ declare module 'discord-giveaways' {
startAt: number;
endAt: number;
winnerCount: number;
winnerIDs: Snowflake[];
messages: GiveawaysMessages;
ended: boolean;
prize: string;
channelID: Snowflake;
guildID: Snowflake;
ended?: boolean;
winnerIDs?: Snowflake[];
messageID?: Snowflake | null;
reaction?: EmojiIdentifierResolvable;
exemptPermissions?: PermissionResolvable[];
Expand Down

0 comments on commit 375099d

Please sign in to comment.