Skip to content

Commit

Permalink
ts strict true
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasB25 committed Aug 6, 2024
1 parent 208b04b commit 5a042fe
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 48 deletions.
6 changes: 2 additions & 4 deletions src/commands/config/Language.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Command, type Context, type Lavamusic } from "../../structures/index.js";
import { Language, LocaleFlags } from "../../types.js";
import type { AutocompleteInteraction } from "discord.js";

export default class LanguageCommand extends Command {
constructor(client: Lavamusic) {
Expand Down Expand Up @@ -131,19 +132,16 @@ export default class LanguageCommand extends Command {
}
}

public async autocomplete(interaction) {
public async autocomplete(interaction: AutocompleteInteraction): Promise<void> {
const focusedValue = interaction.options.getFocused();

// Fetch all available languages
const languages = Object.values(Language).map((language) => ({
name: language,
value: language,
}));

// Filter languages based on the focused value
const filtered = languages.filter((language) => language.name.toLowerCase().includes(focusedValue.toLowerCase()));

// Respond with the filtered language options
await interaction.respond(filtered.slice(0, 25)).catch(console.error);
}
}
3 changes: 2 additions & 1 deletion src/commands/music/Play.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { LoadType } from "shoukaku";
import { Command, type Context, type Lavamusic } from "../../structures/index.js";
import type { AutocompleteInteraction } from "discord.js";

export default class Play extends Command {
constructor(client: Lavamusic) {
Expand Down Expand Up @@ -165,7 +166,7 @@ export default class Play extends Command {
}
}

public async autocomplete(interaction) {
public async autocomplete(interaction: AutocompleteInteraction): Promise<void> {
const focusedValue = interaction.options.getFocused();

try {
Expand Down
5 changes: 2 additions & 3 deletions src/commands/music/PlayNext.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { LoadType } from "shoukaku";
import { Command, type Context, type Lavamusic } from "../../structures/index.js";
import type { AutocompleteInteraction } from "discord.js";

export default class PlayNext extends Command {
constructor(client: Lavamusic) {
Expand Down Expand Up @@ -153,10 +154,9 @@ export default class PlayNext extends Command {
}
}

public async autocomplete(interaction) {
public async autocomplete(interaction: AutocompleteInteraction): Promise<void> {
const focusedValue = interaction.options.getFocused();

// Search for songs based on the focused value
const res = await this.client.queue.search(focusedValue);
const songs = [];

Expand All @@ -169,7 +169,6 @@ export default class PlayNext extends Command {
});
}

// Respond with the song suggestions
await interaction.respond(songs).catch(console.error);
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/commands/playlist/AddSong.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { LoadType } from "shoukaku";
import { Command, type Context, type Lavamusic } from "../../structures/index.js";
import type { AutocompleteInteraction } from "discord.js";

export default class AddSong extends Command {
constructor(client: Lavamusic) {
Expand Down Expand Up @@ -108,15 +109,12 @@ export default class AddSong extends Command {
await ctx.sendMessage({ embeds: [successMessage] });
}

// Add autocomplete handler
public async autocomplete(interaction) {
public async autocomplete(interaction: AutocompleteInteraction): Promise<void> {
const focusedValue = interaction.options.getFocused();
const userId = interaction.user.id;

// Fetch user playlists from the database
const playlists = await this.client.db.getUserPlaylists(userId);

// Filter playlists based on the focused value and respond
const filtered = playlists.filter((playlist) => playlist.name.toLowerCase().startsWith(focusedValue.toLowerCase()));

await interaction.respond(
Expand Down
6 changes: 2 additions & 4 deletions src/commands/playlist/Delete.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Command, type Context, type Lavamusic } from "../../structures/index.js";
import type { AutocompleteInteraction } from "discord.js";

export default class DeletePlaylist extends Command {
constructor(client: Lavamusic) {
Expand Down Expand Up @@ -66,15 +67,12 @@ export default class DeletePlaylist extends Command {
});
}

// Add autocomplete handler
public async autocomplete(interaction) {
public async autocomplete(interaction: AutocompleteInteraction): Promise<void> {
const focusedValue = interaction.options.getFocused();
const userId = interaction.user.id;

// Fetch user playlists from the database
const playlists = await this.client.db.getUserPlaylists(userId);

// Filter playlists based on the focused value and respond
const filtered = playlists.filter((playlist) => playlist.name.toLowerCase().startsWith(focusedValue.toLowerCase()));

await interaction.respond(
Expand Down
2 changes: 1 addition & 1 deletion src/commands/playlist/List.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class GetPlaylists extends Command {
{
name: "user",
description: "cmd.list.options.user",
type: 6, // USER type
type: 6,
required: false,
},
],
Expand Down
6 changes: 2 additions & 4 deletions src/commands/playlist/Load.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Command, type Context, type Lavamusic } from "../../structures/index.js";
import type { AutocompleteInteraction } from "discord.js";

export default class LoadPlaylist extends Command {
constructor(client: Lavamusic) {
Expand Down Expand Up @@ -94,15 +95,12 @@ export default class LoadPlaylist extends Command {
});
}

// Add autocomplete handler
public async autocomplete(interaction) {
public async autocomplete(interaction: AutocompleteInteraction): Promise<void> {
const focusedValue = interaction.options.getFocused();
const userId = interaction.user.id;

// Fetch user playlists from the database
const playlists = await this.client.db.getUserPlaylists(userId);

// Filter playlists based on the focused value and respond
const filtered = playlists.filter((playlist) => playlist.name.toLowerCase().startsWith(focusedValue.toLowerCase()));

await interaction.respond(
Expand Down
6 changes: 2 additions & 4 deletions src/commands/playlist/RemoveSong.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { LoadType } from "shoukaku";
import { Command, type Context, type Lavamusic } from "../../structures/index.js";
import type { AutocompleteInteraction } from "discord.js";

export default class RemoveSong extends Command {
constructor(client: Lavamusic) {
Expand Down Expand Up @@ -109,15 +110,12 @@ export default class RemoveSong extends Command {
return await ctx.sendMessage({ embeds: [genericError] });
}
}
// Add autocomplete handler
public async autocomplete(interaction) {
public async autocomplete(interaction: AutocompleteInteraction): Promise<void> {
const focusedValue = interaction.options.getFocused();
const userId = interaction.user.id;

// Fetch user playlists from the database
const playlists = await this.client.db.getUserPlaylists(userId);

// Filter playlists based on the focused value and respond
const filtered = playlists.filter((playlist) => playlist.name.toLowerCase().startsWith(focusedValue.toLowerCase()));

await interaction.respond(
Expand Down
11 changes: 3 additions & 8 deletions src/commands/playlist/Steal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default class StealPlaylist extends Command {
{
name: "user",
description: "cmd.steal.options.user",
type: 6, // USER type
type: 6,
required: true,
},
],
Expand Down Expand Up @@ -129,17 +129,14 @@ export default class StealPlaylist extends Command {
return;
}

// Fetch the user object using the client
const user = await interaction.client.users.fetch(userOptionId);
if (!user) {
await interaction.respond([{ name: "User not found.", value: "NoUserFound" }]).catch(console.error);
return; // Exit early if user cannot be found
return;
}

// Proceed with fetching the user's playlists
const playlists = await this.client.db.getUserPlaylists(user.id);

// If no playlists are found, respond accordingly
if (!playlists || playlists.length === 0) {
await interaction
.respond([
Expand All @@ -149,13 +146,11 @@ export default class StealPlaylist extends Command {
},
])
.catch(console.error);
return; // Exit early as there are no playlists
return;
}

// Filter playlists based on the focused value
const filtered = playlists.filter((playlist) => playlist.name.toLowerCase().startsWith(focusedValue.toLowerCase()));

// Respond with filtered playlist names
await interaction
.respond(
filtered.map((playlist) => ({
Expand Down
19 changes: 8 additions & 11 deletions src/structures/Lavamusic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export default class Lavamusic extends Client {
public readonly emoji = config.emoji;
public readonly color = config.color;
private body: RESTPostAPIChatInputApplicationCommandsJSONBody[] = [];
public shoukaku: ShoukakuClient;
public topGG: Api;
public shoukaku!: ShoukakuClient;
public topGG!: Api;
public utils = Utils;
public queue = new Queue(this);

Expand All @@ -56,8 +56,8 @@ export default class Lavamusic extends Client {
loadPlugins(this);
await this.login(token);

this.on(Events.InteractionCreate, async (interaction: Interaction<"cached">) => {
if (interaction.isButton()) {
this.on(Events.InteractionCreate, async (interaction: Interaction) => {
if (interaction.isButton() && interaction.guildId) {
const setup = await this.db.getSetup(interaction.guildId);
if (setup && interaction.channelId === setup.textId && interaction.message.id === setup.messageId) {
this.emit("setupButtons", interaction);
Expand Down Expand Up @@ -96,11 +96,12 @@ export default class Lavamusic extends Client {
name_localizations: null,
description_localizations: null,
};
// command description and name localizations

const localizations = [];
i18n.getLocales().map((locale) => {
localizations.push(localization(locale, command.name, command.description.content));
});

for (const localization of localizations) {
const [language, name] = localization.name;
const [language2, description] = localization.description;
Expand All @@ -114,14 +115,13 @@ export default class Lavamusic extends Client {
};
}

// command options localizations
if (command.options.length > 0) {
command.options.map((option) => {
// command options name and description localizations
const optionsLocalizations = [];
i18n.getLocales().map((locale) => {
optionsLocalizations.push(localization(locale, option.name, option.description));
});

for (const localization of optionsLocalizations) {
const [language, name] = localization.name;
const [language2, description] = localization.description;
Expand All @@ -134,19 +134,17 @@ export default class Lavamusic extends Client {
[language2]: description,
};
}
// command options description localization
option.description = T(Locale.EnglishUS, option.description);
});

// subcommand options localizations
data.options.map((option) => {
if ("options" in option && option.options.length > 0) {
option.options.map((subOption) => {
// subcommand options name and description localizations
const subOptionsLocalizations = [];
i18n.getLocales().map((locale) => {
subOptionsLocalizations.push(localization(locale, subOption.name, subOption.description));
});

for (const localization of subOptionsLocalizations) {
const [language, name] = localization.name;
const [language2, description] = localization.description;
Expand All @@ -159,7 +157,6 @@ export default class Lavamusic extends Client {
[language2]: description,
};
}
// subcommand options description localization
subOption.description = T(Locale.EnglishUS, subOption.description);
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/BotLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default class BotLog {
public static send(client: Lavamusic, message: string, type: "error" | "warn" | "info" | "success" = "info"): void {
if (!client?.channels.cache && client.config.logChannelId) return;

const channel = client.channels.cache.get(client.config.logChannelId) as TextChannel;
const channel = client.channels.cache.get(client.config.logChannelId!) as TextChannel;
if (!channel) return;

const colors = {
Expand Down
7 changes: 4 additions & 3 deletions src/utils/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class Utils {
public static updateStatus(client: Lavamusic, guildId?: string): void {
const { user } = client;
if (user && guildId === config.guildId) {
const player = client.queue.get(config.guildId);
const player = client.queue.get(config.guildId!);
user.setPresence({
activities: [
{
Expand Down Expand Up @@ -80,6 +80,7 @@ export class Utils {
ctx.deferred ? ctx.interaction.followUp({ embeds: embed }) : ctx.interaction.reply({ embeds: embed });
return;
}

(ctx.channel as TextChannel).send({ embeds: embed });
return;
}
Expand Down Expand Up @@ -117,11 +118,11 @@ export class Utils {
const msgOptions = getButton(0);
const msg = ctx.isInteraction
? await (ctx.deferred
? ctx.interaction.followUp({
? ctx.interaction!.followUp({
...msgOptions,
fetchReply: true as boolean,
})
: ctx.interaction.reply({ ...msgOptions, fetchReply: true }))
: ctx.interaction!.reply({ ...msgOptions, fetchReply: true }))
: await (ctx.channel as TextChannel).send({
...msgOptions,
fetchReply: true,
Expand Down

0 comments on commit 5a042fe

Please sign in to comment.