Skip to content

Commit

Permalink
Merge branch 'lang' into main
Browse files Browse the repository at this point in the history
Signed-off-by: Appu <[email protected]>
  • Loading branch information
appujet authored Jul 18, 2024
2 parents dc2bf49 + 3194c21 commit 54b557d
Show file tree
Hide file tree
Showing 19 changed files with 325 additions and 84 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "languages"]
path = languages
url = https://github.com/appujet/languages
1 change: 1 addition & 0 deletions languages
Submodule languages added at b6c410
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@
"homepage": "https://github.com/appujet/lavamusic#readme",
"devDependencies": {
"@biomejs/biome": "^1.8.3",

"@types/node": "^20.14.11",

"@types/i18n": "^0.13.12",
"@types/node": "^20.14.10",
"@types/signale": "^1.4.7",
"prisma": "^5.17.0",
"typescript": "^5.5.3"
Expand All @@ -45,6 +49,7 @@
"@prisma/client": "^5.17.0",
"discord.js": "^14.15.3",
"dotenv": "^16.4.5",
"i18n": "^0.15.1",
"node-system-stats": "^1.3.0",
"shoukaku": "github:shipgirlproject/Shoukaku",
"signale": "^1.4.0",
Expand Down
36 changes: 35 additions & 1 deletion prisma/example.mongodb.schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ datasource db {
model Guild {
guildId String @id @map("_id")
prefix String
language String?
stay Stay?
dj Dj?
roles Role[]
Expand Down Expand Up @@ -55,7 +56,7 @@ model Playlist {
}

model Song {
id String @id @map("_id")
id String @id @map("_id") @default(cuid())
track String
playlistId String
playlist Playlist @relation(fields: [playlistId], references: [id])
Expand All @@ -80,3 +81,36 @@ model Premium {
userId String @id @map("_id")
guildId String
}

enum Languages {
EnglishUS
EnglishGB
German
Bulgarian
ChineseCN
ChineseTW
Croatian
Czech
Danish
Dutch
Finnish
French
Greek
Hindi
Hungarian
Italian
Japanese
Korean
Lithuanian
Norwegian
Polish
PortugueseBR
Romanian
Russian
SpanishES
Swedish
Thai
Turkish
Ukrainian
Vietnamese
}
34 changes: 34 additions & 0 deletions prisma/example.postgresql.schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ datasource db {
model Guild {
guildId String @id
prefix String
language String?
stay Stay?
dj Dj?
roles Role[]
Expand Down Expand Up @@ -80,3 +81,36 @@ model Premium {
userId String @id
guildId String
}

enum Languages {
EnglishUS
EnglishGB
German
Bulgarian
ChineseCN
ChineseTW
Croatian
Czech
Danish
Dutch
Finnish
French
Greek
Hindi
Hungarian
Italian
Japanese
Korean
Lithuanian
Norwegian
Polish
PortugueseBR
Romanian
Russian
SpanishES
Swedish
Thai
Turkish
Ukrainian
Vietnamese
}
1 change: 1 addition & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ datasource db {
model Guild {
guildId String @id
prefix String
language String?
stay Stay?
dj Dj?
roles Role[]
Expand Down
87 changes: 47 additions & 40 deletions src/commands/info/Help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default class Help extends Command {
super(client, {
name: "help",
description: {
content: "Shows the help menu",
content: "cmd.help.description",
examples: ["help"],
usage: "help",
},
Expand All @@ -28,7 +28,7 @@ export default class Help extends Command {
options: [
{
name: "command",
description: "The command you want to get info on",
description: "cmd.help.options.command",
type: 3,
required: false,
},
Expand All @@ -45,49 +45,56 @@ 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(`Command \`${args[0]}\` not found`)],
embeds: [client.embed().setColor(client.color.red).setDescription(ctx.locale("cmd.help.not_found", { cmdName: args[0] }))],
});
}
const helpEmbed = embed
.setColor(this.client.color.main)
.setTitle(`Help Menu - ${command.name}`)
.setDescription(`**Description:** ${command.description.content}
**Usage:** ${guild.prefix}${command.description.usage}
**Examples:** ${command.description.examples.map((example) => `${guild.prefix}${example}`).join(", ")}
**Aliases:** ${command.aliases.map((alias) => `\`${alias}\``).join(", ")}
**Category:** ${command.category}
**Cooldown:** ${command.cooldown} seconds
**Permissions:** ${command.permissions.user.length > 0 ? command.permissions.user.map((perm) => `\`${perm}\``).join(", ") : "None"}
**Bot Permissions:** ${command.permissions.client.map((perm) => `\`${perm}\``).join(", ")}
**Developer Only:** ${command.permissions.dev ? "Yes" : "No"}
**Slash Command:** ${command.slashCommand ? "Yes" : "No"}
**Args:** ${command.args ? "Yes" : "No"}
**Player:** ${command.player.active ? "Yes" : "No"}
**DJ:** ${command.player.dj ? "Yes" : "No"}
**DJ Permissions:** ${command.player.djPerm ? command.player.djPerm : "None"}
**Voice:** ${command.player.voice ? "Yes" : "No"}`);
ctx.sendMessage({ embeds: [helpEmbed] });
} else {
const fields = categories.map((category) => ({
name: category,
value: commands
.filter((cmd) => cmd.category === category)
.map((cmd) => `\`${cmd.name}\``)
.join(", "),
inline: false,
}));
const helpEmbed = embed
.setColor(this.client.color.main)
.setTitle("Help Menu")
.setColor(client.color.main)
.setTitle(`${ctx.locale("cmd.help.title")} - ${command.name}`)
.setDescription(
`Hey there! I'm ${this.client.user.username}, a music bot made with [Lavamusic](https://github.com/appujet/lavamusic) and Discord. You can use \`${guild.prefix}help <command>\` to get more info on a command.`,
)
.setFooter({
text: `Use ${guild.prefix}help <command> for more info on a command`,
});
helpEmbed.addFields(...fields);
ctx.sendMessage({ embeds: [helpEmbed] });
ctx.locale("cmd.help.help_cmd", {
description: ctx.locale(command.description.content),
usage: `${guild.prefix}${command.description.usage}`,
examples: command.description.examples.map((example) => `${guild.prefix}${example}`).join(", "),
aliases: command.aliases.map((alias) => `\`${alias}\``).join(", "),
category: command.category,
cooldown: command.cooldown,
premUser:
command.permissions.user.length > 0 ? command.permissions.user.map((perm) => `\`${perm}\``).join(", ") : "None",
premBot: command.permissions.client.map((perm) => `\`${perm}\``).join(", "),
dev: command.permissions.dev ? "Yes" : "No",
slash: command.slashCommand ? "Yes" : "No",
args: command.args ? "Yes" : "No",
player: command.player.active ? "Yes" : "No",
dj: command.player.dj ? "Yes" : "No",
djPerm: command.player.djPerm ? command.player.djPerm : "None",
voice: command.player.voice ? "Yes" : "No",
}),
);
return await ctx.sendMessage({ embeds: [helpEmbed] });
}
const fields = categories.map((category) => ({
name: category,
value: commands
.filter((cmd) => cmd.category === category)
.map((cmd) => `\`${cmd.name}\``)
.join(", "),
inline: false,
}));
const helpEmbed = embed
.setColor(client.color.main)
.setTitle(ctx.locale("cmd.help.title"))
.setDescription(
ctx.locale("cmd.help.content", {
bot: client.user.username,
prefix: guild.prefix,
}),
)
.setFooter({
text: ctx.locale("cmd.help.footer", { prefix: guild.prefix }),
});
helpEmbed.addFields(...fields);
return await ctx.sendMessage({ embeds: [helpEmbed] });
}
}

