fix: more typing errors

This commit is contained in:
Skillz4Killz
2021-04-12 18:09:15 +00:00
committed by GitHub
parent f7024a5bf0
commit 8523a5ceea
7 changed files with 67 additions and 16 deletions
@@ -3,10 +3,10 @@ import { eventHandlers } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts"; import { cacheHandlers } from "../../cache.ts";
import { structures } from "../../structures/mod.ts"; import { structures } from "../../structures/mod.ts";
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.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) { export async function handleInteractionCreate(data: DiscordGatewayPayload) {
const payload = data.d as Interaction; const payload = data.d as DiscordInteraction;
const discordenoMember = await structures.createDiscordenoMember( const discordenoMember = await structures.createDiscordenoMember(
payload.member, payload.member,
payload.guild_id, payload.guild_id,
+6 -5
View File
@@ -2,15 +2,16 @@ import { eventHandlers } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts"; import { cacheHandlers } from "../../cache.ts";
import { structures } from "../../structures/mod.ts"; import { structures } from "../../structures/mod.ts";
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.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) { export async function handleMessageCreate(data: DiscordGatewayPayload) {
const payload = data.d as DiscordMessage; const payload = snakeKeysToCamelCase(data.d as DiscordMessage) as Message;
const channel = await cacheHandlers.get("channels", payload.channel_id); const channel = await cacheHandlers.get("channels", payload.channelId);
if (channel) channel.lastMessageId = payload.id; if (channel) channel.lastMessageId = payload.id;
const guild = payload.guild_id const guild = payload.guildId
? await cacheHandlers.get("guilds", payload.guild_id) ? await cacheHandlers.get("guilds", payload.guildId)
: undefined; : undefined;
if (payload.member && guild) { if (payload.member && guild) {
+2 -1
View File
@@ -1,9 +1,10 @@
import { rest } from "../../rest/rest.ts"; import { rest } from "../../rest/rest.ts";
import { Ban } from "../../types/guilds/ban.ts";
import { endpoints } from "../../util/constants.ts"; import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.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. */ /** 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"]); await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]);
const result = await rest.runMethod("put", endpoints.GUILD_BAN(guildId, id), { const result = await rest.runMethod("put", endpoints.GUILD_BAN(guildId, id), {
+4 -3
View File
@@ -3,6 +3,7 @@ import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts"; import { structures } from "../../structures/mod.ts";
import { DiscordGuildMember } from "../../types/guilds/guild_member.ts"; import { DiscordGuildMember } from "../../types/guilds/guild_member.ts";
import { Errors } from "../../types/misc/errors.ts"; import { Errors } from "../../types/misc/errors.ts";
import { PermissionStrings } from "../../types/permissions/permission_strings.ts";
import { endpoints } from "../../util/constants.ts"; import { endpoints } from "../../util/constants.ts";
import { import {
requireBotChannelPermissions, requireBotChannelPermissions,
@@ -13,9 +14,9 @@ import {
export async function editMember( export async function editMember(
guildId: string, guildId: string,
memberId: 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) {
if (options.nick.length > 32) { if (options.nick.length > 32) {
@@ -47,7 +48,7 @@ export async function editMember(
} }
if (options.channel_id) { if (options.channel_id) {
const requiredVoicePerms: Set<Permission> = new Set([ const requiredVoicePerms: Set<PermissionStrings> = new Set([
"CONNECT", "CONNECT",
"MOVE_MEMBERS", "MOVE_MEMBERS",
]); ]);
+1 -1
View File
@@ -56,7 +56,7 @@ const baseRole: Partial<DiscordenoRole> = {
const guild = this.guild; const guild = this.guild;
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND); 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); const memberHighestRole = await highestRole(guild, memberId);
return this.higherThanRole!( return this.higherThanRole!(
+45 -1
View File
@@ -6,7 +6,51 @@ export interface GatewayPayload {
/** Sequence number, used for resuming sessions and heartbeats */ /** Sequence number, used for resuming sessions and heartbeats */
s: number | null; s: number | null;
/** The event name for this payload */ /** 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 */ /** https://discord.com/developers/docs/topics/gateway#payloads-gateway-payload-structure */
+7 -3
View File
@@ -1,6 +1,8 @@
import { eventHandlers } from "../bot.ts"; import { eventHandlers } from "../bot.ts";
import { handlers } from "../handlers/mod.ts"; import { handlers } from "../handlers/mod.ts";
import { DiscordGatewayOpcodes } from "../types/codes/gateway_opcodes.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 { DiscordReady } from "../types/gateway/ready.ts";
import { decompressWith } from "./deps.ts"; import { decompressWith } from "./deps.ts";
import { identify } from "./identify.ts"; import { identify } from "./identify.ts";
@@ -24,14 +26,14 @@ export async function handleOnMessage(message: any, shardId: number) {
if (typeof message !== "string") return; if (typeof message !== "string") return;
const messageData = JSON.parse(message); const messageData = JSON.parse(message) as DiscordGatewayPayload;
ws.log("RAW", messageData); ws.log("RAW", { shardId, payload: messageData});
switch (messageData.op) { switch (messageData.op) {
case DiscordGatewayOpcodes.Hello: case DiscordGatewayOpcodes.Hello:
ws.heartbeat( ws.heartbeat(
shardId, shardId,
(messageData.d as DiscordHeartbeat).heartbeat_interval, (messageData.d as DiscordHello).heartbeat_interval,
); );
break; break;
case DiscordGatewayOpcodes.HeartbeatACK: case DiscordGatewayOpcodes.HeartbeatACK:
@@ -99,6 +101,8 @@ export async function handleOnMessage(message: any, shardId: number) {
if (messageData.op !== DiscordGatewayOpcodes.Dispatch) return; if (messageData.op !== DiscordGatewayOpcodes.Dispatch) return;
if (!messageData.t) return;
return handlers[messageData.t]?.(messageData, shardId); return handlers[messageData.t]?.(messageData, shardId);
} }