Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New from main #627

Merged
merged 8 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,17 @@
"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.16.2",
"prisma": "^5.17.0",
"typescript": "^5.5.3"
},
"dependencies": {
"@prisma/client": "^5.16.2",
"@prisma/client": "^5.17.0",
"discord.js": "^14.15.3",
"dotenv": "^16.4.5",
"i18n": "^0.15.1",
Expand Down
4 changes: 2 additions & 2 deletions src/commands/config/247.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default class _247 extends Command {
}

public async run(client: Lavamusic, ctx: Context): Promise<any> {
const embed = client.embed();
const embed = this.client.embed();
let player = client.shoukaku.players.get(ctx.guild.id) as any;
try {
const data = await client.db.get_247(ctx.guild.id);
Expand Down Expand Up @@ -62,7 +62,7 @@ export default class _247 extends Command {
.setDescription(
"**24/7 mode has been enabled. The bot will not leave the voice channel even if there are no people in the voice channel.**",
)
.setColor(client.color.main),
.setColor(this.client.color.main),
],
});
} catch (error) {
Expand Down
135 changes: 69 additions & 66 deletions src/commands/config/Dj.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//TODO
import { Command, type Context, type Lavamusic } from "../../structures/index.js";

export default class Dj extends Command {
Expand Down Expand Up @@ -29,47 +28,50 @@ export default class Dj extends Command {
options: [
{
name: "add",
description: "The dj role you want to add",
description: "The DJ role you want to add",
type: 1,
options: [
{
name: "role",
description: "The dj role you want to add",
description: "The DJ role you want to add",
type: 8,
required: true,
},
],
},
{
name: "remove",
description: "The dj role you want to remove",
description: "The DJ role you want to remove",
type: 1,
options: [
{
name: "role",
description: "The dj role you want to remove",
description: "The DJ role you want to remove",
type: 8,
required: true,
},
],
},
{
name: "clear",
description: "Clears all dj roles",
description: "Clears all DJ roles",
type: 1,
},
{
name: "toggle",
description: "Toggles the dj role",
description: "Toggles the DJ role",
type: 1,
},
],
});
}

