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

Fixed typings for event handlers on the DBLWebhook class #26

Merged
merged 1 commit into from
Aug 10, 2020
Merged
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
76 changes: 54 additions & 22 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,34 @@ declare class DBLAPI extends EventEmitter {
constructor(token: string, client?: object);

public webhook?: DBLWebhook;
public postStats(serverCount: number, shardId?: number, shardCount?: number): Promise<object>
public getStats(id: string): Promise<DBLAPI.BotStats>
public getBot(id: string): Promise<DBLAPI.Bot>
public getUser(id: string): Promise<DBLAPI.User>
public getBots(query: DBLAPI.BotsQuery): Promise<DBLAPI.BotSearchResult>
public getVotes(): Promise<DBLAPI.Vote[]>
public hasVoted(id: string): Promise<boolean>
public isWeekend(): Promise<boolean>
public postStats(
serverCount: number,
shardId?: number,
shardCount?: number
): Promise<object>;
public getStats(id: string): Promise<DBLAPI.BotStats>;
public getBot(id: string): Promise<DBLAPI.Bot>;
public getUser(id: string): Promise<DBLAPI.User>;
public getBots(query: DBLAPI.BotsQuery): Promise<DBLAPI.BotSearchResult>;
public getVotes(): Promise<DBLAPI.Vote[]>;
public hasVoted(id: string): Promise<boolean>;
public isWeekend(): Promise<boolean>;

public token?: string;

private _request(method: string, endpoint: string, data?: object): Promise<object>
private _request(
method: string,
endpoint: string,
data?: object
): Promise<object>;

public on(event: 'posted', listener: () => void): this;
public on(event: 'error', listener: (error: Error) => void): this;
}

import { Server, ServerResponse, IncomingMessage } from 'http';
declare class DBLWebhook extends EventEmitter {
constructor(port?: number, path?: string, auth?: string, server?: Server)
constructor(port?: number, path?: string, auth?: string, server?: Server);

public port: number;
public path: string;
Expand All @@ -36,10 +44,20 @@ declare class DBLWebhook extends EventEmitter {
private _startWebhook(): void;
private _attachWebhook(server: Server): void;
private _handleRequest(req: IncomingMessage, res: ServerResponse): void;
private _returnResponse(res: ServerResponse, statusCode: number, data?: string): void;

public on(event: 'ready', listener: (hostname: string, port: number, path: string) => void): this;
public on(event: 'vote', listener: (bot: string, user: string, type: string, isWeekend: boolean, query?: object) => void): this;
private _returnResponse(
res: ServerResponse,
statusCode: number,
data?: string
): void;

public on(
event: 'ready',
listener: (hook: DBLAPI.ReadyEventArgs) => void
): this;
public on(
event: 'vote',
listener: (vote: DBLAPI.VoteEventArgs) => void
): this;
}

declare namespace DBLAPI {
Expand All @@ -49,13 +67,13 @@ declare namespace DBLAPI {
webhookAuth?: string;
webhookPath?: string;
webhookServer?: Server;
}
};

export type BotStats = {
server_count: number;
shards: number[];
shard_count: number;
}
};

export type Bot = {
id: number;
Expand All @@ -77,7 +95,7 @@ declare namespace DBLAPI {
certifiedBot: boolean;
vanity?: string;
points: number;
}
};

export type User = {
id: number;
Expand All @@ -94,36 +112,50 @@ declare namespace DBLAPI {
mod: boolean;
webMod: boolean;
admin: boolean;
}
};

export type UserSocial = {
youtube?: string;
reddit?: string;
twitter?: string;
instagram?: string;
github?: string;
}
};

export type BotsQuery = {
limit?: number;
offset?: number;
search: string;
sort: string;
fields?: string;
}
};

export type BotSearchResult = {
results: Bot[];
limit: number;
offset: number;
count: number;
total: number;
}
};

export type Vote = {
username: string;
discriminator: string;
id: string;
avatar: string;
}
};

export type VoteEventArgs = {
bot: string;
user: string;
type: string;
isWeekend: boolean;
query?: object;
};

export type ReadyEventArgs = {
hostname: string;
port: number;
path: string;
};
}