mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-01 08:20:08 +00:00
chore: setup "deno lint" (#331)
* chore: setup "deno lint" * ci(lint): add --unstable flat to lint script * lint * lint * refactor: destructure assignment for Message#guildID * chore: remove TODO comment * refactor: remove redundant async * chore: switch to Deno stable vscode ext * chore: remove ignore comments * chore: remove ignore comments * chore: remove @ts-ignore comment * fixes * fixes * chore: remove deno-lint-ignore comment * chore: add index signature
This commit is contained in:
4
.github/workflows/lint.yml
vendored
4
.github/workflows/lint.yml
vendored
@@ -16,5 +16,5 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: denolib/setup-deno@v2
|
||||
- name: Run format script with --check
|
||||
run: deno fmt --ignore=./docs --check
|
||||
- name: Run lint script
|
||||
run: deno lint src/** --unstable
|
||||
|
||||
12
.vscode/settings.json
vendored
12
.vscode/settings.json
vendored
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"deno.enable": true,
|
||||
"deno.lint": true,
|
||||
"deno.unstable": true,
|
||||
"editor.defaultFormatter": "denoland.vscode-deno",
|
||||
"editor.formatOnSave": true,
|
||||
"deno.import_intellisense_origins": {
|
||||
"https://deno.land": true
|
||||
},
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.organizeImports": true
|
||||
},
|
||||
"editor.defaultFormatter": "denoland.vscode-deno"
|
||||
"source.organizeImports": true,
|
||||
"source.fixAll": true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// deno-lint-ignore-file require-await no-explicit-any prefer-const
|
||||
|
||||
import { PresenceUpdatePayload } from "../../types/mod.ts";
|
||||
import { cache } from "../../util/cache.ts";
|
||||
import { Collection } from "../../util/collection.ts";
|
||||
|
||||
@@ -83,7 +83,6 @@ export async function handleInternalGuildUpdate(data: DiscordPayload) {
|
||||
.map(([key, value]) => {
|
||||
if (keysToSkip.includes(key)) return;
|
||||
|
||||
// @ts-ignore
|
||||
const cachedValue = cachedGuild[key];
|
||||
if (cachedValue !== value) {
|
||||
// Guild create sends undefined and update sends false.
|
||||
@@ -91,13 +90,12 @@ export async function handleInternalGuildUpdate(data: DiscordPayload) {
|
||||
|
||||
if (Array.isArray(cachedValue) && Array.isArray(value)) {
|
||||
const different = (cachedValue.length !== value.length) ||
|
||||
// @ts-ignore no idea how to fix this
|
||||
cachedValue.find((val) => !value.includes(val)) ||
|
||||
value.find((val) => !cachedValue.includes(val));
|
||||
if (!different) return;
|
||||
}
|
||||
|
||||
// This will update the cached guild with the new values
|
||||
// @ts-ignore
|
||||
cachedGuild[key] = value;
|
||||
return { key, oldValue: cachedValue, value };
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ export async function handleInternalInteractionCreate(data: DiscordPayload) {
|
||||
);
|
||||
}
|
||||
|
||||
export async function handleInternalApplicationCommandCreate(
|
||||
export function handleInternalApplicationCommandCreate(
|
||||
data: DiscordPayload,
|
||||
) {
|
||||
if (data.t !== "APPLICATION_COMMAND_CREATE") return;
|
||||
|
||||
@@ -56,7 +56,9 @@ export async function handleInternalGuildMemberUpdate(data: DiscordPayload) {
|
||||
|
||||
const newMemberData = {
|
||||
...payload,
|
||||
// deno-lint-ignore camelcase
|
||||
premium_since: payload.premium_since || undefined,
|
||||
// deno-lint-ignore camelcase
|
||||
joined_at: new Date(guildMember?.joinedAt || Date.now())
|
||||
.toISOString(),
|
||||
deaf: guildMember?.deaf || false,
|
||||
|
||||
@@ -11,10 +11,8 @@ import {
|
||||
import { cache } from "../../util/cache.ts";
|
||||
import { delay } from "../../util/utils.ts";
|
||||
import { allowNextShard } from "../../ws/shard_manager.ts";
|
||||
import {
|
||||
initialMemberLoadQueue,
|
||||
structures,
|
||||
} from "../structures/structures.ts";
|
||||
import { initialMemberLoadQueue } from "../structures/guild.ts";
|
||||
import { structures } from "../structures/mod.ts";
|
||||
import { cacheHandlers } from "./cache.ts";
|
||||
|
||||
/** This function is the internal handler for the ready event. Users can override this with controllers if desired. */
|
||||
@@ -75,7 +73,6 @@ export async function handleInternalUserUpdate(data: DiscordPayload) {
|
||||
if (!member) return;
|
||||
|
||||
Object.entries(userData).forEach(([key, value]) => {
|
||||
// @ts-ignore
|
||||
if (member[key] !== value) return member[key] = value;
|
||||
});
|
||||
return eventHandlers.botUpdate?.(userData);
|
||||
|
||||
@@ -399,9 +399,13 @@ export async function editChannel(
|
||||
|
||||
const payload = {
|
||||
...options,
|
||||
// deno-lint-ignore camelcase
|
||||
rate_limit_per_user: options.slowmode,
|
||||
// deno-lint-ignore camelcase
|
||||
parent_id: options.parentID,
|
||||
// deno-lint-ignore camelcase
|
||||
user_limit: options.userLimit,
|
||||
// deno-lint-ignore camelcase
|
||||
permission_overwrites: options.overwrites?.map(
|
||||
(overwrite) => {
|
||||
return {
|
||||
|
||||
@@ -429,8 +429,8 @@ export function fetchMembers(guild: Guild, options?: FetchMembersOptions) {
|
||||
options.limit = options.userIDs.length;
|
||||
}
|
||||
|
||||
return new Promise(async (resolve) => {
|
||||
await requestAllMembers(guild, resolve, options);
|
||||
return new Promise((resolve) => {
|
||||
requestAllMembers(guild, resolve, options);
|
||||
}) as Promise<Collection<string, Member>>;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { botID } from "../../bot.ts";
|
||||
import { RequestManager } from "../../rest/mod.ts";
|
||||
import {
|
||||
ChannelCreatePayload,
|
||||
DMChannelCreatePayload,
|
||||
EditMemberOptions,
|
||||
Errors,
|
||||
@@ -128,7 +129,9 @@ export async function sendDirectMessage(
|
||||
) as DMChannelCreatePayload;
|
||||
// Channel create event will have added this channel to the cache
|
||||
await cacheHandlers.delete("channels", dmChannelData.id);
|
||||
const channel = await structures.createChannel(dmChannelData);
|
||||
const channel = await structures.createChannel(
|
||||
dmChannelData as unknown as ChannelCreatePayload,
|
||||
);
|
||||
// Recreate the channel and add it undert he users id
|
||||
await cacheHandlers.set("channels", memberID, channel);
|
||||
dmChannel = channel;
|
||||
|
||||
@@ -32,34 +32,34 @@ export async function createChannel(
|
||||
guildID?: string,
|
||||
) {
|
||||
const {
|
||||
guild_id: rawGuildID,
|
||||
guild_id: rawGuildID = "",
|
||||
last_message_id: lastMessageID,
|
||||
user_limit: userLimit,
|
||||
rate_limit_per_user: rateLimitPerUser,
|
||||
parent_id: parentID,
|
||||
parent_id: parentID = undefined,
|
||||
last_pin_timestamp: lastPinTimestamp,
|
||||
permission_overwrites,
|
||||
nsfw,
|
||||
permission_overwrites: permissionOverwrites = [],
|
||||
nsfw = false,
|
||||
...rest
|
||||
} = data;
|
||||
|
||||
const restProps: Record<string, ReturnType<typeof createNewProp>> = {};
|
||||
for (const key of Object.keys(rest)) {
|
||||
restProps[key] = createNewProp((rest as any)[key]);
|
||||
restProps[key] = createNewProp(rest[key]);
|
||||
}
|
||||
|
||||
const channel = Object.create(baseChannel, {
|
||||
...restProps,
|
||||
guildID: createNewProp(guildID || rawGuildID || ""),
|
||||
guildID: createNewProp(guildID || rawGuildID),
|
||||
lastMessageID: createNewProp(lastMessageID),
|
||||
userLimit: createNewProp(userLimit),
|
||||
rateLimitPerUser: createNewProp(rateLimitPerUser),
|
||||
parentID: createNewProp(parentID || undefined),
|
||||
parentID: createNewProp(parentID),
|
||||
lastPinTimestamp: createNewProp(
|
||||
lastPinTimestamp ? Date.parse(lastPinTimestamp) : undefined,
|
||||
),
|
||||
permissionOverwrites: createNewProp(permission_overwrites || []),
|
||||
nsfw: createNewProp(data.nsfw || false),
|
||||
permissionOverwrites: createNewProp(permissionOverwrites),
|
||||
nsfw: createNewProp(nsfw),
|
||||
});
|
||||
|
||||
await cacheHandlers.set("channels", data.id, channel);
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
MemberCreatePayload,
|
||||
Presence,
|
||||
RoleData,
|
||||
ValueOf,
|
||||
VoiceState,
|
||||
} from "../../types/mod.ts";
|
||||
import { cache } from "../../util/cache.ts";
|
||||
@@ -32,8 +33,7 @@ import {
|
||||
unban,
|
||||
} from "../handlers/guild.ts";
|
||||
import { Member } from "./member.ts";
|
||||
import { Role, structures } from "./mod.ts";
|
||||
import { Channel } from "./structures.ts";
|
||||
import { Channel, Role, structures } from "./mod.ts";
|
||||
|
||||
export const initialMemberLoadQueue = new Map<string, MemberCreatePayload[]>();
|
||||
|
||||
@@ -135,7 +135,7 @@ export async function createGuild(data: CreateGuildPayload, shardID: number) {
|
||||
premium_subscription_count: premiumSubscriptionCount,
|
||||
preferred_locale: preferredLocale,
|
||||
joined_at: joinedAt,
|
||||
member_count: memberCount,
|
||||
member_count: memberCount = 0,
|
||||
voice_states: voiceStates = [],
|
||||
channels = [],
|
||||
members,
|
||||
@@ -155,7 +155,7 @@ export async function createGuild(data: CreateGuildPayload, shardID: number) {
|
||||
|
||||
const restProps: Record<string, ReturnType<typeof createNewProp>> = {};
|
||||
for (const key of Object.keys(rest)) {
|
||||
restProps[key] = createNewProp((rest as any)[key]);
|
||||
restProps[key] = createNewProp(rest[key]);
|
||||
}
|
||||
|
||||
const guild = Object.create(baseGuild, {
|
||||
@@ -188,7 +188,7 @@ export async function createGuild(data: CreateGuildPayload, shardID: number) {
|
||||
presences: createNewProp(
|
||||
new Collection(presences.map((p: Presence) => [p.user.id, p])),
|
||||
),
|
||||
memberCount: createNewProp(memberCount || 0),
|
||||
memberCount: createNewProp(memberCount),
|
||||
voiceStates: createNewProp(
|
||||
new Collection(
|
||||
voiceStates.map((vs: VoiceState) => [
|
||||
@@ -345,6 +345,9 @@ export interface Guild {
|
||||
unban(memberID: string): ReturnType<typeof unban>;
|
||||
/** Get all the invites for this guild. Requires MANAGE_GUILD permission */
|
||||
invites(): ReturnType<typeof getInvites>;
|
||||
|
||||
// Index signature
|
||||
[key: string]: ValueOf<Guild>;
|
||||
}
|
||||
|
||||
interface CleanVoiceState extends VoiceState {
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
ImageSize,
|
||||
MemberCreatePayload,
|
||||
MessageContent,
|
||||
ValueOf,
|
||||
} from "../../types/mod.ts";
|
||||
import { cache } from "../../util/cache.ts";
|
||||
import { Collection } from "../../util/collection.ts";
|
||||
@@ -88,12 +89,12 @@ export async function createMember(data: MemberCreatePayload, guildID: string) {
|
||||
data.user || {};
|
||||
|
||||
const restProps: Record<string, ReturnType<typeof createNewProp>> = {};
|
||||
|
||||
for (const key of Object.keys(rest)) {
|
||||
restProps[key] = createNewProp((rest as any)[key]);
|
||||
restProps[key] = createNewProp(rest[key]);
|
||||
}
|
||||
|
||||
for (const key of Object.keys(user)) {
|
||||
// @ts-ignore
|
||||
restProps[key] = createNewProp(user[key]);
|
||||
}
|
||||
|
||||
@@ -198,4 +199,7 @@ export interface Member {
|
||||
roleID: string,
|
||||
reason?: string,
|
||||
): ReturnType<typeof removeRole>;
|
||||
|
||||
// Index signature
|
||||
[key: string]: ValueOf<Member>;
|
||||
}
|
||||
|
||||
@@ -34,15 +34,15 @@ const baseMessage: Partial<Message> = {
|
||||
return cache.channels.get(this.channelID!);
|
||||
},
|
||||
get guild() {
|
||||
if (!this.guildID) return;
|
||||
if (!this.guildID) return undefined;
|
||||
return cache.guilds.get(this.guildID);
|
||||
},
|
||||
get member() {
|
||||
if (!this.author?.id) return;
|
||||
if (!this.author?.id) return undefined;
|
||||
return cache.members.get(this.author?.id);
|
||||
},
|
||||
get guildMember() {
|
||||
if (!this.guildID) return;
|
||||
if (!this.guildID) return undefined;
|
||||
return this.member?.guilds.get(this.guildID);
|
||||
},
|
||||
get link() {
|
||||
@@ -116,12 +116,13 @@ const baseMessage: Partial<Message> = {
|
||||
},
|
||||
};
|
||||
|
||||
// deno-lint-ignore require-await
|
||||
export async function createMessage(data: MessageCreateOptions) {
|
||||
const {
|
||||
guild_id: guildID,
|
||||
guild_id: guildID = "",
|
||||
channel_id: channelID,
|
||||
mentions_everyone: mentionsEveryone,
|
||||
mention_channels: mentionChannelIDs,
|
||||
mention_channels: mentionChannelIDs = [],
|
||||
mention_roles: mentionRoleIDs,
|
||||
webhook_id: webhookID,
|
||||
message_reference: messageReference,
|
||||
@@ -133,7 +134,7 @@ export async function createMessage(data: MessageCreateOptions) {
|
||||
|
||||
const restProps: Record<string, ReturnType<typeof createNewProp>> = {};
|
||||
for (const key of Object.keys(rest)) {
|
||||
restProps[key] = createNewProp((rest as any)[key]);
|
||||
restProps[key] = createNewProp(rest[key]);
|
||||
}
|
||||
|
||||
const message = Object.create(baseMessage, {
|
||||
@@ -141,11 +142,11 @@ export async function createMessage(data: MessageCreateOptions) {
|
||||
/** The message id of the original message if this message was sent as a reply. If null, the original message was deleted. */
|
||||
referencedMessageID: createNewProp(referencedMessageID),
|
||||
channelID: createNewProp(channelID),
|
||||
guildID: createNewProp(guildID || ""),
|
||||
guildID: createNewProp(guildID),
|
||||
mentions: createNewProp(data.mentions.map((m) => m.id)),
|
||||
mentionsEveryone: createNewProp(mentionsEveryone),
|
||||
mentionRoleIDs: createNewProp(mentionRoleIDs),
|
||||
mentionChannelIDs: createNewProp(mentionChannelIDs?.map((m) => m.id) || []),
|
||||
mentionChannelIDs: createNewProp(mentionChannelIDs.map((m) => m.id)),
|
||||
webhookID: createNewProp(webhookID),
|
||||
messageReference: createNewProp(messageReference),
|
||||
timestamp: createNewProp(Date.parse(data.timestamp)),
|
||||
|
||||
@@ -6,16 +6,16 @@ import { deleteRole, editRole } from "../handlers/guild.ts";
|
||||
import { Guild } from "./guild.ts";
|
||||
import { Member } from "./member.ts";
|
||||
|
||||
const baseRole: any = {
|
||||
const baseRole: Partial<Role> = {
|
||||
get guild() {
|
||||
return cache.guilds.find((g) => g.roles.has(this.id));
|
||||
return cache.guilds.find((g) => g.roles.has(this.id!));
|
||||
},
|
||||
get hexColor() {
|
||||
return this.color!.toString(16);
|
||||
},
|
||||
get members() {
|
||||
return cache.members.filter((m) =>
|
||||
m.guilds.some((g) => g.roles.includes(this.id))
|
||||
m.guilds.some((g) => g.roles.includes(this.id!))
|
||||
);
|
||||
},
|
||||
get mention() {
|
||||
@@ -66,19 +66,18 @@ const baseRole: any = {
|
||||
},
|
||||
};
|
||||
|
||||
export async function createRole(data: RoleData) {
|
||||
const { tags, ...rest } = data;
|
||||
|
||||
// deno-lint-ignore require-await
|
||||
export async function createRole({ tags = {}, ...rest }: RoleData) {
|
||||
const restProps: Record<string, ReturnType<typeof createNewProp>> = {};
|
||||
for (const key of Object.keys(rest)) {
|
||||
restProps[key] = createNewProp((rest as any)[key]);
|
||||
restProps[key] = createNewProp(rest[key]);
|
||||
}
|
||||
|
||||
const role = Object.create(baseRole, {
|
||||
...restProps,
|
||||
botID: createNewProp(tags?.bot_id),
|
||||
isNitroBoostRole: createNewProp("premium_subscriber" in (tags ?? {})),
|
||||
integrationID: createNewProp(tags?.integration_id),
|
||||
botID: createNewProp(tags.bot_id),
|
||||
isNitroBoostRole: createNewProp("premium_subscriber" in tags),
|
||||
integrationID: createNewProp(tags.integration_id),
|
||||
});
|
||||
|
||||
return role as Role;
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
export * from "./channel.ts";
|
||||
export * from "./guild.ts";
|
||||
export * from "./member.ts";
|
||||
export * from "./message.ts";
|
||||
export * from "./mod.ts";
|
||||
export * from "./role.ts";
|
||||
export * from "./template.ts";
|
||||
@@ -3,8 +3,10 @@ import { cache } from "../../util/cache.ts";
|
||||
import { createNewProp } from "../../util/utils.ts";
|
||||
import { Guild } from "./guild.ts";
|
||||
|
||||
const baseTemplate: any = {
|
||||
const baseTemplate: Partial<Template> = {
|
||||
get sourceGuild() {
|
||||
// deno-lint-ignore getter-return
|
||||
if (!this.sourceGuildID) return;
|
||||
return cache.guilds.get(this.sourceGuildID);
|
||||
},
|
||||
};
|
||||
@@ -25,7 +27,7 @@ export function createTemplate(
|
||||
|
||||
const restProps: Record<string, Partial<PropertyDescriptor>> = {};
|
||||
for (const key of Object.keys(rest)) {
|
||||
restProps[key] = createNewProp((rest as any)[key]);
|
||||
restProps[key] = createNewProp(rest[key]);
|
||||
}
|
||||
|
||||
return Object.create(baseTemplate, {
|
||||
|
||||
@@ -69,7 +69,7 @@ export async function startServer(
|
||||
}
|
||||
}
|
||||
|
||||
async function handlePayload(payload: Interaction) {
|
||||
function handlePayload(payload: Interaction) {
|
||||
switch (payload.type) {
|
||||
case InteractionType.PING:
|
||||
return { status: 200, body: { type: InteractionResponseType.PONG } };
|
||||
@@ -79,6 +79,7 @@ async function handlePayload(payload: Interaction) {
|
||||
}
|
||||
|
||||
/** The function that handles your commands. This command can be overriden by you and you can receive the payload and handle accordingly and respond back. The status if not provided will default to 200. */
|
||||
// deno-lint-ignore require-await
|
||||
async function handleApplicationCommand(
|
||||
payload: Interaction,
|
||||
): Promise<{ status?: number; body: InteractionResponse }> {
|
||||
@@ -116,11 +117,11 @@ function verifySecurity(buffer: Uint8Array, signature: string, time: string) {
|
||||
sig[offset / 2] = parseInt(signature!.substring(offset, offset += 2), 16);
|
||||
}
|
||||
|
||||
const slash_key = new Uint8Array(32);
|
||||
|
||||
const slashKey = new Uint8Array(32);
|
||||
let keyoffset = 0;
|
||||
|
||||
while (keyoffset < 2 * 32) {
|
||||
slash_key[keyoffset / 2] = parseInt(
|
||||
slashKey[keyoffset / 2] = parseInt(
|
||||
serverOptions.publicKey.substring(keyoffset, keyoffset += 2),
|
||||
16,
|
||||
);
|
||||
@@ -129,5 +130,5 @@ function verifySecurity(buffer: Uint8Array, signature: string, time: string) {
|
||||
message.set(timestamp);
|
||||
message.set(buffer, timestamp.length);
|
||||
|
||||
return verify(slash_key, sig, message);
|
||||
return verify(slashKey, sig, message);
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ export interface SlashCommandInteractionDataOption {
|
||||
/** The name of the parameter */
|
||||
name: string;
|
||||
/** The value of the pair */
|
||||
// deno-lint-ignore no-explicit-any
|
||||
value?: any;
|
||||
/** Present if this option is a group or subcommand */
|
||||
options?: SlashCommandInteractionDataOption[];
|
||||
|
||||
@@ -17,6 +17,7 @@ let queueInProcess = false;
|
||||
export interface QueuedRequest {
|
||||
callback: () => Promise<
|
||||
void | {
|
||||
// deno-lint-ignore no-explicit-any
|
||||
rateLimited: any;
|
||||
beforeFetch: boolean;
|
||||
bucketID?: string | null;
|
||||
@@ -58,7 +59,7 @@ function addToQueue(request: QueuedRequest) {
|
||||
}
|
||||
}
|
||||
|
||||
async function cleanupQueues() {
|
||||
function cleanupQueues() {
|
||||
Object.entries(pathQueues).forEach(([key, value]) => {
|
||||
if (!value.length) {
|
||||
// Remove it entirely
|
||||
@@ -123,7 +124,7 @@ async function processQueue() {
|
||||
processRateLimitedPaths();
|
||||
|
||||
export const RequestManager = {
|
||||
get: async (url: string, body?: unknown) => {
|
||||
get: (url: string, body?: unknown) => {
|
||||
return runMethod("get", url, body);
|
||||
},
|
||||
post: (url: string, body?: unknown) => {
|
||||
@@ -140,6 +141,7 @@ export const RequestManager = {
|
||||
},
|
||||
};
|
||||
|
||||
// deno-lint-ignore no-explicit-any
|
||||
function createRequestBody(body: any, method: RequestMethods) {
|
||||
const headers: { [key: string]: string } = {
|
||||
Authorization: authorization,
|
||||
@@ -170,7 +172,7 @@ function createRequestBody(body: any, method: RequestMethods) {
|
||||
};
|
||||
}
|
||||
|
||||
async function checkRatelimits(url: string) {
|
||||
function checkRatelimits(url: string) {
|
||||
const ratelimited = ratelimitedPaths.get(url);
|
||||
const global = ratelimitedPaths.get("global");
|
||||
const now = Date.now();
|
||||
@@ -185,7 +187,7 @@ async function checkRatelimits(url: string) {
|
||||
return false;
|
||||
}
|
||||
|
||||
async function runMethod(
|
||||
function runMethod(
|
||||
method: RequestMethods,
|
||||
url: string,
|
||||
body?: unknown,
|
||||
@@ -225,10 +227,12 @@ async function runMethod(
|
||||
}
|
||||
|
||||
const query = method === "get" && body
|
||||
? Object.entries(body as any).map(([key, value]) =>
|
||||
`${encodeURIComponent(key)}=${encodeURIComponent(value as any)}`
|
||||
)
|
||||
.join("&")
|
||||
? // deno-lint-ignore no-explicit-any
|
||||
Object.entries(body as any).map(([key, value]) =>
|
||||
// deno-lint-ignore no-explicit-any
|
||||
`${encodeURIComponent(key)}=${encodeURIComponent(value as any)}`
|
||||
)
|
||||
.join("&")
|
||||
: "";
|
||||
const urlToUse = method === "get" && query ? `${url}?${query}` : url;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Overwrite, RawOverwrite } from "./guild.ts";
|
||||
import { Embed } from "./message.ts";
|
||||
import { ValueOf } from "./mod.ts";
|
||||
|
||||
export interface ChannelEditOptions {
|
||||
/** 2-100 character channel name. All */
|
||||
@@ -72,6 +73,7 @@ export interface ChannelCreatePayload extends BaseChannelCreate {
|
||||
type: ChannelType;
|
||||
/** Explicit permission overwrites for members and roles */
|
||||
permission_overwrites?: RawOverwrite[];
|
||||
[key: string]: ValueOf<ChannelCreatePayload>;
|
||||
}
|
||||
|
||||
export type ChannelType = 0 | 1 | 2 | 4 | 5 | 6;
|
||||
|
||||
@@ -3,6 +3,7 @@ import { ChannelCreatePayload, ChannelTypes } from "./channel.ts";
|
||||
import { Emoji, StatusType } from "./discord.ts";
|
||||
import { MemberCreatePayload } from "./member.ts";
|
||||
import { Activity } from "./message.ts";
|
||||
import { ValueOf } from "./mod.ts";
|
||||
import { Permission } from "./permission.ts";
|
||||
import { ClientStatusPayload } from "./presence.ts";
|
||||
import { RoleData } from "./role.ts";
|
||||
@@ -158,6 +159,7 @@ export interface CreateGuildPayload extends UpdateGuildPayload {
|
||||
/** Channels in the guild */
|
||||
channels: ChannelCreatePayload[];
|
||||
presences: Presence[];
|
||||
[key: string]: ValueOf<CreateGuildPayload>;
|
||||
}
|
||||
|
||||
export type GuildFeatures =
|
||||
@@ -303,6 +305,9 @@ export interface UserPayload {
|
||||
flags?: number;
|
||||
/** The type of Nitro subscription on a user's account. */
|
||||
premium_type?: number;
|
||||
|
||||
// Index signature
|
||||
[key: string]: ValueOf<UserPayload>;
|
||||
}
|
||||
|
||||
export interface PartialUser {
|
||||
@@ -638,6 +643,7 @@ export interface GuildTemplate {
|
||||
serialized_source_guild: Guild;
|
||||
/** whether the template has unsynced changes */
|
||||
is_dirty: boolean | null;
|
||||
[key: string]: ValueOf<GuildTemplate>;
|
||||
}
|
||||
|
||||
export interface CreateGuildFromTemplate {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { UserPayload } from "./guild.ts";
|
||||
import { ValueOf } from "./mod.ts";
|
||||
|
||||
export interface EditMemberOptions {
|
||||
/** Value to set users nickname to. Requires MANAGE_NICKNAMES permission. */
|
||||
@@ -30,6 +31,7 @@ export interface MemberCreatePayload {
|
||||
mute: boolean;
|
||||
/** Whether the user has passed the guild's Membership Screening requirements */
|
||||
pending?: boolean;
|
||||
[key: string]: ValueOf<MemberCreatePayload>;
|
||||
}
|
||||
|
||||
export interface GuildMember {
|
||||
|
||||
@@ -2,8 +2,10 @@ import { Channel } from "../api/structures/mod.ts";
|
||||
import { ChannelType } from "./channel.ts";
|
||||
import { UserPayload } from "./guild.ts";
|
||||
import { MemberCreatePayload } from "./member.ts";
|
||||
import { ValueOf } from "./mod.ts";
|
||||
|
||||
export interface MentionedUser extends UserPayload {
|
||||
// @ts-ignore no idea how to fix this
|
||||
member: MemberCreatePayload;
|
||||
}
|
||||
|
||||
@@ -283,6 +285,7 @@ export interface MessageCreateOptions {
|
||||
stickers?: MessageSticker[];
|
||||
/** The message id of the original message if this message was sent as a reply. If null, the original message was deleted. */
|
||||
referenced_message?: MessageCreateOptions | null;
|
||||
[key: string]: ValueOf<MessageCreateOptions>;
|
||||
}
|
||||
|
||||
export interface BaseMessageDeletePayload {
|
||||
|
||||
@@ -246,3 +246,5 @@ export enum Intents {
|
||||
*/
|
||||
DIRECT_MESSAGE_TYPING = 1 << 14,
|
||||
}
|
||||
|
||||
export type ValueOf<T> = T[keyof T];
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { ValueOf } from "./mod.ts";
|
||||
|
||||
export interface RoleData {
|
||||
/** role id */
|
||||
id: string;
|
||||
@@ -17,6 +19,7 @@ export interface RoleData {
|
||||
mentionable: boolean;
|
||||
/** Certain roles may have tags that allow you to determine if this role is related to a bot, an integration, or the booster role. */
|
||||
tags?: RoleTags;
|
||||
[key: string]: ValueOf<RoleData>;
|
||||
}
|
||||
|
||||
export interface RoleTags {
|
||||
|
||||
@@ -160,6 +160,7 @@ export interface SlashCommandInteractionDataOption {
|
||||
/** The name of the parammeter */
|
||||
name: string;
|
||||
/** The value of the pair */
|
||||
// deno-lint-ignore no-explicit-any
|
||||
value?: any;
|
||||
/** Present if this option is a group or subcommand */
|
||||
options?: SlashCommandInteractionDataOption[];
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
import {
|
||||
Channel,
|
||||
Guild,
|
||||
Member,
|
||||
Message,
|
||||
} from "../api/structures/structures.ts";
|
||||
import { Channel, Guild, Member, Message } from "../api/structures/mod.ts";
|
||||
import { PresenceUpdatePayload } from "../types/mod.ts";
|
||||
import { Collection } from "./collection.ts";
|
||||
|
||||
@@ -15,6 +10,8 @@ export interface CacheData {
|
||||
members: Collection<string, Member>;
|
||||
unavailableGuilds: Collection<string, number>;
|
||||
presences: Collection<string, PresenceUpdatePayload>;
|
||||
// TODO: The type Collection's second provided generic [function] should have a definite shape.
|
||||
// deno-lint-ignore ban-types
|
||||
fetchAllMembersProcessingRequests: Collection<string, Function>;
|
||||
executedSlashCommands: Collection<string, string>;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { cacheHandlers } from "../api/controllers/cache.ts";
|
||||
import { Guild, Role } from "../api/structures/structures.ts";
|
||||
import { Guild, Role } from "../api/structures/mod.ts";
|
||||
import { botID } from "../bot.ts";
|
||||
import { Permission, Permissions, RawOverwrite } from "../types/mod.ts";
|
||||
|
||||
@@ -115,7 +115,7 @@ export async function hasChannelPermissions(
|
||||
|
||||
let memberOverwrite: RawOverwrite | undefined;
|
||||
let everyoneOverwrite: RawOverwrite | undefined;
|
||||
let rolesOverwrites: RawOverwrite[] = [];
|
||||
const rolesOverwrites: RawOverwrite[] = [];
|
||||
|
||||
for (const overwrite of channel.permissionOverwrites || []) {
|
||||
// If the overwrite on this channel is specific to this member
|
||||
|
||||
@@ -39,6 +39,7 @@ export async function urlToBase64(url: string) {
|
||||
}
|
||||
|
||||
/** Allows easy way to add a prop to a base object when needing to use complicated getters solution. */
|
||||
// deno-lint-ignore no-explicit-any
|
||||
export function createNewProp(value: any): Partial<PropertyDescriptor> {
|
||||
return { configurable: true, enumerable: true, writable: true, value };
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ interface RequestMemberQueuedRequest {
|
||||
options?: FetchMembersOptions;
|
||||
}
|
||||
|
||||
export async function createShard(
|
||||
export function createShard(
|
||||
data: DiscordBotGatewayData,
|
||||
identifyPayload: IdentifyPayload,
|
||||
resuming = false,
|
||||
@@ -58,7 +58,7 @@ export async function createShard(
|
||||
|
||||
basicShards.set(basicShard.id, basicShard);
|
||||
|
||||
ws.onopen = async () => {
|
||||
ws.onopen = () => {
|
||||
if (!resuming) {
|
||||
// Initial identify with the gateway
|
||||
identify(basicShard, identifyPayload);
|
||||
|
||||
@@ -88,8 +88,10 @@ export async function handleDiscordPayload(
|
||||
}
|
||||
}
|
||||
|
||||
export async function requestAllMembers(
|
||||
export function requestAllMembers(
|
||||
guild: Guild,
|
||||
// TODO: The parameter "resolve" should have a "stronger" type.
|
||||
// deno-lint-ignore ban-types
|
||||
resolve: Function,
|
||||
options?: FetchMembersOptions,
|
||||
) {
|
||||
@@ -98,7 +100,11 @@ export async function requestAllMembers(
|
||||
return requestGuildMembers(guild.id, guild.shardID, nonce, options);
|
||||
}
|
||||
|
||||
export function sendGatewayCommand(type: "EDIT_BOTS_STATUS", payload: object) {
|
||||
export function sendGatewayCommand(
|
||||
type: "EDIT_BOTS_STATUS",
|
||||
// deno-lint-ignore no-explicit-any
|
||||
payload: Record<string, any>,
|
||||
) {
|
||||
if (type === "EDIT_BOTS_STATUS") {
|
||||
botGatewayStatusRequest(payload as BotStatusRequest);
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ Deno.test({
|
||||
|
||||
Deno.test({
|
||||
name: "channel overwrite has permission",
|
||||
async fn() {
|
||||
fn() {
|
||||
const channel = cache.channels.get(data.channelID);
|
||||
if (!channel) throw "Channel not found";
|
||||
|
||||
@@ -247,7 +247,7 @@ Deno.test({
|
||||
// This is meant to be the final test that forcefully crashes the bot
|
||||
Deno.test({
|
||||
name: "exit the process forcefully after all the tests are done",
|
||||
async fn() {
|
||||
fn() {
|
||||
Deno.exit();
|
||||
},
|
||||
...testOptions,
|
||||
|
||||
Reference in New Issue
Block a user