3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 04:25:01 +00:00

refactor: convert /backend to ESM

This commit is contained in:
Dragory 2024-04-09 20:57:18 +03:00
parent 31d74c05aa
commit 5772e27cda
No known key found for this signature in database
766 changed files with 3473 additions and 3500 deletions

View file

@ -1,5 +1,5 @@
import { StrictMessageContent } from "../utils";
import { calculateEmbedSize } from "./calculateEmbedSize";
import { StrictMessageContent } from "../utils.js";
import { calculateEmbedSize } from "./calculateEmbedSize.js";
import Timeout = NodeJS.Timeout;
type ConsumeFn = (part: StrictMessageContent) => void;

View file

@ -1,4 +1,4 @@
import { Awaitable } from "./typeUtils";
import { Awaitable } from "./typeUtils.js";
export async function asyncReduce<T, V>(
arr: T[],

View file

@ -1,6 +1,6 @@
import { Guild, GuildMember, PermissionsBitField, Role, Snowflake } from "discord.js";
import { getMissingPermissions } from "./getMissingPermissions";
import { hasDiscordPermissions } from "./hasDiscordPermissions";
import { getMissingPermissions } from "./getMissingPermissions.js";
import { hasDiscordPermissions } from "./hasDiscordPermissions.js";
export function canAssignRole(guild: Guild, member: GuildMember, roleId: string) {
if (getMissingPermissions(member.permissions, PermissionsBitField.Flags.ManageRoles)) {

View file

@ -1,6 +1,6 @@
import { GuildMember, GuildTextBasedChannel } from "discord.js";
import { getMissingChannelPermissions } from "./getMissingChannelPermissions";
import { readChannelPermissions } from "./readChannelPermissions";
import { getMissingChannelPermissions } from "./getMissingChannelPermissions.js";
import { readChannelPermissions } from "./readChannelPermissions.js";
export function canReadChannel(channel: GuildTextBasedChannel, member: GuildMember) {
// Not missing permissions required to read the channel = can read channel

View file

@ -9,8 +9,8 @@ import {
TextBasedChannel,
User,
} from "discord.js";
import { MINUTES, noop } from "../utils";
import { Awaitable } from "./typeUtils";
import { MINUTES, noop } from "../utils.js";
import { Awaitable } from "./typeUtils.js";
import Timeout = NodeJS.Timeout;
export type LoadPageFn = (page: number) => Awaitable<MessageCreateOptions & MessageEditOptions>;

View file

@ -1,5 +1,5 @@
import test from "ava";
import { decrypt, encrypt } from "./crypt";
import { decrypt, encrypt } from "./crypt.js";
test("encrypt() followed by decrypt()", async (t) => {
const original = "banana 123 👀 💕"; // Includes emojis to verify utf8 stuff works

View file

@ -1,7 +1,7 @@
import { Pool, spawn, Worker } from "threads";
import { env } from "../env";
import "../threadsSignalFix";
import { MINUTES } from "../utils";
import { env } from "../env.js";
import "../threadsSignalFix.js";
import { MINUTES } from "../utils.js";
const pool = Pool(() => spawn(new Worker("./cryptWorker"), { timeout: 10 * MINUTES }), 8);

View file

@ -1,4 +1,4 @@
import { decrypt, encrypt } from "./crypt";
import { decrypt, encrypt } from "./crypt.js";
export async function encryptJson(obj: any): Promise<string> {
const serialized = JSON.stringify(obj);

View file

@ -1,5 +1,5 @@
import crypto from "crypto";
import { expose } from "threads";
import { expose } from "threads/worker";
const ALGORITHM = "aes-256-gcm";

View file

@ -1,6 +1,6 @@
import type { Knub } from "knub";
import { performance } from "perf_hooks";
import { noop, SECONDS } from "../utils";
import { noop, SECONDS } from "../utils.js";
type Profiler = Knub["profiler"];

View file

@ -1,5 +1,5 @@
import { AuditLogEvent, Guild, GuildAuditLogsEntry } from "discord.js";
import { SECONDS, sleep } from "../utils";
import { SECONDS, sleep } from "../utils.js";
const BATCH_DEBOUNCE_TIME = 2 * SECONDS;
const BATCH_FETCH_COUNT_INCREMENT = 10;

View file

@ -1,5 +1,5 @@
import { EmbedField } from "discord.js";
import { chunkMessageLines, emptyEmbedValue } from "../utils";
import { chunkMessageLines, emptyEmbedValue } from "../utils.js";
export function getChunkedEmbedFields(name: string, value: string): EmbedField[] {
const fields: EmbedField[] = [];

View file

@ -1,5 +1,5 @@
import { GuildMember, GuildTextBasedChannel } from "discord.js";
import { getMissingPermissions } from "./getMissingPermissions";
import { getMissingPermissions } from "./getMissingPermissions.js";
/**
* @param requiredPermissions Bitmask of required permissions

View file

@ -1,5 +1,5 @@
import yaml from "js-yaml";
import { validateNoObjectAliases } from "./validateNoObjectAliases";
import { validateNoObjectAliases } from "./validateNoObjectAliases.js";
/**
* Loads a YAML file safely while removing object anchors/aliases (including arrays)

View file

@ -1,5 +1,5 @@
import { GuildMember, Message, User } from "discord.js";
import { SavedMessage } from "../data/entities/SavedMessage";
import { SavedMessage } from "../data/entities/SavedMessage.js";
export function allStarboardsLock() {
return `starboards`;

View file

@ -1,4 +1,4 @@
import { categorize } from "./categorize";
import { categorize } from "./categorize.js";
const hasBackreference = /(?:^|[^\\]|[\\]{2})\\\d+/;

View file

@ -1,6 +1,6 @@
import { MessageCreateOptions } from "discord.js";
import { StrictMessageContent } from "../utils.js";
import { messageHasContent } from "./messageHasContent";
import { messageHasContent } from "./messageHasContent.js";
export function messageIsEmpty(content: string | MessageCreateOptions | StrictMessageContent): boolean {
return !messageHasContent(content);

View file

@ -1,4 +1,4 @@
import { getPermissionNames } from "./getPermissionNames";
import { getPermissionNames } from "./getPermissionNames.js";
export function missingPermissionError(missingPermissions: number | bigint): string {
const permissionNames = getPermissionNames(missingPermissions);

View file

@ -1,5 +1,5 @@
import test from "ava";
import { normalizeText } from "./normalizeText";
import { normalizeText } from "./normalizeText.js";
test("Replaces special characters", (t) => {
const from = "𝗧:regional_indicator_e:ᔕ7 𝗧:regional_indicator_e:ᔕ7 𝗧:regional_indicator_e:ᔕ7";

View file

@ -1,4 +1,4 @@
import { logger } from "../logger";
import { logger } from "../logger.js";
const customIdFormat = /^([^:]+):\d+:(.*)$/;

View file

@ -1,5 +1,5 @@
import type { PermissionFlagsBits } from "discord.js";
import { EMPTY_CHAR } from "../utils";
import { EMPTY_CHAR } from "../utils.js";
export const PERMISSION_NAMES = {
AddReactions: "Add Reactions",

View file

@ -1,7 +1,7 @@
import { CategoryChannel, Channel } from "discord.js";
import { isDmChannel } from "./isDmChannel";
import { isGuildChannel } from "./isGuildChannel";
import { isThreadChannel } from "./isThreadChannel";
import { isDmChannel } from "./isDmChannel.js";
import { isGuildChannel } from "./isGuildChannel.js";
import { isThreadChannel } from "./isThreadChannel.js";
type ResolvedChannelIds = {
category: string | null;

View file

@ -1,7 +1,7 @@
import { GuildTextBasedChannel, Snowflake } from "discord.js";
import { GuildPluginData } from "knub";
import { getChannelIdFromMessageId } from "../data/getChannelIdFromMessageId";
import { isSnowflake } from "../utils";
import { getChannelIdFromMessageId } from "../data/getChannelIdFromMessageId.js";
import { isSnowflake } from "../utils.js";
const channelAndMessageIdRegex = /^(\d+)[-/](\d+)$/;
const messageLinkRegex = /^https:\/\/(?:\w+\.)?discord(?:app)?\.com\/channels\/\d+\/(\d+)\/(\d+)$/i;

View file

@ -1,6 +1,6 @@
import { MessagePayload, User } from "discord.js";
import { logger } from "../logger";
import { HOURS, createChunkedMessage, isDiscordAPIError } from "../utils";
import { logger } from "../logger.js";
import { HOURS, createChunkedMessage, isDiscordAPIError } from "../utils.js";
import Timeout = NodeJS.Timeout;
let dmsDisabled = false;

View file

@ -1,4 +1,4 @@
import { isValidSnowflake } from "../utils";
import { isValidSnowflake } from "../utils.js";
/**
* @return Unix timestamp in milliseconds

View file

@ -13,20 +13,20 @@ import {
User,
} from "discord.js";
import { GuildPluginData } from "knub";
import { Case } from "../data/entities/Case";
import { Case } from "../data/entities/Case.js";
import {
ISavedMessageAttachmentData,
ISavedMessageData,
ISavedMessageEmbedData,
ISavedMessageStickerData,
SavedMessage,
} from "../data/entities/SavedMessage";
} from "../data/entities/SavedMessage.js";
import {
TemplateSafeValueContainer,
TypedTemplateSafeValueContainer,
ingestDataIntoTemplateSafeValueContainer,
} from "../templateFormatter";
import { UnknownUser, renderUsername } from "../utils";
} from "../templateFormatter.js";
import { UnknownUser, renderUsername } from "../utils.js";
type InputProps<T> = Omit<
{

View file

@ -1,5 +1,5 @@
import test from "ava";
import { ObjectAliasError, validateNoObjectAliases } from "./validateNoObjectAliases";
import { ObjectAliasError, validateNoObjectAliases } from "./validateNoObjectAliases.js";
test("validateNoObjectAliases() disallows object aliases at top level", (t) => {
const obj: any = {

View file

@ -9,7 +9,7 @@ import {
} from "discord.js";
import moment from "moment";
import { v4 as uuidv4 } from "uuid";
import { noop } from "../utils";
import { noop } from "../utils.js";
export async function waitForButtonConfirm(
channel: GuildTextBasedChannel,

View file

@ -1,6 +1,6 @@
import z from "zod";
import { parseColor } from "./parseColor";
import { rgbToInt } from "./rgbToInt";
import { parseColor } from "./parseColor.js";
import { rgbToInt } from "./rgbToInt.js";
export const zColor = z.string().transform((val, ctx) => {
const parsedColor = parseColor(val);

View file

@ -1,5 +1,5 @@
import { ZodString } from "zod";
import { isValidTimezone } from "./isValidTimezone";
import { isValidTimezone } from "./isValidTimezone.js";
export function zValidTimezone<Z extends ZodString>(z: Z) {
return z.refine((val) => isValidTimezone(val), {