diff --git a/.gitignore b/.gitignore index 39a78730..66f223f5 100644 --- a/.gitignore +++ b/.gitignore @@ -36,9 +36,6 @@ build/Release node_modules/ jspm_packages/ -# TypeScript v1 declaration files -typings/ - # Optional npm cache directory .npm diff --git a/package.json b/package.json index 151bc867..016fccfc 100644 --- a/package.json +++ b/package.json @@ -33,13 +33,16 @@ "url": "https://github.com/Androz2091/discord-giveaways/issues" }, "homepage": "https://discord-giveaways.js.org", + "typings": "typings/index.d.ts", "dependencies": { "deepmerge": "^4.2.2" }, "devDependencies": { + "@types/node": "^14.0.5", "discord.js": "^12.2.0", "jsdoc": "^3.6.4", "minami": "github:Androz2091/minami", - "prettier": "^2.0.5" + "prettier": "^2.0.5", + "typescript": "^3.9.3" } } diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000..f88d02b1 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,21 @@ +{ + "compilerOptions": { + "strict": true, + "moduleResolution": "node", + "declaration": false, + "removeComments": false, + "alwaysStrict": true, + "pretty": false, + "module": "commonjs", + "target": "es2019", + "lib": [ + "esnext", + "esnext.array", + "esnext.asynciterable", + "esnext.intl", + "esnext.symbol" + ], + "sourceMap": false, + "skipDefaultLibCheck": true + } + } \ No newline at end of file diff --git a/typings/index.d.ts b/typings/index.d.ts new file mode 100644 index 00000000..c224d026 --- /dev/null +++ b/typings/index.d.ts @@ -0,0 +1,144 @@ +declare module "discord-giveaways" { + import { EventEmitter } from "events"; + import { Client, PermissionResolvable, ColorResolvable, User, Snowflake, GuildMember, TextChannel, MessageReaction, Message } from "discord.js"; + + export const version: string; + export class GiveawaysManager extends EventEmitter { + constructor(client: Client, options?: GiveawaysManagerOptions) + + public client: Client; + public giveaways: Giveaway[]; + public options: GiveawaysManagerOptions; + public ready: boolean; + public v12: boolean; + + public delete(messageID: Snowflake, doNotDeleteMessage?: boolean): Promise + // @ts-ignore-next-line + public async deleteGiveaway(messageID: Snowflake): Promise + public edit(messageID: Snowflake, options: GiveawayEditOptions): Promise; + public end(messageID: Snowflake): Promise + public reroll(messageID: Snowflake, options?: GiveawayRerollOptions): Promise + public start(channel: TextChannel, options: GiveawayStartOptions): Promise; + + public on(event: K, listener: (...args: GiveawaysManagerEvents[K]) => void): this; + + public once(event: K, listener: (...args: GiveawaysManagerEvents[K]) => void): this; + + public emit(event: K, ...args: GiveawaysManagerEvents[K]): boolean; + } + interface GiveawaysManagerOptions { + storage?: string; + updateCountdownEvery?: number ; + DJSlib?: "v12" | "v11"; + default?: GiveawayStartOptions; + botsCanWin?: boolean; + exemptPermissions?: PermissionResolvable[]; + exemptMembers?: (member: GuildMember) => boolean; + embedColor?: ColorResolvable; + embedColorEnd?: ColorResolvable; + reaction?: string; + } + interface GiveawayStartOptions { + time?: number; + winnerCount?: number; + prize?: string; + hostedBy?: User; + botsCanWin?: boolean; + exemptPermissions?: PermissionResolvable[]; + exemptMembers?: () => boolean; + embedColor?: ColorResolvable; + embedColorEnd?: ColorResolvable; + reaction?: string; + messages?: GiveawaysMessages; + } + interface GiveawaysMessages { + giveaway?: string; + giveawayEnded?: string; + inviteToParticipate?: string; + timeRemaining?: string; + winMessage?: string; + embedFooter?: string; + noWinner?: string; + winners?: string; + endedAt?: string; + hostedBy?: string; + units?: { + seconds?: string; + minutes?: string; + hours?: string; + days?: string; + pluralS?: false; + }; + } + interface GiveawaysManagerEvents { + giveawayEnded: [Giveaway, GuildMember[]]; + giveawayReactionAdded: [Giveaway, GuildMember, MessageReaction]; + giveawayReactionRemoved: [Giveaway, GuildMember, MessageReaction]; + } + class Giveaway extends EventEmitter { + constructor(manager: GiveawaysManager, options: GiveawayData) + + public botsCanWin: boolean; + readonly channel: TextChannel; + public channelID: Snowflake; + public client: Client; + readonly content: string; + public data: GiveawayData; + public embedColor: ColorResolvable; + public embedColorEnd: ColorResolvable; + public endAt: number; + public ended: boolean; + public exemptPermissions: PermissionResolvable[]; + readonly giveawayDuration: number; + public guildID: Snowflake; + public hostedBy: string | null; + public manager: GiveawaysManager; + public message: Message | null; + public messageID: Snowflake | null; + public messages: GiveawaysMessages; + public options: GiveawayData; + public prize: string; + readonly remainingTime: number; + public startAt: number; + public winnerCount: number; + + public exemptMembers(): boolean; + public edit(options: GiveawayEditOptions): Promise; + public end(): Promise + // @ts-ignore-next-line + public async fetchMessage(): Promise + public reroll(options: GiveawayRerollOptions): Promise + // @ts-ignore-next-line + public async roll(winnerCount?: number): Promise; + } + interface GiveawayEditOptions { + newWinnerCount?: number; + newPrize?: string; + addTime?: number; + setEndTimestamp?: number; + } + interface GiveawayRerollOptions { + winnerCount?: number | null; + messages?: { + congrat?: string; + error?: string; + }; + } + interface GiveawayData { + startAt: number; + endAt: number; + winnerCount: number; + messages: GiveawaysMessages; + ended: boolean; + prize: string; + channelID: Snowflake; + guildID: Snowflake; + messageID?: Snowflake | null; + reaction?: string; + exemptPermissions?: PermissionResolvable[]; + exemptMembers?: (member: GuildMember) => boolean; + embedColor?: string; + embedColorEnd?: string; + hostedBy?: string | null; + } +}