mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-01 08:20:08 +00:00
fix: get rid of type errors for now (#2113)
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import type { Guild } from "../../transformers/guild.ts";
|
||||
import { DiscordGatewayPayload, DiscordGuild } from "../../types/discord.ts";
|
||||
|
||||
export function handleGuildCreate(bot: Bot, data: DiscordGatewayPayload, shardId: number) {
|
||||
const payload = data.d as DiscordGuild;
|
||||
bot.events.guildCreate(bot, bot.transformers.guild(bot, { guild: payload, shardId }));
|
||||
bot.events.guildCreate(bot, bot.transformers.guild(bot, { guild: payload, shardId }) as Guild);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import type { Guild } from "../../transformers/guild.ts";
|
||||
import { DiscordGatewayPayload, DiscordGuild } from "../../types/discord.ts";
|
||||
|
||||
export function handleGuildLoaded(bot: Bot, data: DiscordGatewayPayload, shardId: number) {
|
||||
const payload = data.d as DiscordGuild;
|
||||
|
||||
const guild = bot.transformers.guild(bot, { guild: payload, shardId });
|
||||
bot.events.guildLoaded(bot, guild);
|
||||
bot.events.guildLoaded(bot, guild as Guild);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import type { Guild } from "../../transformers/guild.ts";
|
||||
import { DiscordGatewayPayload, DiscordGuild } from "../../types/discord.ts";
|
||||
|
||||
export async function handleGuildUpdate(bot: Bot, data: DiscordGatewayPayload, shardId: number) {
|
||||
export function handleGuildUpdate(bot: Bot, data: DiscordGatewayPayload, shardId: number) {
|
||||
const payload = data.d as DiscordGuild;
|
||||
|
||||
bot.events.guildUpdate(bot, bot.transformers.guild(bot, { guild: payload, shardId }));
|
||||
bot.events.guildUpdate(bot, bot.transformers.guild(bot, { guild: payload, shardId }) as Guild);
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ export async function getScheduledEventUsers(
|
||||
return new Collection(
|
||||
result.map((res) => {
|
||||
const user = bot.transformers.user(bot, res.user);
|
||||
const member = bot.transformers.member(bot, res.member!, guildId, user.id);
|
||||
const member: Member = bot.transformers.member(bot, res.member!, guildId, user.id);
|
||||
|
||||
return [user.id, { member, user }];
|
||||
}),
|
||||
|
||||
3
plugins/cache/src/dispatchRequirements.ts
vendored
3
plugins/cache/src/dispatchRequirements.ts
vendored
@@ -1,3 +1,4 @@
|
||||
import type { Guild } from "../deps.ts";
|
||||
import { Bot, DiscordGatewayPayload } from "../deps.ts";
|
||||
import { BotWithCache } from "./addCacheCollections.ts";
|
||||
|
||||
@@ -55,7 +56,7 @@ export async function dispatchRequirements<B extends Bot>(
|
||||
.getGuild(id, {
|
||||
counts: true,
|
||||
})
|
||||
.catch(console.log));
|
||||
.catch(console.log)) as Guild;
|
||||
|
||||
if (!guild) {
|
||||
processing.delete(id);
|
||||
|
||||
10
plugins/cache/src/setupCacheRemovals.ts
vendored
10
plugins/cache/src/setupCacheRemovals.ts
vendored
@@ -1,3 +1,5 @@
|
||||
import type { Emoji, Guild } from "../deps.ts";
|
||||
import type { BotWithCache } from "./addCacheCollections.ts";
|
||||
import {
|
||||
Bot,
|
||||
Collection,
|
||||
@@ -10,7 +12,6 @@ import {
|
||||
DiscordMessageDeleteBulk,
|
||||
DiscordUnavailableGuild,
|
||||
} from "../deps.ts";
|
||||
import { BotWithCache } from "./addCacheCollections.ts";
|
||||
|
||||
export function setupCacheRemovals<B extends Bot>(bot: BotWithCache<B>) {
|
||||
const {
|
||||
@@ -67,10 +68,11 @@ export function setupCacheRemovals<B extends Bot>(bot: BotWithCache<B>) {
|
||||
bot.handlers.GUILD_EMOJIS_UPDATE = function (_, data, shardId) {
|
||||
const payload = data.d as DiscordGuildEmojisUpdate;
|
||||
|
||||
const guild = bot.guilds.get(bot.transformers.snowflake(payload.guild_id));
|
||||
const guild= bot.guilds.get(bot.transformers.snowflake(payload.guild_id));
|
||||
|
||||
if (guild) {
|
||||
guild.emojis = new Collection(payload.emojis.map((e) => {
|
||||
const emoji = bot.transformers.emoji(bot, e);
|
||||
guild.emojis! = new Collection(payload.emojis.map((e) => {
|
||||
const emoji: Emoji = bot.transformers.emoji(bot, e);
|
||||
return [emoji.id!, emoji];
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { Emoji } from "../transformers/emoji.ts";
|
||||
import { Bot } from "../bot.ts";
|
||||
import { Collection } from "../util/collection.ts";
|
||||
import { DiscordGuild } from "../types/discord.ts";
|
||||
@@ -69,7 +70,7 @@ export function transformGuild(
|
||||
),
|
||||
emojis: new Collection(
|
||||
(payload.guild.emojis || []).map((emoji) => {
|
||||
const em = bot.transformers.emoji(bot, emoji);
|
||||
const em: Emoji = bot.transformers.emoji(bot, emoji);
|
||||
return [em.id!, em];
|
||||
}),
|
||||
),
|
||||
|
||||
@@ -66,7 +66,7 @@ export function transformInteractionDataResolved(
|
||||
if (resolved.messages) {
|
||||
transformed.messages = new Collection(
|
||||
Object.entries(resolved.messages).map(([id, value]) => {
|
||||
const message = bot.transformers.message(bot, value);
|
||||
const message: Message = bot.transformers.message(bot, value);
|
||||
return [message.id, message];
|
||||
}),
|
||||
);
|
||||
@@ -84,7 +84,7 @@ export function transformInteractionDataResolved(
|
||||
if (guildId && resolved.members) {
|
||||
transformed.members = new Collection(
|
||||
Object.entries(resolved.members).map(([id, value]) => {
|
||||
const member = bot.transformers.member(bot, value, guildId, bot.transformers.snowflake(id));
|
||||
const member: Member = bot.transformers.member(bot, value, guildId, bot.transformers.snowflake(id));
|
||||
return [member.id, member];
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -1242,10 +1242,6 @@ export type Camelize<T> = {
|
||||
: never;
|
||||
};
|
||||
|
||||
export type KeysWithUndefined<T> = {
|
||||
[K in keyof T]-?: undefined extends T[K] ? K : never;
|
||||
}[keyof T];
|
||||
|
||||
// export type Optionalize<T> = T extends object ?
|
||||
// & {
|
||||
// [K in KeysWithUndefined<T>]?: Optionalize<T[K]>;
|
||||
@@ -1255,12 +1251,18 @@ export type KeysWithUndefined<T> = {
|
||||
// }
|
||||
// : T;
|
||||
|
||||
export type Optionalize<T> = {
|
||||
[K in KeysWithUndefined<T>]?: Optionalize<T[K]>
|
||||
} & {
|
||||
[K in Exclude<keyof T, KeysWithUndefined<T>>]: T[K] extends object
|
||||
? {} extends Pick<T[K], keyof T[K]>
|
||||
? T[K]
|
||||
: Optionalize<T[K]>
|
||||
: T[K]
|
||||
}
|
||||
export type KeysWithUndefined<T> = {
|
||||
[K in keyof T]-?: (undefined | null) extends T[K] ? K : never;
|
||||
}[keyof T];
|
||||
|
||||
export type Optionalize<T> = (
|
||||
& {
|
||||
[K in KeysWithUndefined<T>]?: Optionalize<T[K]>;
|
||||
}
|
||||
& {
|
||||
[K in Exclude<keyof T, KeysWithUndefined<T>>]: (
|
||||
// deno-lint-ignore ban-types
|
||||
T[K] extends object ? Object extends Pick<T[K], keyof T[K]> ? T[K] : Optionalize<T[K]> : T[K]
|
||||
);
|
||||
}
|
||||
);
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Bot } from "../bot.ts";
|
||||
|
||||
export class Collection<K, V> extends Map<K, V> {
|
||||
maxSize?: number;
|
||||
sweeper?: CollectionSweeper<K, V> & { intervalId?: number };
|
||||
maxSize: number | undefined;
|
||||
sweeper: CollectionSweeper<K, V> & { intervalId?: number } | undefined;
|
||||
|
||||
constructor(entries?: (readonly (readonly [K, V])[] | null) | Map<K, V>, options?: CollectionOptions<K, V>) {
|
||||
super(entries ?? []);
|
||||
|
||||
Reference in New Issue
Block a user