Skip to content

Commit

Permalink
Refactor .gitignore and .env.example files, update playlist commands,…
Browse files Browse the repository at this point in the history
… and fix bugs in config and client events
  • Loading branch information
appujet committed Apr 13, 2024
1 parent 0dc67fe commit 555c679
Show file tree
Hide file tree
Showing 24 changed files with 704 additions and 107 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ SEARCH_ENGINE= "ytsearch" # ytsearch, scsearch or ytmsearch

MAX_PLAYLIST_SIZE= "100" # Max playlist size

DATABASE_URL= "" # Your database url (if sqlite then you can leave it blank)

MAX_QUEUE_SIZE= "100" # Max queue size

BOT_STATUS= "online" # Your bot status
Expand Down
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,5 @@

/Lavalink/plugins

lavamusic.db
lavamusic.db-shm
lavamusic.db-wal
/prisma/lavamusic.db
/prisma/migrations
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ Before starting with the installation, you need to have the following:
- ![Node.js](https://img.shields.io/badge/Node.js-43853D?style=for-the-badge&logo=node.js&logoColor=white) [v18.17.1 or higher](https://nodejs.org/en/download/)
- ![Lavalink](https://img.shields.io/badge/Lavalink-7289DA?style=for-the-badge&logo=discord&logoColor=white) [v4.0.x or higher](https://github.com/freyacodes/Lavalink)

### Optional
- ![MongoDB](https://img.shields.io/badge/MongoDB-47A248?style=for-the-badge&logo=mongodb&logoColor=white) [Optional](https://www.mongodb.com/try/download/community) (For MongoDB database)
- ![PostgreSQL](https://img.shields.io/badge/PostgreSQL-336791?style=for-the-badge&logo=postgresql&logoColor=white) [Optional](https://www.postgresql.org/download/) (For PostgreSQL database)

- ![Docker](https://img.shields.io/badge/Docker-2496ED?style=for-the-badge&logo=docker&logoColor=white) [Optional](https://www.docker.com/) (For Docker Installation)
- ![Docker-Compose](https://img.shields.io/badge/Docker--Compose-2496ED?style=for-the-badge&logo=docker&logoColor=white) [Optional](https://docs.docker.com/compose/) (For Docker Installation)

## 🚀 Installation from source

1. Clone the Lavamusic repository:
Expand Down Expand Up @@ -194,6 +201,8 @@ Do note that the bot will restart itself to update to the latest!
- ![Node.js](https://img.shields.io/badge/Node.js-43853D?style=for-the-badge&logo=node.js&logoColor=white) [Node.js](https://nodejs.org/en/download/)
- ![Discord.js](https://img.shields.io/badge/Discord.js-7289DA?style=for-the-badge&logo=discord&logoColor=white) [Discord.js](https://discord.js.org/#/)
- ![Lavalink](https://img.shields.io/badge/Lavalink-7289DA?style=for-the-badge&logo=discord&logoColor=white) [Lavalink](https://github.com/lavalink-devs/Lavalink)
- ![MongoDB](https://img.shields.io/badge/MongoDB-47A248?style=for-the-badge&logo=mongodb&logoColor=white) [MongoDB](https://www.mongodb.com/try/download/community)
- ![PostgreSQL](https://img.shields.io/badge/PostgreSQL-336791?style=for-the-badge&logo=postgresql&logoColor=white) [PostgreSQL](https://www.postgresql.org/download/)
- ![Docker](https://img.shields.io/badge/Docker-2496ED?style=for-the-badge&logo=docker&logoColor=white) [Docker](https://www.docker.com/)
- ![Docker-Compose](https://img.shields.io/badge/Docker--Compose-2496ED?style=for-the-badge&logo=docker&logoColor=white) [Docker-Compose](https://docs.docker.com/compose/)

Expand Down
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
{
"name": "lavamusic",
"version": "4.0.9",
"version": "4.1.0",
"description": "LavaMusic is a music bot for Discord, written in JavaScript using the Discord.js, Typescript, Shoukaku (Lavalink) library.",
"main": "dist/index.js",
"type": "module",
"scripts": {
"start": "npm run build && node dist/index.js",
"prisma:generate": "npx prisma generate",
"build": "tsc --project tsconfig.json",
"clean": "rm -rf dist",
"lint": "eslint . --cache --ext .js,.jsx,.ts,.tsx",
"lint:fix": "eslint . --fix --cache --ext .js,.jsx,.ts,.tsx",
"format": "prettier --check .",
"format:fix": "prettier --write ."
"format:fix": "prettier --write .",
"postinstall": "npm run prisma:generate && npx prisma migrate dev --name init"
},
"repository": {
"type": "git",
Expand All @@ -34,7 +36,6 @@
},
"homepage": "https://github.com/appujet/lavamusic#readme",
"devDependencies": {
"@types/better-sqlite3": "^7.6.9",
"@types/node": "^20.12.7",
"@types/signale": "^1.4.7",
"@typescript-eslint/eslint-plugin": "^7.6.0",
Expand All @@ -43,11 +44,12 @@
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-unicorn": "^52.0.0",
"prettier": "^3.2.5",
"prisma": "^5.12.1",
"ts-node": "^10.9.2",
"typescript": "^5.4.3"
},
"dependencies": {
"better-sqlite3": "^9.5.0",
"@prisma/client": "^5.12.1",
"discord.js": "^14.14.1",
"dotenv": "^16.4.5",
"shoukaku": "^4.0.1",
Expand Down
81 changes: 81 additions & 0 deletions prisma/example.mongodb.schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init

generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}

model Guild {
guildId String @id @map("_id")
prefix String
stay Stay?
dj Dj?
roles Role[]
botchannel Botchannel?
setup Setup?
}

model Stay {
guildId String @id @map("_id")
textId String
voiceId String
Guild Guild @relation(fields: [guildId], references: [guildId])
}

model Dj {
guildId String @id @map("_id")
mode Boolean
Guild Guild @relation(fields: [guildId], references: [guildId])
}

model Role {
guildId String @id @map("_id")
roleId String
Guild Guild @relation(fields: [guildId], references: [guildId])
@@unique([guildId, roleId])
}

model Playlist {
id String @id @map("_id") @default(cuid())
userId String
name String
songs Song[]
@@unique([userId, name])
}

model Song {
id String @id @map("_id")
track String
playlistId String
playlist Playlist @relation(fields: [playlistId], references: [id])
@@unique([track, playlistId])
}

model Botchannel {
guildId String @id @map("_id")
textId String
Guild Guild @relation(fields: [guildId], references: [guildId])
}

model Setup {
guildId String @id @map("_id")
textId String
messageId String
Guild Guild @relation(fields: [guildId], references: [guildId])
}

model Premium {
userId String @id @map("_id")
guildId String
}
81 changes: 81 additions & 0 deletions prisma/example.postgresql.schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init

generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

model Guild {
guildId String @id
prefix String
stay Stay?
dj Dj?
roles Role[]
botchannel Botchannel?
setup Setup?
}

model Stay {
guildId String @id
textId String
voiceId String
Guild Guild @relation(fields: [guildId], references: [guildId])
}

model Dj {
guildId String @id
mode Boolean
Guild Guild @relation(fields: [guildId], references: [guildId])
}

model Role {
guildId String
roleId String
Guild Guild @relation(fields: [guildId], references: [guildId])
@@unique([guildId, roleId])
}

model Playlist {
id String @id @default(uuid())
userId String
name String
songs Song[]
@@unique([userId, name])
}

model Song {
id String @id @default(uuid())
track String
playlistId String
playlist Playlist @relation(fields: [playlistId], references: [id])
@@unique([track, playlistId])
}

model Botchannel {
guildId String @id
textId String
Guild Guild @relation(fields: [guildId], references: [guildId])
}

model Setup {
guildId String @id
textId String
messageId String
Guild Guild @relation(fields: [guildId], references: [guildId])
}

model Premium {
userId String @id
guildId String
}
81 changes: 81 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init

generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "sqlite"
url = "file:./lavamusic.db"
}

model Guild {
guildId String @id
prefix String
stay Stay?
dj Dj?
roles Role[]
botchannel Botchannel?
setup Setup?
}

model Stay {
guildId String @id
textId String
voiceId String
Guild Guild @relation(fields: [guildId], references: [guildId])
}

model Dj {
guildId String @id
mode Boolean
Guild Guild @relation(fields: [guildId], references: [guildId])
}

model Role {
guildId String
roleId String
Guild Guild @relation(fields: [guildId], references: [guildId])
@@unique([guildId, roleId])
}

model Playlist {
id String @id @default(uuid())
userId String
name String
songs Song[]
@@unique([userId, name])
}

model Song {
id String @id @default(uuid())
track String
playlistId String
playlist Playlist @relation(fields: [playlistId], references: [id])
@@unique([track, playlistId])
}

model Botchannel {
guildId String @id
textId String
Guild Guild @relation(fields: [guildId], references: [guildId])
}

model Setup {
guildId String @id
textId String
messageId String
Guild Guild @relation(fields: [guildId], references: [guildId])
}

model Premium {
userId String @id
guildId String
}
2 changes: 1 addition & 1 deletion src/commands/config/247.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default class _247 extends Command {
const embed = client.embed();
let player = client.shoukaku.players.get(ctx.guild.id) as any;

const data = client.db.get_247(ctx.guild.id);
const data = await client.db.get_247(ctx.guild.id);
const vc = ctx.member as any;
if (!data) {
client.db.set_247(ctx.guild.id, ctx.channel.id, vc.voice.channel.id);
Expand Down
12 changes: 6 additions & 6 deletions src/commands/config/Dj.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ export default class Dj extends Command {
role = ctx.message.mentions.roles.first() || ctx.guild.roles.cache.get(args[1]);
}
const embed = client.embed().setColor(client.color.main);
let dj = client.db.getDj(ctx.guild.id);
let 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 = client.db
const isExRole = await client.db
.getRoles(ctx.guild.id)
.find((r: any) => r.roleId === role.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`)],
Expand All @@ -103,9 +103,9 @@ export default class Dj extends Command {
return await ctx.sendMessage({
embeds: [embed.setDescription('Please provide a role to remove')],
});
const isExRole = client.db
const isExRole = await client.db
.getRoles(ctx.guild.id)
.find((r: any) => r.roleId === role.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`)],
Expand All @@ -128,7 +128,7 @@ export default class Dj extends Command {
return await ctx.sendMessage({
embeds: [embed.setDescription('There are no dj roles to toggle')],
});
const data = client.db.getDj(ctx.guild.id);
const data = await client.db.getDj(ctx.guild.id);
if (data) {
client.db.setDj(ctx.guild.id, !data.mode);
return await ctx.sendMessage({
Expand Down
Loading

0 comments on commit 555c679

Please sign in to comment.