Skip to content

Commit

Permalink
Merge pull request #12 from moonstar-x/djs-extended
Browse files Browse the repository at this point in the history
Version 2.0.0
  • Loading branch information
moonstar-x authored Sep 4, 2021
2 parents 8a5bf2a + 2b2c2b2 commit ef4c0c1
Show file tree
Hide file tree
Showing 48 changed files with 9,218 additions and 63,246 deletions.
32 changes: 28 additions & 4 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,11 +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
data/data.sqlite
.github
.git
data
dev-data

# Tests
__mocks__
test
jest.config.js

# Git
.github
.git

# Root files
.eslintignore
.eslintrc
.gitignore
jest.config.js
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
node_modules
node_modules/
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"extends": [
"greencoast/node"
],
"rules": {
"one-var": "off"
},
"parserOptions": {
"ecmaVersion": 2020
}
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,4 @@ dist
config/settings.json

# Data
data/data.sqlite
data/
10 changes: 0 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,12 @@ LABEL org.opencontainers.image.title="Discord Free Games Notifier"
LABEL org.opencontainers.image.description="A Discord bot that will notify when free games on Steam or Epic Games come out."
LABEL org.opencontainers.image.source="https://github.com/moonstar-x/discord-free-games-notifier"

RUN apk add --no-cache git

WORKDIR /opt/app

COPY package*.json ./

RUN npm ci --only=prod

# These are added here as a way to define which env variables will be used.
ENV DISCORD_TOKEN ""
ENV PREFIX ""
ENV OWNER_ID ""
ENV INVITE_URL ""

COPY . .

VOLUME /opt/app/config /opt/app/data

