initial commit
This commit is contained in:
commit
d0e00292e6
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-automod",
|
||||
"description": "Automod plugin for Aurora",
|
||||
"version": "1.0.2",
|
||||
"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-automod-*.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-automod"
|
||||
},
|
||||
"author": "Badstagram",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://git.badstagram.gay/aurora/plugin-automod/issues"
|
||||
},
|
||||
"homepage": "https://git.badstagram.gay/aurora/plugin-automod",
|
||||
"devDependencies": {
|
||||
"@sapphire/framework": "^5.4.0",
|
||||
"@types/node": "^24.10.1",
|
||||
"discord.js": "^14.25.1",
|
||||
"tsdown": "^0.16.7",
|
||||
"typescript": "^5.9.3"
|
||||
}
|
||||
}
|
||||
50
src/Structures/AutoMod.ts
Normal file
50
src/Structures/AutoMod.ts
Normal file
@ -0,0 +1,50 @@
|
||||
import {
|
||||
Piece,
|
||||
Precondition,
|
||||
PreconditionError,
|
||||
Result,
|
||||
UserError,
|
||||
} from "@sapphire/framework";
|
||||
import { type Awaitable, Message } from "discord.js";
|
||||
import { AutomodError } from "./AutoModError.js";
|
||||
|
||||
export type AutoModResult = Awaitable<Result<unknown, UserError>>;
|
||||
|
||||
export abstract class AutoMod<
|
||||
Options extends AutoMod.Options = AutoMod.Options
|
||||
> extends Piece<Options, "automod"> {
|
||||
constructor(ctx: AutoMod.LoaderContext, opts: AutoMod.Options) {
|
||||
super(ctx, opts);
|
||||
}
|
||||
|
||||
public abstract run(message: Message): Awaitable<AutoMod.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 AutomodError({ automod: this, ...options }));
|
||||
}
|
||||
}
|
||||
|
||||
export interface AutoModOptions extends Piece.Options {
|
||||
name: string;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||
export namespace AutoMod {
|
||||
/** @deprecated Use {@linkcode LoaderContext} instead. */
|
||||
export type Context = LoaderContext; // NOSONAR
|
||||
export type LoaderContext = Piece.LoaderContext<"automod">;
|
||||
export type Options = AutoModOptions;
|
||||
export type JSON = Piece.JSON;
|
||||
export type LocationJSON = Piece.LocationJSON;
|
||||
export type Result = AutoModResult;
|
||||
}
|
||||
40
src/Structures/AutoModError.ts
Normal file
40
src/Structures/AutoModError.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import { UserError } from '@sapphire/framework';
|
||||
import { AutoMod } from './AutoMod.js';
|
||||
|
||||
export class AutomodError extends UserError {
|
||||
public readonly automod: AutoMod;
|
||||
|
||||
public constructor(options: AutomodError.Options) {
|
||||
super({
|
||||
...options,
|
||||
identifier: options.identifier ?? options.automod.name
|
||||
});
|
||||
this.automod = options.automod;
|
||||
}
|
||||
|
||||
public override get name(): string {
|
||||
return 'AutomodError';
|
||||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||
export namespace AutomodError {
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
automod: AutoMod;
|
||||
|
||||
/**
|
||||
* The identifier.
|
||||
* @since 1.0.0
|
||||
* @default precondition.name
|
||||
*/
|
||||
identifier?: string;
|
||||
}
|
||||
}
|
||||
13
src/Structures/AutoModStore.ts
Normal file
13
src/Structures/AutoModStore.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { Store } from '@sapphire/framework';
|
||||
import { AutoMod } from './AutoMod.js';
|
||||
|
||||
export class AutoModStore extends Store<AutoMod, 'automod'> {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
constructor() {
|
||||
super(AutoMod, {
|
||||
name: 'automod'
|
||||
});
|
||||
}
|
||||
}
|
||||
10
src/index.ts
Normal file
10
src/index.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import { AutoModStore } from './Structures/AutoModStore.js';
|
||||
|
||||
export * from './Structures/AutoMod.js';
|
||||
export * from './Structures/AutoModStore.js';
|
||||
|
||||
declare module '@sapphire/pieces' {
|
||||
interface StoreRegistryEntries {
|
||||
automod: AutoModStore;
|
||||
}
|
||||
}
|
||||
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 { AutoModStore } from './Structures/AutoModStore.js';
|
||||
|
||||
export class AutoModPlugin extends Plugin {
|
||||
public static override [preInitialization](this: SapphireClient): void {
|
||||
this.stores.register(new AutoModStore());
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
SapphireClient.plugins.registerPreInitializationHook(AutoModPlugin[preInitialization], 'AutoMod-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