Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasB25 committed Sep 4, 2024
1 parent d10045f commit d51dccf
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 98 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@
"devDependencies": {
"@biomejs/biome": "^1.8.3",
"@types/i18n": "^0.13.12",
"@types/node": "^22.5.1",
"@types/node": "^22.5.3",
"@types/signale": "^1.4.7",
"prisma": "^5.19.0",
"prisma": "^5.19.1",
"typescript": "^5.5.4"
},
"dependencies": {
"@prisma/client": "^5.19.0",
"@prisma/client": "^5.19.1",
"@top-gg/sdk": "^3.1.6",
"discord.js": "^14.15.3",
"discord.js": "^14.16.1",
"dotenv": "^16.4.5",
"i18n": "^0.15.1",
"node-system-stats": "^1.3.0",
Expand Down
14 changes: 13 additions & 1 deletion src/structures/Context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
type PartialDMChannel,
type TextChannel,
type User,
ChannelType,
} from "discord.js";
import { T } from "./I18n.js";
import type { Lavamusic } from "./index.js";
Expand All @@ -36,11 +37,18 @@ export default class Context {
public args: any[];
public msg: any;
public guildLocale: string;

constructor(ctx: ChatInputCommandInteraction | Message, args: any[]) {
this.ctx = ctx;
this.interaction = ctx instanceof ChatInputCommandInteraction ? ctx : null;
this.message = ctx instanceof Message ? ctx : null;
this.channel = ctx.channel;

if (ctx.channel && ctx.channel.type !== ChannelType.GroupDM) {
this.channel = ctx.channel
} else {
this.channel = null;
}

this.id = ctx.id;
this.channelId = ctx.channelId;
this.client = ctx.client as Lavamusic;
Expand All @@ -53,6 +61,7 @@ export default class Context {
this.setArgs(args);
this.setUpLocale();
}

private async setUpLocale(): Promise<void> {
this.guildLocale = this.guild ? await this.client.db.getLanguage(this.guild.id) : "en";
}
Expand All @@ -64,6 +73,7 @@ export default class Context {
public setArgs(args: any[]): void {
this.args = this.isInteraction ? args.map((arg: { value: any }) => arg.value) : args;
}

public async sendMessage(content: string | MessagePayload | MessageCreateOptions | InteractionReplyOptions): Promise<Message> {
if (this.isInteraction) {
if (typeof content === "string" || isInteractionReplyOptions(content)) {
Expand Down Expand Up @@ -98,9 +108,11 @@ export default class Context {
this.msg = await (this.message.channel as TextChannel).send(content);
return this.msg;
}

public locale(key: string, ...args: any) {
return T(this.guildLocale, key, ...args);
}

public async sendFollowUp(content: string | MessagePayload | MessageCreateOptions | InteractionReplyOptions): Promise<void> {
if (this.isInteraction) {
if (typeof content === "string" || isInteractionReplyOptions(content)) {
Expand Down
188 changes: 95 additions & 93 deletions src/utils/SetupSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,73 +44,107 @@ async function setupStart(client: Lavamusic, query: string, player: Dispatcher,
}
if (m) {
try {
const res = await client.queue.search(query);
switch (res.loadType) {
case LoadType.ERROR:
await message.channel
.send({
embeds: [embed.setColor(client.color.red).setDescription(T(locale, "player.setupStart.error_searching"))],
})
.then((msg) => setTimeout(() => msg.delete(), 5000));
break;
case LoadType.EMPTY:
await message.channel
.send({
embeds: [embed.setColor(client.color.red).setDescription(T(locale, "player.setupStart.no_results"))],
})
.then((msg) => setTimeout(() => msg.delete(), 5000));
break;
case LoadType.TRACK: {
const track = player.buildTrack(res.data, message.author);
if (player.queue.length > client.config.maxQueueSize) {
if (message.inGuild()) {
const res = await client.queue.search(query);
switch (res.loadType) {
case LoadType.ERROR:
await message.channel
.send({
embeds: [embed.setColor(client.color.red).setDescription(T(locale, "player.setupStart.error_searching"))],
})
.then((msg) => setTimeout(() => msg.delete(), 5000));
break;
case LoadType.EMPTY:
await message.channel
.send({
embeds: [embed.setColor(client.color.red).setDescription(T(locale, "player.setupStart.no_results"))],
})
.then((msg) => setTimeout(() => msg.delete(), 5000));
break;
case LoadType.TRACK: {
const track = player.buildTrack(res.data, message.author);
if (player.queue.length > client.config.maxQueueSize) {
await message.channel
.send({
embeds: [
embed.setColor(client.color.red).setDescription(
T(locale, "player.setupStart.queue_too_long", {
maxQueueSize: client.config.maxQueueSize,
}),
),
],
})
.then((msg) => setTimeout(() => msg.delete(), 5000));
return;
}
player.queue.push(track);
await player.isPlaying();
await message.channel
.send({
embeds: [
embed.setColor(client.color.red).setDescription(
T(locale, "player.setupStart.queue_too_long", {
maxQueueSize: client.config.maxQueueSize,
embed.setColor(client.color.main).setDescription(
T(locale, "player.setupStart.added_to_queue", {
title: res.data.info.title,
uri: res.data.info.uri,
}),
),
],
})
.then((msg) => setTimeout(() => msg.delete(), 5000));
return;
neb(n, player, client, locale);
await m.edit({ embeds: [n] }).catch(() => {});
break;
}
player.queue.push(track);
await player.isPlaying();
await message.channel
.send({
embeds: [
embed.setColor(client.color.main).setDescription(
T(locale, "player.setupStart.added_to_queue", {
title: res.data.info.title,
uri: res.data.info.uri,
}),
),
],
})
.then((msg) => setTimeout(() => msg.delete(), 5000));
neb(n, player, client, locale);
await m.edit({ embeds: [n] }).catch(() => {});
break;
}
case LoadType.PLAYLIST:
if (res.data.tracks.length > client.config.maxPlaylistSize) {
case LoadType.PLAYLIST:
if (res.data.tracks.length > client.config.maxPlaylistSize) {
await message.channel
.send({
embeds: [
embed.setColor(client.color.red).setDescription(
T(locale, "player.setupStart.playlist_too_long", {
maxPlaylistSize: client.config.maxPlaylistSize,
}),
),
],
})
.then((msg) => setTimeout(() => msg.delete(), 5000));
return;
}
for (const track of res.data.tracks) {
const pl = player.buildTrack(track, message.author);
if (player.queue.length > client.config.maxQueueSize) {
await message.channel
.send({
embeds: [
embed.setColor(client.color.red).setDescription(
T(locale, "player.setupStart.queue_too_long", {
maxQueueSize: client.config.maxQueueSize,
}),
),
],
})
.then((msg) => setTimeout(() => msg.delete(), 5000));
return;
}
player.queue.push(pl);
}
await player.isPlaying();
await message.channel
.send({
embeds: [
embed.setColor(client.color.red).setDescription(
T(locale, "player.setupStart.playlist_too_long", {
maxPlaylistSize: client.config.maxPlaylistSize,
}),
),
embed
.setColor(client.color.main)
.setDescription(
T(locale, "player.setupStart.added_playlist_to_queue", { length: res.data.tracks.length }),
),
],
})
.then((msg) => setTimeout(() => msg.delete(), 5000));
return;
}
for (const track of res.data.tracks) {
const pl = player.buildTrack(track, message.author);
neb(n, player, client, locale);
await m.edit({ embeds: [n] }).catch(() => {});
break;
case LoadType.SEARCH: {
const track = player.buildTrack(res.data[0], message.author);
if (player.queue.length > client.config.maxQueueSize) {
await message.channel
.send({
Expand All @@ -125,56 +159,24 @@ async function setupStart(client: Lavamusic, query: string, player: Dispatcher,
.then((msg) => setTimeout(() => msg.delete(), 5000));
return;
}
player.queue.push(pl);
}
await player.isPlaying();
await message.channel
.send({
embeds: [
embed
.setColor(client.color.main)
.setDescription(
T(locale, "player.setupStart.added_playlist_to_queue", { length: res.data.tracks.length }),
),
],
})
.then((msg) => setTimeout(() => msg.delete(), 5000));
neb(n, player, client, locale);
await m.edit({ embeds: [n] }).catch(() => {});
break;
case LoadType.SEARCH: {
const track = player.buildTrack(res.data[0], message.author);
if (player.queue.length > client.config.maxQueueSize) {
player.queue.push(track);
await player.isPlaying();
await message.channel
.send({
embeds: [
embed.setColor(client.color.red).setDescription(
T(locale, "player.setupStart.queue_too_long", {
maxQueueSize: client.config.maxQueueSize,
embed.setColor(client.color.main).setDescription(
T(locale, "player.setupStart.added_to_queue", {
title: res.data[0].info.title,
uri: res.data[0].info.uri,
}),
),
],
})
.then((msg) => setTimeout(() => msg.delete(), 5000));
return;
neb(n, player, client, locale);
await m.edit({ embeds: [n] }).catch(() => {});
break;
}
player.queue.push(track);
await player.isPlaying();
await message.channel
.send({
embeds: [
embed.setColor(client.color.main).setDescription(
T(locale, "player.setupStart.added_to_queue", {
title: res.data[0].info.title,
uri: res.data[0].info.uri,
}),
),
],
})
.then((msg) => setTimeout(() => msg.delete(), 5000));
neb(n, player, client, locale);
await m.edit({ embeds: [n] }).catch(() => {});
break;
}
}
} catch (error) {
Expand Down

0 comments on commit d51dccf

Please sign in to comment.