refactor allat

This commit is contained in:
jacob
2024-05-01 16:46:12 -05:00
parent e8cfcc2525
commit 0488f45677
13 changed files with 44 additions and 50 deletions

View File

@@ -20,22 +20,21 @@ export function reconstruct<T extends Interaction>(event: T) {
*
* A magic number to represent any commandtype that is an ApplicationCommand.
*/
const appBitField = 0b000000001111;
const PUBLISHABLE = 0b000000001111;
const TypeMap = new Map<number, number>([
[CommandType.Text, 0],
[CommandType.Both, 0],
[CommandType.Slash, ApplicationCommandType.ChatInput],
[CommandType.CtxUser, ApplicationCommandType.User],
[CommandType.CtxMsg, ApplicationCommandType.Message],
[CommandType.Button, ComponentType.Button],
[CommandType.Modal, InteractionType.ModalSubmit],
[CommandType.StringSelect, ComponentType.StringSelect],
[CommandType.UserSelect, ComponentType.UserSelect],
[CommandType.MentionableSelect, ComponentType.MentionableSelect],
[CommandType.RoleSelect, ComponentType.RoleSelect],
[CommandType.ChannelSelect, ComponentType.ChannelSelect]]);
const TypeMap = new Map<number, number>([[CommandType.Text, 0],
[CommandType.Both, 0],
[CommandType.Slash, ApplicationCommandType.ChatInput],
[CommandType.CtxUser, ApplicationCommandType.User],
[CommandType.CtxMsg, ApplicationCommandType.Message],
[CommandType.Button, ComponentType.Button],
[CommandType.Modal, InteractionType.ModalSubmit],
[CommandType.StringSelect, ComponentType.StringSelect],
[CommandType.UserSelect, ComponentType.UserSelect],
[CommandType.MentionableSelect, ComponentType.MentionableSelect],
[CommandType.RoleSelect, ComponentType.RoleSelect],
[CommandType.ChannelSelect, ComponentType.ChannelSelect]]);
/*
* Generates an id based on name and CommandType.
@@ -52,7 +51,7 @@ export function create(name: string, type: CommandType | EventType) {
if(type == CommandType.Modal) {
return `${name}_M`;
}
const am = (appBitField & type) !== 0 ? 'A' : 'C';
const am = (PUBLISHABLE & type) !== 0 ? 'A' : 'C';
return `${name}_${am}${TypeMap.get(type)!}`
}

View File

@@ -3,14 +3,11 @@ import type { IntoDependencies } from '../../types/ioc';
import { useContainerRaw } from './base';
/**
* @__PURE__
* @since 2.0.0.
* Creates a singleton object.
* @param cb
*/
export function single<T>(cb: () => T) {
return cb;
}
export function single<T>(cb: () => T) { return cb; }
/**
* @__PURE__
@@ -18,9 +15,7 @@ export function single<T>(cb: () => T) {
* Creates a transient object
* @param cb
*/
export function transient<T>(cb: () => () => T) {
return cb;
}
export function transient<T>(cb: () => () => T) { return cb; }
/**
* The new Service api, a cleaner alternative to useContainer
* To obtain intellisense, ensure a .d.ts file exists in the root of compilation.

View File

@@ -9,7 +9,6 @@ import {
EMPTY,
every,
fromEvent,
map,
Observable,
of,
OperatorFunction,
@@ -46,7 +45,7 @@ export function callPlugin(args: unknown): OperatorFunction<PluginExecutable, Vo
});
}
export const arrayifySource = map(src => (Array.isArray(src) ? (src as unknown[]) : [src]));
export const arrayifySource = <T>(src: T) => (Array.isArray(src) ? (src as unknown[]) : [src]);
/**
* Checks if the stream of results is all ok.

View File

@@ -105,8 +105,7 @@ export class Context extends CoreContext<Message, ChatInputCommandInteraction> {
this.ctx
.map(m => m.reply(content as MessageReplyOptions))
.mapErr(i =>
i.reply(content as InteractionReplyOptions).then(() => i.fetchReply()),
),
i.reply(content as InteractionReplyOptions).then(() => i.fetchReply())),
);
}