discord-slim
Advanced tools
Comparing version 2.1.0 to 2.1.1
@@ -52,3 +52,3 @@ "use strict"; | ||
this._onMessage = (data) => { | ||
const intent = util_1.SafeJsonParse(data.toString()); | ||
const intent = util_1.SafeJsonParse(String(data)); | ||
if (!intent) | ||
@@ -55,0 +55,0 @@ return; |
@@ -210,3 +210,6 @@ export declare const HOST: "https://discord.com", API: "https://discord.com/api", API_VERSION = 9, API_PATH: "https://discord.com/api/v9", CDN = "https://cdn.discordapp.com"; | ||
VIP_REGIONS = "VIP_REGIONS", | ||
WELCOME_SCREEN_ENABLED = "WELCOME_SCREEN_ENABLED" | ||
WELCOME_SCREEN_ENABLED = "WELCOME_SCREEN_ENABLED", | ||
TICKETED_EVENTS_ENABLED = "TICKETED_EVENTS_ENABLED", | ||
MONETIZATION_ENABLED = "MONETIZATION_ENABLED", | ||
MORE_STICKERS = "MORE_STICKERS" | ||
} | ||
@@ -213,0 +216,0 @@ export declare enum IntegrationExpireBehaviors { |
@@ -230,2 +230,5 @@ "use strict"; | ||
GuildFeatures["WELCOME_SCREEN_ENABLED"] = "WELCOME_SCREEN_ENABLED"; | ||
GuildFeatures["TICKETED_EVENTS_ENABLED"] = "TICKETED_EVENTS_ENABLED"; | ||
GuildFeatures["MONETIZATION_ENABLED"] = "MONETIZATION_ENABLED"; | ||
GuildFeatures["MORE_STICKERS"] = "MORE_STICKERS"; | ||
})(GuildFeatures = exports.GuildFeatures || (exports.GuildFeatures = {})); | ||
@@ -232,0 +235,0 @@ var IntegrationExpireBehaviors; |
@@ -47,4 +47,4 @@ "use strict"; | ||
} | ||
if (options?.authorization) | ||
headers["Authorization"] = options.authorization.toString(); | ||
if (options?.authorization instanceof Authorization) | ||
headers["Authorization"] = String(options.authorization); | ||
const requestOptions = { | ||
@@ -55,7 +55,7 @@ method, | ||
}; | ||
const URL = helpers_1.API_PATH + endpoint, retryCount = options?.rateLimit?.retryCount ?? DEFAULT_RETRY_COUNT, rateLimitCallback = options?.rateLimit?.callback; | ||
return new Promise((resolve, reject) => { | ||
const URL = helpers_1.API_PATH + endpoint, retryCount = options?.rateLimit?.retryCount ?? DEFAULT_RETRY_COUNT; | ||
let attempts = 0; | ||
const TryRequest = async () => { | ||
const result = await HttpsRequest(URL, requestOptions, content), code = result.code; | ||
const TryRequest = () => HttpsRequest(URL, requestOptions, content).then((result) => { | ||
const code = result.code; | ||
if ((code >= 200) && (code < 300)) | ||
@@ -68,3 +68,3 @@ return resolve(util_1.SafeJsonParse(result.data)); | ||
attempts++; | ||
options?.rateLimit?.callback?.(response, attempts); | ||
rateLimitCallback?.(response, attempts); | ||
return (response.retry_after && (attempts < retryCount)) ? | ||
@@ -75,3 +75,3 @@ setTimeout(TryRequest, Math.ceil(Number(response.retry_after) * 1000)) : | ||
reject({ code }); | ||
}; | ||
}).catch(reject); | ||
TryRequest(); | ||
@@ -81,28 +81,27 @@ }); | ||
exports.Request = Request; | ||
const HttpsRequest = (url, options, data) => { | ||
return new Promise((resolve, reject) => { | ||
const request = https_1.default.request(url, options, (response) => { | ||
if (!response.statusCode) | ||
return reject('Unknown response.'); | ||
const ReturnResult = (result) => resolve({ code: response.statusCode, data: result }); | ||
const chunks = []; | ||
let totalLength = 0; | ||
response.on('data', (chunk) => { | ||
chunks.push(chunk); | ||
totalLength += chunk.length; | ||
}); | ||
response.on('end', () => { | ||
if (!response.complete) | ||
return reject('Response error.'); | ||
if (totalLength == 0) | ||
return ReturnResult(); | ||
if (chunks.length == 1) | ||
return ReturnResult(chunks[0].toString()); | ||
return ReturnResult(Buffer.concat(chunks, totalLength).toString()); | ||
}); | ||
const HttpsRequest = (url, options, content) => new Promise((resolve, reject) => { | ||
const request = https_1.default.request(url, options, (response) => { | ||
const code = response.statusCode; | ||
if (!code) | ||
return reject('Unknown response.'); | ||
const ReturnResult = (data) => resolve({ code, data }); | ||
const chunks = []; | ||
let totalLength = 0; | ||
response.on('data', (chunk) => { | ||
chunks.push(chunk); | ||
totalLength += chunk.length; | ||
}); | ||
request.on('error', reject); | ||
request.on('timeout', () => reject('Request timeout.')); | ||
request.end(data); | ||
response.on('end', () => { | ||
if (!response.complete) | ||
return reject('Response error.'); | ||
if (totalLength == 0) | ||
return ReturnResult(); | ||
if (chunks.length == 1) | ||
return ReturnResult(String(chunks[0])); | ||
return ReturnResult(String(Buffer.concat(chunks, totalLength))); | ||
}); | ||
}); | ||
}; | ||
request.on('error', reject); | ||
request.on('timeout', () => reject('Request timeout.')); | ||
request.end(content); | ||
}); |
import { Permissions as Flags } from './helpers'; | ||
import { Guild, User, Application, Team, Emoji, Message } from './types'; | ||
import type { Guild, User, Application, Team, Emoji, Message, Channel, Role } from './types'; | ||
declare type Permission = typeof Flags[keyof typeof Flags]; | ||
@@ -14,5 +14,11 @@ declare type PermissionSet = string | number | bigint; | ||
export declare const Mentions: { | ||
User: (user_id: string) => string; | ||
Channel: (channel_id: string) => string; | ||
Role: (role_id: string) => string; | ||
User: (user: User | { | ||
id: string; | ||
} | string) => string; | ||
Channel: (channel: Channel | { | ||
id: string; | ||
} | string) => string; | ||
Role: (role: Role | { | ||
id: string; | ||
} | string) => string; | ||
}; | ||
@@ -24,16 +30,48 @@ export declare const Format: { | ||
export declare const Link: { | ||
Message: (message: Message) => string; | ||
Message: (message: Message | { | ||
id: string; | ||
channel_id: string; | ||
guild_id?: string; | ||
}) => string; | ||
}; | ||
export declare const CdnImages: { | ||
CustomEmoji: (emoji_id: string, size?: number | undefined, ext?: "png" | "jpg" | "webp" | "gif" | undefined) => string; | ||
GuildIcon: (guild: Guild, size?: number | undefined, ext?: "png" | "jpg" | "webp" | "gif" | undefined) => string | null; | ||
GuildSplash: (guild: Guild, size?: number | undefined, ext?: "png" | "jpg" | "webp" | undefined) => string | null; | ||
GuildDiscoverySplash: (guild: Guild, size?: number | undefined, ext?: "png" | "jpg" | "webp" | undefined) => string | null; | ||
GuildBanner: (guild: Guild, size?: number | undefined, ext?: "png" | "jpg" | "webp" | undefined) => string | null; | ||
UserAvatar: (user: User, size?: number | undefined, ext?: "png" | "jpg" | "webp" | "gif" | undefined) => string; | ||
ApplicationIcon: (application: Application, size?: number | undefined, ext?: "png" | "jpg" | "webp" | undefined) => string | null; | ||
ApplicationAsset: (application: Application, asset_id: string, size?: number | undefined, ext?: "png" | "jpg" | "webp" | undefined) => string; | ||
AchievementIcon: (application: Application, achievement_id: string, icon_hash: string, size?: number | undefined, ext?: "png" | "jpg" | "webp" | undefined) => string; | ||
TeamIcon: (team: Team, size?: number | undefined, ext?: "png" | "jpg" | "webp" | undefined) => string | null; | ||
CustomEmoji: (emoji: Emoji | { | ||
id: string; | ||
} | string, size?: number | undefined, ext?: "png" | "jpg" | "webp" | "gif" | undefined) => string; | ||
GuildIcon: (guild: Guild | { | ||
id: string; | ||
icon: string; | ||
}, size?: number | undefined, ext?: "png" | "jpg" | "webp" | "gif" | undefined) => string | null; | ||
GuildSplash: (guild: Guild | { | ||
id: string; | ||
splash: string; | ||
}, size?: number | undefined, ext?: "png" | "jpg" | "webp" | undefined) => string | null; | ||
GuildDiscoverySplash: (guild: Guild | { | ||
id: string; | ||
discovery_splash: string; | ||
}, size?: number | undefined, ext?: "png" | "jpg" | "webp" | undefined) => string | null; | ||
GuildBanner: (guild: Guild | { | ||
id: string; | ||
banner: string; | ||
}, size?: number | undefined, ext?: "png" | "jpg" | "webp" | undefined) => string | null; | ||
UserAvatar: (user: User | { | ||
id: string; | ||
discriminator: string | number; | ||
avatar?: string; | ||
}, size?: number | undefined, ext?: "png" | "jpg" | "webp" | "gif" | undefined) => string; | ||
ApplicationIcon: (application: Application | { | ||
id: string; | ||
icon: string; | ||
}, size?: number | undefined, ext?: "png" | "jpg" | "webp" | undefined) => string | null; | ||
ApplicationAsset: (application: Application | { | ||
id: string; | ||
} | string, asset_id: string, size?: number | undefined, ext?: "png" | "jpg" | "webp" | undefined) => string; | ||
AchievementIcon: (application: Application | { | ||
id: string; | ||
} | string, achievement_id: string, icon_hash: string, size?: number | undefined, ext?: "png" | "jpg" | "webp" | undefined) => string; | ||
TeamIcon: (team: Team | { | ||
id: string; | ||
icon: string; | ||
}, size?: number | undefined, ext?: "png" | "jpg" | "webp" | undefined) => string | null; | ||
}; | ||
export {}; |
@@ -11,13 +11,14 @@ "use strict"; | ||
result |= BigInt(p); | ||
return result.toString(); | ||
return String(result); | ||
}, | ||
check: (source, permission) => (BigInt(source) & BigInt(permission)) == BigInt(permission), | ||
has: (source, permission) => exports.Permissions.check(source, helpers_1.Permissions.ADMINISTRATOR) || exports.Permissions.check(source, permission), | ||
add: (source, permission) => (BigInt(source) | BigInt(permission)).toString(), | ||
remove: (source, permission) => (BigInt(source) & ~BigInt(permission)).toString(), | ||
add: (source, permission) => String(BigInt(source) | BigInt(permission)), | ||
remove: (source, permission) => String(BigInt(source) & ~BigInt(permission)), | ||
}; | ||
const EID = (value) => (typeof value == 'object') ? value.id : value; | ||
exports.Mentions = { | ||
User: (user_id) => `<@${user_id}>`, | ||
Channel: (channel_id) => `<#${channel_id}>`, | ||
Role: (role_id) => `<@&${role_id}>`, | ||
User: (user) => `<@${EID(user)}>`, | ||
Channel: (channel) => `<#${EID(channel)}>`, | ||
Role: (role) => `<@&${EID(role)}>`, | ||
}; | ||
@@ -33,26 +34,14 @@ exports.Format = { | ||
exports.CdnImages = { | ||
CustomEmoji: (emoji_id, size, ext) => `${helpers_1.CDN}/emojis/${emoji_id}${SizeExtOpt(size, ext)}`, | ||
GuildIcon: (guild, size, ext) => guild.icon ? | ||
`${helpers_1.CDN}/icons/${guild.id}/${guild.icon}${SizeExtOpt(size, ext)}` : | ||
null, | ||
GuildSplash: (guild, size, ext) => guild.splash ? | ||
`${helpers_1.CDN}/splashes/${guild.id}/${guild.splash}${SizeExtOpt(size, ext)}` : | ||
null, | ||
GuildDiscoverySplash: (guild, size, ext) => guild.discovery_splash ? | ||
`${helpers_1.CDN}/discovery-splashes/${guild.id}/${guild.discovery_splash}${SizeExtOpt(size, ext)}` : | ||
null, | ||
GuildBanner: (guild, size, ext) => guild.banner ? | ||
`${helpers_1.CDN}/banners/${guild.id}/${guild.banner}${SizeExtOpt(size, ext)}` : | ||
null, | ||
CustomEmoji: (emoji, size, ext) => `${helpers_1.CDN}/emojis/${EID(emoji)}${SizeExtOpt(size, ext)}`, | ||
GuildIcon: (guild, size, ext) => guild.icon ? `${helpers_1.CDN}/icons/${guild.id}/${guild.icon}${SizeExtOpt(size, ext)}` : null, | ||
GuildSplash: (guild, size, ext) => guild.splash ? `${helpers_1.CDN}/splashes/${guild.id}/${guild.splash}${SizeExtOpt(size, ext)}` : null, | ||
GuildDiscoverySplash: (guild, size, ext) => guild.discovery_splash ? `${helpers_1.CDN}/discovery-splashes/${guild.id}/${guild.discovery_splash}${SizeExtOpt(size, ext)}` : null, | ||
GuildBanner: (guild, size, ext) => guild.banner ? `${helpers_1.CDN}/banners/${guild.id}/${guild.banner}${SizeExtOpt(size, ext)}` : null, | ||
UserAvatar: (user, size, ext) => user.avatar ? | ||
`${helpers_1.CDN}/avatars/${user.id}/${user.avatar}${SizeExtOpt(size, ext)}` : | ||
`${helpers_1.CDN}/embed/avatars/${Number(user.discriminator) % 5}.png`, | ||
ApplicationIcon: (application, size, ext) => application.icon ? | ||
`${helpers_1.CDN}/app-icons/${application.id}/${application.icon}${SizeExtOpt(size, ext)}` : | ||
null, | ||
ApplicationAsset: (application, asset_id, size, ext) => `${helpers_1.CDN}/app-assets/${application.id}/${asset_id}${SizeExtOpt(size, ext)}`, | ||
AchievementIcon: (application, achievement_id, icon_hash, size, ext) => `${helpers_1.CDN}/app-assets/${application.id}/achievements/${achievement_id}/icons/${icon_hash}${SizeExtOpt(size, ext)}`, | ||
TeamIcon: (team, size, ext) => team.icon ? | ||
`${helpers_1.CDN}/team-icons/${team.id}/${team.icon}${SizeExtOpt(size, ext)}` : | ||
null, | ||
ApplicationIcon: (application, size, ext) => application.icon ? `${helpers_1.CDN}/app-icons/${application.id}/${application.icon}${SizeExtOpt(size, ext)}` : null, | ||
ApplicationAsset: (application, asset_id, size, ext) => `${helpers_1.CDN}/app-assets/${EID(application)}/${asset_id}${SizeExtOpt(size, ext)}`, | ||
AchievementIcon: (application, achievement_id, icon_hash, size, ext) => `${helpers_1.CDN}/app-assets/${EID(application)}/achievements/${achievement_id}/icons/${icon_hash}${SizeExtOpt(size, ext)}`, | ||
TeamIcon: (team, size, ext) => team.icon ? `${helpers_1.CDN}/team-icons/${team.id}/${team.icon}${SizeExtOpt(size, ext)}` : null, | ||
}; |
@@ -308,3 +308,2 @@ import type * as helpers from './helpers'; | ||
permissions?: string; | ||
region: string; | ||
afk_channel_id: string | null; | ||
@@ -689,3 +688,3 @@ afk_timeout: number; | ||
privacy_policy_url?: string; | ||
owner: User; | ||
owner?: User; | ||
summary: string; | ||
@@ -692,0 +691,0 @@ verify_key: string; |
@@ -41,3 +41,3 @@ "use strict"; | ||
this._onMessage = (data) => { | ||
const intent = util_1.SafeJsonParse(data.toString()); | ||
const intent = util_1.SafeJsonParse(String(data)); | ||
if (!intent) | ||
@@ -44,0 +44,0 @@ return; |
{ | ||
"name": "discord-slim", | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"description": "Lightweight Discord API library for Node.js.", | ||
@@ -15,3 +15,5 @@ "author": "Hanabishi", | ||
"client", | ||
"library" | ||
"library", | ||
"framework", | ||
"backend" | ||
], | ||
@@ -18,0 +20,0 @@ "main": "./dist/index.js", |
@@ -97,3 +97,3 @@ # Discord Slim | ||
client.events.on(Events.READY, () => { | ||
client.UpdateStatus({ | ||
client.UpdatePresence({ | ||
status: Helpers.StatusTypes.ONLINE, | ||
@@ -100,0 +100,0 @@ activities: [{ type: Helpers.ActivityTypes.WATCHING, name: 'YOU' }], |
164115
9
3360