snowtransfer 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +21 -0
- package/README.md +46 -0
- package/dist/Constants.d.ts +8 -0
- package/dist/Constants.js +8 -0
- package/dist/Endpoints.d.ts +89 -0
- package/dist/Endpoints.js +99 -0
- package/dist/Ratelimiter.d.ts +39 -0
- package/dist/Ratelimiter.js +69 -0
- package/dist/RequestHandler.d.ts +112 -0
- package/dist/RequestHandler.js +238 -0
- package/dist/SnowTransfer.d.ts +51 -0
- package/dist/SnowTransfer.js +56 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +12 -0
- package/dist/methods/AuditLog.d.ts +45 -0
- package/dist/methods/AuditLog.js +35 -0
- package/dist/methods/Bots.d.ts +40 -0
- package/dist/methods/Bots.js +46 -0
- package/dist/methods/Channels.d.ts +749 -0
- package/dist/methods/Channels.js +685 -0
- package/dist/methods/GuildAssets.d.ts +191 -0
- package/dist/methods/GuildAssets.js +172 -0
- package/dist/methods/GuildTemplate.d.ts +57 -0
- package/dist/methods/GuildTemplate.js +68 -0
- package/dist/methods/Guilds.d.ts +733 -0
- package/dist/methods/Guilds.js +598 -0
- package/dist/methods/Interactions.d.ts +221 -0
- package/dist/methods/Interactions.js +262 -0
- package/dist/methods/Invites.d.ts +37 -0
- package/dist/methods/Invites.js +44 -0
- package/dist/methods/StageInstance.d.ts +64 -0
- package/dist/methods/StageInstance.js +73 -0
- package/dist/methods/Users.d.ts +76 -0
- package/dist/methods/Users.js +93 -0
- package/dist/methods/Voices.d.ts +21 -0
- package/dist/methods/Voices.js +29 -0
- package/dist/methods/Webhooks.d.ts +288 -0
- package/dist/methods/Webhooks.js +222 -0
- package/dist/ratelimitBuckets/LocalBucket.d.ts +58 -0
- package/dist/ratelimitBuckets/LocalBucket.js +77 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +48 -0
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/ban-types */
|
|
3
|
+
/* eslint-disable no-async-promise-executor */
|
|
4
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
+
};
|
|
7
|
+
const events_1 = require("events");
|
|
8
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
9
|
+
const centra_1 = __importDefault(require("centra"));
|
|
10
|
+
const Endpoints_1 = __importDefault(require("./Endpoints"));
|
|
11
|
+
const form_data_1 = __importDefault(require("form-data"));
|
|
12
|
+
const { version } = require("../package.json");
|
|
13
|
+
const Constants_1 = __importDefault(require("./Constants"));
|
|
14
|
+
class DiscordAPIError extends Error {
|
|
15
|
+
constructor(path, error, method, status) {
|
|
16
|
+
super();
|
|
17
|
+
const flattened = DiscordAPIError.flattenErrors(error.errors || error).join("\n");
|
|
18
|
+
this.name = "DiscordAPIError";
|
|
19
|
+
this.message = error.message && flattened ? `${error.message}\n${flattened}` : error.message || flattened;
|
|
20
|
+
this.method = method;
|
|
21
|
+
this.path = path;
|
|
22
|
+
this.code = error.code;
|
|
23
|
+
this.httpStatus = status;
|
|
24
|
+
}
|
|
25
|
+
static flattenErrors(obj, key = "") {
|
|
26
|
+
let messages = [];
|
|
27
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
28
|
+
if (k === "message")
|
|
29
|
+
continue;
|
|
30
|
+
const newKey = key ? (isNaN(Number(k)) ? `${key}.${k}` : `${key}[${k}]`) : k;
|
|
31
|
+
if (v._errors) {
|
|
32
|
+
messages.push(`${newKey}: ${v._errors.map(e => e.message).join(" ")}`);
|
|
33
|
+
}
|
|
34
|
+
else if (v.code || v.message) {
|
|
35
|
+
messages.push(`${v.code ? `${v.code}: ` : ""}${v.message}`.trim());
|
|
36
|
+
}
|
|
37
|
+
else if (typeof v === "string") {
|
|
38
|
+
messages.push(v);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
messages = messages.concat(this.flattenErrors(v, newKey));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return messages;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Request Handler class
|
|
49
|
+
*/
|
|
50
|
+
class RequestHandler extends events_1.EventEmitter {
|
|
51
|
+
/**
|
|
52
|
+
* Create a new request handler
|
|
53
|
+
* @param ratelimiter ratelimiter to use for ratelimiting requests
|
|
54
|
+
* @param options options
|
|
55
|
+
*/
|
|
56
|
+
constructor(ratelimiter, options) {
|
|
57
|
+
super();
|
|
58
|
+
this.ratelimiter = ratelimiter;
|
|
59
|
+
this.options = {
|
|
60
|
+
baseHost: Endpoints_1.default.BASE_HOST,
|
|
61
|
+
baseURL: Endpoints_1.default.BASE_URL,
|
|
62
|
+
headers: {
|
|
63
|
+
Authorization: options.token,
|
|
64
|
+
"User-Agent": `DiscordBot (https://github.com/DasWolke/SnowTransfer, ${version})`
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
Object.assign(this.options, options);
|
|
68
|
+
this.apiURL = this.options.baseHost + Endpoints_1.default.BASE_URL;
|
|
69
|
+
this.latency = 500;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Request a route from the discord api
|
|
73
|
+
* @param endpoint endpoint to request
|
|
74
|
+
* @param method http method to use
|
|
75
|
+
* @param dataType type of the data being sent
|
|
76
|
+
* @param data data to send, if any
|
|
77
|
+
* @param amount amount of requests previously executed
|
|
78
|
+
* @returns Result of the request
|
|
79
|
+
*/
|
|
80
|
+
request(endpoint, method, dataType = "json", data = {}, amount = 0) {
|
|
81
|
+
if (typeof data === "number")
|
|
82
|
+
data = String(data);
|
|
83
|
+
const stack = new Error().stack;
|
|
84
|
+
return new Promise(async (res, rej) => {
|
|
85
|
+
this.ratelimiter.queue(async (bkt) => {
|
|
86
|
+
const reqID = crypto_1.default.randomBytes(20).toString("hex");
|
|
87
|
+
const latency = Date.now();
|
|
88
|
+
try {
|
|
89
|
+
this.emit("request", reqID, { endpoint, method, dataType, data });
|
|
90
|
+
let request;
|
|
91
|
+
if (dataType == "json") {
|
|
92
|
+
request = await this._request(endpoint, method, data, (method === "get" || endpoint.includes("/bans") || endpoint.includes("/prune")), amount);
|
|
93
|
+
}
|
|
94
|
+
else if (dataType == "multipart") {
|
|
95
|
+
request = await this._multiPartRequest(endpoint, method, data, amount);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
const e = new Error("Forbidden dataType. Use json or multipart");
|
|
99
|
+
e.stack = stack;
|
|
100
|
+
throw e;
|
|
101
|
+
}
|
|
102
|
+
// 429 and 502 are recoverable and will be re-tried automatically with 3 attempts max.
|
|
103
|
+
if (request.statusCode && !Constants_1.default.OK_STATUS_CODES.includes(request.statusCode) && ![429, 502].includes(request.statusCode)) {
|
|
104
|
+
const e = new DiscordAPIError(endpoint, request.headers["content-type"] === "application/json" ? await request.json() : request.body, method, request.statusCode);
|
|
105
|
+
e.stack = stack;
|
|
106
|
+
throw e;
|
|
107
|
+
}
|
|
108
|
+
if (request.headers["date"]) {
|
|
109
|
+
this.latency = Date.now() - latency;
|
|
110
|
+
const offsetDate = this._getOffsetDateFromHeader(request.headers["date"]);
|
|
111
|
+
const match = endpoint.match(/\/reactions\//);
|
|
112
|
+
this._applyRatelimitHeaders(bkt, request.headers, offsetDate, !!match);
|
|
113
|
+
}
|
|
114
|
+
if (request.statusCode && [429, 502].includes(request.statusCode)) {
|
|
115
|
+
if (request.statusCode === 429)
|
|
116
|
+
this.emit("rateLimit", { timeout: bkt.reset, limit: bkt.limit, method: method, path: endpoint, route: this.ratelimiter.routify(endpoint, method) });
|
|
117
|
+
return this.request(endpoint, method, dataType, data, amount++);
|
|
118
|
+
}
|
|
119
|
+
this.emit("done", reqID, request);
|
|
120
|
+
if (request.body) {
|
|
121
|
+
let b;
|
|
122
|
+
try {
|
|
123
|
+
b = JSON.parse(request.body.toString());
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
res(undefined);
|
|
127
|
+
}
|
|
128
|
+
return res(b);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
return res(undefined);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
if (error && error.stack)
|
|
136
|
+
error.stack = stack;
|
|
137
|
+
this.emit("requestError", reqID, error);
|
|
138
|
+
return rej(error);
|
|
139
|
+
}
|
|
140
|
+
}, endpoint, method);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Calculate the time difference between the local server and discord
|
|
145
|
+
* @param dateHeader Date header value returned by discord
|
|
146
|
+
* @returns Offset in milliseconds
|
|
147
|
+
*/
|
|
148
|
+
_getOffsetDateFromHeader(dateHeader) {
|
|
149
|
+
const discordDate = Date.parse(dateHeader);
|
|
150
|
+
const offset = Date.now() - discordDate;
|
|
151
|
+
return Date.now() + offset;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Apply the received ratelimit headers to the ratelimit bucket
|
|
155
|
+
* @param bkt Ratelimit bucket to apply the headers to
|
|
156
|
+
* @param headers Http headers received from discord
|
|
157
|
+
* @param offsetDate Unix timestamp of the current date + offset to discord time
|
|
158
|
+
* @param reactions Whether to use reaction ratelimits (1/250ms)
|
|
159
|
+
*/
|
|
160
|
+
_applyRatelimitHeaders(bkt, headers, offsetDate, reactions = false) {
|
|
161
|
+
if (headers["x-ratelimit-global"]) {
|
|
162
|
+
bkt.ratelimiter.global = true;
|
|
163
|
+
bkt.ratelimiter.globalResetAt = Date.now() + (parseFloat(headers["retry_after"]) * 1000);
|
|
164
|
+
}
|
|
165
|
+
if (headers["x-ratelimit-reset"]) {
|
|
166
|
+
const reset = (headers["x-ratelimit-reset"] * 1000) - offsetDate;
|
|
167
|
+
if (reactions) {
|
|
168
|
+
bkt.reset = Math.max(reset, 250);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
bkt.reset = reset;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (headers["x-ratelimit-remaining"]) {
|
|
175
|
+
bkt.remaining = parseInt(headers["x-ratelimit-remaining"]);
|
|
176
|
+
if (bkt.remaining === 0)
|
|
177
|
+
bkt.resetAt = Date.now() + bkt.reset;
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
bkt.remaining = 1;
|
|
181
|
+
}
|
|
182
|
+
if (headers["x-ratelimit-limit"]) {
|
|
183
|
+
bkt.limit = parseInt(headers["x-ratelimit-limit"]);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Execute a normal json request
|
|
188
|
+
* @param endpoint Endpoint to use
|
|
189
|
+
* @param data Data to send
|
|
190
|
+
* @param useParams Whether to send the data in the body or use query params
|
|
191
|
+
* @param amount amount of requests previously executed
|
|
192
|
+
* @returns Result of the request
|
|
193
|
+
*/
|
|
194
|
+
async _request(endpoint, method, data, useParams = false, amount = 0) {
|
|
195
|
+
if (amount >= 3)
|
|
196
|
+
throw new Error("Max amount of rety attempts reached");
|
|
197
|
+
const headers = {};
|
|
198
|
+
if (typeof data != "string" && data.reason) {
|
|
199
|
+
headers["X-Audit-Log-Reason"] = encodeURIComponent(data.reason);
|
|
200
|
+
delete data.reason;
|
|
201
|
+
}
|
|
202
|
+
const req = (0, centra_1.default)(this.apiURL, method).path(endpoint).header(this.options.headers);
|
|
203
|
+
if (useParams) {
|
|
204
|
+
return req.query(data).send();
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
if (data && typeof data === "object")
|
|
208
|
+
req.body(data, "json");
|
|
209
|
+
else if (data)
|
|
210
|
+
req.body(data);
|
|
211
|
+
return req.send();
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Execute a multipart/form-data request
|
|
216
|
+
* @param endpoint Endpoint to use
|
|
217
|
+
* @param method Http Method to use
|
|
218
|
+
* @param data data to send
|
|
219
|
+
* @returns Result of the request
|
|
220
|
+
*/
|
|
221
|
+
async _multiPartRequest(endpoint, method, data, amount = 0) {
|
|
222
|
+
if (amount >= 3)
|
|
223
|
+
throw new Error("Max amount of rety attempts reached");
|
|
224
|
+
const form = new form_data_1.default();
|
|
225
|
+
if (data.files && Array.isArray(data.files) && data.files.every(f => !!f.name && !!f.file)) {
|
|
226
|
+
for (const file of data.files) {
|
|
227
|
+
form.append(file.name, file.file, file.name);
|
|
228
|
+
delete file.file;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
form.append("payload_json", JSON.stringify(data));
|
|
232
|
+
// duplicate headers in options as to not risk mutating the state.
|
|
233
|
+
const newHeaders = Object.assign({}, this.options.headers, form.getHeaders());
|
|
234
|
+
return (0, centra_1.default)(this.apiURL, method).path(endpoint).header(newHeaders).body(form.getBuffer()).timeout(15000).send();
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
RequestHandler.DiscordAPIErrror = DiscordAPIError;
|
|
238
|
+
module.exports = RequestHandler;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import Ratelimiter from "./Ratelimiter";
|
|
2
|
+
import RequestHandler from "./RequestHandler";
|
|
3
|
+
import ChannelMethods from "./methods/Channels";
|
|
4
|
+
import UserMethods from "./methods/Users";
|
|
5
|
+
import GuildAssetsMethods from "./methods/GuildAssets";
|
|
6
|
+
import WebhookMethods from "./methods/Webhooks";
|
|
7
|
+
import GuildMethods from "./methods/Guilds";
|
|
8
|
+
import GuildTemplateMethods from "./methods/GuildTemplate";
|
|
9
|
+
import InteractionMethods from "./methods/Interactions";
|
|
10
|
+
import InviteMethods from "./methods/Invites";
|
|
11
|
+
import VoiceMethods from "./methods/Voices";
|
|
12
|
+
import BotMethods from "./methods/Bots";
|
|
13
|
+
import AuditLogMethods from "./methods/AuditLog";
|
|
14
|
+
import StageInstanceMethods from "./methods/StageInstance";
|
|
15
|
+
declare class SnowTransfer {
|
|
16
|
+
options: {
|
|
17
|
+
baseHost: string;
|
|
18
|
+
disableEveryone: boolean;
|
|
19
|
+
sentryOptions: {
|
|
20
|
+
extra: {
|
|
21
|
+
snowtransferVersion: string;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
useRedis: boolean;
|
|
25
|
+
};
|
|
26
|
+
token: string;
|
|
27
|
+
channel: ChannelMethods;
|
|
28
|
+
requestHandler: RequestHandler;
|
|
29
|
+
user: UserMethods;
|
|
30
|
+
guildAssets: GuildAssetsMethods;
|
|
31
|
+
webhook: WebhookMethods;
|
|
32
|
+
guild: GuildMethods;
|
|
33
|
+
guildTemplate: GuildTemplateMethods;
|
|
34
|
+
interaction: InteractionMethods;
|
|
35
|
+
invite: InviteMethods;
|
|
36
|
+
voice: VoiceMethods;
|
|
37
|
+
bot: BotMethods;
|
|
38
|
+
auditLog: AuditLogMethods;
|
|
39
|
+
stageInstance: StageInstanceMethods;
|
|
40
|
+
ratelimiter: Ratelimiter;
|
|
41
|
+
/**
|
|
42
|
+
* Create a new Rest Client
|
|
43
|
+
* @param token Discord Bot token to use
|
|
44
|
+
* @param options options
|
|
45
|
+
*/
|
|
46
|
+
constructor(token: string, options?: {
|
|
47
|
+
baseHost?: string;
|
|
48
|
+
disableEveryone?: boolean;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
export = SnowTransfer;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
const Ratelimiter_1 = __importDefault(require("./Ratelimiter"));
|
|
6
|
+
const RequestHandler_1 = __importDefault(require("./RequestHandler"));
|
|
7
|
+
const Channels_1 = __importDefault(require("./methods/Channels"));
|
|
8
|
+
const Users_1 = __importDefault(require("./methods/Users"));
|
|
9
|
+
const GuildAssets_1 = __importDefault(require("./methods/GuildAssets"));
|
|
10
|
+
const Webhooks_1 = __importDefault(require("./methods/Webhooks"));
|
|
11
|
+
const Guilds_1 = __importDefault(require("./methods/Guilds"));
|
|
12
|
+
const GuildTemplate_1 = __importDefault(require("./methods/GuildTemplate"));
|
|
13
|
+
const Interactions_1 = __importDefault(require("./methods/Interactions"));
|
|
14
|
+
const Invites_1 = __importDefault(require("./methods/Invites"));
|
|
15
|
+
const Voices_1 = __importDefault(require("./methods/Voices"));
|
|
16
|
+
const Bots_1 = __importDefault(require("./methods/Bots"));
|
|
17
|
+
const AuditLog_1 = __importDefault(require("./methods/AuditLog"));
|
|
18
|
+
const StageInstance_1 = __importDefault(require("./methods/StageInstance"));
|
|
19
|
+
const Endpoints_1 = __importDefault(require("./Endpoints"));
|
|
20
|
+
const { version } = require("../package.json");
|
|
21
|
+
class SnowTransfer {
|
|
22
|
+
/**
|
|
23
|
+
* Create a new Rest Client
|
|
24
|
+
* @param token Discord Bot token to use
|
|
25
|
+
* @param options options
|
|
26
|
+
*/
|
|
27
|
+
constructor(token, options) {
|
|
28
|
+
if (!token || token === "") {
|
|
29
|
+
throw new Error("Missing token");
|
|
30
|
+
}
|
|
31
|
+
if (!token.startsWith("Bot")) {
|
|
32
|
+
token = `Bot ${token}`;
|
|
33
|
+
}
|
|
34
|
+
this.options = { baseHost: Endpoints_1.default.BASE_HOST, disableEveryone: false, sentryOptions: { extra: { snowtransferVersion: version } }, useRedis: false };
|
|
35
|
+
this.token = token;
|
|
36
|
+
Object.assign(this.options, options);
|
|
37
|
+
this.ratelimiter = new Ratelimiter_1.default();
|
|
38
|
+
this.requestHandler = new RequestHandler_1.default(this.ratelimiter, {
|
|
39
|
+
token: this.token,
|
|
40
|
+
baseHost: this.options.baseHost || Endpoints_1.default.BASE_HOST
|
|
41
|
+
});
|
|
42
|
+
this.channel = new Channels_1.default(this.requestHandler, this.options.disableEveryone);
|
|
43
|
+
this.user = new Users_1.default(this.requestHandler);
|
|
44
|
+
this.guildAssets = new GuildAssets_1.default(this.requestHandler);
|
|
45
|
+
this.webhook = new Webhooks_1.default(this.requestHandler, this.options.disableEveryone);
|
|
46
|
+
this.guild = new Guilds_1.default(this.requestHandler);
|
|
47
|
+
this.guildTemplate = new GuildTemplate_1.default(this.requestHandler);
|
|
48
|
+
this.interaction = new Interactions_1.default(this.requestHandler, this.webhook);
|
|
49
|
+
this.invite = new Invites_1.default(this.requestHandler);
|
|
50
|
+
this.voice = new Voices_1.default(this.requestHandler);
|
|
51
|
+
this.bot = new Bots_1.default(this.requestHandler);
|
|
52
|
+
this.auditLog = new AuditLog_1.default(this.requestHandler);
|
|
53
|
+
this.stageInstance = new StageInstance_1.default(this.requestHandler);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
module.exports = SnowTransfer;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SnowTransfer = exports.Endpoints = exports.Constants = void 0;
|
|
7
|
+
const Constants_1 = __importDefault(require("./Constants"));
|
|
8
|
+
exports.Constants = Constants_1.default;
|
|
9
|
+
const Endpoints_1 = __importDefault(require("./Endpoints"));
|
|
10
|
+
exports.Endpoints = Endpoints_1.default;
|
|
11
|
+
const SnowTransfer_1 = __importDefault(require("./SnowTransfer"));
|
|
12
|
+
exports.SnowTransfer = SnowTransfer_1.default;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Methods for interacting with Guild Audit Logs
|
|
3
|
+
*/
|
|
4
|
+
declare class AuditLogMethods {
|
|
5
|
+
requestHandler: import("../RequestHandler");
|
|
6
|
+
/**
|
|
7
|
+
* Create a new Audit Log Method Handler
|
|
8
|
+
*
|
|
9
|
+
* Usually SnowTransfer creates a method handler for you, this is here for completion
|
|
10
|
+
*
|
|
11
|
+
* You can access the methods listed via `client.auditLog.method`, where `client` is an initialized SnowTransfer instance
|
|
12
|
+
* @param requestHandler request handler that calls the rest api
|
|
13
|
+
*/
|
|
14
|
+
constructor(requestHandler: import("../RequestHandler"));
|
|
15
|
+
/**
|
|
16
|
+
* Get the audit logs of the specified guild id
|
|
17
|
+
* @param guildId id of a guild
|
|
18
|
+
* @param data optional audit log filter values
|
|
19
|
+
* @returns An object with [audit log data](https://discord.com/developers/docs/resources/audit-log#audit-log-object)
|
|
20
|
+
*
|
|
21
|
+
* | Permissions needed | Condition |
|
|
22
|
+
* |--------------------|-----------|
|
|
23
|
+
* | VIEW_AUDIT_LOG | always |
|
|
24
|
+
*/
|
|
25
|
+
getAuditLog(guildId: string, data?: GetAuditLogOptions): Promise<import("discord-typings").AuditLogObject>;
|
|
26
|
+
}
|
|
27
|
+
interface GetAuditLogOptions {
|
|
28
|
+
/**
|
|
29
|
+
* Filter the audit log with the id of a user
|
|
30
|
+
*/
|
|
31
|
+
user_id?: string;
|
|
32
|
+
/**
|
|
33
|
+
* [Type](https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-audit-log-events) of the audit log event
|
|
34
|
+
*/
|
|
35
|
+
action_type?: import("discord-typings").AuditLogEventType;
|
|
36
|
+
/**
|
|
37
|
+
* Filter the audit log before a certain entry id
|
|
38
|
+
*/
|
|
39
|
+
before?: string;
|
|
40
|
+
/**
|
|
41
|
+
* How many entries are returned (min 1, max 100)
|
|
42
|
+
*/
|
|
43
|
+
limit: number;
|
|
44
|
+
}
|
|
45
|
+
export = AuditLogMethods;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
const Endpoints_1 = __importDefault(require("../Endpoints"));
|
|
6
|
+
/**
|
|
7
|
+
* Methods for interacting with Guild Audit Logs
|
|
8
|
+
*/
|
|
9
|
+
class AuditLogMethods {
|
|
10
|
+
/**
|
|
11
|
+
* Create a new Audit Log Method Handler
|
|
12
|
+
*
|
|
13
|
+
* Usually SnowTransfer creates a method handler for you, this is here for completion
|
|
14
|
+
*
|
|
15
|
+
* You can access the methods listed via `client.auditLog.method`, where `client` is an initialized SnowTransfer instance
|
|
16
|
+
* @param requestHandler request handler that calls the rest api
|
|
17
|
+
*/
|
|
18
|
+
constructor(requestHandler) {
|
|
19
|
+
this.requestHandler = requestHandler;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Get the audit logs of the specified guild id
|
|
23
|
+
* @param guildId id of a guild
|
|
24
|
+
* @param data optional audit log filter values
|
|
25
|
+
* @returns An object with [audit log data](https://discord.com/developers/docs/resources/audit-log#audit-log-object)
|
|
26
|
+
*
|
|
27
|
+
* | Permissions needed | Condition |
|
|
28
|
+
* |--------------------|-----------|
|
|
29
|
+
* | VIEW_AUDIT_LOG | always |
|
|
30
|
+
*/
|
|
31
|
+
async getAuditLog(guildId, data) {
|
|
32
|
+
return this.requestHandler.request(Endpoints_1.default.GUILD_AUDIT_LOGS(guildId), "get", "json", data);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
module.exports = AuditLogMethods;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Methods for interacting with bot specific endpoints
|
|
3
|
+
*/
|
|
4
|
+
declare class BotMethods {
|
|
5
|
+
requestHandler: import("../RequestHandler");
|
|
6
|
+
/**
|
|
7
|
+
* Create a new Bot Method Handler
|
|
8
|
+
*
|
|
9
|
+
* Usually SnowTransfer creates a method handler for you, this is here for completion
|
|
10
|
+
*
|
|
11
|
+
* You can access the methods listed via `client.bot.method`, where `client` is an initialized SnowTransfer instance
|
|
12
|
+
* @param requestHandler request handler that calls the rest api
|
|
13
|
+
*/
|
|
14
|
+
constructor(requestHandler: import("../RequestHandler"));
|
|
15
|
+
/**
|
|
16
|
+
* Get the gateway url to connect to
|
|
17
|
+
* @returns [Gateway data](https://discord.com/developers/docs/topics/gateway#get-gateway-example-response)
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* let client = new SnowTransfer('TOKEN');
|
|
21
|
+
* let result = await client.bot.getGateway();
|
|
22
|
+
* // result should be something like {"url": "wss://gateway.discord.gg"}
|
|
23
|
+
*/
|
|
24
|
+
getGateway(): Promise<GatewayData>;
|
|
25
|
+
/**
|
|
26
|
+
* Get the gateway url to connect to and a recommended amount of shards to use
|
|
27
|
+
* @returns [Gateway data](https://discord.com/developers/docs/topics/gateway#get-gateway-example-response)
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* let client = new SnowTransfer('TOKEN');
|
|
31
|
+
* let result = await client.bot.getGateway();
|
|
32
|
+
* // result should be something like {"url": "wss://gateway.discord.gg", "shards": 1}
|
|
33
|
+
*/
|
|
34
|
+
getGatewayBot(): Promise<GatewayData>;
|
|
35
|
+
}
|
|
36
|
+
interface GatewayData {
|
|
37
|
+
url: string;
|
|
38
|
+
shards?: number;
|
|
39
|
+
}
|
|
40
|
+
export = BotMethods;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
const Endpoints_1 = __importDefault(require("../Endpoints"));
|
|
6
|
+
/**
|
|
7
|
+
* Methods for interacting with bot specific endpoints
|
|
8
|
+
*/
|
|
9
|
+
class BotMethods {
|
|
10
|
+
/**
|
|
11
|
+
* Create a new Bot Method Handler
|
|
12
|
+
*
|
|
13
|
+
* Usually SnowTransfer creates a method handler for you, this is here for completion
|
|
14
|
+
*
|
|
15
|
+
* You can access the methods listed via `client.bot.method`, where `client` is an initialized SnowTransfer instance
|
|
16
|
+
* @param requestHandler request handler that calls the rest api
|
|
17
|
+
*/
|
|
18
|
+
constructor(requestHandler) {
|
|
19
|
+
this.requestHandler = requestHandler;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Get the gateway url to connect to
|
|
23
|
+
* @returns [Gateway data](https://discord.com/developers/docs/topics/gateway#get-gateway-example-response)
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* let client = new SnowTransfer('TOKEN');
|
|
27
|
+
* let result = await client.bot.getGateway();
|
|
28
|
+
* // result should be something like {"url": "wss://gateway.discord.gg"}
|
|
29
|
+
*/
|
|
30
|
+
getGateway() {
|
|
31
|
+
return this.requestHandler.request(Endpoints_1.default.GATEWAY, "get", "json");
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Get the gateway url to connect to and a recommended amount of shards to use
|
|
35
|
+
* @returns [Gateway data](https://discord.com/developers/docs/topics/gateway#get-gateway-example-response)
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* let client = new SnowTransfer('TOKEN');
|
|
39
|
+
* let result = await client.bot.getGateway();
|
|
40
|
+
* // result should be something like {"url": "wss://gateway.discord.gg", "shards": 1}
|
|
41
|
+
*/
|
|
42
|
+
getGatewayBot() {
|
|
43
|
+
return this.requestHandler.request(Endpoints_1.default.GATEWAY_BOT, "get", "json");
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
module.exports = BotMethods;
|