CMD ["npm", "start"]
57 changes: 36 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
[![discord](https://img.shields.io/discord/730998659008823296.svg?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://discord.gg/mhj3Zsv)
[![trello](https://img.shields.io/badge/Trello-discord--free--games--notifier-ff69b4)](https://trello.com/b/Iz8cQJAD/discord-free-games-notifier)
[![ci-build-status](https://img.shields.io/github/workflow/status/moonstar-x/discord-free-games-notifier/CI?logo=github)](https://github.com/moonstar-x/discord-free-games-notifier)
[![open-issues-count](https://img.shields.io/github/issues-raw/moonstar-x/discord-free-games-notifier?logo=github)](https://github.com/moonstar-x/discord-free-games-notifier)
[![docker-image-size](https://img.shields.io/docker/image-size/moonstarx/discord-free-games-notifier?logo=docker)](https://hub.docker.com/repository/docker/moonstarx/discord-free-games-notifier)
[![docker-pulls](https://img.shields.io/docker/pulls/moonstarx/discord-free-games-notifier?logo=docker)](https://hub.docker.com/repository/docker/moonstarx/discord-free-games-notifier)

# discord-free-games-notifier
# Discord Free Games Notifier

A Discord bot that will notify when free games on Steam or Epic Games come out. The bot will fetch offers from Steam and Epic Games every 30 minutes and will send a notification message to the set channel once a new offer is found.

Expand All @@ -30,39 +29,52 @@ Once cloned, proceed to install the dependencies:
npm ci --only=prod
```

If you prefer to install everything including the devDependencies, you may run:
Or, if you prefer to install everything including `devDependencies`, you may run:

```text
npm install
```

After you have [configured](#configuration) your bot, you can run it with:

```text
npm start
```

## Configuration

There are two ways to configure the bot, one with a `settings.json` file inside the `config` folder or with environment variables.

Here's a table with the available options you may configure:

| Environment Variable | JSON property | Required | Description |
|------------------------|--------------------------|---------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------|
| DISCORD_TOKEN | `discord_token` | Yes | Your Discord bot's token. |
| PREFIX | `prefix` | No (Defaults to `$`) | The prefix the bot will use for the commands. |
| OWNER_ID | `owner_id` | No | The ID of the owner of the bot, mainly for owner-only commands. (None available yet.) |
| INVITE_URL | `invite_url` | No | Invite URL for the bot. (Nothing is done with this URL yet.) |
| Environment Variable | JSON Property | Required | Type | Description |
|-----------------------------------|-----------------------------|-----------------------------|--------------------|----------------------------------------------------------------------------------------------------------------------------|
| DISCORD_TOKEN | `token` | Yes. | `string` | The bot's token. |
| DISCORD_PREFIX | `prefix` | No. (Defaults to: `$`) | `string` | The bot's prefix. Used for the commands. |
| DISCORD_OWNER_ID | `owner_id` | No. (Defaults to: `null`) | `string` or `null` | The ID of the bot's owner. |
| DISCORD_OWNER_REPORTING | `owner_reporting` | No. (Defaults to: `false`) | `boolean` | Whether the bot should send error reports to the owner via DM when a command errors. |
| DISCORD_PRESENCE_REFRESH_INTERVAL | `presence_refresh_interval` | No. (Defaults to: `900000`) | `number` or `null` | The time interval in ms in which the bot updates its presence. If set to `null` the presence auto update will be disabled. |

> **Note on `Required`**: A required settings HAS to be in the JSON or environment variables.
>
> **Note on `Default`**: If a setting is missing from the JSON or environment variables, the default value takes place.
>
> * To see how to find the IDs for users or channels, you can check out [this guide](<https://github.com/moonstar-x/discord-downtime-notifier/wiki/Getting-User,-Channel-and-Server-IDs>).
> * If you don't have a Discord token yet, you can see a guide on how to get one [here](<https://github.com/moonstar-x/discord-downtime-notifier/wiki/Getting-a-Discord-Bot-Token>).
## Using the Config File
### Using the Config File

Inside the `config` folder you will see a file named `settings.json.example`, rename it to `settings.json` and replace all the properties with your own values.

Your file should look like this:

```json
{
"discord_token": "YOUR DISCORD TOKEN",
"token": "YOUR_DISCORD_TOKEN",
"prefix": "!",
"owner_id": "YOUR USER ID (IF YOU'RE THE OWNER)",
"invite_url": "YOUR BOT INVITE URL HERE",
"owner_id": "YOUR_USER_ID",
"owner_reporting": false,
"presence_refresh_interval": 900000
}
```

Expand All @@ -77,22 +89,23 @@ npm start
You'll need to configure which channel should be used for the bot to send notifications. To do this, run the command:

```text
$setchannel <channel_mention>
n!setchannel <channel_mention>
```

> Replace `$` with your actual bot prefix and `<channel_mention>` with the mention of the channel you wish to set.
> Replace `n!` with your actual bot prefix and `<channel_mention>` with the mention of the channel you wish to set.
>
> Make sure that the channel you're setting is viewable by the bot and that you have the `MANAGE_CHANNELS` permission.
## Commands

The following commands are available:

| Command | Description |
|---------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `$help` | Receive a message with the available commands. |
| `$setchannel <channel_mention>` | Set the channel that should be used for the bot to send the automatic game offer announcements. The user issuing this command must have the `MANAGE_CHANNELS` permission. |
| `$offers <provider>` | Get a list of current available offers. Replace `<provider>` with **epic** for Epic Games Store offers or **steam** for Steam offers. You can omit this argument to receive all offers from all providers supported. |
| Command | Aliases | Description |
|----------------------------------|-------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `n!help` | `n!h` | Receive a message with the available commands. |
| `n!setchannel <channel_mention>` | `n!channel` | Set the channel that should be used for the bot to send the automatic game offer announcements. The user issuing this command must have the `MANAGE_CHANNELS` permission. |
| `n!disable` | | Disable the automatic game offer announcements on this server. You can still use the `n!offers` command. The user issuing this command must have the `MANAGE_CHANNELS` permission. |
| `n!offers <provider>` | | Get a list of current available offers. Replace `<provider>` with **epic** for Epic Games Store offers or **steam** for Steam offers. You can omit this argument to receive all offers from all providers supported. |

## Docker Support

Expand All @@ -116,7 +129,7 @@ You can configure the bot using environment variables. To do so, check out [conf
Starting the bot's container can be done by running:

```text
docker run -it -e DISCORD_TOKEN="YOUR DISCORD TOKEN" -e CHANNEL_ID="YOUR CHANNEL ID" -v "/local/folder/for/data":"/opt/app/data" moonstarx/discord-free-games-notifier:latest
docker run -it -e DISCORD_TOKEN="YOUR DISCORD TOKEN" -v "/local/folder/for/data":"/opt/app/data" moonstarx/discord-free-games-notifier:latest
```

## Add this bot to your server
Expand All @@ -125,6 +138,8 @@ You can add this bot to your server by clicking in the image below:

[![Add this bot to your server](https://i.imgur.com/SVAwPTU.png)](https://discord.com/oauth2/authorize?client_id=795561965954269205&scope=bot&permissions=2048)

> The prefix for this bot is `n!`
## Author

This bot was made by [moonstar-x](https://github.com/moonstar-x).
34 changes: 23 additions & 11 deletions __mocks__/discordMocks.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { Collection } = require('discord.js');

const channelMock = {
name: 'channel',
id: '123',
Expand All @@ -8,13 +10,12 @@ const channelMock = {
}
};

const channelStoreMock = {
cache: [channelMock, channelMock]
};

const guildMock = {
name: 'guild',
channels: channelStoreMock
id: '123',
channels: {
cache: new Collection([[channelMock.id, channelMock], [channelMock.id, channelMock]])
}
};

const commandMock = {
Expand All @@ -34,10 +35,16 @@ const clientMock = {
},
setProvider: jest.fn(() => Promise.resolve()),
updatePresence: jest.fn(),
provider: {
dataProvider: {
set: jest.fn(),
get: jest.fn(),
clear: jest.fn()
clear: jest.fn(),
getGlobal: jest.fn(),
setGlobal: jest.fn(),
clearGlobal: jest.fn()
},
guilds: {
cache: new Collection([[guildMock.id, guildMock], [guildMock.id, guildMock]])
}
};

Expand All @@ -54,8 +61,14 @@ const messageMock = {
guild: guildMock,
author: userMock,
member: memberMock,
embed: jest.fn(),
say: jest.fn()
channel: {
send: jest.fn()
},
mentions: {
channels: {
first: jest.fn(() => channelMock)
}
}
};

module.exports = {
Expand All @@ -66,6 +79,5 @@ module.exports = {
memberMock,
commandGroupMock,
commandMock,
channelMock,
channelStoreMock
channelMock
};
Loading

0 comments on commit ef4c0c1

Please sign in to comment.