style: change prettier print width and reformat

This commit is contained in:
Jacob Nguyen
2022-05-21 23:58:52 -05:00
parent a2209494bd
commit 26756077ef
8 changed files with 101 additions and 65 deletions

View File

@@ -2,7 +2,7 @@
"semi": true,
"trailingComma": "all",
"singleQuote": true,
"printWidth": 120,
"printWidth": 100,
"tabWidth": 4,
"arrowParens": "avoid"
}

View File

@@ -1,4 +1,9 @@
import type { CommandInteraction, Interaction, MessageComponentInteraction, SelectMenuInteraction } from 'discord.js';
import type {
CommandInteraction,
Interaction,
MessageComponentInteraction,
SelectMenuInteraction,
} from 'discord.js';
import { concatMap, fromEvent, map, Observable, of, throwError } from 'rxjs';
import type Wrapper from '../structures/wrapper';
import * as Files from '../utilities/readFile';
@@ -27,7 +32,11 @@ function applicationCommandHandler(mod: Module | undefined, interaction: Command
const ctx = Context.wrap(i);
return mod$(CommandType.Slash).pipe(
concatMap(m => {
return of(m.onEvent?.map(e => e.execute([ctx, ['slash', i.options]], controller)) ?? []).pipe(
return of(
m.onEvent?.map(e =>
e.execute([ctx, ['slash', i.options]], controller),
) ?? [],
).pipe(
map(res => ({
mod,
res,
@@ -75,7 +84,10 @@ function applicationCommandHandler(mod: Module | undefined, interaction: Command
);
}
function messageComponentInteractionHandler(mod: Module | undefined, interaction: MessageComponentInteraction) {
function messageComponentInteractionHandler(
mod: Module | undefined,
interaction: MessageComponentInteraction,
) {
const mod$ = <T extends CommandType>(ty: T) => of(mod).pipe(filterCorrectModule(ty));
//Todo: refactor so that we dont have to have two separate branches. They're near identical!!
//Only thing that differs is type of interaction
@@ -124,12 +136,15 @@ export function onInteractionCreate(wrapper: Wrapper) {
concatMap(interaction => {
if (interaction.isCommand()) {
const modul =
Files.ApplicationCommands[interaction.commandType].get(interaction.commandName) ??
Files.BothCommands.get(interaction.commandName);
Files.ApplicationCommands[interaction.commandType].get(
interaction.commandName,
) ?? Files.BothCommands.get(interaction.commandName);
return applicationCommandHandler(modul, interaction);
}
if (interaction.isMessageComponent()) {
const modul = Files.MessageCompCommands[interaction.componentType].get(interaction.customId);
const modul = Files.MessageCompCommands[interaction.componentType].get(
interaction.customId,
);
return messageComponentInteractionHandler(modul, interaction);
} else return throwError(() => SernError.NotSupportedInteraction);
}),

View File

@@ -52,9 +52,11 @@ export const onReady = (wrapper: Wrapper) => {
)
.pipe(
concatMap(pl =>
from(Promise.all(pl.cmdPluginsRes.map(async e => ({ ...e, execute: await e.execute })))).pipe(
map(res => ({ ...pl, cmdPluginsRes: res })),
),
from(
Promise.all(
pl.cmdPluginsRes.map(async e => ({ ...e, execute: await e.execute })),
),
).pipe(map(res => ({ ...pl, cmdPluginsRes: res }))),
),
)
.subscribe(({ mod, cmdPluginsRes }) => {

View File

@@ -34,7 +34,11 @@ export type CommandPlugin = Override<
BasePlugin,
{
type: PluginType.Command;
execute: (wrapper: Client, module: Module, controller: Controller) => Awaitable<Result<void, void>>;
execute: (
wrapper: Client,
module: Module,
controller: Controller,
) => Awaitable<Result<void, void>>;
}
>;
@@ -44,7 +48,10 @@ export type EventPlugin<T extends keyof ModuleDefs> = Override<
BasePlugin,
{
type: PluginType.Event;
execute: (event: Parameters<ModuleDefs[T]['execute']>, controller: Controller) => Awaitable<Result<void, void>>;
execute: (
event: Parameters<ModuleDefs[T]['execute']>,
controller: Controller,
) => Awaitable<Result<void, void>>;
}
>;

View File

@@ -26,7 +26,10 @@ export default class SernEmitter extends EventEmitter {
return super.once(eventName, listener);
}
public override emit<T extends keyof SernEventsMapping>(eventName: T, ...args: SernEventsMapping[T]): boolean {
public override emit<T extends keyof SernEventsMapping>(
eventName: T,
...args: SernEventsMapping[T]
): boolean {
return super.emit(eventName, ...args);
}
}

View File

@@ -1,6 +1,7 @@
import type { APIGuildMember } from 'discord-api-types/v9';
import type {
ChatInputCommandInteraction,
Client,
Guild,
GuildMember,
InteractionReplyOptions,
@@ -12,7 +13,6 @@ import type {
} from 'discord.js';
import { None, Option, Some } from 'ts-results';
import type { Nullish } from '../../types/handler';
import type { Client } from 'discord.js';
import { ExternallyUsed } from '../utilities/externallyUsed';
function firstSome<T>(...args: Option<T>[]): Nullish<T> {
@@ -21,6 +21,7 @@ function firstSome<T>(...args: Option<T>[]): Nullish<T> {
}
return null;
}
//Could I refactor with Either monad?
/**
* The Context class will provide values that are shared between
@@ -35,14 +36,17 @@ export default class Context {
this.oMsg = oMsg;
this.oInterac = oInterac;
}
@ExternallyUsed
public get message() {
return this.oMsg.unwrap();
}
@ExternallyUsed
public get interaction() {
return this.oInterac.unwrap();
}
@ExternallyUsed
public get id(): Snowflake {
return firstSome(
@@ -50,6 +54,7 @@ export default class Context {
this.oMsg.map(m => m.id),
)!;
}
@ExternallyUsed
public get channel(): Nullish<TextBasedChannel> {
return firstSome(
@@ -57,6 +62,7 @@ export default class Context {
this.oInterac.map(i => i.channel),
);
}
@ExternallyUsed
public get user(): User {
return firstSome(
@@ -64,6 +70,7 @@ export default class Context {
this.oInterac.map(i => i.user),
)!;
}
@ExternallyUsed
public get createdTimestamp(): number {
return firstSome(
@@ -71,6 +78,7 @@ export default class Context {
this.oInterac.map(i => i.createdTimestamp),
)!;
}
@ExternallyUsed
public get guild(): Guild {
return firstSome(
@@ -78,6 +86,7 @@ export default class Context {
this.oInterac.map(i => i.guild),
)!;
}
@ExternallyUsed
public get guildId(): Snowflake {
return firstSome(
@@ -97,12 +106,29 @@ export default class Context {
);
}
@ExternallyUsed
public get client(): Client {
return firstSome(
this.oMsg.map(m => m.client),
this.oInterac.map(i => i.client),
)!;
}
@ExternallyUsed
public get inGuild(): boolean {
return firstSome(
this.oMsg.map(m => m.inGuild()),
this.oInterac.map(i => i.inGuild()),
)!;
}
static wrap(wrappable: ChatInputCommandInteraction | Message): Context {
if ('token' in wrappable) {
return new Context(None, Some(wrappable));
}
return new Context(Some(wrappable), None);
}
@ExternallyUsed
public isEmpty() {
return this.oMsg.none && this.oInterac.none;
@@ -120,18 +146,4 @@ export default class Context {
}),
)!;
}
@ExternallyUsed
public get client(): Client {
return firstSome(
this.oMsg.map(m => m.client),
this.oInterac.map(i => i.client),
)!;
}
@ExternallyUsed
public get inGuild(): boolean {
return firstSome(
this.oMsg.map(m => m.inGuild()),
this.oInterac.map(i => i.inGuild()),
)!;
}
}

View File

@@ -657,43 +657,37 @@ class MatchInner {
while ((match = regex.exec(this.raw))) {
const result: DiscordRegexMatch = { matched: match[0], species: type };
switch (type) {
case DiscordRegexNames.EMOJI:
{
result.name = match[1] as string;
result.id = match[2] as string;
result.animated = this.raw.startsWith('<a:');
}
case DiscordRegexNames.EMOJI: {
result.name = match[1] as string;
result.id = match[2] as string;
result.animated = this.raw.startsWith('<a:');
}
break;
case DiscordRegexNames.JUMP_CHANNEL:
{
result.guildId = match[1] as string;
result.channelId = match[2] as string;
}
case DiscordRegexNames.JUMP_CHANNEL: {
result.guildId = match[1] as string;
result.channelId = match[2] as string;
}
break;
case DiscordRegexNames.JUMP_CHANNEL_MESSAGE:
{
result.guildId = match[1] as string;
result.channelId = match[2] as string;
result.messageId = match[3] as string;
}
case DiscordRegexNames.JUMP_CHANNEL_MESSAGE: {
result.guildId = match[1] as string;
result.channelId = match[2] as string;
result.messageId = match[3] as string;
}
break;
case DiscordRegexNames.MENTION_CHANNEL:
case DiscordRegexNames.MENTION_ROLE:
{
result.id = match[1] as string;
}
case DiscordRegexNames.MENTION_ROLE: {
result.id = match[1] as string;
}
break;
case DiscordRegexNames.MENTION_USER:
{
result.id = match[2] as string;
result.mentionType = match[1] as string;
}
case DiscordRegexNames.MENTION_USER: {
result.id = match[2] as string;
result.mentionType = match[1] as string;
}
break;
case DiscordRegexNames.TEXT_CODEBLOCK:
{
result.language = match[2] as string;
result.text = match[3] as string;
}
case DiscordRegexNames.TEXT_CODEBLOCK: {
result.language = match[2] as string;
result.text = match[3] as string;
}
break;
case DiscordRegexNames.TEXT_BOLD:
case DiscordRegexNames.TEXT_CODESTRING:
@@ -702,10 +696,9 @@ class MatchInner {
case DiscordRegexNames.TEXT_SPOILER:
case DiscordRegexNames.TEXT_STRIKE:
case DiscordRegexNames.TEXT_UNDERLINE:
case DiscordRegexNames.TEXT_URL:
{
result.text = match[1] as string;
}
case DiscordRegexNames.TEXT_URL: {
result.text = match[1] as string;
}
break;
default: {
throw new global.Error(`Unknown regex type: ${type}`);

View File

@@ -32,11 +32,15 @@ export function isSelectMenu(i: MessageComponentInteraction): i is SelectMenuInt
return i.isSelectMenu();
}
export function isMessageCtxMenuCmd(i: CommandInteraction): i is MessageContextMenuCommandInteraction {
export function isMessageCtxMenuCmd(
i: CommandInteraction,
): i is MessageContextMenuCommandInteraction {
return i.isMessageContextMenuCommand();
}
export function isUserContextMenuCmd(i: CommandInteraction): i is UserContextMenuCommandInteraction {
export function isUserContextMenuCmd(
i: CommandInteraction,
): i is UserContextMenuCommandInteraction {
return i.isUserContextMenuCommand();
}