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

Up to date #1

Merged
merged 6 commits into from
Mar 6, 2023
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
32 changes: 32 additions & 0 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: docker build

on:
push:
branches:
- master
workflow_dispatch:

jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: |
ghcr.io/tannergabriel/discord-bot:latest
29 changes: 15 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
FROM node:17.4.0

WORKDIR /usr/src/app

RUN apt-get update || : && apt-get install python -y
RUN apt-get install ffmpeg -y

COPY package*.json ./

RUN npm ci

COPY . .

CMD [ "node", "index.js" ]
FROM node:18 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 upx && \
upx -1 /ffmpeg

FROM gcr.io/distroless/nodejs18
WORKDIR /app
COPY --from=build /app /app
COPY --from=build /ffmpeg /bin/
USER nonroot
CMD [ "index.js" ]
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ You can find the tutorial about building a discord music bot [here](https://gabr

* [Requirements](#requirements)
* [Getting started](#getting-started)
* [Docker](#docker)
* [Features & Commands](#features--commands)
* [Common errors](#common-errors)
* [Contributing](#contributing)
Expand Down Expand Up @@ -81,6 +82,18 @@ After deploying the commands you should be able to see and access them by typing

<img src="./assets/commands.png">

## Docker

A mutliarch docker image for `amd64` and `arm64` based on the main branch is available from Github Container Registry:

```bash
docker pull ghcr.io/TannerGabriel/discord-bot:latest
```

A Github Action automatically builds and push `amd64` and `arm64` to ghcr.io, all builds are based on the main branch.

Only `:latest` tag is supported, otherwise use SHA256 from https://github.com/TannerGabriel/discord-bot/pkgs/container/discord-bot for pinning to a specific commit.

## Features & Commands

> Note: The repository now uses the new Discord slash commands
Expand Down Expand Up @@ -237,4 +250,4 @@ You are welcome to contribute by submitting a Pull Request to the repository.

## License

This project is licensed under the MIT License - see the [LICENSE.md](LICENSE) file for details
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE) file for details
19 changes: 17 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@ console.log(client.commands);

const player = new Player(client);

player.on('connectionCreate', (queue) => {
queue.connection.voiceConnection.on('stateChange', (oldState, newState) => {
const oldNetworking = Reflect.get(oldState, 'networking');
const newNetworking = Reflect.get(newState, 'networking');

const networkStateChangeHandler = (oldNetworkState, newNetworkState) => {
const newUdp = Reflect.get(newNetworkState, 'udp');
clearInterval(newUdp?.keepAliveInterval);
}

oldNetworking?.off('stateChange', networkStateChangeHandler);
newNetworking?.on('stateChange', networkStateChangeHandler);
});
});

player.on('error', (queue, error) => {
console.log(`[${queue.guild.name}] Error emitted from the queue: ${error.message}`);
});
Expand Down Expand Up @@ -56,8 +71,8 @@ client.once('ready', async () => {

client.on('ready', function() {
client.user.setPresence({
activities: [{ name: config.activity, type: config.activityType }],
status: 'Playing music',
activities: [{ name: config.activity, type: Number(config.activityType) }],
status: Discord.PresenceUpdateStatus.Online,
});
});

Expand Down
Loading