This repository has been archived by the owner on Feb 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.d.ts
168 lines (143 loc) · 3.99 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
declare module 'laffey' {
import { Request, Response, NextFunction } from 'express';
import { EventEmitter } from 'events';
namespace laffey {
/**
* Returns the version of Laffey
*/
export const version: string;
/**
* Express middleware for Laffey
* @param options The options to use
* @example
* ```js
* const { express: laffey } = require('laffey');
* const express = require('express');
*
* const app = express();
* app.use(express.json());
* app.use(laffey({
* callback: (error, bot, voter) => {
* if (error) return console.error(error);
*
* // vote logic is here
* },
* token: 'any random token you wanna set',
* path: '/votes'
* }));
*
* app.listen(3000, () => console.log('localhost:3000'));
* ```
*/
export function express(options: ExpressOptions): ExpressMiddleware;
/**
* Options avaliable
*/
interface LaffeyOptions {
/**
* Discord webhook option
*/
webhook?: { enabled: boolean; url?: string; }
/**
* The authorization token
*
* @note `token` is a customisable thing! It can be anything
* you like it to be set. You must put your token and URL in
* your bot's page.
*/
token: string;
}
export class Server extends EventEmitter {
/**
* Amount of requests we have received from discord.boats
*/
public requests: number;
/**
* The webhook
*/
public webhook: { enabled: boolean; url?: string; }
/**
* How many successful votes Laffey has seen
*/
public votes: number;
/**
* The path
*/
public path: string;
/**
* The port to connect to
*/
public port: number;
/**
* Creates a new [laffey.Server] instance
* @param port The port
* @param path The path
* @param opts The options to use
*/
constructor(port: number, path: string, opts: laffey.LaffeyOptions);
/**
* Listens to the port you specified
* @returns This context to chain methods?
*/
public listen(): this;
/**
* Closes the server down
*/
public close(): void;
/**
* Emitted when the user has started the server
*/
public on(event: 'listen', listener: () => void): this;
/**
* Emitted when Laffey errored during execution
*/
public on(event: 'error', listener: (error: string) => void): this;
/**
* Emitted when the server has closed (called by Server#close)
*/
public on(event: 'close', listener: () => void): this;
/**
* Emitted when Laffey has successfully received a vote
*/
public on(event: 'vote', listener: (bot: laffey.BotPacket, user: laffey.UserPacket) => void): this;
/**
* Emitted when any debug events happen
*/
public on(event: 'debug', listener: (data: any) => void): this;
}
/**
* The packet the webhook payload sends as `bot`
*/
interface BotPacket {
/**
* The bot's name
*/
name: string;
/**
* The URL of the bot (discord.boats URL!)
*/
id: string;
}
interface UserPacket {
/**
* The user's discriminator (i.e: `#0001`)
*/
discriminator: string;
/**
* The user's username
*/
username: string;
/**
* The user's ID
*/
id: string;
}
interface ExpressOptions {
callback(error: Error | null, bot: laffey.BotPacket, voter: laffey.UserPacket): void;
token: string;
path: string;
}
type ExpressMiddleware = (req: Request, res: Response, next: NextFunction) => void;
}
export = laffey;
}