mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-16 22:21:51 +00:00
more fixes
Signed-off-by: GitHub <noreply@github.com>
This commit is contained in:
parent
e48ca5c075
commit
7c5e6eb91f
18 changed files with 51 additions and 45 deletions
|
@ -1,4 +1,4 @@
|
||||||
import { MessageEmbedOptions, MessageMentionTypes, Snowflake, TextChannel } from "discord.js";
|
import { MessageCreateOptions, MessageMentionTypes, Snowflake, TextChannel } from "discord.js";
|
||||||
import { GuildPluginData } from "knub";
|
import { GuildPluginData } from "knub";
|
||||||
import { allowTimeout } from "../../../RegExpRunner";
|
import { allowTimeout } from "../../../RegExpRunner";
|
||||||
import { ILogTypeData, LogsPluginType, TLogChannel, TLogChannelMap } from "../types";
|
import { ILogTypeData, LogsPluginType, TLogChannel, TLogChannelMap } from "../types";
|
||||||
|
@ -141,7 +141,7 @@ export async function log<TLogType extends keyof ILogTypeData>(
|
||||||
const buffer = pluginData.state.buffers.get(channelId)!;
|
const buffer = pluginData.state.buffers.get(channelId)!;
|
||||||
buffer.push({
|
buffer.push({
|
||||||
content: typeof message === "string" ? message : message.content || "",
|
content: typeof message === "string" ? message : message.content || "",
|
||||||
embeds: typeof message === "string" ? [] : ((message.embeds || []) as MessageEmbedOptions[]),
|
embeds: typeof message === "string" ? [] : ((message.embeds || []) as MessageCreateOptions[]),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { MessageEmbedOptions, User } from "discord.js";
|
import { EmbedData, MessageCreateOptions, User } from "discord.js";
|
||||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||||
import { sendErrorMessage } from "../../../pluginUtils";
|
import { sendErrorMessage } from "../../../pluginUtils";
|
||||||
import { emptyEmbedValue, resolveUser, trimLines } from "../../../utils";
|
import { emptyEmbedValue, resolveUser, trimLines } from "../../../utils";
|
||||||
|
@ -54,7 +54,7 @@ export const CasesModCmd = modActionsCmd({
|
||||||
const lastCaseNum = page * casesPerPage;
|
const lastCaseNum = page * casesPerPage;
|
||||||
const title = `Most recent cases ${firstCaseNum}-${lastCaseNum} of ${totalCases} by ${modName}`;
|
const title = `Most recent cases ${firstCaseNum}-${lastCaseNum} of ${totalCases} by ${modName}`;
|
||||||
|
|
||||||
const embed: MessageEmbedOptions = {
|
const embed: EmbedData = {
|
||||||
author: {
|
author: {
|
||||||
name: title,
|
name: title,
|
||||||
iconURL: mod instanceof User ? mod.displayAvatarURL() : undefined,
|
iconURL: mod instanceof User ? mod.displayAvatarURL() : undefined,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { MessageEmbedOptions, User } from "discord.js";
|
import { EmbedData, User } from "discord.js";
|
||||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||||
import { CaseTypes } from "../../../data/CaseTypes";
|
import { CaseTypes } from "../../../data/CaseTypes";
|
||||||
import { CasesPlugin } from "../../../plugins/Cases/CasesPlugin";
|
import { CasesPlugin } from "../../../plugins/Cases/CasesPlugin";
|
||||||
|
@ -116,13 +116,13 @@ export const CasesUserCmd = modActionsCmd({
|
||||||
const chunkStart = i * linesPerChunk + 1;
|
const chunkStart = i * linesPerChunk + 1;
|
||||||
const chunkEnd = Math.min((i + 1) * linesPerChunk, lines.length);
|
const chunkEnd = Math.min((i + 1) * linesPerChunk, lines.length);
|
||||||
|
|
||||||
const embed: MessageEmbedOptions = {
|
const embed: EmbedData = {
|
||||||
author: {
|
author: {
|
||||||
name:
|
name:
|
||||||
lineChunks.length === 1
|
lineChunks.length === 1
|
||||||
? `Cases for ${userName} (${lines.length} total)`
|
? `Cases for ${userName} (${lines.length} total)`
|
||||||
: `Cases ${chunkStart}–${chunkEnd} of ${lines.length} for ${userName}`,
|
: `Cases ${chunkStart}–${chunkEnd} of ${lines.length} for ${userName}`,
|
||||||
icon_url: user instanceof User ? user.displayAvatarURL() : undefined,
|
iconURL: user instanceof User ? user.displayAvatarURL() : undefined,
|
||||||
},
|
},
|
||||||
fields: [
|
fields: [
|
||||||
...getChunkedEmbedFields(emptyEmbedValue, linesInChunk.join("\n")),
|
...getChunkedEmbedFields(emptyEmbedValue, linesInChunk.join("\n")),
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { MessageEmbedOptions } from "discord.js";
|
import { EmbedData } from "discord.js";
|
||||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||||
import { sendErrorMessage } from "../../../pluginUtils";
|
import { sendErrorMessage } from "../../../pluginUtils";
|
||||||
import { isValidEmbed, trimLines } from "../../../utils";
|
import { isValidEmbed, trimLines } from "../../../utils";
|
||||||
|
@ -46,7 +46,7 @@ export const PostEmbedCmd = postCmd({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let embed: MessageEmbedOptions = {};
|
let embed: EmbedData = {};
|
||||||
if (args.title) embed.title = args.title;
|
if (args.title) embed.title = args.title;
|
||||||
if (color) embed.color = color;
|
if (color) embed.color = color;
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ export function createStarboardEmbedFromMessage(
|
||||||
embed.color = color;
|
embed.color = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
embed.author.icon_url = msg.author.displayAvatarURL({ dynamic: true });
|
embed.author.iconURL = msg.author.displayAvatarURL();
|
||||||
|
|
||||||
// The second condition here checks for messages with only an image link that is then embedded.
|
// The second condition here checks for messages with only an image link that is then embedded.
|
||||||
// The message content in that case is hidden by the Discord client, so we hide it here too.
|
// The message content in that case is hidden by the Discord client, so we hide it here too.
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Message, MessageEmbedOptions, Snowflake, TextChannel } from "discord.js";
|
import { EmbedData, Message, Snowflake, TextChannel } from "discord.js";
|
||||||
import { GuildPluginData } from "knub";
|
import { GuildPluginData } from "knub";
|
||||||
import { StarboardPluginType, TStarboardOpts } from "../types";
|
import { StarboardPluginType, TStarboardOpts } from "../types";
|
||||||
import { createStarboardEmbedFromMessage } from "./createStarboardEmbedFromMessage";
|
import { createStarboardEmbedFromMessage } from "./createStarboardEmbedFromMessage";
|
||||||
|
@ -16,6 +16,6 @@ export async function saveMessageToStarboard(
|
||||||
const embed = createStarboardEmbedFromMessage(msg, Boolean(starboard.copy_full_embed), starboard.color);
|
const embed = createStarboardEmbedFromMessage(msg, Boolean(starboard.copy_full_embed), starboard.color);
|
||||||
embed.fields!.push(createStarboardPseudoFooterForMessage(starboard, msg, starboard.star_emoji![0], starCount));
|
embed.fields!.push(createStarboardPseudoFooterForMessage(starboard, msg, starboard.star_emoji![0], starCount));
|
||||||
|
|
||||||
const starboardMessage = await (channel as TextChannel).send({ embeds: [embed as MessageEmbedOptions] });
|
const starboardMessage = await (channel as TextChannel).send({ embeds: [embed as EmbedData] });
|
||||||
await pluginData.state.starboardMessages.createStarboardMessage(channel.id, msg.id, starboardMessage.id);
|
await pluginData.state.starboardMessages.createStarboardMessage(channel.id, msg.id, starboardMessage.id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ export async function getChannelInfoEmbed(
|
||||||
|
|
||||||
embed.author = {
|
embed.author = {
|
||||||
name: `${channelType}: ${channel.name}`,
|
name: `${channelType}: ${channel.name}`,
|
||||||
icon_url: icon,
|
iconURL: icon,
|
||||||
};
|
};
|
||||||
|
|
||||||
let channelName = `#${channel.name}`;
|
let channelName = `#${channel.name}`;
|
||||||
|
|
|
@ -36,7 +36,7 @@ export async function getInviteInfoEmbed(
|
||||||
};
|
};
|
||||||
|
|
||||||
if (invite.guild.icon) {
|
if (invite.guild.icon) {
|
||||||
embed.author.icon_url = `https://cdn.discordapp.com/icons/${invite.guild.id}/${invite.guild.icon}.png?size=256`;
|
embed.author.iconURL = `https://cdn.discordapp.com/icons/${invite.guild.id}/${invite.guild.icon}.png?size=256`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (invite.guild.description) {
|
if (invite.guild.description) {
|
||||||
|
|
|
@ -31,7 +31,7 @@ export async function getMessageInfoEmbed(
|
||||||
|
|
||||||
embed.author = {
|
embed.author = {
|
||||||
name: `Message: ${message.id}`,
|
name: `Message: ${message.id}`,
|
||||||
icon_url: MESSAGE_ICON,
|
iconURL: MESSAGE_ICON,
|
||||||
};
|
};
|
||||||
|
|
||||||
const createdAt = moment.utc(message.createdAt, "x");
|
const createdAt = moment.utc(message.createdAt, "x");
|
||||||
|
|
|
@ -20,7 +20,7 @@ export async function getRoleInfoEmbed(
|
||||||
|
|
||||||
embed.author = {
|
embed.author = {
|
||||||
name: `Role: ${role.name}`,
|
name: `Role: ${role.name}`,
|
||||||
icon_url: MENTION_ICON,
|
iconURL: MENTION_ICON,
|
||||||
};
|
};
|
||||||
|
|
||||||
embed.color = role.color;
|
embed.color = role.color;
|
||||||
|
|
|
@ -21,7 +21,7 @@ export async function getSnowflakeInfoEmbed(
|
||||||
|
|
||||||
embed.author = {
|
embed.author = {
|
||||||
name: `Snowflake: ${snowflake}`,
|
name: `Snowflake: ${snowflake}`,
|
||||||
icon_url: SNOWFLAKE_ICON,
|
iconURL: SNOWFLAKE_ICON,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (showUnknownWarning) {
|
if (showUnknownWarning) {
|
||||||
|
|
|
@ -47,7 +47,7 @@ export async function getUserInfoEmbed(
|
||||||
};
|
};
|
||||||
|
|
||||||
const avatarURL = user.displayAvatarURL();
|
const avatarURL = user.displayAvatarURL();
|
||||||
embed.author.icon_url = avatarURL;
|
embed.author.iconURL = avatarURL;
|
||||||
|
|
||||||
const createdAt = moment.utc(user.createdAt, "x");
|
const createdAt = moment.utc(user.createdAt, "x");
|
||||||
const tzCreatedAt = requestMemberId
|
const tzCreatedAt = requestMemberId
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
import {
|
import {
|
||||||
|
ActionRowBuilder,
|
||||||
|
ButtonBuilder,
|
||||||
|
ButtonStyle,
|
||||||
GuildMember,
|
GuildMember,
|
||||||
Message,
|
Message,
|
||||||
MessageActionRow,
|
MessageActionRowComponent,
|
||||||
MessageButton,
|
MessageActionRowComponentBuilder,
|
||||||
MessageComponentInteraction,
|
MessageComponentInteraction,
|
||||||
PermissionsBitField,
|
PermissionsBitField,
|
||||||
Snowflake,
|
Snowflake,
|
||||||
|
@ -169,23 +172,23 @@ export async function displaySearch(
|
||||||
// Set up pagination reactions if needed. The reactions are cleared after a timeout.
|
// Set up pagination reactions if needed. The reactions are cleared after a timeout.
|
||||||
if (searchResult.totalResults > perPage) {
|
if (searchResult.totalResults > perPage) {
|
||||||
const idMod = `${searchMsg.id}:${moment.utc().valueOf()}`;
|
const idMod = `${searchMsg.id}:${moment.utc().valueOf()}`;
|
||||||
const buttons: MessageButton[] = [];
|
const buttons: ButtonBuilder[] = [];
|
||||||
|
|
||||||
buttons.push(
|
buttons.push(
|
||||||
new MessageButton()
|
new ButtonBuilder()
|
||||||
.setStyle("SECONDARY")
|
.setStyle(ButtonStyle.Secondary)
|
||||||
.setEmoji("⬅")
|
.setEmoji("⬅")
|
||||||
.setCustomId(`previousButton:${idMod}`)
|
.setCustomId(`previousButton:${idMod}`)
|
||||||
.setDisabled(currentPage === 1),
|
.setDisabled(currentPage === 1),
|
||||||
new MessageButton()
|
new ButtonBuilder()
|
||||||
.setStyle("SECONDARY")
|
.setStyle(ButtonStyle.Secondary)
|
||||||
.setEmoji("➡")
|
.setEmoji("➡")
|
||||||
.setCustomId(`nextButton:${idMod}`)
|
.setCustomId(`nextButton:${idMod}`)
|
||||||
.setDisabled(currentPage === searchResult.lastPage),
|
.setDisabled(currentPage === searchResult.lastPage),
|
||||||
new MessageButton().setStyle("SECONDARY").setEmoji("🔄").setCustomId(`reloadButton:${idMod}`),
|
new ButtonBuilder().setStyle(ButtonStyle.Secondary).setEmoji("🔄").setCustomId(`reloadButton:${idMod}`),
|
||||||
);
|
);
|
||||||
|
|
||||||
const row = new MessageActionRow().addComponents(buttons);
|
const row = new ActionRowBuilder<MessageActionRowComponentBuilder>().addComponents(buttons);
|
||||||
await searchMsg.edit({ content: result, components: [row] });
|
await searchMsg.edit({ content: result, components: [row] });
|
||||||
|
|
||||||
const collector = searchMsg.createMessageComponentCollector({ time: 2 * MINUTES });
|
const collector = searchMsg.createMessageComponentCollector({ time: 2 * MINUTES });
|
||||||
|
|
|
@ -3,6 +3,9 @@ import {
|
||||||
Client,
|
Client,
|
||||||
Constants,
|
Constants,
|
||||||
DiscordAPIError,
|
DiscordAPIError,
|
||||||
|
Embed,
|
||||||
|
EmbedData,
|
||||||
|
EmbedType,
|
||||||
Emoji,
|
Emoji,
|
||||||
escapeCodeBlock,
|
escapeCodeBlock,
|
||||||
Guild,
|
Guild,
|
||||||
|
@ -16,10 +19,8 @@ import {
|
||||||
InviteGuild,
|
InviteGuild,
|
||||||
LimitedCollection,
|
LimitedCollection,
|
||||||
Message,
|
Message,
|
||||||
MessageEmbed,
|
MessageCreateOptions,
|
||||||
MessageEmbedOptions,
|
|
||||||
MessageMentionOptions,
|
MessageMentionOptions,
|
||||||
MessageOptions,
|
|
||||||
PartialChannelData,
|
PartialChannelData,
|
||||||
PartialMessage,
|
PartialMessage,
|
||||||
Snowflake,
|
Snowflake,
|
||||||
|
@ -391,8 +392,7 @@ export const zEmbedInput = z.object({
|
||||||
.nullable(),
|
.nullable(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export type EmbedWith<T extends keyof MessageEmbedOptions> = MessageEmbedOptions &
|
export type EmbedWith<T extends keyof EmbedData> = EmbedData & Pick<Required<EmbedData>, T>;
|
||||||
Pick<Required<MessageEmbedOptions>, T>;
|
|
||||||
|
|
||||||
export const zStrictMessageContent = z.object({
|
export const zStrictMessageContent = z.object({
|
||||||
content: z.string().optional(),
|
content: z.string().optional(),
|
||||||
|
@ -405,7 +405,7 @@ export type ZStrictMessageContent = z.infer<typeof zStrictMessageContent>;
|
||||||
export type StrictMessageContent = {
|
export type StrictMessageContent = {
|
||||||
content?: string;
|
content?: string;
|
||||||
tts?: boolean;
|
tts?: boolean;
|
||||||
embeds?: MessageEmbedOptions[];
|
embeds?: EmbedData[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export const tStrictMessageContent = t.type({
|
export const tStrictMessageContent = t.type({
|
||||||
|
@ -647,7 +647,7 @@ interface MatchedURL extends URL {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getUrlsInString(str: string, onlyUnique = false): MatchedURL[] {
|
export function getUrlsInString(str: string, onlyUnique = false): MatchedURL[] {
|
||||||
let matches = [...str.match(urlRegex)];
|
let matches = [...(str.match(urlRegex) ?? [])];
|
||||||
if (onlyUnique) {
|
if (onlyUnique) {
|
||||||
matches = unique(matches);
|
matches = unique(matches);
|
||||||
}
|
}
|
||||||
|
@ -1405,7 +1405,7 @@ export async function resolveStickerId(bot: Client, id: Snowflake): Promise<Stic
|
||||||
export async function confirm(
|
export async function confirm(
|
||||||
channel: GuildTextBasedChannel,
|
channel: GuildTextBasedChannel,
|
||||||
userId: string,
|
userId: string,
|
||||||
content: MessageOptions,
|
content: MessageCreateOptions,
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
return waitForButtonConfirm(channel, content, { restrictToId: userId });
|
return waitForButtonConfirm(channel, content, { restrictToId: userId });
|
||||||
}
|
}
|
||||||
|
@ -1415,7 +1415,7 @@ export function messageSummary(msg: SavedMessage) {
|
||||||
let result = "```\n" + (msg.data.content ? escapeCodeBlock(msg.data.content) : "<no text content>") + "```";
|
let result = "```\n" + (msg.data.content ? escapeCodeBlock(msg.data.content) : "<no text content>") + "```";
|
||||||
|
|
||||||
// Rich embed
|
// Rich embed
|
||||||
const richEmbed = (msg.data.embeds || []).find((e) => (e as MessageEmbed).type === "rich");
|
const richEmbed = (msg.data.embeds || []).find((e) => (e as EmbedData).type === EmbedType.Rich);
|
||||||
if (richEmbed) result += "Embed:```" + escapeCodeBlock(JSON.stringify(richEmbed)) + "```";
|
if (richEmbed) result += "Embed:```" + escapeCodeBlock(JSON.stringify(richEmbed)) + "```";
|
||||||
|
|
||||||
// Attachments
|
// Attachments
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { MessageEmbedOptions } from "discord.js";
|
import { EmbedData } from "discord.js";
|
||||||
|
|
||||||
function sumStringLengthsRecursively(obj: any): number {
|
function sumStringLengthsRecursively(obj: any): number {
|
||||||
if (obj == null) return 0;
|
if (obj == null) return 0;
|
||||||
|
@ -12,6 +12,6 @@ function sumStringLengthsRecursively(obj: any): number {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function calculateEmbedSize(embed: MessageEmbedOptions): number {
|
export function calculateEmbedSize(embed: EmbedData): number {
|
||||||
return sumStringLengthsRecursively(embed);
|
return sumStringLengthsRecursively(embed);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
import {
|
import {
|
||||||
Client,
|
Client,
|
||||||
|
GuildTextBasedChannel,
|
||||||
Message,
|
Message,
|
||||||
|
MessageCreateOptions,
|
||||||
MessageEditOptions,
|
MessageEditOptions,
|
||||||
MessageOptions,
|
|
||||||
MessageReaction,
|
MessageReaction,
|
||||||
PartialMessageReaction,
|
PartialMessageReaction,
|
||||||
PartialUser,
|
PartialUser,
|
||||||
|
TextBasedChannel,
|
||||||
TextChannel,
|
TextChannel,
|
||||||
User,
|
User,
|
||||||
} from "discord.js";
|
} from "discord.js";
|
||||||
|
@ -13,7 +15,7 @@ import { Awaitable } from "knub/dist/utils";
|
||||||
import { MINUTES, noop } from "../utils";
|
import { MINUTES, noop } from "../utils";
|
||||||
import Timeout = NodeJS.Timeout;
|
import Timeout = NodeJS.Timeout;
|
||||||
|
|
||||||
export type LoadPageFn = (page: number) => Awaitable<MessageOptions & MessageEditOptions>;
|
export type LoadPageFn = (page: number) => Awaitable<MessageCreateOptions & MessageEditOptions>;
|
||||||
|
|
||||||
export interface PaginateMessageOpts {
|
export interface PaginateMessageOpts {
|
||||||
timeout: number;
|
timeout: number;
|
||||||
|
@ -27,7 +29,7 @@ const defaultOpts: PaginateMessageOpts = {
|
||||||
|
|
||||||
export async function createPaginatedMessage(
|
export async function createPaginatedMessage(
|
||||||
client: Client,
|
client: Client,
|
||||||
channel: TextChannel | User,
|
channel: TextBasedChannel | User,
|
||||||
totalPages: number,
|
totalPages: number,
|
||||||
loadPageFn: LoadPageFn,
|
loadPageFn: LoadPageFn,
|
||||||
opts: Partial<PaginateMessageOpts> = {},
|
opts: Partial<PaginateMessageOpts> = {},
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { MessageOptions } from "discord.js";
|
import { MessageOptions } from "child_process";
|
||||||
|
import { MessageCreateOptions, MessagePayload } from "discord.js";
|
||||||
|
|
||||||
function embedHasContent(embed: any) {
|
function embedHasContent(embed: any) {
|
||||||
for (const [key, value] of Object.entries(embed)) {
|
for (const [key, value] of Object.entries(embed)) {
|
||||||
|
@ -18,7 +19,7 @@ function embedHasContent(embed: any) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function messageHasContent(content: string | MessageOptions): boolean {
|
export function messageHasContent(content: string | MessageCreateOptions): boolean {
|
||||||
if (typeof content === "string") {
|
if (typeof content === "string") {
|
||||||
return content.trim() !== "";
|
return content.trim() !== "";
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { MessageOptions } from "discord.js";
|
import { MessageCreateOptions } from "discord.js";
|
||||||
import { messageHasContent } from "./messageHasContent";
|
import { messageHasContent } from "./messageHasContent";
|
||||||
|
|
||||||
export function messageIsEmpty(content: string | MessageOptions): boolean {
|
export function messageIsEmpty(content: string | MessageCreateOptions): boolean {
|
||||||
return !messageHasContent(content);
|
return !messageHasContent(content);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue