mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 03:18:17 +00:00
fix: more typing errors
This commit is contained in:
@@ -3,10 +3,10 @@ import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { Interaction } from "../../types/mod.ts";
|
||||
import { DiscordInteraction } from "../../types/mod.ts";
|
||||
|
||||
export async function handleInteractionCreate(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as Interaction;
|
||||
const payload = data.d as DiscordInteraction;
|
||||
const discordenoMember = await structures.createDiscordenoMember(
|
||||
payload.member,
|
||||
payload.guild_id,
|
||||
|
||||
@@ -2,15 +2,16 @@ import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { DiscordMessage } from "../../types/messages/message.ts";
|
||||
import { DiscordMessage, Message } from "../../types/messages/message.ts";
|
||||
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||
|
||||
export async function handleMessageCreate(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as DiscordMessage;
|
||||
const channel = await cacheHandlers.get("channels", payload.channel_id);
|
||||
const payload = snakeKeysToCamelCase(data.d as DiscordMessage) as Message;
|
||||
const channel = await cacheHandlers.get("channels", payload.channelId);
|
||||
if (channel) channel.lastMessageId = payload.id;
|
||||
|
||||
const guild = payload.guild_id
|
||||
? await cacheHandlers.get("guilds", payload.guild_id)
|
||||
const guild = payload.guildId
|
||||
? await cacheHandlers.get("guilds", payload.guildId)
|
||||
: undefined;
|
||||
|
||||
if (payload.member && guild) {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { Ban } from "../../types/guilds/ban.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
|
||||
/** Ban a user from the guild and optionally delete previous messages sent by the user. Requires the BAN_MEMBERS permission. */
|
||||
export async function ban(guildId: string, id: string, options: BanOptions) {
|
||||
export async function ban(guildId: string, id: string, options: Ban) {
|
||||
await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]);
|
||||
|
||||
const result = await rest.runMethod("put", endpoints.GUILD_BAN(guildId, id), {
|
||||
|
||||
@@ -3,6 +3,7 @@ import { rest } from "../../rest/rest.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { DiscordGuildMember } from "../../types/guilds/guild_member.ts";
|
||||
import { Errors } from "../../types/misc/errors.ts";
|
||||
import { PermissionStrings } from "../../types/permissions/permission_strings.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import {
|
||||
requireBotChannelPermissions,
|
||||
@@ -13,9 +14,9 @@ import {
|
||||
export async function editMember(
|
||||
guildId: string,
|
||||
memberId: string,
|
||||
options: EditMemberOptions,
|
||||
options: EditMember,
|
||||
) {
|
||||
const requiredPerms: Set<Permission> = new Set();
|
||||
const requiredPerms: Set<PermissionStrings> = new Set();
|
||||
|
||||
if (options.nick) {
|
||||
if (options.nick.length > 32) {
|
||||
@@ -47,7 +48,7 @@ export async function editMember(
|
||||
}
|
||||
|
||||
if (options.channel_id) {
|
||||
const requiredVoicePerms: Set<Permission> = new Set([
|
||||
const requiredVoicePerms: Set<PermissionStrings> = new Set([
|
||||
"CONNECT",
|
||||
"MOVE_MEMBERS",
|
||||
]);
|
||||
|
||||
@@ -56,7 +56,7 @@ const baseRole: Partial<DiscordenoRole> = {
|
||||
const guild = this.guild;
|
||||
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
|
||||
|
||||
if (this.guild.ownerId === memberId) return false;
|
||||
if (guild.ownerId === memberId) return false;
|
||||
|
||||
const memberHighestRole = await highestRole(guild, memberId);
|
||||
return this.higherThanRole!(
|
||||
|
||||
@@ -6,7 +6,51 @@ export interface GatewayPayload {
|
||||
/** Sequence number, used for resuming sessions and heartbeats */
|
||||
s: number | null;
|
||||
/** The event name for this payload */
|
||||
t: string | null;
|
||||
t:
|
||||
| "READY"
|
||||
| "RESUMED"
|
||||
| "CHANNEL_CREATE"
|
||||
| "CHANNEL_DELETE"
|
||||
| "CHANNEL_PINS_UPDATE"
|
||||
| "CHANNEL_UPDATE"
|
||||
| "APPLICATION_COMMAND_CREATE"
|
||||
| "APPLICATION_COMMAND_DELETE"
|
||||
| "APPLICATION_COMMAND_UPDATE"
|
||||
| "GUILD_BAN_ADD"
|
||||
| "GUILD_BAN_REMOVE"
|
||||
| "GUILD_CREATE"
|
||||
| "GUILD_DELETE"
|
||||
| "GUILD_EMOJIS_UPDATE"
|
||||
| "GUILD_INTEGRATIONS_UPDATE"
|
||||
| "GUILD_MEMBER_ADD"
|
||||
| "GUILD_MEMBER_REMOVE"
|
||||
| "GUILD_MEMBER_UPDATE"
|
||||
| "GUILD_MEMBERS_CHUNK"
|
||||
| "GUILD_ROLE_CREATE"
|
||||
| "GUILD_ROLE_DELETE"
|
||||
| "GUILD_ROLE_UPDATE"
|
||||
| "GUILD_UPDATE"
|
||||
| "INTERACTION_CREATE"
|
||||
| "INVITE_CREATE"
|
||||
| "INVITE_DELETE"
|
||||
| "MESSAGE_CREATE"
|
||||
| "MESSAGE_DELETE_BULK"
|
||||
| "MESSAGE_DELETE"
|
||||
| "MESSAGE_REACTION_ADD"
|
||||
| "MESSAGE_REACTION_REMOVE_ALL"
|
||||
| "MESSAGE_REACTION_REMOVE_EMOJI"
|
||||
| "MESSAGE_REACTION_REMOVE"
|
||||
| "MESSAGE_UPDATE"
|
||||
| "PRESENCE_UPDATE"
|
||||
| "TYPING_START"
|
||||
| "USER_UPDATE"
|
||||
| "VOICE_SERVER_UPDATE"
|
||||
| "VOICE_STATE_UPDATE"
|
||||
| "WEBHOOKS_UPDATE"
|
||||
| "INTEGRATION_CREATE"
|
||||
| "INTEGRATION_UPDATE"
|
||||
| "INTEGRATION_DELETE"
|
||||
| null;
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/topics/gateway#payloads-gateway-payload-structure */
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { eventHandlers } from "../bot.ts";
|
||||
import { handlers } from "../handlers/mod.ts";
|
||||
import { DiscordGatewayOpcodes } from "../types/codes/gateway_opcodes.ts";
|
||||
import { DiscordGatewayPayload } from "../types/gateway/gateway_payload.ts";
|
||||
import { DiscordHello } from "../types/gateway/hello.ts";
|
||||
import { DiscordReady } from "../types/gateway/ready.ts";
|
||||
import { decompressWith } from "./deps.ts";
|
||||
import { identify } from "./identify.ts";
|
||||
@@ -24,14 +26,14 @@ export async function handleOnMessage(message: any, shardId: number) {
|
||||
|
||||
if (typeof message !== "string") return;
|
||||
|
||||
const messageData = JSON.parse(message);
|
||||
ws.log("RAW", messageData);
|
||||
const messageData = JSON.parse(message) as DiscordGatewayPayload;
|
||||
ws.log("RAW", { shardId, payload: messageData});
|
||||
|
||||
switch (messageData.op) {
|
||||
case DiscordGatewayOpcodes.Hello:
|
||||
ws.heartbeat(
|
||||
shardId,
|
||||
(messageData.d as DiscordHeartbeat).heartbeat_interval,
|
||||
(messageData.d as DiscordHello).heartbeat_interval,
|
||||
);
|
||||
break;
|
||||
case DiscordGatewayOpcodes.HeartbeatACK:
|
||||
@@ -99,6 +101,8 @@ export async function handleOnMessage(message: any, shardId: number) {
|
||||
|
||||
if (messageData.op !== DiscordGatewayOpcodes.Dispatch) return;
|
||||
|
||||
if (!messageData.t) return;
|
||||
|
||||
return handlers[messageData.t]?.(messageData, shardId);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user