feat(interactionCreate.ts) finish basic interaction handling for chat input commands

This commit is contained in:
Jacob Nguyen
2022-03-22 00:47:06 -05:00
parent d34c1881bd
commit a227f1a8f2
5 changed files with 9 additions and 10 deletions

View File

@@ -3,7 +3,7 @@
"version": "0.1.0",
"description": "",
"main": "dist/index.js",
"scripts": {
"scripts": {
"compile": "tsc",
"watch": "tsc -w",
"lint": "eslint src/**/*.ts",

View File

@@ -16,8 +16,8 @@ export const onInteractionCreate = ( wrapper : Wrapper ) => {
concatMap ( interaction => {
if (interaction.isChatInputCommand()) {
return of(interaction.commandName).pipe(
map ( Files.Commands.get ),
filter ( mod => mod !== undefined && (mod.type & CommandType.SLASH) != 0),
map ( name => Files.Commands.get(name) ),
filter( mod => mod !== undefined && (mod.type & CommandType.SLASH) != 0),
tap ( mod => {
const ctx = new Context(None, Some(interaction));
mod!.execute(ctx, ['slash', interaction.options]);
@@ -31,9 +31,8 @@ export const onInteractionCreate = ( wrapper : Wrapper ) => {
else { return of() }
})
).subscribe({
error() {
//log things
console.log('Failed to finished message subscription!');
error(e) {
throw e;
},
next(command) {
//log on each command emitted

View File

@@ -21,6 +21,7 @@ export const onReady = ( wrapper : Wrapper ) => {
)
.subscribe({
complete() {
console.log(Files.Commands);
// on ready event, complete!
// log stuff?
}

View File

@@ -6,20 +6,19 @@ import type {
Client,
} from 'discord.js';
import Logger from './logger';
import type Wrapper from './structures/wrapper';
import { fromEvent } from 'rxjs';
import { SernError } from './structures/errors';
import { onReady } from './events/readyEvent';
import { onMessageCreate } from './events/messageEvent';
import { onInteractionCreate } from './events/interactionCreate';
export function init( wrapper : Wrapper) {
const logger = new Logger();
const { events, client } = wrapper;
if (events !== undefined) eventObserver(client, events);
onReady( wrapper );
onMessageCreate( wrapper );
onInteractionCreate ( wrapper );
}

View File

@@ -8,7 +8,7 @@ import type Context from "../context";
export interface BaseModule {
name? : string;
description : string;
execute<T>(ctx: Context, args: Args) : Awaitable<T>
execute: (ctx: Context, args: Args) => Awaitable<void>;
}
export type Text = {
type : CommandType.TEXT;