This commit is contained in:
Skillz4Killz
2022-03-22 10:17:44 +00:00
committed by GitHub
2 changed files with 11 additions and 11 deletions

View File

@@ -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;
}

View File

@@ -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 (