refactor: Simplifying logic of message filter

This commit is contained in:
Jacob Nguyen
2022-05-25 15:49:55 -05:00
parent d63423cfc4
commit 9eef9dd318
5 changed files with 16 additions and 12 deletions

View File

@@ -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();

View File

@@ -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),
};
}),
);

View File

@@ -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);
}
},

View File

@@ -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;
})

View File

@@ -11,6 +11,9 @@ type SernEventsMapping = {
['error']: [Error | string];
};
/**
*
*/
export default class SernEmitter extends EventEmitter {
public override on<T extends keyof SernEventsMapping>(
eventName: T,