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

Add typings for typescript support #56

Merged
merged 8 commits into from
May 27, 2020
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
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ build/Release
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
21 changes: 21 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -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
}
}
144 changes: 144 additions & 0 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
@@ -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<void>
// @ts-ignore-next-line
public async deleteGiveaway(messageID: Snowflake): Promise<void>
public edit(messageID: Snowflake, options: GiveawayEditOptions): Promise<Giveaway>;
public end(messageID: Snowflake): Promise<GuildMember[]>
public reroll(messageID: Snowflake, options?: GiveawayRerollOptions): Promise<GuildMember[]>
public start(channel: TextChannel, options: GiveawayStartOptions): Promise<Giveaway>;

public on<K extends keyof GiveawaysManagerEvents>(event: K, listener: (...args: GiveawaysManagerEvents[K]) => void): this;

public once<K extends keyof GiveawaysManagerEvents>(event: K, listener: (...args: GiveawaysManagerEvents[K]) => void): this;

public emit<K extends keyof GiveawaysManagerEvents>(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<Giveaway>;
public end(): Promise<GuildMember[]>
// @ts-ignore-next-line
public async fetchMessage(): Promise<Message>
public reroll(options: GiveawayRerollOptions): Promise<GuildMember[]>
// @ts-ignore-next-line
public async roll(winnerCount?: number): Promise<GuildMember[]>;
}
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;
}
}