mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 12:25:02 +00:00
Type fixes for djs
This commit is contained in:
parent
653d6c1dc2
commit
0822fc15e5
130 changed files with 8877 additions and 411 deletions
|
@ -1,4 +1,4 @@
|
|||
import { Guild, GuildMember, Permissions, Role } from "discord.js";
|
||||
import { Guild, GuildMember, Permissions, Role, Snowflake } from "discord.js";
|
||||
import { getMissingPermissions } from "./getMissingPermissions";
|
||||
import { hasDiscordPermissions } from "./hasDiscordPermissions";
|
||||
|
||||
|
@ -11,7 +11,7 @@ export function canAssignRole(guild: Guild, member: GuildMember, roleId: string)
|
|||
return false;
|
||||
}
|
||||
|
||||
const targetRole = guild.roles.cache.get(roleId);
|
||||
const targetRole = guild.roles.cache.get(roleId as Snowflake);
|
||||
if (!targetRole) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ export async function createPaginatedMessage(
|
|||
): Promise<Message> {
|
||||
const fullOpts = { ...defaultOpts, ...opts } as PaginateMessageOpts;
|
||||
const firstPageContent = await loadPageFn(1);
|
||||
const message = await channel.send({ content: firstPageContent });
|
||||
const message = await channel.send(firstPageContent);
|
||||
|
||||
let page = 1;
|
||||
let pageLoadId = 0; // Used to avoid race conditions when rapidly switching pages
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { MessageMentionOptions, MessageMentionTypes } from "discord.js";
|
||||
import { MessageMentionOptions, MessageMentionTypes, Snowflake } from "discord.js";
|
||||
|
||||
export function erisAllowedMentionsToDjsMentionOptions(
|
||||
allowedMentions: ErisAllowedMentionFormat | undefined,
|
||||
|
@ -6,17 +6,17 @@ export function erisAllowedMentionsToDjsMentionOptions(
|
|||
if (allowedMentions === undefined) return undefined;
|
||||
|
||||
const parse: MessageMentionTypes[] = [];
|
||||
let users: string[] | undefined;
|
||||
let roles: string[] | undefined;
|
||||
let users: Snowflake[] | undefined;
|
||||
let roles: Snowflake[] | undefined;
|
||||
|
||||
if (Array.isArray(allowedMentions.users)) {
|
||||
users = allowedMentions.users;
|
||||
users = allowedMentions.users as Snowflake[];
|
||||
} else if (allowedMentions.users === true) {
|
||||
parse.push("users");
|
||||
}
|
||||
|
||||
if (Array.isArray(allowedMentions.roles)) {
|
||||
roles = allowedMentions.roles;
|
||||
roles = allowedMentions.roles as Snowflake[];
|
||||
} else if (allowedMentions.roles === true) {
|
||||
parse.push("roles");
|
||||
}
|
||||
|
|
|
@ -9,12 +9,12 @@ export function getMissingPermissions(
|
|||
resolvedPermissions: Permissions | Readonly<Permissions>,
|
||||
requiredPermissions: number | bigint,
|
||||
): bigint {
|
||||
const allowedPermissions = BigInt(resolvedPermissions);
|
||||
const nRequiredPermissions = BigInt(requiredPermissions);
|
||||
const allowedPermissions = resolvedPermissions;
|
||||
const nRequiredPermissions = requiredPermissions;
|
||||
|
||||
if (Boolean(allowedPermissions & BigInt(Permissions.FLAGS.ADMINISTRATOR))) {
|
||||
if (Boolean(allowedPermissions.bitfield & Permissions.FLAGS.ADMINISTRATOR)) {
|
||||
return BigInt(0);
|
||||
}
|
||||
|
||||
return nRequiredPermissions & ~allowedPermissions;
|
||||
return BigInt(nRequiredPermissions) & ~allowedPermissions.bitfield;
|
||||
}
|
||||
|
|
|
@ -8,12 +8,12 @@ export function hasDiscordPermissions(
|
|||
resolvedPermissions: Permissions | Readonly<Permissions> | null,
|
||||
requiredPermissions: number | bigint,
|
||||
) {
|
||||
const allowedPermissions = BigInt(resolvedPermissions);
|
||||
const nRequiredPermissions = BigInt(requiredPermissions);
|
||||
const allowedPermissions = resolvedPermissions;
|
||||
const nRequiredPermissions = requiredPermissions;
|
||||
|
||||
if (Boolean(allowedPermissions & BigInt(Permissions.FLAGS.ADMINISTRATOR))) {
|
||||
if (Boolean(allowedPermissions?.bitfield! & Permissions.FLAGS.ADMINISTRATOR)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return Boolean((allowedPermissions & nRequiredPermissions) === nRequiredPermissions);
|
||||
return Boolean((allowedPermissions?.bitfield! & BigInt(nRequiredPermissions)) === nRequiredPermissions);
|
||||
}
|
||||
|
|
|
@ -27,8 +27,12 @@ export function messageHasContent(content: string | MessageOptions): boolean {
|
|||
return true;
|
||||
}
|
||||
|
||||
if (content.embed && embedHasContent(content.embed)) {
|
||||
return true;
|
||||
if (content.embeds) {
|
||||
for (const embed of content.embeds) {
|
||||
if (embed && embedHasContent(embed)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { TextChannel } from "discord.js";
|
||||
import { Snowflake, TextChannel } from "discord.js";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { getChannelIdFromMessageId } from "../data/getChannelIdFromMessageId";
|
||||
import { isSnowflake } from "../utils";
|
||||
|
@ -46,7 +46,7 @@ export async function resolveMessageTarget(pluginData: GuildPluginData<any>, val
|
|||
return null;
|
||||
}
|
||||
|
||||
const channel = pluginData.guild.channels.resolve(result.channelId);
|
||||
const channel = pluginData.guild.channels.resolve(result.channelId as Snowflake);
|
||||
if (!channel || !(channel instanceof TextChannel)) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { APIMessage, User } from "discord.js";
|
||||
import { MessagePayload, User } from "discord.js";
|
||||
import { logger } from "../logger";
|
||||
import { createChunkedMessage, HOURS, isDiscordRESTError } from "../utils";
|
||||
import Timeout = NodeJS.Timeout;
|
||||
|
@ -16,7 +16,7 @@ export class DMError extends Error {}
|
|||
|
||||
const error20026 = "The bot cannot currently send DMs";
|
||||
|
||||
export async function sendDM(user: User, content: string | APIMessage, source: string) {
|
||||
export async function sendDM(user: User, content: string | MessagePayload, source: string) {
|
||||
if (dmsDisabled) {
|
||||
throw new DMError(error20026);
|
||||
}
|
||||
|
|
|
@ -13,23 +13,21 @@ export async function waitForButtonConfirm(
|
|||
new MessageButton()
|
||||
.setStyle("SUCCESS")
|
||||
.setLabel(options?.confirmText || "Confirm")
|
||||
.setType("BUTTON")
|
||||
.setCustomID(`confirmButton:${idMod}`),
|
||||
|
||||
new MessageButton()
|
||||
.setStyle("DANGER")
|
||||
.setLabel(options?.cancelText || "Cancel")
|
||||
.setType("BUTTON")
|
||||
.setCustomID(`cancelButton:${idMod}`),
|
||||
]);
|
||||
const message = await channel.send({ ...toPost, components: [row], split: false });
|
||||
const message = await channel.send({ ...toPost, components: [row] });
|
||||
|
||||
const filter = (iac: MessageComponentInteraction) => iac.message.id === message.id;
|
||||
const collector = message.createMessageComponentInteractionCollector(filter, { time: 10000 });
|
||||
const collector = message.createMessageComponentInteractionCollector({ filter, time: 10000 });
|
||||
|
||||
collector.on("collect", (interaction: MessageComponentInteraction) => {
|
||||
if (options?.restrictToId && options.restrictToId !== interaction.user.id) {
|
||||
interaction.reply(`You are not permitted to use these buttons.`, { ephemeral: true });
|
||||
interaction.reply({ content: `You are not permitted to use these buttons.`, ephemeral: true });
|
||||
} else {
|
||||
if (interaction.customID === `confirmButton:${idMod}`) {
|
||||
message.delete();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue