mirror of
https://github.com/sern-handler/handler
synced 2026-06-06 01:16:55 +00:00
Merge branch 'main' of https://github.com/jacoobes/Sern
This commit is contained in:
19
README.md
19
README.md
@@ -1,11 +1,24 @@
|
||||
# Sern Handler
|
||||
# Sern
|
||||
|
||||
Sern is making easier to create & automate your discord bot with new version compatibility and full customization.
|
||||
|
||||
- A reincarnation of [this old project](https://github.com/jacoobes/sern_handler)
|
||||
|
||||
# Links
|
||||
# Installation
|
||||
|
||||
```sh
|
||||
npm install sern-handler
|
||||
```
|
||||
|
||||
```sh
|
||||
yarn add sern-handler
|
||||
```
|
||||
|
||||
# Documentation
|
||||
|
||||
- 📑 [Documentation](https://sernhandler.js.org)
|
||||
|
||||
# Contributions
|
||||
# Contribute
|
||||
- Pull up on issues and tell me if there are bugs
|
||||
- Check issues
|
||||
- Any contributions are open to suggestion!
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "sernhandler2",
|
||||
"name": "sern-handler",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "dist/index.js",
|
||||
|
||||
@@ -15,7 +15,6 @@ import type * as Sern from '../sern';
|
||||
export type CommandVal = {
|
||||
mod: Sern.Module<unknown>,
|
||||
options: ApplicationCommandOptionData[],
|
||||
testOnly: boolean
|
||||
}
|
||||
export const Commands = new Map<string, CommandVal>();
|
||||
export const Alias = new Map<string, CommandVal>();
|
||||
@@ -37,12 +36,7 @@ async function readPath(dir: string, arrayOfFiles: string[] = []): Promise<strin
|
||||
return arrayOfFiles;
|
||||
}
|
||||
|
||||
export const fmtFileName = (n: string) => {
|
||||
const endsW = n.toLowerCase().endsWith('-test.js') || n.toLowerCase().endsWith('-test.ts');
|
||||
return endsW
|
||||
? { cmdName: n.substring(0, n.length - 8), testOnly: true }
|
||||
: { cmdName: n.substring(0, n.length - 3), testOnly: false };
|
||||
};
|
||||
export const fmtFileName = (n: string) => n.substring(0, n.length - 3);
|
||||
|
||||
/**
|
||||
* @param {Sern.Handler} handler an instance of Sern.Handler
|
||||
|
||||
16
src/handler/logger.ts
Normal file
16
src/handler/logger.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
enum sEvent {
|
||||
GLOBAL_SLASH,
|
||||
LOCAL_SLASH,
|
||||
TEXT_CMD,
|
||||
CRASH,
|
||||
DM,
|
||||
|
||||
}
|
||||
|
||||
class Logger {
|
||||
|
||||
public log<T extends sEvent>(e : T, message: string) {
|
||||
console.log(`[${"ISOSTRING (todo) "}][${sEvent[e]}] :: ${message}`)
|
||||
}
|
||||
}
|
||||
@@ -63,7 +63,7 @@ export class Handler {
|
||||
const cmdResult = (await this.commandResult(module, message, tryFmt.join(' ')))
|
||||
if (cmdResult === undefined) return;
|
||||
|
||||
message.channel.send(cmdResult)
|
||||
message.channel.send(cmdResult);
|
||||
|
||||
})
|
||||
|
||||
@@ -115,7 +115,7 @@ export class Handler {
|
||||
if (module.mod.visibility === 'private') {
|
||||
const checkIsTestServer = this.privateServers.find(({ id }) => id === message.guildId!)?.test;
|
||||
if (checkIsTestServer === undefined) return 'This command has the private modifier but is not registered under Handler#privateServers';
|
||||
if (checkIsTestServer !== module.testOnly) {
|
||||
if (checkIsTestServer !== module.mod.test) {
|
||||
const msg = `This command is only available on test servers.`; // TODO: Customizable private message
|
||||
|
||||
return msg;
|
||||
@@ -143,13 +143,13 @@ export class Handler {
|
||||
}[]
|
||||
) {
|
||||
for await (const { name, mod, absPath } of modArr) {
|
||||
const { cmdName, testOnly } = Files.fmtFileName(name);
|
||||
const cmdName = Files.fmtFileName(name);
|
||||
switch (mod.type) {
|
||||
case 1: Files.Commands.set(cmdName, { mod, options: [], testOnly }); break;
|
||||
case 1: Files.Commands.set(cmdName, { mod, options: [] }); break;
|
||||
case 2:
|
||||
case (1 | 2): {
|
||||
const options = ((await import(absPath)).options as ApplicationCommandOptionData[])
|
||||
Files.Commands.set(cmdName, { mod, options: options ?? [], testOnly });
|
||||
Files.Commands.set(cmdName, { mod, options: options ?? [] });
|
||||
switch (mod.visibility) {
|
||||
case 'private': {
|
||||
// Loading guild slash commands only
|
||||
@@ -171,7 +171,7 @@ export class Handler {
|
||||
|
||||
if (mod.alias.length > 0) {
|
||||
for (const alias of mod.alias) {
|
||||
Files.Alias.set(alias, { mod, options: [], testOnly })
|
||||
Files.Alias.set(alias, { mod, options: [] })
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -269,6 +269,7 @@ export interface Module<T = string> {
|
||||
desc: string,
|
||||
visibility: Visibility,
|
||||
type: CommandType,
|
||||
test : boolean,
|
||||
delegate: (eventParams: Context, args: Ok<T>) => Awaitable<Result<possibleOutput, string> | void>
|
||||
parse?: (ctx: Context, args: Arg) => Utils.ArgType<T>
|
||||
}
|
||||
|
||||
@@ -28,8 +28,13 @@ export type Context = {
|
||||
message: Option<Message>,
|
||||
interaction: Option<CommandInteraction>
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
|
||||
export type Arg = ParseType<{ text: string, slash: SlashOptions }>;
|
||||
=======
|
||||
// `string` | `SlashOptions`, narrow down your type by checking `text` | `slash`
|
||||
export type Arg = ParseType<{text : string, slash : SlashOptions}>
|
||||
>>>>>>> 6ce7649311f1d077f6437528cbad10da16e58435
|
||||
|
||||
// TypeAlias for interaction.options
|
||||
export type SlashOptions = Omit<CommandInteractionOptionResolver, 'getMessage' | 'getFocused'>;
|
||||
|
||||
Reference in New Issue
Block a user