Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
hwangsihu committed Jul 18, 2024
1 parent 2f00d39 commit 93016f7
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 51 deletions.
7 changes: 6 additions & 1 deletion src/commands/info/Help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ export default class Help extends Command {
const command = this.client.commands.get(args[0].toLowerCase());
if (!command) {
return await ctx.sendMessage({
embeds: [client.embed().setColor(client.color.red).setDescription(ctx.locale("cmd.help.not_found", { cmdName: args[0] }))],
embeds: [
client
.embed()
.setColor(client.color.red)
.setDescription(ctx.locale("cmd.help.not_found", { cmdName: args[0] })),
],
});
}
const helpEmbed = embed
Expand Down
7 changes: 1 addition & 6 deletions src/commands/info/Invite.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ActionRowBuilder, ButtonBuilder, ButtonStyle } from "discord.js";
import { Command, type Context, type Lavamusic } from "../../structures/index.js";


export default class Invite extends Command {
constructor(client: Lavamusic) {
super(client, {
Expand Down Expand Up @@ -43,11 +42,7 @@ export default class Invite extends Command {
new ButtonBuilder().setLabel(ctx.locale("buttons.support")).setStyle(ButtonStyle.Link).setURL("https://discord.gg/STXurwnZD5"),
);
return await ctx.sendMessage({
embeds: [
embed
.setColor(this.client.color.main)
.setDescription(ctx.locale("cmd.invite.content"))
],
embeds: [embed.setColor(this.client.color.main).setDescription(ctx.locale("cmd.invite.content"))],
components: [row],
});
}
Expand Down
1 change: 0 additions & 1 deletion src/commands/info/LavaLink.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Command, type Context, type Lavamusic } from "../../structures/index.js";


export default class LavaLink extends Command {
constructor(client: Lavamusic) {
super(client, {
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import dotenv from "dotenv";
import { SearchEngine, Language } from "./types.js";
import { Language, SearchEngine } from "./types.js";
dotenv.config();

const parseBoolean = (value?: string): boolean => value?.trim().toLowerCase() === "true";
Expand Down
2 changes: 1 addition & 1 deletion src/database/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export default class ServerData {
await this.prisma.song.create({
data: {
track: JSON.stringify(song),
playlistId: playlist.id
playlistId: playlist.id,
},
});
} else {
Expand Down
6 changes: 5 additions & 1 deletion src/events/client/InteractionCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ export default class InteractionCreate extends Event {
const allowedCategories = ["filters", "music", "playlist"];
const commandInSetup = this.client.commands.get(interaction.commandName);

if (setup && interaction.channelId === setup.textId && (!commandInSetup || !allowedCategories.includes(commandInSetup.category))) {
if (
setup &&
interaction.channelId === setup.textId &&
(!commandInSetup || !allowedCategories.includes(commandInSetup.category))
) {
return await interaction.reply({
content: `You can't use this command in setup channel.`,
ephemeral: true,
Expand Down
2 changes: 1 addition & 1 deletion src/structures/Context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import {
type TextChannel,
type User,
} from "discord.js";
import type { Lavamusic } from "./index.js";
import { T } from "./I18n.js";
import type { Lavamusic } from "./index.js";

export default class Context {
public ctx: CommandInteraction | Message;
Expand Down
12 changes: 5 additions & 7 deletions src/structures/I18n.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@

import i18n from "i18n";

import Logger from "./Logger.js";
import { Locale } from "discord.js";
import { Language } from "../types.js";
import Logger from "./Logger.js";

const logger = new Logger();


export function initI18n() {
i18n.configure({
locales: Object.keys(Language),
Expand All @@ -23,8 +21,8 @@ export function initI18n() {
},
mustacheConfig: {
tags: ["{", "}"],
disable: false
}
disable: false,
},
});

logger.info("I18n has been initialized");
Expand All @@ -40,10 +38,10 @@ export function T(locale: string, text: string | i18n.TranslateOptions, ...param
export function localization(lan: any, name: any, desc: any) {
return {
name: [Locale[lan], name],
description: [Locale[lan], T(lan, desc)]
description: [Locale[lan], T(lan, desc)],
};
}

export function descriptionLocalization(name: any, text: any) {
return i18n.getLocales().map((locale) => localization(Locale[locale] || locale, name, text));
}
}
14 changes: 8 additions & 6 deletions src/structures/Lavamusic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import {
type RESTPostAPIChatInputApplicationCommandsJSONBody,
Routes,
} from "discord.js";
import { Locale } from "discord.js";
import config from "../config.js";
import ServerData from "../database/server.js";
import loadPlugins from "../plugin/index.js";
import { Utils } from "../utils/Utils.js";
import { T, i18n, initI18n, localization } from "./I18n.js";
import Logger from "./Logger.js";
import { type Command, Queue, ShoukakuClient } from "./index.js";
import { initI18n, T, i18n, localization } from "./I18n.js";
import { Locale } from 'discord.js';

const __dirname = path.dirname(fileURLToPath(import.meta.url));

Expand Down Expand Up @@ -86,12 +86,14 @@ export default class Lavamusic extends Client {
type: ApplicationCommandType.ChatInput,
options: command.options || [],
default_member_permissions:
Array.isArray(command.permissions.user) && command.permissions.user.length > 0 ? PermissionsBitField.resolve(command.permissions.user as any).toString() : null,
Array.isArray(command.permissions.user) && command.permissions.user.length > 0
? PermissionsBitField.resolve(command.permissions.user as any).toString()
: null,
name_localizations: null,
description_localizations: null
description_localizations: null,
};
// command description and name localizations
const localizations = []
const localizations = [];
i18n.getLocales().map((locale) => {
localizations.push(localization(locale, command.name, command.description.content));
});
Expand All @@ -106,7 +108,7 @@ export default class Lavamusic extends Client {
if (command.options.length > 0) {
command.options.map((option) => {
// command options name and description localizations
const optionsLocalizations = []
const optionsLocalizations = [];
i18n.getLocales().map((locale) => {
optionsLocalizations.push(localization(locale, option.name, option.description));
});
Expand Down
52 changes: 26 additions & 26 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,37 @@ export enum Language {
French = "French",
}
export const LocaleFlags = {
// [Locale.Indonesian]: "🇮🇩",
// [Locale.Indonesian]: "🇮🇩",
[Locale.EnglishUS]: "🇺🇸",
// [Locale.EnglishGB]: "🇬🇧",
// [Locale.Bulgarian]: "🇧🇬",
// [Locale.ChineseCN]: "🇨🇳",
// [Locale.ChineseTW]: "🇹🇼",
// [Locale.Croatian]: "🇭🇷",
// [Locale.Czech]: "🇨🇿",
// [Locale.Danish]: "🇩🇰",
// [Locale.Dutch]: "🇳🇱",
// [Locale.Finnish]: "🇫🇮",
// [Locale.EnglishGB]: "🇬🇧",
// [Locale.Bulgarian]: "🇧🇬",
// [Locale.ChineseCN]: "🇨🇳",
// [Locale.ChineseTW]: "🇹🇼",
// [Locale.Croatian]: "🇭🇷",
// [Locale.Czech]: "🇨🇿",
// [Locale.Danish]: "🇩🇰",
// [Locale.Dutch]: "🇳🇱",
// [Locale.Finnish]: "🇫🇮",
[Locale.French]: "🇫🇷",
// [Locale.German]: "🇩🇪",
// [Locale.Greek]: "🇬🇷",
// [Locale.German]: "🇩🇪",
// [Locale.Greek]: "🇬🇷",
[Locale.Hindi]: "🇮🇳",
// [Locale.Hungarian]: "🇭🇺",
// [Locale.Italian]: "🇮🇹",
// [Locale.Japanese]: "🇯🇵",
// [Locale.Hungarian]: "🇭🇺",
// [Locale.Italian]: "🇮🇹",
// [Locale.Japanese]: "🇯🇵",
[Locale.Korean]: "🇰🇷",
// [Locale.Lithuanian]: "🇱🇹",
// [Locale.Norwegian]: "🇳🇴",
// [Locale.Lithuanian]: "🇱🇹",
// [Locale.Norwegian]: "🇳🇴",
[Locale.Polish]: "🇵🇱",
// [Locale.PortugueseBR]: "🇧🇷",
// [Locale.Romanian]: "🇷🇴",
// [Locale.Russian]: "🇷🇺",
// [Locale.SpanishES]: "🇪🇸",
// [Locale.Swedish]: "🇸🇪",
// [Locale.Thai]: "🇹🇭",
// [Locale.Turkish]: "🇹🇷",
// [Locale.Ukrainian]: "🇺🇦",
// [Locale.Vietnamese]: "🇻🇳"
// [Locale.PortugueseBR]: "🇧🇷",
// [Locale.Romanian]: "🇷🇴",
// [Locale.Russian]: "🇷🇺",
// [Locale.SpanishES]: "🇪🇸",
// [Locale.Swedish]: "🇸🇪",
// [Locale.Thai]: "🇹🇭",
// [Locale.Turkish]: "🇹🇷",
// [Locale.Ukrainian]: "🇺🇦",
// [Locale.Vietnamese]: "🇻🇳"
};
/**
* Project: lavamusic
Expand Down

0 comments on commit 93016f7

Please sign in to comment.