mirror of
https://github.com/sern-handler/handler
synced 2026-06-10 09:52:14 +00:00
feat (handler) more progress on message handler
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
import type { Message } from "discord.js";
|
||||
import { filter, fromEvent, Observable } from "rxjs";
|
||||
import { map, filter, fromEvent, Observable, of, concatMap } from "rxjs";
|
||||
import { None, Some } from "ts-results";
|
||||
import Context from "../structures/context";
|
||||
import type Wrapper from "../structures/wrapper";
|
||||
import { isNotFromDM, isNotFromBot, hasPrefix } from "../utilities/messageHelpers";
|
||||
import { isNotFromDM, isNotFromBot, hasPrefix, fmt } from "../utilities/messageHelpers";
|
||||
import * as Files from '../utilities/readFile';
|
||||
|
||||
export const onMessageCreate = ( wrapper : Wrapper) => {
|
||||
const { client, defaultPrefix } = wrapper;
|
||||
@@ -9,9 +12,21 @@ export const onMessageCreate = ( wrapper : Wrapper) => {
|
||||
.pipe (
|
||||
filter( isNotFromBot ),
|
||||
filter( isNotFromDM ),
|
||||
filter(m => hasPrefix(m, defaultPrefix)),
|
||||
filter( m => hasPrefix(m, defaultPrefix)),
|
||||
concatMap ( m => of(fmt(m, defaultPrefix))
|
||||
.pipe (
|
||||
map(([prefix, ...args ]) =>{
|
||||
return [Files.Commands.get(prefix) ?? Files.Alias.get(prefix), new Context(Some(m), None), args ] as const;
|
||||
}),
|
||||
filter( ([mod]) => mod !== undefined),
|
||||
map ( ([mod, ctx, args ]) => {
|
||||
const parsedArgs = mod!.parse?.(ctx, args);
|
||||
return mod!.execute(ctx, parsedArgs);
|
||||
})
|
||||
)
|
||||
)
|
||||
|
||||
).subscribe(console.log)
|
||||
).subscribe()
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ function setCommands ( { mod, absPath } : { mod : Modules.Module, absPath : stri
|
||||
|
||||
async function createCommandCache(
|
||||
arr: Promise<{mod: Modules.Module, absPath: string}[]>
|
||||
) {
|
||||
) {
|
||||
console.log(await arr);
|
||||
from(await arr).subscribe ( setCommands );
|
||||
}
|
||||
|
||||
@@ -1,27 +1,19 @@
|
||||
import type { ApplicationCommandOptionData, Awaitable, PartialWebhookMixin } from "discord.js";
|
||||
import type { possibleOutput } from "../../../types/handler";
|
||||
import type { ApplicationCommandOptionData, Awaitable } from "discord.js";
|
||||
import type { parseArgs, possibleOutput } from "../../../types/handler";
|
||||
import type { CommandType } from "../../sern";
|
||||
import type Context from "../context";
|
||||
|
||||
|
||||
|
||||
export interface BaseModule {
|
||||
name? : string;
|
||||
description : string;
|
||||
execute() : Awaitable<possibleOutput | void>
|
||||
execute(ctx: Context, args: unknown) : Awaitable<possibleOutput | void>
|
||||
}
|
||||
|
||||
export type Text = { type : CommandType.TEXT; alias : string[] | [] };
|
||||
export type Slash = { type : CommandType.SLASH; options : ApplicationCommandOptionData[] | [] };
|
||||
export type Both = { type : CommandType.BOTH; alias : string[] | []; options : ApplicationCommandOptionData[] | [] }
|
||||
export type Text = { type : CommandType.TEXT; alias : string[] | [], parse? : parseArgs };
|
||||
export type Slash = { type : CommandType.SLASH; options : ApplicationCommandOptionData[] | [], parse? : parseArgs };
|
||||
export type Both = { type : CommandType.BOTH; alias : string[] | []; options : ApplicationCommandOptionData[] | [], parse? : parseArgs }
|
||||
|
||||
export type Module =
|
||||
(BaseModule & Slash) | (BaseModule & Both) | (BaseModule & Text);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -7,10 +7,10 @@ import type {
|
||||
Awaitable,
|
||||
} from 'discord.js';
|
||||
|
||||
import type { Modules } from '../handler/structures/structxports';
|
||||
import type { Context, Modules } from '../handler/structures/structxports';
|
||||
|
||||
export type Visibility = 'private' | 'public';
|
||||
|
||||
export type parseArgs = <T>( ctx: Context, args : string[] ) => T | possibleOutput;
|
||||
// Anything that can be sent in a `<TextChannel>#send` or `<CommandInteraction>#reply`
|
||||
export type possibleOutput<T = string> = T | (MessagePayload & MessageOptions);
|
||||
export type execute = Modules.Module['execute'];
|
||||
|
||||
Reference in New Issue
Block a user