Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Giveaway param in exemptmember #452

Merged
merged 5 commits into from
Apr 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
"homepage": "https://discord-giveaways.js.org",
"dependencies": {
"deepmerge-ts": "^4.0.0",
"deepmerge-ts": "^4.0.3",
"serialize-javascript": "^6.0.0"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions src/Giveaway.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ class Giveaway extends EventEmitter {
async exemptMembers(member) {
if (typeof this.exemptMembersFunction === 'function') {
try {
const result = await this.exemptMembersFunction(member);
const result = await this.exemptMembersFunction(member, this);
return result;
} catch (err) {
console.error(
Expand All @@ -282,7 +282,7 @@ class Giveaway extends EventEmitter {
}
}
if (typeof this.manager.options.default.exemptMembers === 'function') {
return await this.manager.options.default.exemptMembers(member);
return await this.manager.options.default.exemptMembers(member, this);
}
return false;
}
Expand Down
21 changes: 11 additions & 10 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EventEmitter } from 'node:events';
import {
import type { EventEmitter } from 'node:events';
import type {
Client,
Collection,
ColorResolvable,
Expand All @@ -17,16 +17,17 @@ import {
Snowflake,
TextChannel,
ThreadChannel,
User
User,
Awaitable
} from 'discord.js';

export const version: string;
export class GiveawaysManager<ExtraData = any> extends EventEmitter {
constructor(client: Client, options?: GiveawaysManagerOptions, init?: boolean);
constructor(client: Client, options?: GiveawaysManagerOptions<ExtraData>, init?: boolean);

public client: Client;
public giveaways: Giveaway<ExtraData>[];
public options: GiveawaysManagerOptions;
public options: GiveawaysManagerOptions<ExtraData>;
public ready: boolean;

public delete(messageId: Snowflake, doNotDeleteMessage?: boolean): Promise<Giveaway<ExtraData>>;
Expand Down Expand Up @@ -60,7 +61,7 @@ export class GiveawaysManager<ExtraData = any> extends EventEmitter {
): boolean;
}
export interface BonusEntry {
bonus(member?: GuildMember): number | Promise<number>;
bonus(member?: GuildMember): Awaitable<number>;
cumulative?: boolean;
}
export interface LastChanceOptions {
Expand All @@ -77,14 +78,14 @@ export interface PauseOptions {
durationAfterPause?: number | null;
infiniteDurationText?: string;
}
export interface GiveawaysManagerOptions {
export interface GiveawaysManagerOptions<ExtraData> {
storage?: string;
forceUpdateEvery?: number;
endedGiveawaysLifetime?: number;
default?: {
botsCanWin?: boolean;
exemptPermissions?: PermissionResolvable[];
exemptMembers?: (member: GuildMember) => boolean | Promise<boolean>;
exemptMembers?: (member: GuildMember, giveaway: Giveaway<ExtraData>) => Awaitable<boolean>;
embedColor?: ColorResolvable;
embedColorEnd?: ColorResolvable;
reaction?: EmojiIdentifierResolvable;
Expand All @@ -98,7 +99,7 @@ export interface GiveawayStartOptions<ExtraData> {
hostedBy?: User;
botsCanWin?: boolean;
exemptPermissions?: PermissionResolvable[];
exemptMembers?: (member: GuildMember) => boolean | Promise<boolean>;
exemptMembers?: (member: GuildMember, giveaway: Giveaway<ExtraData>) => Awaitable<boolean>;
bonusEntries?: BonusEntry[];
embedColor?: ColorResolvable;
embedColorEnd?: ColorResolvable;
Expand Down Expand Up @@ -208,7 +209,7 @@ export interface GiveawayEditOptions<ExtraData> {
newMessages?: GiveawaysMessages;
newThumbnail?: string;
newBonusEntries?: BonusEntry[];
newExemptMembers?: (member: GuildMember) => boolean | Promise<boolean>;
newExemptMembers?: (member: GuildMember, giveaway: Giveaway<ExtraData>) => Awaitable<boolean>;
newExtraData?: ExtraData;
newLastChance?: LastChanceOptions;
}
Expand Down