From e6581e6eba6408ceffd96e8bb739bfb8a0b52ace Mon Sep 17 00:00:00 2001 From: Evo <85353424+EvolutionX-10@users.noreply.github.com> Date: Mon, 3 Oct 2022 21:02:54 +0530 Subject: [PATCH] refactor: pretty imports (#24) --- package.json | 5 +++++ src/commands/docs.ts | 4 ++-- src/commands/emoji.ts | 5 ++--- src/commands/eval.ts | 2 +- src/commands/games/rps.ts | 15 +++++++++------ src/commands/games/ttt.ts | 2 +- src/commands/handlers/emojiAccept.ts | 2 +- src/commands/handlers/emojiDeny.ts | 9 +++++++-- src/commands/handlers/falseTrigger.ts | 2 +- src/commands/handlers/tagCreate.ts | 2 +- src/commands/handlers/tagEdit.ts | 2 +- src/commands/menu.ts | 5 ++--- src/commands/ping.ts | 3 ++- src/commands/plugin.ts | 6 +----- src/commands/refresh.ts | 6 +++--- src/commands/solved.ts | 5 ++--- src/commands/tag.ts | 4 ++-- src/commands/tags.ts | 7 +++---- src/constants.ts | 3 +++ src/plugins/index.ts | 5 +++++ src/plugins/ownerOnly.ts | 16 +++++++--------- src/utils/index.ts | 7 +++++++ tsconfig.json | 7 ++++++- 23 files changed, 74 insertions(+), 50 deletions(-) create mode 100644 src/plugins/index.ts create mode 100644 src/utils/index.ts diff --git a/package.json b/package.json index 5dfab57..86dff71 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,11 @@ "name": "EvolutionX-10", "url": "https://github.com/EvolutionX-10" }, + "imports": { + "#plugins": "./dist/src/plugins/index.js", + "#utils": "./dist/src/utils/index.js", + "#constants": "./dist/src/constants.js" + }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "start": "tsup && node .", diff --git a/src/commands/docs.ts b/src/commands/docs.ts index fd67daa..9a38240 100644 --- a/src/commands/docs.ts +++ b/src/commands/docs.ts @@ -1,8 +1,8 @@ import { commandModule, CommandType } from '@sern/handler'; import { ApplicationCommandOptionType, Colors, EmbedBuilder } from 'discord.js'; import { Kind, PurpleComment, PurpleSummary, TentacledKindString } from '../../typings/docs.js'; -import { Paginator } from '../utils/Paginator.js'; -import { publish } from '../plugins/publish.js'; +import { Paginator } from '#utils'; +import { publish } from '#plugins'; import DocHandler from '../trie/doc-autocmp.js'; function handleComments(sum : PurpleSummary) { diff --git a/src/commands/emoji.ts b/src/commands/emoji.ts index 31e3bb4..13ab146 100644 --- a/src/commands/emoji.ts +++ b/src/commands/emoji.ts @@ -12,9 +12,8 @@ import { TextChannel, } from "discord.js"; import { fetch } from "undici"; -import { cooldown } from "../plugins/cooldown.js"; -import { publish } from "../plugins/publish.js"; -import { Resolver } from "../utils/Resolver.js"; +import { cooldown, publish } from "#plugins"; +import { Resolver } from "#utils"; export default commandModule({ type: CommandType.Slash, diff --git a/src/commands/eval.ts b/src/commands/eval.ts index 884a88a..07b65b8 100644 --- a/src/commands/eval.ts +++ b/src/commands/eval.ts @@ -1,7 +1,7 @@ import { commandModule, CommandType } from "@sern/handler"; import { EmbedBuilder } from "discord.js"; import { inspect } from "util"; -import { ownerOnly } from "../plugins/ownerOnly.js"; +import { ownerOnly } from "#plugins"; export default commandModule({ type: CommandType.Text, diff --git a/src/commands/games/rps.ts b/src/commands/games/rps.ts index 85ec73f..76df082 100644 --- a/src/commands/games/rps.ts +++ b/src/commands/games/rps.ts @@ -8,10 +8,11 @@ import { ComponentType, User, } from "discord.js"; -import { publish } from "../../plugins/publish.js"; +import { publish } from "#plugins"; + export default commandModule({ type: CommandType.Slash, - plugins: [publish()], + plugins: [publish({ dmPermission: false })], description: "wanna win in rps?", options: [ { @@ -125,10 +126,12 @@ export default commandModule({ collector.on("end", async (_, r) => { if (r === "finished") return; - await context.interaction.editReply({ - content: "Time up!", - components: [row.setComponents(buttons)], - }).catch(() => null); + await context.interaction + .editReply({ + content: "Time up!", + components: [row.setComponents(buttons)], + }) + .catch(() => null); }); }, }); diff --git a/src/commands/games/ttt.ts b/src/commands/games/ttt.ts index a8dd25d..4a85c4a 100644 --- a/src/commands/games/ttt.ts +++ b/src/commands/games/ttt.ts @@ -6,7 +6,7 @@ import { Timestamp } from "../../utils/Timestamp.js"; export default commandModule({ type: CommandType.Slash, - plugins: [publish()], + plugins: [publish({ dmPermission: false })], options: [ { name: "opponent", diff --git a/src/commands/handlers/emojiAccept.ts b/src/commands/handlers/emojiAccept.ts index 65f446b..f1b8416 100644 --- a/src/commands/handlers/emojiAccept.ts +++ b/src/commands/handlers/emojiAccept.ts @@ -1,3 +1,4 @@ +import { ownerIDs } from "#constants"; import { commandModule, CommandType } from "@sern/handler"; import { ActionRowBuilder, @@ -5,7 +6,6 @@ import { TextInputBuilder, TextInputStyle, } from "discord.js"; -import { ownerIDs } from "../../plugins/ownerOnly.js"; export default commandModule({ type: CommandType.Button, diff --git a/src/commands/handlers/emojiDeny.ts b/src/commands/handlers/emojiDeny.ts index 874b443..a77d33b 100644 --- a/src/commands/handlers/emojiDeny.ts +++ b/src/commands/handlers/emojiDeny.ts @@ -1,6 +1,6 @@ +import { ownerIDs } from "#constants"; import { commandModule, CommandType } from "@sern/handler"; import { ActionRowBuilder, ButtonBuilder, EmbedBuilder } from "discord.js"; -import { ownerIDs } from "../../plugins/ownerOnly.js"; export default commandModule({ type: CommandType.Button, @@ -32,6 +32,11 @@ export default commandModule({ .setColor("Red") .setTimestamp(); - await ctx.message?.edit({ content: null, embeds: [embed], components, files: [] }); + await ctx.message?.edit({ + content: null, + embeds: [embed], + components, + files: [], + }); }, }); diff --git a/src/commands/handlers/falseTrigger.ts b/src/commands/handlers/falseTrigger.ts index 6407116..757916f 100644 --- a/src/commands/handlers/falseTrigger.ts +++ b/src/commands/handlers/falseTrigger.ts @@ -1,5 +1,5 @@ import { commandModule, CommandType } from "@sern/handler"; -import type { TagMessage } from "../../types/index.js"; +import type { TagMessage } from "../../types"; export default commandModule({ type: CommandType.Button, diff --git a/src/commands/handlers/tagCreate.ts b/src/commands/handlers/tagCreate.ts index b771fe4..3547e21 100644 --- a/src/commands/handlers/tagCreate.ts +++ b/src/commands/handlers/tagCreate.ts @@ -1,6 +1,6 @@ import { commandModule, CommandType } from "@sern/handler"; import { existsSync, writeFileSync } from "fs"; -import type { TagData } from "../../types/index.js"; +import type { TagData } from "../../types"; import { createRequire } from "module"; const require = createRequire(import.meta.url); diff --git a/src/commands/handlers/tagEdit.ts b/src/commands/handlers/tagEdit.ts index d4f36d7..ef0cad4 100644 --- a/src/commands/handlers/tagEdit.ts +++ b/src/commands/handlers/tagEdit.ts @@ -1,7 +1,7 @@ import { commandModule, CommandType } from "@sern/handler"; import { writeFileSync } from "fs"; import { createRequire } from "module"; -import type { TagData } from "../../types/index.js"; +import type { TagData } from "../../types"; const require = createRequire(import.meta.url); export default commandModule({ diff --git a/src/commands/menu.ts b/src/commands/menu.ts index fa154f6..b7d1624 100644 --- a/src/commands/menu.ts +++ b/src/commands/menu.ts @@ -9,9 +9,8 @@ import { ChannelType, EmbedBuilder, } from "discord.js"; -import { ownerOnly } from "../plugins/ownerOnly.js"; -import { publish } from "../plugins/publish.js"; -import { Resolver } from "../utils/Resolver.js"; +import { ownerOnly, publish } from "#plugins"; +import { Resolver } from "#utils"; export default commandModule({ plugins: [ownerOnly(), publish()], diff --git a/src/commands/ping.ts b/src/commands/ping.ts index 68a4bf7..7e04fa9 100644 --- a/src/commands/ping.ts +++ b/src/commands/ping.ts @@ -1,5 +1,6 @@ import { commandModule, CommandType } from "@sern/handler"; -import { publish } from "../plugins/publish.js"; +import { publish } from "#plugins"; + export default commandModule({ type: CommandType.Slash, plugins: [publish()], diff --git a/src/commands/plugin.ts b/src/commands/plugin.ts index 2e8bf86..863ab68 100644 --- a/src/commands/plugin.ts +++ b/src/commands/plugin.ts @@ -1,10 +1,7 @@ import { commandModule, CommandType } from "@sern/handler"; -import { publish } from "../plugins/publish.js"; -import { fetch } from "undici"; import { ApplicationCommandOptionType, EmbedBuilder } from "discord.js"; -import { cooldown } from "../plugins/cooldown.js"; +import { cooldown, publish } from "#plugins"; import { parse } from "jsdoc-parse-plus"; -import { refreshCache } from "../plugins/refreshCache.js"; export default commandModule({ type: CommandType.Slash, description: "View sern plugins", @@ -38,7 +35,6 @@ export default commandModule({ }, ], plugins: [ - refreshCache(), publish(), cooldown.add([["user", "1/10"]], ({ seconds, context }) => context.reply({ diff --git a/src/commands/refresh.ts b/src/commands/refresh.ts index 36a429a..24862c1 100644 --- a/src/commands/refresh.ts +++ b/src/commands/refresh.ts @@ -1,14 +1,14 @@ import { commandModule, CommandType } from "@sern/handler"; import { Collection, Client } from "discord.js"; -import { publish } from "../plugins/publish.js"; import { fetch } from "undici"; import type { Data } from "./plugin.js"; -import { ownerOnly } from "../plugins/ownerOnly.js"; -import { Evo } from "../constants.js"; +import { ownerOnly, publish, refreshCache } from "#plugins"; +import { Evo } from "#constants"; export default commandModule({ type: CommandType.Slash, plugins: [ + refreshCache(), publish({ dmPermission: false, defaultMemberPermissions: ["Administrator"], diff --git a/src/commands/solved.ts b/src/commands/solved.ts index f4c525c..49670d8 100644 --- a/src/commands/solved.ts +++ b/src/commands/solved.ts @@ -1,8 +1,7 @@ import { commandModule, CommandType } from "@sern/handler"; import { ChannelType } from "discord.js"; -import { channelOnly } from "../plugins/channelOnly.js"; -import { ownerIDs } from "../plugins/ownerOnly.js"; -import { publish } from "../plugins/publish.js"; +import { publish, channelOnly } from "#plugins"; +import { ownerIDs } from "#constants"; export default commandModule({ type: CommandType.Slash, diff --git a/src/commands/tag.ts b/src/commands/tag.ts index d46ba2c..a69e7b7 100644 --- a/src/commands/tag.ts +++ b/src/commands/tag.ts @@ -1,8 +1,8 @@ import { commandModule, CommandType } from "@sern/handler"; import { ApplicationCommandOptionType, EmbedBuilder } from "discord.js"; import { existsSync } from "fs"; -import { Paginator } from "../utils/Paginator.js"; -import { publish } from "../plugins/publish.js"; +import { publish } from "#plugins"; +import { Paginator } from "#utils"; import { createRequire } from "module"; import type { TagData } from "../types/index.js"; diff --git a/src/commands/tags.ts b/src/commands/tags.ts index 8ddc29c..4f2966f 100644 --- a/src/commands/tags.ts +++ b/src/commands/tags.ts @@ -8,10 +8,9 @@ import { } from "discord.js"; import { existsSync, writeFileSync } from "fs"; import { createRequire } from "module"; -import { Evo } from "../constants.js"; -import { ownerOnly } from "../plugins/ownerOnly.js"; -import { publish } from "../plugins/publish.js"; -import type { TagData } from "../types/index.js"; +import { Evo } from "#constants"; +import { ownerOnly, publish } from "#plugins"; +import type { TagData } from "../types"; const require = createRequire(import.meta.url); export default commandModule({ diff --git a/src/constants.ts b/src/constants.ts index 6bc2ff8..bbbbc89 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1 +1,4 @@ export const Evo = "697795666373640213"; +export const Seren = "182326315813306368"; +export const Ropox = "756393473430519849"; +export const ownerIDs = [Evo, Seren, Ropox]; diff --git a/src/plugins/index.ts b/src/plugins/index.ts new file mode 100644 index 0000000..58a2583 --- /dev/null +++ b/src/plugins/index.ts @@ -0,0 +1,5 @@ +export * from "./channelOnly.js"; +export * from "./cooldown.js"; +export * from "./ownerOnly.js"; +export * from "./publish.js"; +export * from "./refreshCache.js"; diff --git a/src/plugins/ownerOnly.ts b/src/plugins/ownerOnly.ts index ce4954a..cc87a6f 100644 --- a/src/plugins/ownerOnly.ts +++ b/src/plugins/ownerOnly.ts @@ -1,20 +1,18 @@ import { CommandType, EventPlugin, PluginType } from "@sern/handler"; -export const ownerIDs = [ - "697795666373640213", - "182326315813306368", - "756393473430519849", -]; +import { ownerIDs } from "#constants"; + export function ownerOnly(override?: string[]): EventPlugin { return { type: PluginType.Event, description: "Allows only bot owner to run command", async execute(event, controller) { const [ctx] = event; - if ((override ?? ownerIDs).includes(ctx.user.id)) return controller.next(); + if ((override ?? ownerIDs).includes(ctx.user.id)) + return controller.next(); await ctx.reply({ - content: 'Not for you!', - ephemeral: true - }) + content: "Not for you!", + ephemeral: true, + }); return controller.stop(); }, }; diff --git a/src/utils/index.ts b/src/utils/index.ts new file mode 100644 index 0000000..8c93716 --- /dev/null +++ b/src/utils/index.ts @@ -0,0 +1,7 @@ +export * from "./FuzzyMatcher.js"; +export * from "./Paginator.js"; +export * from "./Resolver.js"; +export * from "./TicTacToe.js"; +export * from "./Timestamp.js"; +export * from "./pagination.js"; +export * from "./randomStatus.js"; diff --git a/tsconfig.json b/tsconfig.json index 339a4a1..e609c54 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,6 +11,11 @@ "strictNullChecks": true, "importsNotUsedAsValues": "error", "skipLibCheck": true, - "forceConsistentCasingInFileNames": true + "forceConsistentCasingInFileNames": true, + "paths": { + "#plugins": ["./src/plugins/index.js"], + "#utils": ["./src/utils/index.js"], + "#constants": ["./src/constants.js"] + } } }