public async run(client: Lavamusic, ctx: Context, args: string[]): Promise<any> {
const embed = this.client.embed().setColor(this.client.color.main);
const dj = await client.db.getDj(ctx.guild.id);
let subCommand: string;
let role: any;

if (ctx.isInteraction) {
subCommand = ctx.interaction.options.data[0].name;
if (subCommand === "add" || subCommand === "remove") {
Expand All @@ -79,70 +81,71 @@ export default class Dj extends Command {
subCommand = args[0];
role = ctx.message.mentions.roles.first() || ctx.guild.roles.cache.get(args[1]);
}
const embed = client.embed().setColor(client.color.main);
const dj = await client.db.getDj(ctx.guild.id);
if (subCommand === "add") {
if (!role)
return await ctx.sendMessage({
embeds: [embed.setDescription("Please provide a role to add.")],
});
const isExRole = await client.db.getRoles(ctx.guild.id).then((r) => r.find((re) => re.roleId === role.id));
if (isExRole)
return await ctx.sendMessage({
embeds: [embed.setDescription(`The dj role <@&${role.id}> is already added.`)],
});
client.db.addRole(ctx.guild.id, role.id);
client.db.setDj(ctx.guild.id, true);
return await ctx.sendMessage({
embeds: [embed.setDescription(`The dj role <@&${role.id}> has been added.`)],
});
}
if (subCommand === "remove") {
if (!role)
return await ctx.sendMessage({
embeds: [embed.setDescription("Please provide a role to remove.")],

switch (subCommand) {
case "add":
if (!role) {
return ctx.sendMessage({
embeds: [embed.setDescription("Please provide a role to add.")],
});
}
if (await client.db.getRoles(ctx.guild.id).then((r) => r.some((re) => re.roleId === role.id))) {
return ctx.sendMessage({
embeds: [embed.setDescription(`The DJ role <@&${role.id}> is already added.`)],
});
}
await client.db.addRole(ctx.guild.id, role.id);
await client.db.setDj(ctx.guild.id, true);
return ctx.sendMessage({
embeds: [embed.setDescription(`The DJ role <@&${role.id}> has been added.`)],
});
const isExRole = await client.db.getRoles(ctx.guild.id).then((r) => r.find((re) => re.roleId === role.id));
if (!isExRole)
return await ctx.sendMessage({
embeds: [embed.setDescription(`The dj role <@&${role.id}> is not added.`)],

case "remove":
if (!role) {
return ctx.sendMessage({
embeds: [embed.setDescription("Please provide a role to remove.")],
});
}
if (!(await client.db.getRoles(ctx.guild.id).then((r) => r.some((re) => re.roleId === role.id)))) {
return ctx.sendMessage({
embeds: [embed.setDescription(`The DJ role <@&${role.id}> is not added.`)],
});
}
await client.db.removeRole(ctx.guild.id, role.id);
return ctx.sendMessage({
embeds: [embed.setDescription(`The DJ role <@&${role.id}> has been removed.`)],
});
client.db.removeRole(ctx.guild.id, role.id);
return await ctx.sendMessage({
embeds: [embed.setDescription(`The dj role <@&${role.id}> has been removed.`)],
});
}
if (subCommand === "clear") {
if (!dj)
return await ctx.sendMessage({
embeds: [embed.setDescription("The dj role is already empty.")],

case "clear":
if (!dj) {
return ctx.sendMessage({
embeds: [embed.setDescription("The DJ role is already empty.")],
});
}
await client.db.clearRoles(ctx.guild.id);
return ctx.sendMessage({
embeds: [embed.setDescription("All DJ roles have been removed.")],
});
client.db.clearRoles(ctx.guild.id);
return await ctx.sendMessage({
embeds: [embed.setDescription("All dj roles have been removed.")],
});
}
if (subCommand === "toggle") {
if (!dj)
return await ctx.sendMessage({
embeds: [embed.setDescription("The dj role is empty.")],

case "toggle":
if (!dj) {
return ctx.sendMessage({
embeds: [embed.setDescription("The DJ role is empty.")],
});
}
await client.db.setDj(ctx.guild.id, !dj.mode);
return ctx.sendMessage({
embeds: [embed.setDescription(`The DJ mode has been toggled to ${dj.mode ? "disabled." : "enabled."}`)],
});
const data = await client.db.getDj(ctx.guild.id);
if (data) {
client.db.setDj(ctx.guild.id, !data.mode);
return await ctx.sendMessage({
embeds: [embed.setDescription(`The dj mode has been toggled to ${data.mode ? "disabled." : "enabled."}`)],

default:
return ctx.sendMessage({
embeds: [
embed
.setDescription("Please provide a valid subcommand.")
.addFields({ name: "Subcommands", value: "`add`, `remove`, `clear`, `toggle`" }),
],
});
}
} else {
return await ctx.sendMessage({
embeds: [
embed.setDescription("Please provide a valid subcommand.").addFields({
name: "Subcommands",
value: "`add`, `remove`, `clear`, `toggle`",
}),
],
});
}
}
}
Expand Down
12 changes: 7 additions & 5 deletions src/commands/config/Prefix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,21 @@ export default class Prefix extends Command {
}

public async run(client: Lavamusic, ctx: Context, args: string[]): Promise<any> {
const embed = client.embed().setColor(client.color.main);
const embed = client.embed().setColor(this.client.color.main);
const guildId = ctx.guild.id;
const guildData = await client.db.get(guildId);
const isInteraction = ctx.isInteraction;
let subCommand = "";
let prefix = "";
let subCommand: string;
let prefix: string;

if (isInteraction) {
subCommand = ctx.interaction.options.data[0].name;
prefix = ctx.interaction.options.data[0].options[0]?.value.toString();
} else {
subCommand = args[0] || "";
prefix = args[1] || "";
}

switch (subCommand) {
case "set": {
if (!prefix) {
Expand All @@ -73,13 +75,13 @@ export default class Prefix extends Command {
embed.setDescription("The prefix cannot be longer than 3 characters.");
return await ctx.sendMessage({ embeds: [embed] });
}
client.db.setPrefix(guildId, prefix);
await client.db.setPrefix(guildId, prefix);
embed.setDescription(`The prefix for this server is now \`${prefix}\``);
return await ctx.sendMessage({ embeds: [embed] });
}
case "reset": {
const defaultPrefix = client.config.prefix;
client.db.setPrefix(guildId, defaultPrefix);
await client.db.setPrefix(guildId, defaultPrefix);
embed.setDescription(`The prefix for this server is now \`${defaultPrefix}\``);
return await ctx.sendMessage({ embeds: [embed] });
}
Expand Down
6 changes: 3 additions & 3 deletions src/commands/config/Setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default class Setup extends Command {

public async run(client: Lavamusic, ctx: Context, args: string[]): Promise<any> {
const subCommand = ctx.isInteraction ? ctx.interaction.options.data[0].name : args[0];
const embed = client.embed().setColor(client.color.main);
const embed = client.embed().setColor(this.client.color.main);
switch (subCommand) {
case "create": {
const data = await client.db.getSetup(ctx.guild.id);
Expand Down Expand Up @@ -103,7 +103,7 @@ export default class Setup extends Command {
embeds: [
{
description: `The song request channel has been created in <#${textChannel.id}>.`,
color: client.color.main,
color: this.client.color.main,
},
],
});
Expand All @@ -129,7 +129,7 @@ export default class Setup extends Command {
{
description:
"The song request channel has been deleted. If the channel is not deleted normally, please delete it yourself.",
color: client.color.main,
color: this.client.color.main,
},
],
});
Expand Down
11 changes: 8 additions & 3 deletions src/commands/dev/Eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ export default class Eval extends Command {
try {
let evaled = eval(code);
if (evaled === client.config) evaled = "Nice try";
const button = new ButtonBuilder().setStyle(ButtonStyle.Danger).setLabel("Delete").setCustomId("eval-delete");
const row = new ActionRowBuilder<ButtonBuilder>().addComponents(button);

if (typeof evaled !== "string") evaled = util.inspect(evaled);
if (evaled.length > 2000) {
const response = await fetch("https://hasteb.in/post", {
Expand All @@ -54,15 +53,21 @@ export default class Eval extends Command {
content: evaled,
});
}

const button = new ButtonBuilder().setStyle(ButtonStyle.Danger).setLabel("Delete").setCustomId("eval-delete");
const row = new ActionRowBuilder<ButtonBuilder>().addComponents(button);

const msg = await ctx.sendMessage({
content: `\`\`\`js\n${evaled}\n\`\`\``,
components: [row],
});
const filter = (i: any): boolean => i.customId === "eval-delete" && i.user.id === ctx.author.id;

const filter = (i: any) => i.customId === "eval-delete" && i.user.id === ctx.author.id;
const collector = msg.createMessageComponentCollector({
time: 60000,
filter: filter,
});

collector.on("collect", async (i) => {
await i.deferUpdate();
await msg.delete();
Expand Down
14 changes: 7 additions & 7 deletions src/commands/dev/GuildLeave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export default class GuildLeave extends Command {
name: "guildleave",
description: {
content: "Leave a guild",
examples: ["guildleave"],
usage: "guildleave",
examples: ["guildleave <guildId>"],
usage: "guildleave <guildId>",
},
category: "dev",
aliases: ["gl"],
Expand All @@ -29,15 +29,15 @@ export default class GuildLeave extends Command {
});
}

public async run(_client: Lavamusic, ctx: Context, args: string[]): Promise<any> {
public async run(client: Lavamusic, ctx: Context, args: string[]): Promise<any> {
const guildId = args[0];
const guild = this.client.guilds.cache.get(guildId);
const guild = client.guilds.cache.get(guildId);
if (!guild) return await ctx.sendMessage("Guild not found.");
try {
await guild.leave();
ctx.sendMessage(`Left guild ${guild.name}`);
} catch (_error) {
ctx.sendMessage(`Failed to leave guild ${guild.name}`);
await ctx.sendMessage(`Left guild ${guild.name}`);
} catch {
await ctx.sendMessage(`Failed to leave guild ${guild.name}`);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/dev/GuildList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class GuildList extends Command {
}

public async run(client: Lavamusic, ctx: Context): Promise<any> {
const guilds = this.client.guilds.cache.map((guild) => `- **${guild.name}** - (${guild.id})`);
const guilds = client.guilds.cache.map((guild) => `- **${guild.name}** - (${guild.id})`);
const chunks = client.utils.chunk(guilds, 10) || [[]];
const pages = chunks.map((chunk, index) => {
return this.client
Expand Down
Loading