Skip to content

Commit

Permalink
Merge branch 'TannerGabriel:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
thucngyyen authored Jun 11, 2024
2 parents 255c3b8 + edb283b commit 3b78217
Show file tree
Hide file tree
Showing 14 changed files with 369 additions and 60 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
uses: github/codeql-action/autobuild@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -50,4 +50,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v3
2 changes: 1 addition & 1 deletion .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/stale@v4
- uses: actions/stale@v9
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-pr-message: 'Stale pull request message'
Expand Down
4 changes: 2 additions & 2 deletions .prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"requirePragma": false,
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"tabWidth": 4,
"trailingComma": "all",
"useTabs": false,
"vueIndentScriptAndStyle": true,
Expand All @@ -20,4 +20,4 @@
}
}
]
}
}
12 changes: 6 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
FROM node:18 AS build
FROM node:20 AS build
WORKDIR /app
COPY . /app
COPY --from=mwader/static-ffmpeg:5.1.2 /ffmpeg /ffmpeg
RUN npm ci --omit=dev
RUN apt update && \
apt install -y wget xz-utils && \
wget https://github.com/upx/upx/releases/download/v3.96/upx-3.96-amd64_linux.tar.xz && \
tar -xf upx-3.96-amd64_linux.tar.xz && \
mv upx-3.96-amd64_linux/upx /usr/local/bin/
apt install -y wget xz-utils && \
wget https://github.com/upx/upx/releases/download/v3.96/upx-3.96-amd64_linux.tar.xz && \
tar -xf upx-3.96-amd64_linux.tar.xz && \
mv upx-3.96-amd64_linux/upx /usr/local/bin/
RUN upx -1 /ffmpeg

FROM gcr.io/distroless/nodejs18
FROM gcr.io/distroless/nodejs20
WORKDIR /app
COPY --from=build /app /app
COPY --from=build /ffmpeg /bin/
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ After cloning the project and installing all dependencies, you need to add your

### Changing the status

