Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #48 from moonstar-x/djs-extended
Browse files Browse the repository at this point in the history
Version 4.0.0
  • Loading branch information
moonstar-x authored Aug 15, 2021
2 parents e003dd6 + ae28edc commit b69777f
Show file tree
Hide file tree
Showing 58 changed files with 2,631 additions and 19,629 deletions.
32 changes: 29 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,35 @@
# OS Generated
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Thrashes
ehthumbs.db
Thumbs.db

# IDE
.vscode/
.idea/

# Node
node_modules
npm-debug.log

# Development
config/settings.json
.github
.git
data/local-music/
dev-data

# Tests
__mocks__
test
build

# Git
.github
.git

# Root files
.eslintignore
.eslintrc
.gitignore
jest.config.js
4 changes: 1 addition & 3 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
node_modules
build
old
node_modules/
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
"parserOptions": {
"ecmaVersion": 2020
}
}
}
9 changes: 3 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: [master]
pull_request:
branches: [master, rework]
branches: [master]
workflow_dispatch:

jobs:
Expand All @@ -19,10 +19,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v1
with:
node-version: 12.x

- name: Update git global URL
run: git config --global url."https://github.com/".insteadOf ssh://[email protected]/
node-version: 12.x

- name: Install Dependencies
run: npm ci
Expand All @@ -44,4 +41,4 @@ jobs:
uses: peter-evans/repository-dispatch@v1
with:
token: ${{ secrets.REPO_ACCESS_TOKEN }}
event-type: docker-build
event-type: docker-build
2 changes: 1 addition & 1 deletion .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ jobs:
VERSION=${{ steps.package-version.outputs.current-version }}
- name: Image Digest
run: echo ${{ steps.docker_build.outputs.digest }}
run: echo ${{ steps.docker_build.outputs.digest }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,6 @@ build
# Audio Files
*.mp3
*.m4a

# Dev Data
dev-data/
43 changes: 4 additions & 39 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
# Build Stage
FROM node:12.20.0-alpine3.12 AS build

RUN apk add --no-cache git
RUN git config --global url."https://github.com/".insteadOf ssh://[email protected]/

WORKDIR /opt/app

COPY package*.json ./

RUN npm ci

COPY . .

RUN npm run build

# Bot Image
FROM node:12.20.0-alpine3.12

ARG DATE_CREATED
Expand All @@ -28,32 +11,14 @@ LABEL org.opencontainers.image.title="Discord Music 24/7"
LABEL org.opencontainers.image.description="A 24/7 music bot for Discord that pauses when nobody is listening."
LABEL org.opencontainers.image.source="https://github.com/moonstar-x/discord-music-24-7"

RUN apk add --no-cache ffmpeg git
RUN git config --global url."https://github.com/".insteadOf ssh://[email protected]/
RUN apk add --no-cache ffmpeg

WORKDIR /opt/app

COPY package*.json ./LICENSE ./README.md ./
COPY package*.json ./

RUN npm ci --only=prod

COPY ./config ./config
COPY ./data ./data

# These are added here as a way to define which env variables will be used.
ENV DISCORD_TOKEN ""
ENV PREFIX ""
ENV OWNER_ID ""
ENV PRESENCE_TYPE ""
ENV CHANNEL_ID ""
ENV SOUNDCLOUD_CLIENT_ID ""
ENV YOUTUBE_COOKIE ""
ENV SHUFFLE ""
ENV PAUSE_ON_EMPTY ""
ENV CHANNEL_LEAVE_ON_EMPTY ""

COPY --from=build /opt/app/build ./build

VOLUME /opt/app/data /opt/app/config
COPY . .

CMD ["npm", "start"]
CMD ["npm", "start"]
128 changes: 62 additions & 66 deletions README.md

Large diffs are not rendered by default.

76 changes: 56 additions & 20 deletions __mocks__/discordMocks.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,57 @@
import EventEmitter from 'events';

export const userMock = {
username: 'username'
const userMock = {
username: 'username',
id: '123'
};

export const commandMock = {
const commandMock = {
name: 'command',
description: 'description'
};

export const commandGroupMock = {
const commandGroupMock = {
name: 'group',
commands: [commandMock, commandMock]
};

export const memberMock = {
displayName: 'display name'
const memberMock = {
displayName: 'display name',
voice: {
channel: {
id: '123'
}
}
};

export const guildMock = {
const guildMock = {
name: 'guild name'
};

export const dispatcherMock = {
resume: jest.fn(),
pause: jest.fn()
const dispatcherMock = {
resume: jest.fn(function() {
this.paused = false;
}),
pause: jest.fn(function() {
this.paused = true;
}),
paused: false,
pausedTime: 1000
};

export const connectionMock = {
const connectionMock = {
play: jest.fn(() => dispatcherMock)
};

export const channelMock = {
const channelMock = {
joinable: true,
name: 'channel',
id: 'channel_id',
guild: guildMock,
join: jest.fn(() => Promise.resolve(connectionMock)),
send: jest.fn(),
members: [memberMock, memberMock]
};

export const clientMock = {
const clientMock = {
commandPrefix: '!',
handleCommandError: jest.fn(),
registry: {
Expand All @@ -48,16 +60,40 @@ export const clientMock = {
channels: {
fetch: jest.fn(() => Promise.resolve(channelMock))
},
updatePresence: jest.fn(),
player: new EventEmitter()
player: {
channel: channelMock,
skipCurrentSong: jest.fn(),
updateChannel: jest.fn(),
updateListeners: jest.fn(),
updateDispatcherStatus: jest.fn()
},
user: userMock,
config: {
get: jest.fn()
},
presenceManager: {
update: jest.fn()
}
};

export const messageMock = {
const messageMock = {
reply: jest.fn(),
guild: guildMock,
content: 'message',
member: memberMock,
author: userMock,
embed: jest.fn(),
say: jest.fn()
channel: channelMock
};

module.exports = {
userMock,
commandMock,
commandGroupMock,
memberMock,
guildMock,
dispatcherMock,
connectionMock,
channelMock,
clientMock,
messageMock
};
14 changes: 7 additions & 7 deletions __mocks__/fs.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
export const readFileSync = jest.fn(() => []);
export const existsSync = jest.fn(() => false);
export const writeFileSync = jest.fn();
export const mkdirSync = jest.fn();
export const readFile = jest.fn((path, opts, cb) => {
const readFileSync = jest.fn(() => []);
const existsSync = jest.fn(() => true);
const writeFileSync = jest.fn();
const mkdirSync = jest.fn();
const readFile = jest.fn((path, opts, cb) => {
cb(null, Buffer.alloc(1));
});
export const readdirSync = jest.fn(() => []);
const readdirSync = jest.fn(() => []);

export default {
module.exports = {
readFileSync,
existsSync,
writeFileSync,
Expand Down
4 changes: 2 additions & 2 deletions __mocks__/ytdl-core.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/* eslint-disable no-unused-vars */
import { Readable } from 'stream';
const { Readable } = require('stream');

const infoMock = {
videoDetails: {
title: 'video title'
}
};

export default {
module.exports = {
getInfo: jest.fn((url, options) => Promise.resolve(infoMock)),
downloadFromInfo: jest.fn((url, options) => new Readable())
};
12 changes: 0 additions & 12 deletions babel.config.js

This file was deleted.

4 changes: 2 additions & 2 deletions config/settings.json.example
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"discord_token": "",
"token": "",
"prefix": "!",
"owner_id": "",
"presence_type": "PLAYING",
"channel_id": "",
"shuffle": true,
"pause_on_empty": true,
"channel_leave_on_empty": false,
"owner_reporting": false,
"soundcloud_client_id": "",
"youtube_cookie": ""
}
Loading

0 comments on commit b69777f

Please sign in to comment.