mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-15 05:41:51 +00:00
djs typings: Attachment & Util
Signed-off-by: GitHub <noreply@github.com>
This commit is contained in:
parent
aad4ad82a5
commit
010451c7e7
19 changed files with 49 additions and 44 deletions
|
@ -1,4 +1,4 @@
|
|||
import { MessageAttachment } from "discord.js";
|
||||
import { Attachment } from "discord.js";
|
||||
import { Column, Entity, PrimaryColumn, PrimaryGeneratedColumn } from "typeorm";
|
||||
import { StrictMessageContent } from "../../utils";
|
||||
|
||||
|
@ -17,7 +17,7 @@ export class ScheduledPost {
|
|||
|
||||
@Column("simple-json") content: StrictMessageContent;
|
||||
|
||||
@Column("simple-json") attachments: MessageAttachment[];
|
||||
@Column("simple-json") attachments: Attachment[];
|
||||
|
||||
@Column({ type: String, nullable: true }) post_at: string | null;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Snowflake, TextChannel, Util } from "discord.js";
|
||||
import { escapeInlineCode, Snowflake, TextChannel } from "discord.js";
|
||||
import * as t from "io-ts";
|
||||
import { asSingleLine, messageSummary, verboseChannelMention } from "../../../utils";
|
||||
import { automodTrigger } from "../helpers";
|
||||
|
@ -71,7 +71,7 @@ export const MatchAttachmentTypeTrigger = automodTrigger<MatchResultType>()({
|
|||
|
||||
return (
|
||||
asSingleLine(`
|
||||
Matched attachment type \`${Util.escapeInlineCode(matchResult.extra.matchedType)}\`
|
||||
Matched attachment type \`${escapeInlineCode(matchResult.extra.matchedType)}\`
|
||||
(${matchResult.extra.mode === "blacklist" ? "blacklisted" : "not in whitelist"})
|
||||
in message (\`${contexts[0].message!.id}\`) in ${prettyChannel}:
|
||||
`) + messageSummary(contexts[0].message!)
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import { Util } from "discord.js";
|
||||
import escapeStringRegexp from "escape-string-regexp";
|
||||
import * as t from "io-ts";
|
||||
import { allowTimeout } from "../../../RegExpRunner";
|
||||
|
@ -11,6 +10,7 @@ import { mergeRegexes } from "../../../utils/mergeRegexes";
|
|||
import { mergeWordsIntoRegex } from "../../../utils/mergeWordsIntoRegex";
|
||||
import { PhishermanPlugin } from "../../Phisherman/PhishermanPlugin";
|
||||
import { phishermanDomainIsSafe } from "../../../data/Phisherman";
|
||||
import { escapeInlineCode } from "discord.js";
|
||||
|
||||
interface MatchResultType {
|
||||
type: MatchableTextType;
|
||||
|
@ -186,7 +186,7 @@ export const MatchLinksTrigger = automodTrigger<MatchResultType>()({
|
|||
|
||||
renderMatchInformation({ pluginData, contexts, matchResult }) {
|
||||
const partialSummary = getTextMatchPartialSummary(pluginData, matchResult.extra.type, contexts[0]);
|
||||
let information = `Matched link \`${Util.escapeInlineCode(matchResult.extra.link)}\``;
|
||||
let information = `Matched link \`${escapeInlineCode(matchResult.extra.link)}\``;
|
||||
if (matchResult.extra.details) {
|
||||
information += ` ${matchResult.extra.details}`;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { automodTrigger } from "../helpers";
|
||||
import * as t from "io-ts";
|
||||
import { asSingleLine, messageSummary, verboseChannelMention } from "../../../utils";
|
||||
import { GuildChannel, Util } from "discord.js";
|
||||
import { escapeInlineCode, GuildChannel } from "discord.js";
|
||||
|
||||
interface MatchResultType {
|
||||
matchedType: string;
|
||||
|
@ -71,7 +71,7 @@ export const MatchMimeTypeTrigger = automodTrigger<MatchResultType>()({
|
|||
|
||||
return (
|
||||
asSingleLine(`
|
||||
Matched MIME type \`${Util.escapeInlineCode(matchedType)}\`
|
||||
Matched MIME type \`${escapeInlineCode(matchedType)}\`
|
||||
(${mode === "blacklist" ? "blacklisted" : "not in whitelist"})
|
||||
in message (\`${message!.id}\`) in ${prettyChannel}
|
||||
`) + messageSummary(message!)
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import { Util } from "discord.js";
|
||||
import escapeStringRegexp from "escape-string-regexp";
|
||||
import * as t from "io-ts";
|
||||
import { normalizeText } from "../../../utils/normalizeText";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Snowflake } from "discord-api-types/v9";
|
||||
import { User, Util } from "discord.js";
|
||||
import { escapeBold, User } from "discord.js";
|
||||
import * as t from "io-ts";
|
||||
import { tNullable } from "../../../utils";
|
||||
import { automodTrigger } from "../helpers";
|
||||
|
@ -49,7 +49,7 @@ export const ThreadArchiveTrigger = automodTrigger<ThreadArchiveResult>()({
|
|||
const parentName = matchResult.extra.matchedThreadParentName;
|
||||
const base = `Thread **#${threadName}** (\`${threadId}\`) has been archived in the **#${parentName}** (\`${parentId}\`) channel`;
|
||||
if (threadOwner) {
|
||||
return `${base} by **${Util.escapeBold(threadOwner.tag)}** (\`${threadOwner.id}\`)`;
|
||||
return `${base} by **${escapeBold(threadOwner.tag)}** (\`${threadOwner.id}\`)`;
|
||||
}
|
||||
return base;
|
||||
},
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Snowflake } from "discord-api-types/v9";
|
||||
import { User, Util } from "discord.js";
|
||||
import { escapeBold, User } from "discord.js";
|
||||
import * as t from "io-ts";
|
||||
import { automodTrigger } from "../helpers";
|
||||
|
||||
|
@ -41,7 +41,7 @@ export const ThreadCreateTrigger = automodTrigger<ThreadCreateResult>()({
|
|||
const parentName = matchResult.extra.matchedThreadParentName;
|
||||
const base = `Thread **#${threadName}** (\`${threadId}\`) has been created in the **#${parentName}** (\`${parentId}\`) channel`;
|
||||
if (threadOwner) {
|
||||
return `${base} by **${Util.escapeBold(threadOwner.tag)}** (\`${threadOwner.id}\`)`;
|
||||
return `${base} by **${escapeBold(threadOwner.tag)}** (\`${threadOwner.id}\`)`;
|
||||
}
|
||||
return base;
|
||||
},
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Snowflake } from "discord-api-types/v9";
|
||||
import { User, Util } from "discord.js";
|
||||
import { escapeBold, User } from "discord.js";
|
||||
import * as t from "io-ts";
|
||||
import { automodTrigger } from "../helpers";
|
||||
|
||||
|
@ -40,7 +40,7 @@ export const ThreadDeleteTrigger = automodTrigger<ThreadDeleteResult>()({
|
|||
const parentId = matchResult.extra.matchedThreadParentId;
|
||||
const parentName = matchResult.extra.matchedThreadParentName;
|
||||
if (threadOwner) {
|
||||
return `Thread **#${threadName ?? "Unknown"}** (\`${threadId}\`) created by **${Util.escapeBold(
|
||||
return `Thread **#${threadName ?? "Unknown"}** (\`${threadId}\`) created by **${escapeBold(
|
||||
threadOwner.tag,
|
||||
)}** (\`${threadOwner.id}\`) in the **#${parentName}** (\`${parentId}\`) channel has been deleted`;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Snowflake } from "discord-api-types/v9";
|
||||
import { User, Util } from "discord.js";
|
||||
import { escapeBold, User } from "discord.js";
|
||||
import * as t from "io-ts";
|
||||
import { tNullable } from "../../../utils";
|
||||
import { automodTrigger } from "../helpers";
|
||||
|
@ -49,7 +49,7 @@ export const ThreadUnarchiveTrigger = automodTrigger<ThreadUnarchiveResult>()({
|
|||
const parentName = matchResult.extra.matchedThreadParentName;
|
||||
const base = `Thread **#${threadName}** (\`${threadId}\`) has been unarchived in the **#${parentName}** (\`${parentId}\`) channel`;
|
||||
if (threadOwner) {
|
||||
return `${base} by **${Util.escapeBold(threadOwner.tag)}** (\`${threadOwner.id}\`)`;
|
||||
return `${base} by **${escapeBold(threadOwner.tag)}** (\`${threadOwner.id}\`)`;
|
||||
}
|
||||
return base;
|
||||
},
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { MessageEditOptions, MessageOptions, Util } from "discord.js";
|
||||
import { escapeCodeBlock, MessageEditOptions, MessageOptions } from "discord.js";
|
||||
import { GuildPluginData } from "knub";
|
||||
import moment from "moment-timezone";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
|
@ -67,7 +67,7 @@ export async function getCaseEmbed(
|
|||
if (theCase.notes.length) {
|
||||
for (const note of theCase.notes) {
|
||||
const noteDate = moment.utc(note.created_at);
|
||||
let noteBody = Util.escapeCodeBlock(note.body.trim());
|
||||
let noteBody = escapeCodeBlock(note.body.trim());
|
||||
if (noteBody === "") {
|
||||
noteBody = emptyEmbedValue;
|
||||
}
|
||||
|
|
|
@ -35,7 +35,6 @@ import { log } from "./util/log";
|
|||
import { onMessageDelete } from "./util/onMessageDelete";
|
||||
import { onMessageDeleteBulk } from "./util/onMessageDeleteBulk";
|
||||
import { onMessageUpdate } from "./util/onMessageUpdate";
|
||||
import { Util } from "discord.js";
|
||||
import {
|
||||
createTypedTemplateSafeValueContainer,
|
||||
TemplateSafeValueContainer,
|
||||
|
@ -113,6 +112,7 @@ import { logVoiceChannelMove } from "./logFunctions/logVoiceChannelMove";
|
|||
import { logMemberTimedUnban } from "./logFunctions/logMemberTimedUnban";
|
||||
import { logDmFailed } from "./logFunctions/logDmFailed";
|
||||
import { InternalPosterPlugin } from "../InternalPoster/InternalPosterPlugin";
|
||||
import { escapeCodeBlock } from "discord.js";
|
||||
|
||||
const defaultOptions: PluginOptions<LogsPluginType> = {
|
||||
config: {
|
||||
|
@ -300,7 +300,7 @@ export const LogsPlugin = zeppelinGuildPlugin<LogsPluginType>()({
|
|||
The following regex has taken longer than ${timeoutMs}ms for ${failedTimes} times and has been temporarily disabled:
|
||||
`.trim() +
|
||||
"\n```" +
|
||||
Util.escapeCodeBlock(regexSource) +
|
||||
escapeCodeBlock(regexSource) +
|
||||
"```",
|
||||
}),
|
||||
);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { MessageAttachment } from "discord.js";
|
||||
import { Attachment } from "discord.js";
|
||||
|
||||
export function formatReasonWithAttachments(reason: string, attachments: MessageAttachment[]) {
|
||||
export function formatReasonWithAttachments(reason: string, attachments: Attachment[]) {
|
||||
const attachmentUrls = attachments.map((a) => a.url);
|
||||
return ((reason || "") + " " + attachmentUrls.join(" ")).trim();
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Util } from "discord.js";
|
||||
import { escapeCodeBlock } from "discord.js";
|
||||
import humanizeDuration from "humanize-duration";
|
||||
import moment from "moment-timezone";
|
||||
import { createChunkedMessage, DBDateFormat, deactivateMentions, sorter, trimLines } from "../../../utils";
|
||||
|
@ -26,7 +26,7 @@ export const ScheduledPostsListCmd = postCmd({
|
|||
|
||||
const isTruncated = previewText.length > SCHEDULED_POST_PREVIEW_TEXT_LENGTH;
|
||||
|
||||
previewText = Util.escapeCodeBlock(deactivateMentions(previewText))
|
||||
previewText = escapeCodeBlock(deactivateMentions(previewText))
|
||||
.replace(/\s+/g, " ")
|
||||
.slice(0, SCHEDULED_POST_PREVIEW_TEXT_LENGTH);
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import {
|
||||
Attachment,
|
||||
GuildTextBasedChannel,
|
||||
Message,
|
||||
MessageAttachment,
|
||||
MessageOptions,
|
||||
NewsChannel,
|
||||
TextChannel,
|
||||
|
@ -19,7 +19,7 @@ export async function postMessage(
|
|||
pluginData: GuildPluginData<PostPluginType>,
|
||||
channel: GuildTextBasedChannel,
|
||||
content: MessageOptions,
|
||||
attachments: MessageAttachment[] = [],
|
||||
attachments: Attachment[] = [],
|
||||
enableMentions: boolean = false,
|
||||
): Promise<Message> {
|
||||
if (typeof content === "string") {
|
||||
|
|
|
@ -1,4 +1,11 @@
|
|||
import { ChannelType, GuildTextBasedChannel, PermissionsBitField, TextChannel, ThreadChannel, Util } from "discord.js";
|
||||
import {
|
||||
ChannelType,
|
||||
escapeInlineCode,
|
||||
GuildTextBasedChannel,
|
||||
PermissionsBitField,
|
||||
TextChannel,
|
||||
ThreadChannel,
|
||||
} from "discord.js";
|
||||
import humanizeDuration from "humanize-duration";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
|
@ -132,7 +139,7 @@ export const SlowmodeSetCmd = slowmodeCmd({
|
|||
rateLimitPerUser: rateLimitSeconds,
|
||||
});
|
||||
} catch (e) {
|
||||
sendErrorMessage(pluginData, msg.channel, `Failed to set native slowmode: ${Util.escapeInlineCode(e.message)}`);
|
||||
sendErrorMessage(pluginData, msg.channel, `Failed to set native slowmode: ${escapeInlineCode(e.message)}`);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Util } from "discord.js";
|
||||
import { escapeInlineCode } from "discord.js";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
import { trimLines } from "../../../utils";
|
||||
|
@ -20,7 +20,7 @@ export const SetTimezoneCmd = timeAndDateCmd({
|
|||
pluginData,
|
||||
message.channel,
|
||||
trimLines(`
|
||||
Invalid timezone: \`${Util.escapeInlineCode(args.timezone)}\`
|
||||
Invalid timezone: \`${escapeInlineCode(args.timezone)}\`
|
||||
Zeppelin uses timezone locations rather than specific timezone names.
|
||||
See the **TZ database name** column at <https://en.wikipedia.org/wiki/List_of_tz_database_time_zones> for a list of valid options.
|
||||
`),
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { MessageAttachment } from "discord.js";
|
||||
import { Attachment, AttachmentBuilder } from "discord.js";
|
||||
import fs from "fs";
|
||||
import photon from "@silvia-odwyer/photon-node";
|
||||
import twemoji from "twemoji";
|
||||
|
@ -50,7 +50,7 @@ export const JumboCmd = utilityCmd({
|
|||
const emojiRegex = new RegExp(`(<.*:).*:(\\d+)`);
|
||||
const results = emojiRegex.exec(args.emoji);
|
||||
let extension = ".png";
|
||||
let file: MessageAttachment | undefined;
|
||||
let file: AttachmentBuilder | undefined;
|
||||
|
||||
if (!isEmoji(args.emoji)) {
|
||||
sendErrorMessage(pluginData, msg.channel, "Invalid emoji");
|
||||
|
@ -65,10 +65,10 @@ export const JumboCmd = utilityCmd({
|
|||
url += `${results[2]}${extension}`;
|
||||
if (extension === ".png") {
|
||||
const image = resizeBuffer(await getBufferFromUrl(url), size, size);
|
||||
file = new MessageAttachment(image, `emoji${extension}`);
|
||||
file = new AttachmentBuilder(image, { name: `emoji${extension}` });
|
||||
} else {
|
||||
const image = await getBufferFromUrl(url);
|
||||
file = new MessageAttachment(image, `emoji${extension}`);
|
||||
file = new AttachmentBuilder(image, { name: `emoji${extension}` });
|
||||
}
|
||||
} else {
|
||||
let url = `${twemoji.base}${twemoji.size}/${twemoji.convert.toCodePoint(args.emoji)}${twemoji.ext}`;
|
||||
|
@ -87,7 +87,7 @@ export const JumboCmd = utilityCmd({
|
|||
return;
|
||||
}
|
||||
|
||||
file = new MessageAttachment(image, "emoji.png");
|
||||
file = new AttachmentBuilder(image, { name: "emoji.png" });
|
||||
}
|
||||
|
||||
msg.channel.send({ files: [file] });
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { Util } from "discord.js";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { errorMessage } from "../../../utils";
|
||||
import { canActOn, sendSuccessMessage } from "../../../pluginUtils";
|
||||
import { utilityCmd } from "../types";
|
||||
import { escapeBold } from "discord.js";
|
||||
|
||||
export const NicknameCmd = utilityCmd({
|
||||
trigger: ["nickname", "nick"],
|
||||
|
@ -20,7 +20,7 @@ export const NicknameCmd = utilityCmd({
|
|||
if (!args.member.nickname) {
|
||||
msg.channel.send(`<@!${args.member.id}> does not have a nickname`);
|
||||
} else {
|
||||
msg.channel.send(`The nickname of <@!${args.member.id}> is **${Util.escapeBold(args.member.nickname)}**`);
|
||||
msg.channel.send(`The nickname of <@!${args.member.id}> is **${escapeBold(args.member.nickname)}**`);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import {
|
|||
Constants,
|
||||
DiscordAPIError,
|
||||
Emoji,
|
||||
escapeCodeBlock,
|
||||
Guild,
|
||||
GuildAuditLogs,
|
||||
GuildAuditLogsEntry,
|
||||
|
@ -15,7 +16,6 @@ import {
|
|||
InviteGuild,
|
||||
LimitedCollection,
|
||||
Message,
|
||||
MessageAttachment,
|
||||
MessageEmbed,
|
||||
MessageEmbedOptions,
|
||||
MessageMentionOptions,
|
||||
|
@ -27,7 +27,6 @@ import {
|
|||
TextChannel,
|
||||
ThreadChannel,
|
||||
User,
|
||||
Util,
|
||||
} from "discord.js";
|
||||
import emojiRegex from "emoji-regex";
|
||||
import { either } from "fp-ts/lib/Either";
|
||||
|
@ -258,7 +257,7 @@ export function nonNullish<V>(v: V): v is NonNullable<V> {
|
|||
export type GuildInvite = Invite & { guild: InviteGuild | Guild };
|
||||
export type GroupDMInvite = Invite & {
|
||||
channel: PartialChannelData;
|
||||
type: typeof Constants.ChannelTypes.GROUP_DM;
|
||||
type: typeof ChannelType.GroupDM;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -648,7 +647,7 @@ interface MatchedURL extends URL {
|
|||
}
|
||||
|
||||
export function getUrlsInString(str: string, onlyUnique = false): MatchedURL[] {
|
||||
let matches = str.match(urlRegex) || [];
|
||||
let matches = [...str.match(urlRegex)];
|
||||
if (onlyUnique) {
|
||||
matches = unique(matches);
|
||||
}
|
||||
|
@ -1409,11 +1408,11 @@ export async function confirm(channel: TextChannel, userId: string, content: Mes
|
|||
|
||||
export function messageSummary(msg: SavedMessage) {
|
||||
// Regular text content
|
||||
let result = "```\n" + (msg.data.content ? Util.escapeCodeBlock(msg.data.content) : "<no text content>") + "```";
|
||||
let result = "```\n" + (msg.data.content ? escapeCodeBlock(msg.data.content) : "<no text content>") + "```";
|
||||
|
||||
// Rich embed
|
||||
const richEmbed = (msg.data.embeds || []).find((e) => (e as MessageEmbed).type === "rich");
|
||||
if (richEmbed) result += "Embed:```" + Util.escapeCodeBlock(JSON.stringify(richEmbed)) + "```";
|
||||
if (richEmbed) result += "Embed:```" + escapeCodeBlock(JSON.stringify(richEmbed)) + "```";
|
||||
|
||||
// Attachments
|
||||
if (msg.data.attachments && msg.data.attachments.length) {
|
||||
|
|
Loading…
Add table
Reference in a new issue