commit 3dd2c566445e4b7e3a39a313ec3df3cdeb1f1a50 Author: Badstagram Date: Wed Nov 26 15:32:08 2025 +0000 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..704d093 --- /dev/null +++ b/.gitignore @@ -0,0 +1,29 @@ +# Ignore a blackhole and the folder for development +node_modules/ +.vs/ +.idea/ +*.iml + +# Yarn files +.yarn/install-state.gz +.yarn/build-state.yml + +# Environment variables +.DS_Store + +dist/ + +# Ignore the config file (contains sensitive information such as tokens) +config.ts + +# Ignore heapsnapshot and log files +*.heapsnapshot +*.log + +# Ignore npm lockfiles file +package-lock.json + +# Environment variables +.env* +/src/generated/prisma +config.toml diff --git a/package.json b/package.json new file mode 100644 index 0000000..f8b30d6 --- /dev/null +++ b/package.json @@ -0,0 +1,61 @@ +{ + "name": "@aurorabot/plugin-message-meme", + "description": "Message Meme plugin for Aurora", + "version": "1.0.0", + "private": false, + "type": "module", + "main": "dist/cjs/index.cjs", + "module": "dist/esm/index.mjs", + "types": "dist/cjs/index.d.cts", + "publishConfig": { + "access": "public" + }, + "files": [ + "dist" + ], + "scripts": { + "test": "vitest run", + "test:watch": "vitest", + "build": "tsdown", + "clean": "rm -rf ./dist; rm aurorabot-plugin-message-meme-*.tgz" + }, + "exports": { + ".": { + "import": { + "types": "./dist/esm/index.d.mts", + "default": "./dist/esm/index.mjs" + }, + "require": { + "types": "./dist/cjs/index.d.cts", + "default": "./dist/cjs/index.cjs" + } + }, + "./register": { + "import": { + "types": "./dist/esm/register.d.mts", + "default": "./dist/esm/register.mjs" + }, + "require": { + "types": "./dist/cjs/register.d.cts", + "default": "./dist/cjs/register.cjs" + } + } + }, + "repository": { + "type": "git", + "url": "https://git.badstagram.gay/aurora/plugin-message-meme" + }, + "author": "Badstagram", + "license": "MIT", + "bugs": { + "url": "https://git.badstagram.gay/aurora/plugin-message-meme/issues" + }, + "homepage": "https://git.badstagram.gay/aurora/plugin-message-meme", + "devDependencies": { + "@sapphire/framework": "^5.4.0", + "@types/node": "^24.10.1", + "discord.js": "^14.25.1", + "tsdown": "^0.16.7", + "typescript": "^5.9.3" + } +} diff --git a/src/Structures/MessageMeme.ts b/src/Structures/MessageMeme.ts new file mode 100644 index 0000000..aa45253 --- /dev/null +++ b/src/Structures/MessageMeme.ts @@ -0,0 +1,51 @@ +import { + Piece, + Precondition, + PreconditionError, + Result, + UserError, +} from "@sapphire/framework"; +import { type Awaitable, Message } from "discord.js"; +import { MessageMemeError } from "./MessageMemeError.js"; + +export type MessageMemeResult = Awaitable>; + +export abstract class MessageMeme< + Options extends MessageMeme.Options = MessageMeme.Options +> extends Piece { + constructor(ctx: MessageMeme.LoaderContext, opts: MessageMeme.Options) { + super(ctx, opts); + } + + public abstract run(message: Message): Awaitable; + + public ok(): Precondition.Result { + return Result.ok(); + } + + /** + * Constructs a {@link PreconditionError} with the precondition parameter set to `this`. + * @param options The information. + */ + public error( + options: Omit = {} + ): Precondition.Result { + return Result.err(new MessageMemeError({ messageMeme: this, ...options })); + } +} + +export interface MessageMemeOptions extends Piece.Options { + name: string; + pattern: RegExp; +} + +// eslint-disable-next-line @typescript-eslint/no-namespace +export namespace MessageMeme { + /** @deprecated Use {@linkcode LoaderContext} instead. */ + export type Context = LoaderContext; // NOSONAR + export type LoaderContext = Piece.LoaderContext<"messageMeme">; + export type Options = MessageMemeOptions; + export type JSON = Piece.JSON; + export type LocationJSON = Piece.LocationJSON; + export type Result = string; +} diff --git a/src/Structures/MessageMemeError.ts b/src/Structures/MessageMemeError.ts new file mode 100644 index 0000000..d164b11 --- /dev/null +++ b/src/Structures/MessageMemeError.ts @@ -0,0 +1,40 @@ +import { UserError } from '@sapphire/framework'; +import { MessageMeme } from './MessageMeme.js'; + +export class MessageMemeError extends UserError { + public readonly messageMeme: MessageMeme; + + public constructor(options: MessageMemeError.Options) { + super({ + ...options, + identifier: options.identifier ?? options.messageMeme.name + }); + this.messageMeme = options.messageMeme; + } + + public override get name(): string { + return 'MessageMemeError'; + } +} + +// eslint-disable-next-line @typescript-eslint/no-namespace +export namespace MessageMemeError { + /** + * The options for {@link PreconditionError}. + * @since 1.0.0 + */ + export interface Options extends Omit { + /** + * The automod that caused the error. + * @since 1.0.0 + */ + messageMeme: MessageMeme; + + /** + * The identifier. + * @since 1.0.0 + * @default precondition.name + */ + identifier?: string; + } +} diff --git a/src/Structures/MessageMemeStore.ts b/src/Structures/MessageMemeStore.ts new file mode 100644 index 0000000..dc53ae9 --- /dev/null +++ b/src/Structures/MessageMemeStore.ts @@ -0,0 +1,13 @@ +import { Store } from '@sapphire/framework'; +import { MessageMeme } from './MessageMeme.js'; + +export class MessageMemeStore extends Store { + /** + * + */ + constructor() { + super(MessageMeme, { + name: 'messageMeme' + }); + } +} diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..a1a0eae --- /dev/null +++ b/src/index.ts @@ -0,0 +1,10 @@ +import { MessageMemeStore } from './Structures/MessageMemeStore.js'; + +export * from './Structures/MessageMeme.js'; +export * from './Structures/MessageMemeStore.js'; + +declare module '@sapphire/pieces' { + interface StoreRegistryEntries { + messageMeme: MessageMemeStore; + } +} diff --git a/src/register.ts b/src/register.ts new file mode 100644 index 0000000..03ffa0d --- /dev/null +++ b/src/register.ts @@ -0,0 +1,15 @@ +import './index.js'; +import { Plugin, preInitialization, SapphireClient } from '@sapphire/framework'; +import { MessageMemeStore } from './Structures/MessageMemeStore.js'; + +export class MessageMemePlugin extends Plugin { + public static override [preInitialization](this: SapphireClient): void { + this.stores.register(new MessageMemeStore()); + } +} + +try { + SapphireClient.plugins.registerPreInitializationHook(MessageMemePlugin[preInitialization], 'MessageMeme-PreInitialization'); +} catch (e) { + console.error(e); +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..bfa0fea --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,29 @@ +{ + "compilerOptions": { + // Environment setup & latest features + "lib": ["ESNext"], + "target": "ESNext", + "module": "Preserve", + "moduleDetection": "force", + "jsx": "react-jsx", + "allowJs": true, + + // Bundler mode + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "verbatimModuleSyntax": true, + "noEmit": true, + + // Best practices + "strict": true, + "skipLibCheck": true, + "noFallthroughCasesInSwitch": true, + "noUncheckedIndexedAccess": true, + "noImplicitOverride": true, + + // Some stricter flags (disabled by default) + "noUnusedLocals": false, + "noUnusedParameters": false, + "noPropertyAccessFromIndexSignature": false + } +} diff --git a/tsdown.config.ts b/tsdown.config.ts new file mode 100644 index 0000000..f6e16b0 --- /dev/null +++ b/tsdown.config.ts @@ -0,0 +1,28 @@ +import { defineConfig, type UserConfig } from "tsdown"; + +const baseOptions: UserConfig = { + clean: true, + entry: ["src/**/*.ts"], + dts: true, + minify: false, + skipNodeModulesBundle: true, + sourcemap: true, + target: "es2021", + tsconfig: "tsconfig.json", + keepNames: true, + treeshake: true, +}; + +export default [ + defineConfig({ + ...baseOptions, + outDir: "dist/cjs", + format: "cjs", + outExtension: () => ({ js: ".cjs" }), + }), + defineConfig({ + ...baseOptions, + outDir: "dist/esm", + format: "esm", + }), +];