Skip to content

Commit

Permalink
Merge pull request #597 from hwangsihu/main
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
LucasB25 authored Jul 7, 2024
2 parents ea80f33 + 0e1c127 commit b4d63df
Show file tree
Hide file tree
Showing 88 changed files with 164 additions and 505 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
/prisma/migrations
/prisma/lavamusic.db
.env
package-lock.json
package-lock.json
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@
"homepage": "https://github.com/appujet/lavamusic#readme",
"devDependencies": {
"@biomejs/biome": "^1.8.3",
"@types/node": "^20.14.9",
"@types/node": "^20.14.10",
"@types/signale": "^1.4.7",
"lint-staged": "^15.2.7",
"prisma": "^5.16.1",
"ts-node": "^10.9.2",
"typescript": "^5.5.2"
"typescript": "^5.5.3"
},
"dependencies": {
"@prisma/client": "^5.16.1",
Expand Down
4 changes: 0 additions & 4 deletions src/LavaClient.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { type ClientOptions, GatewayIntentBits } from "discord.js";

import config from "./config.js";
import Lavamusic from "./structures/Lavamusic.js";

const { GuildMembers, MessageContent, GuildVoiceStates, GuildMessages, Guilds, GuildMessageTyping } = GatewayIntentBits;

const clientOptions: ClientOptions = {
intents: [Guilds, GuildMessages, MessageContent, GuildVoiceStates, GuildMembers, GuildMessageTyping],
allowedMentions: { parse: ["users", "roles"], repliedUser: false },
};

const client = new Lavamusic(clientOptions);
client.start(config.token);

Expand Down
14 changes: 8 additions & 6 deletions src/commands/config/247.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { GuildMember } from "discord.js";

import { Command, type Context, type Lavamusic } from "../../structures/index.js";

export default class _247 extends Command {
Expand Down Expand Up @@ -34,17 +33,14 @@ export default class _247 extends Command {
public async run(client: Lavamusic, ctx: Context): Promise<any> {
const embed = client.embed();
let player = client.shoukaku.players.get(ctx.guild.id) as any;

try {
const data = await client.db.get_247(ctx.guild.id);
const member = ctx.member as GuildMember;

if (!member.voice.channel) {
return await ctx.sendMessage({
embeds: [embed.setDescription("You need to be in a voice channel to use this command.").setColor(client.color.red)],
});
}

if (data) {
await client.db.delete_247(ctx.guild.id);
return await ctx.sendMessage({
Expand All @@ -61,10 +57,16 @@ export default class _247 extends Command {
);
}
return await ctx.sendMessage({
embeds: [embed.setDescription("**24/7 mode has been enabled**").setColor(client.color.main)],
embeds: [
embed
.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),
],
});
} catch (error) {
console.error("Error in 24/7 command:", error);
console.error("Error in 247 command:", error);
return await ctx.sendMessage({
embeds: [embed.setDescription("An error occurred while trying to execute this command.").setColor(client.color.red)],
});
Expand Down
24 changes: 12 additions & 12 deletions src/commands/config/Dj.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//TODO

import { Command, type Context, type Lavamusic } from "../../structures/index.js";

export default class Dj extends Command {
Expand Down Expand Up @@ -67,6 +66,7 @@ export default class Dj extends Command {
],
});
}

public async run(client: Lavamusic, ctx: Context, args: string[]): Promise<any> {
let subCommand: string;
let role: any;
Expand All @@ -84,60 +84,60 @@ export default class Dj extends Command {
if (subCommand === "add") {
if (!role)
return await ctx.sendMessage({
embeds: [embed.setDescription("Please provide a role to add")],
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`)],
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`)],
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")],
embeds: [embed.setDescription("Please provide a role to remove.")],
});
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`)],
embeds: [embed.setDescription(`The dj role <@&${role.id}> is not added.`)],
});
client.db.removeRole(ctx.guild.id, role.id);
return await ctx.sendMessage({
embeds: [embed.setDescription(`The dj role <@&${role.id}> has been removed`)],
embeds: [embed.setDescription(`The dj role <@&${role.id}> has been removed.`)],
});
}
if (subCommand === "clear") {
if (!dj)
return await ctx.sendMessage({
embeds: [embed.setDescription("There are no dj roles to clear")],
embeds: [embed.setDescription("The dj role is already empty.")],
});
client.db.clearRoles(ctx.guild.id);
return await ctx.sendMessage({
embeds: [embed.setDescription("All dj roles have been removed")],
embeds: [embed.setDescription("All dj roles have been removed.")],
});
}
if (subCommand === "toggle") {
if (!dj)
return await ctx.sendMessage({
embeds: [embed.setDescription("There are no dj roles to toggle")],
embeds: [embed.setDescription("The dj role is empty.")],
});
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"}`)],
embeds: [embed.setDescription(`The dj mode has been toggled to ${data.mode ? "disabled." : "enabled."}`)],
});
}
} else {
return await ctx.sendMessage({
embeds: [
embed.setDescription("Please provide a valid subcommand").addFields({
embed.setDescription("Please provide a valid subcommand.").addFields({
name: "Subcommands",
value: "`add`, `remove`, `clear`, `toggle`",
}),
Expand Down
6 changes: 0 additions & 6 deletions src/commands/config/Prefix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,40 +55,34 @@ export default class Prefix extends Command {
const isInteraction = ctx.isInteraction;
let subCommand = "";
let prefix = "";

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) {
const currentPrefix = guildData ? guildData.prefix : client.config.prefix;
embed.setDescription(`The prefix for this server is \`${currentPrefix}\``);
return await ctx.sendMessage({ embeds: [embed] });
}

if (prefix.length > 3) {
embed.setDescription("The prefix cannot be longer than 3 characters.");
return await ctx.sendMessage({ embeds: [embed] });
}

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);
embed.setDescription(`The prefix for this server is now \`${defaultPrefix}\``);
return await ctx.sendMessage({ embeds: [embed] });
}

default: {
const currentPrefix = guildData ? guildData.prefix : client.config.prefix;
embed.setDescription(`The prefix for this server is \`${currentPrefix}\``);
Expand Down
34 changes: 10 additions & 24 deletions src/commands/config/Setup.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ChannelType, OverwriteType, PermissionFlagsBits } from "discord.js";

import { Command, type Context, type Lavamusic } from "../../structures/index.js";
import { getButtons } from "../../utils/Buttons.js";

Expand Down Expand Up @@ -51,25 +50,23 @@ 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);

switch (subCommand) {
case "create": {
const data = await client.db.getSetup(ctx.guild.id);
if (data?.textId && data.messageId) {
return await ctx.sendMessage({
embeds: [
{
description: "The song request channel already exists",
description: "The song request channel already exists.",
color: client.color.red,
},
],
});
}

const textChannel = await ctx.guild.channels.create({
name: `${this.client.user.username}-song-requests`,
type: ChannelType.GuildText,
topic: "Song requests for the music bot",
topic: "Song requests for the music bot.",
permissionOverwrites: [
{
type: OverwriteType.Member,
Expand All @@ -92,91 +89,80 @@ export default class Setup extends Command {
},
],
});

const player = this.client.queue.get(ctx.guild.id);
const image = this.client.config.links.img;
const desc =
player?.queue && player.current
? `[${player.current.info.title}](${player.current.info.uri})`
: "Nothing playing right now";

: "Nothing playing right now.";
embed.setDescription(desc).setImage(image);
await textChannel.send({ embeds: [embed], components: getButtons(player) }).then((msg) => {
client.db.setSetup(ctx.guild.id, textChannel.id, msg.id);
});

await ctx.sendMessage({
embeds: [
{
description: `The song request channel has been created in <#${textChannel.id}>`,
description: `The song request channel has been created in <#${textChannel.id}>.`,
color: client.color.main,
},
],
});

break;
}

case "delete": {
const data2 = await client.db.getSetup(ctx.guild.id);
if (!data2) {
return await ctx.sendMessage({
embeds: [
{
description: "The song request channel doesn't exist",
description: "The song request channel doesn't exist.",
color: client.color.red,
},
],
});
}

client.db.deleteSetup(ctx.guild.id);
const textChannel = ctx.guild.channels.cache.get(data2.textId);
if (textChannel) await textChannel.delete().catch(() => {});

await ctx.sendMessage({
embeds: [
{
description: "The song request channel has been deleted",
description:
"The song request channel has been deleted. If the channel is not deleted normally, please delete it yourself.",
color: client.color.main,
},
],
});

break;
}

case "info": {
const data3 = await client.db.getSetup(ctx.guild.id);
if (!data3) {
return await ctx.sendMessage({
embeds: [
{
description: "The song request channel doesn't exist",
description: "The song request channel doesn't exist.",
color: client.color.red,
},
],
});
}

const channel = ctx.guild.channels.cache.get(data3.textId);
if (channel) {
embed.setDescription(`The song request channel is <#${channel.id}>`);
embed.setDescription(`The song request channel is <#${channel.id}>.`);
await ctx.sendMessage({ embeds: [embed] });
} else {
await ctx.sendMessage({
embeds: [
{
description: "The song request channel doesn't exist",
description: "The song request channel doesn't exist.",
color: client.color.red,
},
],
});
}

break;
}

default:
break;
}
Expand Down
8 changes: 0 additions & 8 deletions src/commands/dev/Eval.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import util from "node:util";
import { ActionRowBuilder, ButtonBuilder, ButtonStyle } from "discord.js";
import { fetch } from "undici";

import { Command, type Context, type Lavamusic } from "../../structures/index.js";

export default class Eval extends Command {
Expand Down Expand Up @@ -37,14 +36,10 @@ export default class Eval extends Command {
const code = args.join(" ");
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", {
method: "POST",
Expand All @@ -53,7 +48,6 @@ export default class Eval extends Command {
},
body: evaled,
});

const json: any = await response.json();
evaled = `https://hasteb.in/${json.key}`;
return await ctx.sendMessage({
Expand All @@ -64,13 +58,11 @@ export default class Eval extends Command {
content: `\`\`\`js\n${evaled}\n\`\`\``,
components: [row],
});

const filter = (i: any): boolean => 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
4 changes: 1 addition & 3 deletions src/commands/dev/GuildLeave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ export default class GuildLeave extends Command {
public async run(_client: Lavamusic, ctx: Context, args: string[]): Promise<any> {
const guildId = args[0];
const guild = this.client.guilds.cache.get(guildId);

if (!guild) return await ctx.sendMessage("Guild not found");

if (!guild) return await ctx.sendMessage("Guild not found.");
try {
await guild.leave();
ctx.sendMessage(`Left guild ${guild.name}`);
Expand Down
Loading

0 comments on commit b4d63df

Please sign in to comment.