mirror of
https://github.com/sern-handler/handler
synced 2026-06-15 04:12:17 +00:00
refactor: Simplifying logic of message filter
This commit is contained in:
@@ -201,7 +201,9 @@ export function onInteractionCreate(wrapper: Wrapper) {
|
||||
return modalHandler(modul, interaction);
|
||||
}
|
||||
if (interaction.isAutocomplete()) {
|
||||
const modul = Files.ApplicationCommands['1'].get(interaction.commandName);
|
||||
const modul =
|
||||
Files.ApplicationCommands['1'].get(interaction.commandName) ??
|
||||
Files.BothCommands.get(interaction.commandName);
|
||||
return autoCmpHandler(modul, interaction);
|
||||
}
|
||||
return of();
|
||||
|
||||
@@ -23,7 +23,10 @@ export const onMessageCreate = (wrapper: Wrapper) => {
|
||||
return {
|
||||
ctx: Context.wrap(message), //TODO : check for BothCommand
|
||||
args: <Args>['text', rest],
|
||||
mod: Files.BothCommands.get(prefix) ?? Files.TextCommands.aliases.get(prefix),
|
||||
mod:
|
||||
Files.TextCommands.text.get(prefix) ??
|
||||
Files.BothCommands.get(prefix) ??
|
||||
Files.TextCommands.aliases.get(prefix),
|
||||
};
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -30,15 +30,12 @@ export function ignoreNonBot(prefix: string) {
|
||||
new Observable<Message>(subscriber => {
|
||||
return src.subscribe({
|
||||
next(m) {
|
||||
const passAll = [
|
||||
isNotFromBot,
|
||||
(m: Message) =>
|
||||
m.content
|
||||
.slice(0, prefix.length)
|
||||
.localeCompare(prefix, undefined, { sensitivity: 'accent' }) === 0,
|
||||
].every(fn => fn(m));
|
||||
|
||||
if (passAll) {
|
||||
const messageFromHumanAndHasPrefix =
|
||||
!m.author.bot &&
|
||||
m.content
|
||||
.slice(0, prefix.length)
|
||||
.localeCompare(prefix, undefined, { sensitivity: 'accent' }) === 0;
|
||||
if (messageFromHumanAndHasPrefix) {
|
||||
subscriber.next(m);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -104,7 +104,6 @@ function registerModule(mod: DefinitelyDefined<Module, { name: string }>): Resul
|
||||
return Ok.EMPTY;
|
||||
})
|
||||
.with({ type: CommandType.Slash }, mod => {
|
||||
console.log(mod);
|
||||
Files.ApplicationCommands[ApplicationCommandType.ChatInput].set(name, mod);
|
||||
return Ok.EMPTY;
|
||||
})
|
||||
|
||||
@@ -11,6 +11,9 @@ type SernEventsMapping = {
|
||||
['error']: [Error | string];
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
export default class SernEmitter extends EventEmitter {
|
||||
public override on<T extends keyof SernEventsMapping>(
|
||||
eventName: T,
|
||||
|
||||
Reference in New Issue
Block a user