Expand Down
9 changes: 5 additions & 4 deletions src/commands/info/Invite.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
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, {
name: "invite",
description: {
content: "Sends the bot's invite link",
content: "cmd.invite.description",
examples: ["invite"],
usage: "invite",
},
Expand Down Expand Up @@ -34,18 +35,18 @@ export default class Invite extends Command {
const embed = this.client.embed();
const row = new ActionRowBuilder<ButtonBuilder>().addComponents(
new ButtonBuilder()
.setLabel("Invite")
.setLabel(ctx.locale("buttons.invite"))
.setStyle(ButtonStyle.Link)
.setURL(
`https://discord.com/api/oauth2/authorize?client_id=${client.config.clientId}&permissions=8&scope=bot%20applications.commands`,
),
new ButtonBuilder().setLabel("My Server").setStyle(ButtonStyle.Link).setURL("https://discord.gg/STXurwnZD5"),
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("You can invite me by clicking the button below. Any bugs or outages? Join the support server!"),
.setDescription(ctx.locale("cmd.invite.content"))
],
components: [row],
});
Expand Down
27 changes: 16 additions & 11 deletions src/commands/info/LavaLink.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Command, type Context, type Lavamusic } from "../../structures/index.js";


export default class LavaLink extends Command {
constructor(client: Lavamusic) {
super(client, {
name: "lavalink",
description: {
content: "Shows the current Lavalink stats",
content: "cmd.lavalink.description",
examples: ["lavalink"],
usage: "lavalink",
},
Expand All @@ -32,7 +33,7 @@ export default class LavaLink extends Command {
public async run(client: Lavamusic, ctx: Context): Promise<any> {
const embed = this.client
.embed()
.setTitle("Lavalink Stats")
.setTitle(ctx.locale("cmd.lavalink.title"))
.setColor(this.client.color.main)
.setThumbnail(this.client.user.avatarURL({}))
.setTimestamp();
Expand All @@ -46,16 +47,20 @@ export default class LavaLink extends Command {
memory: { used: 0, reservable: 0 },
};
const formattedStats = `\`\`\`yaml
Player: ${stats.players}
Playing Players: ${stats.playingPlayers}
Uptime: ${client.utils.formatTime(stats.uptime)}
Cores: ${stats.cpu.cores} Core(s)
Memory Usage: ${client.utils.formatBytes(stats.memory.used)} / ${client.utils.formatBytes(stats.memory.reservable)}
System Load: ${(stats.cpu.systemLoad * 100).toFixed(2)}%
Lavalink Load: ${(stats.cpu.lavalinkLoad * 100).toFixed(2)}%
\`\`\``;
${ctx.locale("cmd.lavalink.content", {
players: stats.players,
playingPlayers: stats.playingPlayers,
uptime: client.utils.formatTime(stats.uptime),
cores: stats.cpu.cores,
used: client.utils.formatBytes(stats.memory.used),
reservable: client.utils.formatBytes(stats.memory.reservable),
systemLoad: (stats.cpu.systemLoad * 100).toFixed(2),
lavalinkLoad: (stats.cpu.lavalinkLoad * 100).toFixed(2),
})}
\`\`\``;

embed.addFields({
name: `Name: ${node.name} (${statusEmoji})`,
name: `${node.name} (${statusEmoji})`,
value: formattedStats,
});
});
Expand Down
10 changes: 5 additions & 5 deletions src/commands/info/Ping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default class Ping extends Command {
super(client, {
name: "ping",
description: {
content: "Shows the bot's ping",
content: "cmd.ping.description",
examples: ["ping"],
usage: "ping",
},
Expand All @@ -30,25 +30,25 @@ export default class Ping extends Command {
}

public async run(_client: Lavamusic, ctx: Context): Promise<any> {
const msg = await ctx.sendDeferMessage("Pinging...");
const msg = await ctx.sendDeferMessage(ctx.locale("cmd.ping.content"));
const embed = this.client
.embed()
.setAuthor({ name: "Pong", iconURL: this.client.user.displayAvatarURL() })
.setColor(this.client.color.main)
.addFields([
{
name: "Bot Latency",
name: ctx.locale("cmd.ping.bot_latency"),
value: `\`\`\`ini\n[ ${msg.createdTimestamp - ctx.createdTimestamp}ms ]\n\`\`\``,
inline: true,
},
{
name: "API Latency",
name: ctx.locale("cmd.ping.api_latency"),
value: `\`\`\`ini\n[ ${Math.round(ctx.client.ws.ping)}ms ]\n\`\`\``,
inline: true,
},
])
.setFooter({
text: `Requested by ${ctx.author.tag}`,
text: ctx.locale("cmd.ping.requested_by", { author: ctx.author.tag }),
iconURL: ctx.author.avatarURL({}),
})
.setTimestamp();
Expand Down
3 changes: 2 additions & 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 } from "./types.js";
import { SearchEngine, Language } from "./types.js";
dotenv.config();

const parseBoolean = (value?: string): boolean => value?.trim().toLowerCase() === "true";
Expand All @@ -14,6 +14,7 @@ export default {
yellow: 0xffff00,
main: 0x2f3136,
},
defaultLanguage: process.env.DEFAULT_LANGUAGE || Language.EnglishUS,
keepAlive: parseBoolean(process.env.KEEP_ALIVE),
autoNode: parseBoolean(process.env.AUTO_NODE),
searchEngine: process.env.SEARCH_ENGINE || SearchEngine.YouTube,
Expand Down
Loading

0 comments on commit 54b557d

Please sign in to comment.