mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-02 17:00:08 +00:00
Merge branch 'main' of https://github.com/discordeno/discordeno into main
This commit is contained in:
17
plugins/cache/src/addCacheCollections.ts
vendored
17
plugins/cache/src/addCacheCollections.ts
vendored
@@ -2,7 +2,6 @@ import {
|
||||
Bot,
|
||||
Channel,
|
||||
Collection,
|
||||
FinalHelpers,
|
||||
Guild,
|
||||
Member,
|
||||
Message,
|
||||
@@ -12,14 +11,16 @@ import {
|
||||
Webhook,
|
||||
} from "../deps.ts";
|
||||
|
||||
export type BotWithCache<B extends Bot = Bot> = B & CacheProps & { helpers: BotHelpersWithCache };
|
||||
export type BotWithCache<B extends Bot = Bot> = Omit<B, "helpers"> & CacheProps & {
|
||||
helpers: BotHelpersWithCache<B["helpers"]>;
|
||||
};
|
||||
|
||||
export interface BotHelpersWithCache extends FinalHelpers {
|
||||
export type BotHelpersWithCache<T> = Omit<T, "editWebhook"> & {
|
||||
/** The added channelId argument at the end is used to validate permission checks */
|
||||
editWebhook: (webhookId: bigint, options: ModifyWebhook, channelId?: bigint) => Promise<Webhook>;
|
||||
}
|
||||
editWebhook: (webhookId: bigint, options: ModifyWebhook, fromChannelId?: bigint) => Promise<Webhook>;
|
||||
};
|
||||
|
||||
export interface CacheProps extends Bot {
|
||||
export interface CacheProps {
|
||||
guilds: Collection<bigint, Guild>;
|
||||
users: Collection<bigint, User>;
|
||||
members: Collection<bigint, Member>;
|
||||
@@ -32,7 +33,7 @@ export interface CacheProps extends Bot {
|
||||
}
|
||||
|
||||
export function addCacheCollections<B extends Bot>(bot: B): BotWithCache<B> {
|
||||
const cacheBot = bot as BotWithCache<B>;
|
||||
const cacheBot = bot as unknown as BotWithCache<B>;
|
||||
cacheBot.guilds = new Collection();
|
||||
cacheBot.users = new Collection();
|
||||
cacheBot.members = new Collection();
|
||||
@@ -43,5 +44,5 @@ export function addCacheCollections<B extends Bot>(bot: B): BotWithCache<B> {
|
||||
cacheBot.dispatchedChannelIds = new Set();
|
||||
cacheBot.activeGuildIds = new Set();
|
||||
|
||||
return bot as BotWithCache<B>;
|
||||
return cacheBot;
|
||||
}
|
||||
|
||||
@@ -4,10 +4,9 @@ import { requireBotChannelPermissions } from "../permissions.ts";
|
||||
export default function editWebhook(bot: BotWithCache) {
|
||||
const editWebhookOld = bot.helpers.editWebhook;
|
||||
|
||||
// @ts-ignore TODO: itoh need a better way for this
|
||||
bot.helpers.editWebhook = async function (webhookId, options, channelId) {
|
||||
bot.helpers.editWebhook = async function (webhookId, options, fromChannelId) {
|
||||
if (options.channelId) requireBotChannelPermissions(bot, options.channelId, ["MANAGE_WEBHOOKS"]);
|
||||
if (channelId) requireBotChannelPermissions(bot, channelId, ["MANAGE_WEBHOOKS"]);
|
||||
if (fromChannelId) requireBotChannelPermissions(bot, fromChannelId, ["MANAGE_WEBHOOKS"]);
|
||||
|
||||
if (options.name) {
|
||||
if (
|
||||
|
||||
Reference in New Issue
Block a user