You can change the status of your discord bot by editing the `activity` and `activityType` variables inside of the `config.json` file. `activityType` needs to be set to an integer with the following [options](https://discord-api-types.dev/api/discord-api-types-v10/enum/ActivityType).
You can change the status of your discord bot by editing the `activity` and `activityType` variables inside the `config.json` file. `activityType` needs to be set to an integer with the following [options](https://discord-api-types.dev/api/discord-api-types-v10/enum/ActivityType).


### Starting the application

Expand Down
32 changes: 17 additions & 15 deletions commands/play.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const {GuildMember, ApplicationCommandOptionType} = require('discord.js');
const {QueryType, useMainPlayer} = require('discord-player');
const {isInVoiceChannel} = require("../utils/voicechannel");
const {ApplicationCommandOptionType} = require('discord.js');
const {useMainPlayer} = require('discord-player');
const {isInVoiceChannel} = require('../utils/voicechannel');

module.exports = {
name: 'play',
Expand All @@ -14,44 +14,46 @@ module.exports = {
},
],
async execute(interaction) {
const {default: Conf} = await import('conf');
try {
const inVoiceChannel = isInVoiceChannel(interaction)
const inVoiceChannel = isInVoiceChannel(interaction);
if (!inVoiceChannel) {
return
return;
}

await interaction.deferReply();

const player = useMainPlayer()
const player = useMainPlayer();
const query = interaction.options.getString('query');
const searchResult = await player.search(query)
if (!searchResult.hasTracks())
return void interaction.followUp({content: 'No results were found!'});
const searchResult = await player.search(query);
if (!searchResult.hasTracks()) return void interaction.followUp({content: 'No results were found!'});

try {
const res = await player.play(interaction.member.voice.channel.id, searchResult, {
const config = new Conf({projectName: 'volume'});

await player.play(interaction.member.voice.channel.id, searchResult, {
nodeOptions: {
metadata: {
channel: interaction.channel,
client: interaction.guild?.members.me,
requestedBy: interaction.user.username
requestedBy: interaction.user.username,
},
leaveOnEmptyCooldown: 300000,
leaveOnEmpty: true,
leaveOnEnd: false,
bufferingTimeout: 0,
volume: 10,
volume: config.get('volume') || 10,
//defaultFFmpegFilters: ['lofi', 'bassboost', 'normalizer']
}
},
});

await interaction.followUp({
content: `⏱ | Loading your ${searchResult.playlist ? 'playlist' : 'track'}...`,
});
} catch (error) {
await interaction.editReply({
content: 'An error has occurred!'
})
content: 'An error has occurred!',
});
return console.log(error);
}
} catch (error) {
Expand Down
16 changes: 12 additions & 4 deletions commands/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,27 @@ module.exports = {
}

const queue = useQueue(interaction.guild.id)
if (typeof (queue) != 'undefined') {
if (queue != null) {
const trimString = (str, max) => ((str.length > max) ? `${str.slice(0, max - 3)}...` : str);

let queueStr = `🎶 | **Upcoming Songs:**\n`

// Build queue list
queue.tracks.data.forEach((track, index) => {
queueStr += `${index + 1}. ${track.title} - ${track.author}\n`;
});

return void interaction.reply({
embeds: [
{
title: 'Now Playing',
description: trimString(`The Current song playing is 🎶 | **${queue.currentTrack.title}**! \n 🎶 | ${queue}! `, 4095),
title: `Now Playing 🎶 | **${queue.currentTrack.title}**`,
description: trimString(queueStr, 4095),
}
]
})
} else {
return void interaction.reply({
content: 'There is no song in the queue!'
content: 'There are no songs in the queue!'
})
}
}
Expand Down
1 change: 0 additions & 1 deletion commands/resume.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const {GuildMember} = require('discord.js');
const {useQueue} = require("discord-player");
const {isInVoiceChannel} = require("../utils/voicechannel");

Expand Down
28 changes: 14 additions & 14 deletions commands/volume.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const {GuildMember, ApplicationCommandOptionType} = require('discord.js');
const {useQueue} = require("discord-player");
const {isInVoiceChannel} = require("../utils/voicechannel");
const {ApplicationCommandOptionType} = require('discord.js');
const {useQueue} = require('discord-player');
const {isInVoiceChannel} = require('../utils/voicechannel');

module.exports = {
name: 'volume',
Expand All @@ -14,25 +14,25 @@ module.exports = {
},
],
async execute(interaction) {
const inVoiceChannel = isInVoiceChannel(interaction)
if (!inVoiceChannel) {
return
}
const {default: Conf} = await import('conf');

await interaction.deferReply();
const queue = useQueue(interaction.guild.id);
if (!queue || !queue.currentTrack)
return void interaction.followUp({
content: '❌ | No music is being played!',
});

let volume = interaction.options.getInteger('volume');
volume = Math.max(0, volume);
volume = Math.min(200, volume);
const success = queue.node.setVolume(volume);

// Set the general volume (persisted)
const config = new Conf({projectName: 'volume'});
config.set('volume', volume);

// Set the volume of the current queue
const queue = useQueue(interaction.guild.id);
const inVoiceChannel = isInVoiceChannel(interaction);
if (inVoiceChannel && queue && queue.currentTrack) queue.node.setVolume(volume);

return void interaction.followUp({
content: success ? `🔊 | Volume set to ${volume}!` : '❌ | Something went wrong!',
content: `🔊 | Volume set to ${volume}!`,
});
},
};
3 changes: 2 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"activityType": "0",
"activity": "your music selections"
}
}

12 changes: 6 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
require('dotenv').config()
require('dotenv').config();

const fs = require('fs');
const Discord = require('discord.js');
const Client = require('./client/Client');
const config = require('./config.json');
const {Player} = require('discord-player');

const {ActivityType} = require('discord.js');

const client = new Client();
client.commands = new Discord.Collection();

Expand All @@ -22,7 +20,7 @@ console.log(client.commands);

const player = new Player(client);

player.extractors.loadDefault().then(r => console.log('Extractors loaded successfully'))
player.extractors.loadDefault().then(r => console.log('Extractors loaded successfully'));

// Still needs to be refactored for 0.6
/*player.events.on('connection', (queue) => {
Expand Down Expand Up @@ -62,6 +60,8 @@ player.events.on('emptyChannel', queue => {

player.events.on('emptyQueue', queue => {
queue.metadata.channel.send('✅ | Queue finished!');
// Delete queue and disconnect from voice channel
queue.delete();
});

player.events.on('error', (queue, error) => {
Expand All @@ -86,8 +86,8 @@ client.on('ready', function () {
console.log('Ready!');
client.user.presence.set({
activities: [{name: config.activity, type: Number(config.activityType)}],
status: Discord.Status.Ready
})
status: Discord.Status.Ready,
});
});

client.once('reconnecting', () => {
Expand Down
Loading

0 comments on commit 3b78217

Please sign in to comment.