initial commit
This commit is contained in:
commit
3dd2c56644
29
.gitignore
vendored
Normal file
29
.gitignore
vendored
Normal file
@ -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
|
||||
61
package.json
Normal file
61
package.json
Normal file
@ -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"
|
||||
}
|
||||
}
|
||||
51
src/Structures/MessageMeme.ts
Normal file
51
src/Structures/MessageMeme.ts
Normal file
@ -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<Result<unknown, UserError>>;
|
||||
|
||||
export abstract class MessageMeme<
|
||||
Options extends MessageMeme.Options = MessageMeme.Options
|
||||
> extends Piece<Options, "messageMeme"> {
|
||||
constructor(ctx: MessageMeme.LoaderContext, opts: MessageMeme.Options) {
|
||||
super(ctx, opts);
|
||||
}
|
||||
|
||||
public abstract run(message: Message): Awaitable<MessageMeme.Result>;
|
||||
|
||||
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<PreconditionError.Options, "precondition"> = {}
|
||||
): 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;
|
||||
}
|
||||
40
src/Structures/MessageMemeError.ts
Normal file
40
src/Structures/MessageMemeError.ts
Normal file
@ -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<UserError.Options, 'identifier'> {
|
||||
/**
|
||||
* The automod that caused the error.
|
||||
* @since 1.0.0
|
||||
*/
|
||||
messageMeme: MessageMeme;
|
||||
|
||||
/**
|
||||
* The identifier.
|
||||
* @since 1.0.0
|
||||
* @default precondition.name
|
||||
*/
|
||||
identifier?: string;
|
||||
}
|
||||
}
|
||||
13
src/Structures/MessageMemeStore.ts
Normal file
13
src/Structures/MessageMemeStore.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { Store } from '@sapphire/framework';
|
||||
import { MessageMeme } from './MessageMeme.js';
|
||||
|
||||
export class MessageMemeStore extends Store<MessageMeme, 'messageMeme'> {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
constructor() {
|
||||
super(MessageMeme, {
|
||||
name: 'messageMeme'
|
||||
});
|
||||
}
|
||||
}
|
||||
10
src/index.ts
Normal file
10
src/index.ts
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
15
src/register.ts
Normal file
15
src/register.ts
Normal file
@ -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);
|
||||
}
|
||||
29
tsconfig.json
Normal file
29
tsconfig.json
Normal file
@ -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
|
||||
}
|
||||
}
|
||||
28
tsdown.config.ts
Normal file
28
tsdown.config.ts
Normal file
@ -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",
|
||||
}),
|
||||
];
|
||||
Loading…
Reference in New Issue
Block a user