Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ArrowM committed Jun 28, 2024
1 parent 21fd457 commit 6f1f686
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/commands/commands/displays.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ export class DisplaysCommand extends AdminCommand {
queues: new QueuesOption({ required: true, description: "Queue(s) to display" }),
};

static async displays_add(inter: SlashInteraction, queues?: Collection<bigint, DbQueue>) {
queues = queues ?? await DisplaysCommand.ADD_OPTIONS.queues.get(inter);
static async displays_add(inter: SlashInteraction) {
const queues = await DisplaysCommand.ADD_OPTIONS.queues.get(inter);

await ShowCommand.show(inter, queues);

Expand Down
2 changes: 1 addition & 1 deletion src/commands/commands/logging.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class LoggingCommand extends AdminCommand {

logging_get = LoggingCommand.logging_get;
logging_set = LoggingCommand.logging_set;
logging_reset = LoggingCommand.logging_disable;
logging_disable = LoggingCommand.logging_disable;

data = new SlashCommandBuilder()
.setName("logging")
Expand Down
8 changes: 5 additions & 3 deletions src/commands/commands/queues.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,11 @@ export class QueuesCommand extends AdminCommand {
updatedProperties[columnKey] = (QUEUE_TABLE as any)[columnKey]?.default ?? null;
}

const updatedQueues = db.transaction(() =>
queues.map((queue) => inter.store.updateQueue({ id: queue.id, ...updatedProperties }))
);
const updatedQueues = db.transaction(() => {
return queues.map((queue) =>
inter.store.updateQueue({ id: queue.id, ...updatedProperties })
);
});

if (updatedProperties.roleId) {
await MemberUtils.assignInQueueRoleToMembers(inter.store, queues, updatedProperties.roleId, "remove");
Expand Down
11 changes: 3 additions & 8 deletions src/commands/commands/show.command.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Collection, italic, SlashCommandBuilder } from "discord.js";
import { type Collection, SlashCommandBuilder } from "discord.js";

import type { DbQueue } from "../../db/schema.ts";
import { QueuesOption } from "../../options/options/queues.option.ts";
Expand Down Expand Up @@ -28,13 +28,8 @@ export class ShowCommand extends EveryoneCommand {
static async show(inter: SlashInteraction, queues?: Collection<bigint, DbQueue>) {
queues = queues ?? await DisplaysCommand.GET_OPTIONS.queues.get(inter);

const result = await DisplayUtils.insertDisplays(inter.store, queues, inter.channel.id);
await DisplayUtils.insertDisplays(inter.store, queues, inter.channel.id);

if (!inter.replied) {
await inter.respond(italic("displaying..."));
}
// setTimeout(async () => await inter.deleteReply().catch(() => null), 5000);

return result;
await inter.deleteReply().catch(() => null);
}
}
2 changes: 1 addition & 1 deletion src/db/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class Store {
// Common data
// ====================================================================

dbGuild = moize(() => Queries.selectGuild({ guildId: this.guild.id }));
dbGuild = moize(() => this.insertGuild({ guildId: this.guild.id }));
dbQueues = moize(() => toCollection<bigint, DbQueue>("id", Queries.selectManyQueues({ guildId: this.guild.id })));
dbVoices = moize(() => toCollection<bigint, DbVoice>("id", Queries.selectManyVoices({ guildId: this.guild.id })));
dbDisplays = moize(() => toCollection<bigint, DbDisplay>("id", Queries.selectManyDisplays({ guildId: this.guild.id })));
Expand Down
3 changes: 3 additions & 0 deletions src/options/base-option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ export abstract class BaseOption<BuilderType extends ApplicationCommandOptionBas
selection = this.getUncached(inter);
inter.parser.cache.set(this.identifier, selection);
}
if (selection === undefined && (this.config?.required ?? this.required)) {
throw new Error(`Required option ${this.identifier} not found`);
}
return selection;
}

Expand Down
5 changes: 2 additions & 3 deletions src/utils/display.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export namespace DisplayUtils {
try {
const { message, stack } = e as Error;
const isPermissionError = /access|permission/i.test(message);
if (store.inter?.member) {
if (store.inter) {
const embed = new EmbedBuilder()
.setTitle("Failed to display queue")
.setColor(Color.Red)
Expand All @@ -236,9 +236,8 @@ export namespace DisplayUtils {
if (!isPermissionError) {
embed.setFooter({ text: "This error has been logged and will be investigated by the developers." });
}
await store.inter.member.send({ embeds: [embed] });
await store.inter.respond({ embeds: [embed] });
}

if (!isPermissionError) {
console.error("Failed to update displays:");
console.error(`Error: ${message}`);
Expand Down
2 changes: 2 additions & 0 deletions src/utils/message-utils/select-menu-transactor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export class SelectMenuTransactor {
}

async updateWithResult(title: string, selection: ArrayOrCollection<any, any> | string) {
if (!this.userResponse) return;

let description;
if (typeof selection === "string") {
description = selection;
Expand Down
4 changes: 2 additions & 2 deletions src/utils/misc.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ export function size<T>(items: ArrayOrCollection<any, T>): number {
}

export function map<T, S>(items: ArrayOrCollection<any, T>, fn: (queue: T) => S): S[] {
return (items instanceof Collection) ? items.map(fn) : items.map(fn);
return (items instanceof Collection) ? items?.map(fn) : items?.map(fn);
}

export function find<T>(items: ArrayOrCollection<any, T>, fn: (queue: T) => boolean): T {
return (items instanceof Collection) ? items.find(fn) : items.find(fn);
return (items instanceof Collection) ? items?.find(fn) : items?.find(fn);
}

export function filterDbObjectsOnJsMember<T extends {
Expand Down

0 comments on commit 6f1f686

Please sign in to comment.