mirror of
https://github.com/sern-handler/handler
synced 2026-06-19 22:32:14 +00:00
feat(handler) Filters only executable messages now
This commit is contained in:
@@ -1,15 +1,17 @@
|
||||
import type { Message } from "discord.js";
|
||||
import { filter, fromEvent, Observable } from "rxjs";
|
||||
import type Wrapper from "../structures/wrapper";
|
||||
import { isNotFromBot } from "../utilities/messageHelpers";
|
||||
import { isNotFromDM, isNotFromBot, hasPrefix } from "../utilities/messageHelpers";
|
||||
|
||||
export const onMessageCreate = ( wrapper : Wrapper) => {
|
||||
const { client } = wrapper;
|
||||
const { client, defaultPrefix } = wrapper;
|
||||
(fromEvent( client, 'messageCreate') as Observable<Message>)
|
||||
.pipe (
|
||||
filter( isNotFromBot ),
|
||||
|
||||
).subscribe()
|
||||
filter( isNotFromDM ),
|
||||
filter(m => hasPrefix(m, defaultPrefix)),
|
||||
|
||||
).subscribe(console.log)
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ import type {
|
||||
import { Ok, None, Some } from 'ts-results';
|
||||
import { isNotFromBot, hasPrefix, fmt } from './utilities/messageHelpers';
|
||||
import Logger, { sEvent } from './logger';
|
||||
import { AllTrue } from './utilities/higherOrders';
|
||||
import type Module from './structures/module';
|
||||
import Context from './structures/context';
|
||||
import type Wrapper from './structures/wrapper';
|
||||
@@ -51,8 +50,6 @@ export class Handler {
|
||||
|
||||
|
||||
.on('messageCreate', async (message: Message) => {
|
||||
const isExecutable = AllTrue(isNotFromBot, hasPrefix);
|
||||
if (!isExecutable(message, this.prefix)) return;
|
||||
if (message.channel.type === 'DM') return; // TODO: Handle dms
|
||||
const module = this.findModuleFrom(message);
|
||||
if (module === undefined) {
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
export function registerModules () {
|
||||
|
||||
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import type { Message } from 'discord.js';
|
||||
|
||||
type MsgFnArgs = [msgOrInter: Message, prefix?: string];
|
||||
type MsgFn = (...args: MsgFnArgs) => boolean;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {MsgFn} fn any function that has argument `MsgFnArgs` returning boolean
|
||||
* @returns {(message: Message, prefix: string) => boolean}
|
||||
*/
|
||||
export function AllTrue(...fns: MsgFn[]):
|
||||
(message: Message, prefix: string) => boolean {
|
||||
return (message: Message, prefix: string) => {
|
||||
return fns.every(g => g(message, prefix));
|
||||
};
|
||||
}
|
||||
@@ -1,5 +1,16 @@
|
||||
import type { Message } from 'discord.js';
|
||||
|
||||
/**
|
||||
* @param message The message object
|
||||
* @returns `true` if message comes from DM, `false` otherwise
|
||||
* @example isNotFromDM(message) ? 'Not From DM' : 'from DM'
|
||||
*
|
||||
*/
|
||||
|
||||
export function isNotFromDM ( message: Message ) {
|
||||
return message.channel.type !== 'DM';
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the author of message is a bot or not
|
||||
* @param message The message to check
|
||||
|
||||
Reference in New Issue
Block a user