mirror of
https://github.com/sern-handler/handler
synced 2026-06-17 13:22:17 +00:00
consolidate fmt
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import { Err, Ok } from 'ts-results-es';
|
||||
import type { Module, SernAutocompleteData, SernOptionsData } from '../types/core-modules';
|
||||
import type {
|
||||
AnySelectMenuInteraction,
|
||||
@@ -14,6 +13,20 @@ import { PluginType } from './structures/enums';
|
||||
import assert from 'assert';
|
||||
import type { Payload } from '../types/utility';
|
||||
|
||||
/**
|
||||
* Removes the first character(s) _[depending on prefix length]_ of the message
|
||||
* @param msg
|
||||
* @param prefix The prefix to remove
|
||||
* @returns The message without the prefix
|
||||
* @example
|
||||
* message.content = '!ping';
|
||||
* console.log(fmt(message, '!'));
|
||||
* // [ 'ping' ]
|
||||
*/
|
||||
export function fmt(msg: string, prefix?: string): string[] {
|
||||
if(!prefix) throw Error("Unable to parse message without prefix");
|
||||
return msg.slice(prefix.length).trim().split(/\s+/g);
|
||||
}
|
||||
|
||||
|
||||
export function partitionPlugins<T,V>
|
||||
|
||||
@@ -12,11 +12,7 @@ import { CoreContext } from '../structures/core-context';
|
||||
import { Result, Ok, Err } from 'ts-results-es';
|
||||
import * as assert from 'assert';
|
||||
import type { ReplyOptions } from '../../types/utility';
|
||||
|
||||
function fmt(msg: string, prefix?: string): string[] {
|
||||
if(!prefix) throw Error("Unable to parse message without prefix");
|
||||
return msg.slice(prefix.length).trim().split(/\s+/g);
|
||||
}
|
||||
import { fmt } from '../functions'
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
|
||||
@@ -16,7 +16,7 @@ import { CommandType } from '../core/structures/enums'
|
||||
import { inspect } from 'node:util'
|
||||
import { disposeAll } from '../core/ioc/base';
|
||||
import { arrayifySource, handleError } from '../core/operators';
|
||||
import { resultPayload, isAutocomplete, treeSearch } from '../core/functions'
|
||||
import { resultPayload, isAutocomplete, treeSearch, fmt } from '../core/functions'
|
||||
|
||||
interface ExecutePayload {
|
||||
module: Module;
|
||||
@@ -88,19 +88,6 @@ function createGenericHandler<Source, Narrowed extends Source, Output>(
|
||||
concatMap(makeModule)); // create a payload, preparing to execute
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the first character(s) _[depending on prefix length]_ of the message
|
||||
* @param msg
|
||||
* @param prefix The prefix to remove
|
||||
* @returns The message without the prefix
|
||||
* @example
|
||||
* message.content = '!ping';
|
||||
* console.log(fmt(message, '!'));
|
||||
* // [ 'ping' ]
|
||||
*/
|
||||
export function fmt(msg: string, prefix: string): string[] {
|
||||
return msg.slice(prefix.length).trim().split(/\s+/g);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -137,7 +124,7 @@ export function createInteractionHandler<T extends Interaction>(
|
||||
export function createMessageHandler(
|
||||
source: Observable<Message>,
|
||||
defaultPrefix: string,
|
||||
deps: Dependencies
|
||||
deps: Dependencies,
|
||||
) {
|
||||
const mg = deps['@sern/modules'];
|
||||
return createGenericHandler(source, async event => {
|
||||
|
||||
Reference in New Issue
Block a user