Compare commits

...

81 Commits
0.3.2 ... 0.3.6

Author SHA1 Message Date
8b5933749d Merge pull request #47 from warengroup/develop
Version 0.3.6
2021-09-06 22:39:05 +03:00
ab950352fa Added uncaughtException event 2021-09-06 22:35:49 +03:00
984e8aab76 Fixed prev command 2021-09-06 22:35:21 +03:00
cc8b44db9b Fixed next command 2021-09-06 22:35:14 +03:00
1371a83e90 Removed permissions property from commands 2021-09-06 21:56:19 +03:00
33e4a416a9 Updated saveRadios function 2021-09-06 21:46:59 +03:00
5bf4bd9a1c Updated maintenance command 2021-09-06 21:45:13 +03:00
4edfe6848c Updated SIGINT event 2021-09-06 21:44:59 +03:00
884233a938 Updated SIGTERM event 2021-09-06 21:44:45 +03:00
3ac284e237 Updated maintenance command 2021-09-06 20:42:14 +03:00
d1fe9177af Updated play.js 2021-09-06 19:43:28 +03:00
8316723a6a Added reload stations option in maintenance command 2021-09-06 19:43:14 +03:00
f9ce2bfaf9 Updated play command 2021-09-06 19:10:15 +03:00
a9857cb34b Updated play function 2021-09-06 19:09:34 +03:00
894a1d82f5 Updated play command 2021-09-06 18:38:46 +03:00
fa4f5e1e09 Updated labeler workflow (Github Workflows) 2021-09-06 18:07:00 +03:00
12c8b8558f Updated labeler config 2021-09-06 18:06:44 +03:00
bb8a36ad5c Added labeler config 2021-09-06 17:44:52 +03:00
ebeeadd5c3 Added labeler workflow (Github Workflows) 2021-09-06 17:38:43 +03:00
6e0b2f5092 Updated CodeQL Analyze workflow (Github Workflows) 2021-09-06 17:18:08 +03:00
2286815485 Renamed CodeQL Analyze workflow (Github Workflows) 2021-09-06 17:16:05 +03:00
2e402de6bf Added CodeQL Analysis workflow (Github Workflow) 2021-09-06 17:08:34 +03:00
45d68ff4ab Added dependabot config 2021-09-06 16:51:53 +03:00
370701a4b9 Updated Dependencies 2021-09-06 16:28:17 +03:00
956f1f7b6d Updated README.md 2021-09-06 16:19:56 +03:00
115a2e7589 Updated Dependencies 2021-09-06 16:06:17 +03:00
f9d195788c Changed interaction replies to ephemeral in commands 2021-09-06 14:42:49 +03:00
c673ae27f6 Bumb version 2021-09-06 05:48:34 +03:00
e39a24de2a Merge pull request #42 from warengroup/develop
Version 0.3.5
2021-09-06 05:36:30 +03:00
aa715aaafa Updated play command 2021-09-06 05:22:20 +03:00
9303dd1c19 Fixed maintenance command 2021-09-06 05:11:49 +03:00
9a5075f27e Updated ready event 2021-09-06 04:22:47 +03:00
60ef1cd138 Added saveRadios function & imported funcs in Client.ts 2021-09-06 04:22:35 +03:00
235a02ca60 Updated maintenance command 2021-09-06 04:21:50 +03:00
05852b99d4 Updated SIGINT event 2021-09-06 04:20:08 +03:00
01730cd08b Moved restoreRadios function to funcs folder 2021-09-06 04:18:55 +03:00
6335a4617f Show errors except DiscordAPIError[50001] in commands.js 2021-09-06 01:19:09 +03:00
552d3c81f9 Updated listStations function 2021-09-06 00:52:35 +03:00
2d9b0ce732 Updated restoreradio.js 2021-09-05 23:42:17 +03:00
3b0f8068c1 Merge pull request #46 from Vekki000/fix-43
Updated statistics.js
2021-09-05 23:13:21 +03:00
c142fc61b4 Updated statistics.js
xd
2021-09-05 23:11:26 +03:00
dcfde4131f Merge pull request #45 from Vekki000/fix-43
Global percent decimal fix
2021-09-05 22:42:04 +03:00
a1cb21d98e Global percent decimal fix 2021-09-05 22:37:26 +03:00
4c731c1942 Updated interactionCreate.js 2021-09-05 06:59:24 +03:00
d2a6d70cf6 Bumb Version 2021-09-05 06:58:50 +03:00
a86cf0c769 Merge pull request #41 from warengroup/develop
Version 0.3.4
2021-09-05 06:30:15 +03:00
7a0a3e0d50 Updated category in next and prev command 2021-09-05 06:26:34 +03:00
479c0ee13d Fixed check function 2021-09-05 06:22:47 +03:00
b280981e1c Updated statistics command 2021-09-05 06:15:54 +03:00
933140502d Updated prev command 2021-09-05 05:41:22 +03:00
dfada15b00 Updated next command 2021-09-05 05:41:13 +03:00
8fdcdd0116 Updated next & prev command 2021-09-05 04:42:11 +03:00
11573a5113 Updated commands.js 2021-09-05 04:41:53 +03:00
7e3a83743d Disabled removing commands when bot is going offline 2021-09-05 04:36:32 +03:00
38af503626 Fixed bug replated to sending error message in interactionCreate.js 2021-09-05 03:44:28 +03:00
534bc74936 Updated code 2021-09-05 03:37:03 +03:00
ea2be5d5fb Updated check function 2021-09-05 03:33:48 +03:00
38a8571ddc Updated nowplaying command 2021-09-05 03:33:15 +03:00
2d41c7a76b Updated commands and interactionCreate event 2021-09-05 03:17:21 +03:00
16bc2aab52 Updated play function 2021-09-05 03:12:23 +03:00
17132cd51a Moved listStations into funcs folder 2021-09-05 03:11:51 +03:00
ec6ea7e839 Removed unused variable command from commands. 2021-09-05 03:06:47 +03:00
c81dbddab1 Renamed previous to prev command 2021-09-05 02:54:56 +03:00
e0226c5cfe Updated multiple command's metadata 2021-09-05 02:49:03 +03:00
3f12bafee0 Updated Dependencies 2021-09-05 02:46:13 +03:00
3fc28a79cb Moved createAudioResource from discord.js/voice to play function 2021-09-05 02:39:59 +03:00
72d0054d25 Made interaction nullable when replying in play function 2021-09-05 02:36:52 +03:00
25356be323 Moved play function to funcs folder 2021-09-05 02:35:36 +03:00
e8d90f8a3c Fixed file name searchStations to searchStation 2021-09-05 02:23:26 +03:00
c724ae502f Moved searchStations function into funcs folder 2021-09-05 02:16:58 +03:00
a3efdbf3cb Enabled next and previous buttons in restoreradio.js 2021-09-05 02:13:39 +03:00
2857b6886f Enabled prev & next buttons in play command 2021-09-05 02:13:18 +03:00
1e24e89568 Updated maintenance command 2021-09-05 02:12:57 +03:00
3609e6af10 Added empty next and previous command 2021-09-05 02:12:43 +03:00
d5fefcdbbc Removed commandAliases collection in messageCreate.js 2021-09-05 02:12:10 +03:00
8860952c07 Bumb version 2021-09-04 14:18:58 +03:00
d27cdf6ee5 Merge pull request #40 from warengroup/develop
Version 0.3.3
2021-09-04 13:59:01 +03:00
0d4c46cfd4 Fixed typo in bug.js 2021-09-04 13:56:05 +03:00
9ef6b3f36f Fixed bug command 2021-09-04 13:41:53 +03:00
1a5caf244f Ephemeral replies in nowplaying.js 2021-09-03 06:00:31 +03:00
9040b84050 Bumb Version 2021-09-03 05:19:09 +03:00
34 changed files with 796 additions and 680 deletions

19
.github/dependabot.yml vendored Normal file
View File

@ -0,0 +1,19 @@
version: 2
updates:
# GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
target-branch: "develop"
labels:
- "dependencies"
# npm
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "daily"
target-branch: "develop"
labels:
- "dependencies"

7
.github/labeler.yml vendored Normal file
View File

@ -0,0 +1,7 @@
dependencies:
- package-lock.json
documentation:
- README.md
- LICENSE
- .env_example

71
.github/workflows/codeql-analyze.yml vendored Normal file
View File

@ -0,0 +1,71 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL Analyze"
on:
push:
branches: [ master, stable ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ master ]
schedule:
- cron: '24 20 * * 6'
jobs:
analyze:
name: CodeQL Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: [ 'javascript' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
# Learn more:
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
steps:
- name: Checkout repository
uses: actions/checkout@v2
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main
# 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
# Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language
#- run: |
# make bootstrap
# make release
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1

16
.github/workflows/labeler.yml vendored Normal file
View File

@ -0,0 +1,16 @@
name: Labeler
on: [pull_request]
jobs:
label:
name: Labeler
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/labeler@v3
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
sync-labels: true

View File

@ -5,7 +5,7 @@ Internet Radio to your Discord guild
This bot is using Gitea repo to get radio stations from [playlist.json](https://gitea.cwinfo.org/cwchristerw/radio/raw/branch/master/playlist.json) file. List is currently maintained by Christer Warén. You can use alternative list with same format when using RADIOX_STATIONSLISTURL environment variable.
## Docker
1. `docker build -t warengroup/eximiabots-radiox .`
1. `docker build -t warengroup/eximiabots-radiox . --pull`
2. `docker run --name radiox-dev -d --net host -e DISCORD_TOKEN= -v "$PWD/datastore":/usr/src/app/datastore/ warengroup/eximiabots-radiox`
## Join our Discord Server

56
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "eximiabots-radiox",
"version": "0.3.2",
"version": "0.3.6",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "eximiabots-radiox",
"version": "0.3.2",
"version": "0.3.6",
"license": "MIT",
"dependencies": {
"@discordjs/builders": "^0.6.0",
@ -17,7 +17,7 @@
"discord.js": "^13.1.0",
"dotenv": "^10.0.0",
"libsodium-wrappers": "^0.7.9",
"node-fetch": "^2.6.1",
"node-fetch": "^2.6.2",
"path": "^0.12.7"
},
"devDependencies": {
@ -36,7 +36,7 @@
"typescript": "^4.4.2"
},
"engines": {
"node": ">=16.6.0",
"node": ">=16.8.0",
"npm": ">=7.0.0"
}
},
@ -666,9 +666,9 @@
}
},
"node_modules/acorn-walk": {
"version": "8.1.1",
"resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.1.1.tgz",
"integrity": "sha512-FbJdceMlPHEAWJOILDk1fXD8lnTlEIWFkqtfk+MvmL5q/qlHfN7GEHcsFZWt/Tea9jRNPWUZG4G976nqAAmU9w==",
"version": "8.2.0",
"resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.2.0.tgz",
"integrity": "sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==",
"dev": true,
"engines": {
"node": ">=0.4.0"
@ -1228,9 +1228,9 @@
}
},
"node_modules/deep-is": {
"version": "0.1.3",
"resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz",
"integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=",
"version": "0.1.4",
"resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz",
"integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==",
"dev": true
},
"node_modules/defer-to-connect": {
@ -2535,9 +2535,9 @@
"dev": true
},
"node_modules/node-fetch": {
"version": "2.6.1",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz",
"integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==",
"version": "2.6.2",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.2.tgz",
"integrity": "sha512-aLoxToI6RfZ+0NOjmWAgn9+LEd30YCkJKFSyWacNZdEKTit/ZMcKjGkTRo8uWEsnIb/hfKecNPEbln02PdWbcA==",
"engines": {
"node": "4.x || >=6.0.0"
}
@ -3549,9 +3549,9 @@
}
},
"node_modules/ts-node/node_modules/acorn": {
"version": "8.4.1",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.4.1.tgz",
"integrity": "sha512-asabaBSkEKosYKMITunzX177CXxQ4Q8BSSzMTKD+FefUhipQC70gfW5SiUDhYQ3vk8G+81HqQk7Fv9OXwwn9KA==",
"version": "8.5.0",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.5.0.tgz",
"integrity": "sha512-yXbYeFy+jUuYd3/CDcg2NkIYE991XYX/bje7LmjJigUciaeO1JR4XxXgCIV1/Zc/dRuFEyw1L0pbA+qynJkW5Q==",
"dev": true,
"bin": {
"acorn": "bin/acorn"
@ -4358,9 +4358,9 @@
"requires": {}
},
"acorn-walk": {
"version": "8.1.1",
"resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.1.1.tgz",
"integrity": "sha512-FbJdceMlPHEAWJOILDk1fXD8lnTlEIWFkqtfk+MvmL5q/qlHfN7GEHcsFZWt/Tea9jRNPWUZG4G976nqAAmU9w==",
"version": "8.2.0",
"resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.2.0.tgz",
"integrity": "sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==",
"dev": true
},
"agent-base": {
@ -4788,9 +4788,9 @@
"dev": true
},
"deep-is": {
"version": "0.1.3",
"resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz",
"integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=",
"version": "0.1.4",
"resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz",
"integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==",
"dev": true
},
"defer-to-connect": {
@ -5797,9 +5797,9 @@
"dev": true
},
"node-fetch": {
"version": "2.6.1",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz",
"integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw=="
"version": "2.6.2",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.2.tgz",
"integrity": "sha512-aLoxToI6RfZ+0NOjmWAgn9+LEd30YCkJKFSyWacNZdEKTit/ZMcKjGkTRo8uWEsnIb/hfKecNPEbln02PdWbcA=="
},
"nodemon": {
"version": "2.0.12",
@ -6516,9 +6516,9 @@
},
"dependencies": {
"acorn": {
"version": "8.4.1",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.4.1.tgz",
"integrity": "sha512-asabaBSkEKosYKMITunzX177CXxQ4Q8BSSzMTKD+FefUhipQC70gfW5SiUDhYQ3vk8G+81HqQk7Fv9OXwwn9KA==",
"version": "8.5.0",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.5.0.tgz",
"integrity": "sha512-yXbYeFy+jUuYd3/CDcg2NkIYE991XYX/bje7LmjJigUciaeO1JR4XxXgCIV1/Zc/dRuFEyw1L0pbA+qynJkW5Q==",
"dev": true
}
}

View File

@ -1,6 +1,6 @@
{
"name": "eximiabots-radiox",
"version": "0.3.2",
"version": "0.3.6",
"description": "Internet Radio to your Discord guild",
"main": "index.js",
"scripts": {
@ -26,7 +26,7 @@
"discord.js": "^13.1.0",
"dotenv": "^10.0.0",
"libsodium-wrappers": "^0.7.9",
"node-fetch": "^2.6.1",
"node-fetch": "^2.6.2",
"path": "^0.12.7"
},
"devDependencies": {
@ -45,7 +45,7 @@
"typescript": "^4.4.2"
},
"engines": {
"node": ">=16.6.0",
"node": ">=16.8.0",
"npm": ">=7.0.0"
}
}

View File

@ -39,6 +39,11 @@ class RadioClient extends Client {
this.funcs.statisticsUpdate = require("./client/funcs/statisticsUpdate.js");
this.funcs.saveState = require("./client/funcs/saveState.js");
this.funcs.loadState = require("./client/funcs/loadState.js");
this.funcs.searchStation = require("./client/funcs/searchStation.js");
this.funcs.play = require("./client/funcs/play.js");
this.funcs.listStations = require("./client/funcs/listStations.js");
this.funcs.restoreRadios = require("./client/funcs/restoreRadios.js");
this.funcs.saveRadios = require("./client/funcs/saveRadios.js");
console.log('RadioX ' + this.config.version);
console.log('Internet Radio to your Discord guild');
@ -81,6 +86,10 @@ class RadioClient extends Client {
require(`${events}SIGTERM`).execute(this);
});
process.on('uncaughtException', (error) => {
require(`${events}uncaughtException`).execute(this, error);
});
this.on("error", error => {
console.error(error);
});

View File

@ -20,6 +20,7 @@ module.exports = {
if(command.options) {
command.options.forEach(function(option) {
if(option.type == "STRING") option.type = 3;
if(option.type == "NUMBER") option.type = 10;
command.data.options.push(option);
});
}
@ -44,16 +45,18 @@ module.exports = {
try {
await rest.put(
Routes.applicationGuildCommands(client.user.id, guild.id),
{ body: commands },
{ body: commands }
);
client.funcs.logger('Slash Commands', 'Guild Applications Successful' + "\n" + guild.id + " / " + guild.name);
} catch (DiscordAPIError) {
client.funcs.logger('Slash Commands', 'Guild Applications Failed' + "\n" + guild.id + " / " + guild.name);
if(DiscordAPIError.name != "DiscordAPIError[50001]") console.error(DiscordAPIError.message + "\n\n");
}
});
} else {
await rest.put(
Routes.applicationCommands(client.user.id),
{ body: commands },
{ body: commands }
);
}

View File

@ -1,15 +1,14 @@
import Discord from "discord.js";
module.exports = {
name: 'bug',
alias: 'none',
usage: '',
description: 'Report a bug',
permission: 'none',
category: 'info',
async execute(interaction, client, Discord, command) {
async execute(interaction, client) {
let message = {};
message.bugTitle = client.messages.bugTitle.replace("%client.user.username%", client.user.username);
message.bugDescription = message.bugDescription.replace("%client.config.supportGuild%", client.config.supportGuild);
message.bugDescription = client.messages.bugDescription.replace("%client.config.supportGuild%", client.config.supportGuild);
const embed = new Discord.MessageEmbed()
.setTitle(message.bugTitle)

View File

@ -1,11 +1,10 @@
import Discord from "discord.js";
module.exports = {
name: 'help',
alias: 'h',
usage: '<command(opt)>',
description: 'Get help using bot',
permission: 'none',
category: 'info',
execute(interaction, client, Discord, command) {
execute(interaction, client) {
let message = {};
const categories = [];

View File

@ -1,11 +1,10 @@
import Discord from "discord.js";
module.exports = {
name: 'invite',
alias: 'i',
usage: '',
description: 'Invite Bot',
permission: 'none',
category: 'info',
execute(interaction, client, Discord, command) {
execute(interaction, client) {
let message = {};
message.inviteTitle = client.messages.inviteTitle.replace("%client.user.username%", client.user.username);
const embed = new Discord.MessageEmbed()

View File

@ -1,63 +1,23 @@
import Discord from "discord.js";
module.exports = {
name: 'list',
alias: 'l',
usage: '',
description: 'List radio stations',
permission: 'none',
category: 'radio',
execute(interaction, client, Discord, command) {
execute(interaction, client) {
let message = {};
if(!client.stations) {
message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace("%client.config.supportGuild%", client.config.supportGuild);
return interaction.reply(client.messageEmojis["error"] + message.errorToGetPlaylist);
return interaction.reply({
content: client.messageEmojis["error"] + message.errorToGetPlaylist,
ephemeral: true
});
}
const radio = client.radio.get(interaction.guild.id);
if(radio){
let menu = [];
let stations = new Array();
let options = new Array();
options[1] = new Array();
options[2] = new Array();
stations[1] = client.stations.slice(0,24).forEach(station => {
station = {
label: station.name,
description: station.owner,
value: station.name
};
options[1].push(station);
});
stations[2] = client.stations.slice(25).forEach(station => {
station = {
label: station.name,
description: station.owner,
value: station.name
};
options[2].push(station);
});
menu = new Discord.MessageActionRow()
.addComponents(
new Discord.MessageSelectMenu()
.setCustomId('play')
.setPlaceholder('Change station')
.addOptions(options[1])
.addOptions(options[2])
);
stations = null;
options = null;
interaction.reply({
content: '**Select station:**',
components: [menu],
ephemeral: true
});
client.funcs.listStations(client, interaction);
} else {
let stations = `${client.stations.map(s => `**#** ${s.name}`).join('\n')}`
const hashs = stations.split('**#**').length;

View File

@ -1,15 +1,139 @@
import Discord from "discord.js";
import fetch from "node-fetch";
module.exports = {
name: 'maintenance',
alias: 'm',
usage: '',
description: 'Bot Maintenance',
permission: 'none',
category: 'info',
execute(interaction, client, Discord, command) {
options: [
{ type: "NUMBER", name: "action", description: "Select action", required: false}
],
async execute(interaction, client) {
let message = {};
if(!client.funcs.isDev(client.config.devId, interaction.user.id)) return interaction.reply(client.messageEmojis["error"] + client.messages.notAllowed);
if(!client.funcs.isDev(client.config.devId, interaction.user.id)) return interaction.reply({
content: client.messageEmojis["error"] + client.messages.notAllowed,
ephemeral: true
});
let action = interaction.options?.getNumber("action") ?? interaction.values?.[0];
const options = new Array(
{
emoji: "🌀",
label: "Restart Bot",
description: "",
value: "0"
},
{
emoji: "<:RadioXStop:688541155377414168>",
label: "Save Radios",
description: "",
value: "4"
},
{
emoji: "<:RadioXPlay:688541155712827458>",
label: "Restore Radios",
description: "",
value: "5"
},
{
emoji: "#️⃣",
label: "Reload Commands",
description: "",
value: "6"
},
{
emoji: "<:RadioXList:688541155519889482>",
label: "Reload Stations",
description: "",
value: "7"
},
{
emoji: "<:dnd:746069698139127831>",
label: "Enable Maintenance Mode",
description: "",
value: "8"
},
{
emoji: "<:online:746069731836035098>",
label: "Disable Maintenance Mode",
description: "",
value: "9"
}
);
const menu = new Discord.MessageActionRow()
.addComponents(
new Discord.MessageSelectMenu()
.setCustomId('maintenance')
.setPlaceholder('Select action')
.addOptions(options)
);
if(!action){
return interaction.reply({
content: "**" + client.messages.maintenanceTitle + "**",
components: [menu],
ephemeral: true
});
}
client.funcs.logger('Maintenance', options.find(option => option.value == action).label);
const embed = new Discord.MessageEmbed()
.setTitle(client.messages.maintenanceTitle)
.setColor(client.config.embedColor)
.setDescription(options.find(option => option.value == action).label)
.setFooter(client.messages.footerText, "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, ''));
interaction.reply({
embeds: [embed],
ephemeral: true
});
switch(action){
case "0":
process.emit('SIGINT');
break;
case "4":
client.user.setStatus('idle');
client.funcs.saveRadios(client);
client.user.setStatus('online');
break;
case "5":
client.user.setStatus('idle');
let guilds = await client.guilds.fetch();
client.funcs.restoreRadios(client, guilds);
client.user.setStatus('online');
break;
case "6":
client.user.setStatus('idle');
require(`../commands.js`).execute(client);
client.user.setStatus('online');
break;
case "7":
try {
client.funcs.logger('Stations', 'Started fetching list ' + client.config.stationslistUrl);
client.stations = await fetch(client.config.stationslistUrl)
.then(client.funcs.checkFetchStatus)
.then(response => response.json());
client.funcs.logger('Stations', 'Successfully fetched list');
} catch (error) {
client.funcs.logger('Stations', 'Fetching list failed');
}
break;
case "8":
client.user.setStatus('dnd');
break;
case "9":
client.user.setStatus('online');
break;
default:
}
/*
if(!client.stations) {
message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace("%client.config.supportGuild%", client.config.supportGuild);
return interaction.reply(client.messageEmojis["error"] + message.errorToGetPlaylist);
@ -47,6 +171,7 @@ module.exports = {
interaction.reply({
embeds: [embed],
ephemeral: true
});
});*/
}
};

View File

@ -0,0 +1,39 @@
module.exports = {
name: 'next',
description: 'Next Station',
category: 'radio',
async execute(interaction, client, command) {
if (client.funcs.check(client, interaction, command)) {
const radio = client.radio.get(interaction.guild.id);
let index = client.stations.findIndex(station => station.name == radio.station.name) + 1;
if(index == client.stations.length) index = 0;
let station = client.stations[index];
if(!station) return interaction.reply({
content: client.messageEmojis["error"] + client.messages.noSearchResults,
ephemeral: true
});
let url = station.stream[station.stream.default];
client.funcs.statisticsUpdate(client, interaction.guild, radio);
radio.audioPlayer.stop();
let date = new Date();
radio.station = station;
radio.textChannel = interaction.channel;
radio.startTime = date.getTime();
if(interaction.isCommand()) {
client.funcs.play(interaction, interaction.guild, client, url);
}
if(interaction.isButton()) {
interaction.deferUpdate();
client.funcs.play(null, interaction.guild, client, url);
}
}
}
}

View File

@ -1,18 +1,13 @@
import Discord from "discord.js";
module.exports = {
name: 'nowplaying',
alias: 'np',
usage: '',
description: 'Current Radio Station',
permission: 'none',
category: 'radio',
async execute(interaction, client, Discord, command) {
async execute(interaction, client, command) {
if (client.funcs.check(client, interaction, command)) {
let message = {};
const radio = client.radio.get(interaction.guild.id);
if (!radio) return interaction.reply('There is nothing playing.');
if(!client.stations) {
message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace("%client.config.supportGuild%", client.config.supportGuild);
return interaction.reply(client.messageEmojis["error"] + message.errorToGetPlaylist);
}
let date = new Date();
radio.currentTime = date.getTime();
@ -36,4 +31,5 @@ module.exports = {
ephemeral: true
});
}
}
};

View File

@ -1,104 +1,60 @@
const {
createAudioPlayer,
createAudioResource,
getVoiceConnection,
joinVoiceChannel
} = require("@discordjs/voice");
module.exports = {
name: "play",
alias: "p",
usage: "<song name>",
description: "Play radio",
options: [
{ type: "STRING", name: "query", description: "Select station", required: false}
],
permission: "none",
category: "radio",
async execute(interaction, client, Discord, command) {
async execute(interaction, client) {
let message = {};
let query = interaction.options?.getString("query") ?? interaction.values?.[0];
if(!query){
if(!client.stations) {
message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace("%client.config.supportGuild%", client.config.supportGuild);
return interaction.reply(client.messageEmojis["error"] + message.errorToGetPlaylist);
}
let stations = new Array();
let options = new Array();
options[1] = new Array();
options[2] = new Array();
stations[1] = client.stations.slice(0,24).forEach(station => {
station = {
label: station.name,
description: station.owner,
value: station.name
};
options[1].push(station);
});
stations[2] = client.stations.slice(25).forEach(station => {
station = {
label: station.name,
description: station.owner,
value: station.name
};
options[2].push(station);
});
const menu = new Discord.MessageActionRow()
.addComponents(
new Discord.MessageSelectMenu()
.setCustomId('play')
.setPlaceholder('Nothing selected')
.addOptions(options[1])
.addOptions(options[2])
);
stations = null;
options = null;
return interaction.reply({
content: '**Select station:**',
components: [menu],
ephemeral: true
});
}
let url = query ? query.replace(/<(.+)>/g, "$1") : "";
const radio = client.radio.get(interaction.guild.id);
const voiceChannel = interaction.member.voice.channel;
if (!radio) {
if (!interaction.member.voice.channel)
return interaction.reply({
content: client.messageEmojis["error"] + client.messages.noVoiceChannel,
ephemeral: true
});
} else {
if (voiceChannel !== radio.voiceChannel)
return interaction.reply({
content: client.messageEmojis["error"] + client.messages.wrongVoiceChannel,
ephemeral: true
});
}
if (!client.stations) {
message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace(
"%client.config.supportGuild%",
client.config.supportGuild
);
return interaction.reply({
content: client.messageEmojis["error"] + message.errorToGetPlaylist,
ephemeral: true
});
}
if (!query) return interaction.reply(client.messages.noQuery);
let query = interaction.options?.getString("query") ?? interaction.values?.[0];
if(!query){
return client.funcs.listStations(client, interaction);
}
let url = query ? query.replace(/<(.+)>/g, "$1") : "";
const radio = client.radio.get(interaction.guild.id);
const voiceChannel = interaction.member.voice.channel;
if (!voiceChannel) return interaction.reply({
content: client.messageEmojis["error"] + client.messages.noVoiceChannel,
ephemeral: true
});
if (radio) {
if (voiceChannel !== radio.voiceChannel) return interaction.reply({
content: client.messageEmojis["error"] + client.messages.wrongVoiceChannel,
ephemeral: true
});
}
if (!query) return interaction.reply({
content: client.messages.noQuery,
ephemeral: true
});
const permissions = voiceChannel.permissionsFor(interaction.client.user);
if (!permissions.has("CONNECT")) {
return interaction.reply(client.messageEmojis["error"] + client.messages.noPermsConnect);
return interaction.reply({
content: client.messageEmojis["error"] + client.messages.noPermsConnect,
ephemeral: true
});
}
if (!permissions.has("SPEAK")) {
return interaction.reply(client.messageEmojis["error"] + client.messages.noPermsSpeak);
return interaction.reply({
content: client.messageEmojis["error"] + client.messages.noPermsSpeak,
ephemeral: true
});
}
let station;
const number = parseInt(query - 1);
@ -118,14 +74,12 @@ module.exports = {
station = client.stations[number];
}
} else {
if (query.length < 3)
return interaction.reply({
if (query.length < 3) return interaction.reply({
content: client.messageEmojis["error"] + client.messages.tooShortSearch,
ephemeral: true
});
const sstation = await searchStation(query, client);
if (!sstation)
return interaction.reply({
const sstation = await client.funcs.searchStation(query, client);
if (!sstation) return interaction.reply({
content: client.messageEmojis["error"] + client.messages.noSearchResults,
ephemeral: true
});
@ -141,7 +95,7 @@ module.exports = {
radio.station = station;
radio.textChannel = interaction.channel;
radio.startTime = date.getTime();
play(interaction, interaction.guild, client, url, Discord);
client.funcs.play(interaction, interaction.guild, client, url);
return;
}
@ -167,7 +121,7 @@ module.exports = {
construct.connection = connection;
let date = new Date();
construct.startTime = date.getTime();
play(interaction, interaction.guild, client, url, Discord);
client.funcs.play(interaction, interaction.guild, client, url);
client.datastore.checkEntry(interaction.guild.id);
construct.currentGuild = client.datastore.getEntry(interaction.guild.id);
@ -181,161 +135,10 @@ module.exports = {
} catch (error) {
console.log(error);
client.radio.delete(interaction.guild.id);
return interaction.reply(client.messageEmojis["error"] + `An error occured: ${error}`);
return interaction.reply({
content: client.messageEmojis["error"] + `An error occured: ${error}`,
ephemeral: true
});
}
}
};
async function play(interaction, guild, client, url, Discord) {
let message = {};
const radio = client.radio.get(guild.id);
const resource = createAudioResource(url);
radio.connection.subscribe(radio.audioPlayer);
radio.audioPlayer.play(resource);
resource.playStream
.on("readable", () => {
client.funcs.logger('Radio', 'Stream started' + " / " + guild.id + " / " + radio.station.name);
})
.on("finish", () => {
client.funcs.logger('Radio', 'Stream finished' + " / " + guild.id);
client.funcs.statisticsUpdate(client, guild, radio);
radio.connection?.destroy();
radio.audioPlayer?.stop();
client.radio.delete(guild.id);
return;
})
.on("error", error => {
client.funcs.logger('Radio', 'Stream errored');
console.error(error);
radio.connection?.destroy();
radio.audioPlayer?.stop();
client.radio.delete(guild.id);
return interaction.reply(client.messages.errorPlaying);
});
message.nowplayingDescription = client.messages.nowplayingDescription.replace("%radio.station.name%", radio.station.name);
message.nowplayingDescription = message.nowplayingDescription.replace("%radio.station.owner%", radio.station.owner);
message.nowplayingDescription = message.nowplayingDescription.replace("%client.funcs.msToTime(completed)%", "");
message.nowplayingDescription = message.nowplayingDescription.replace("Owner: ", "");
message.nowplayingDescription = message.nowplayingDescription.replace("**", "");
message.nowplayingDescription = message.nowplayingDescription.replace("**", "");
const embed = new Discord.MessageEmbed()
.setTitle(client.user.username)
.setThumbnail((radio.station.logo || "https://cdn.discordapp.com/emojis/" + client.messageEmojis["play"].replace(/[^0-9]+/g, '')))
.setColor(client.config.embedColor)
.addField(client.messages.nowplayingTitle, message.nowplayingDescription, true)
.setImage('https://waren.io/berriabot-temp-sa7a36a9xm6837br/images/empty-3.png')
.setFooter(client.messages.footerText, "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, ''));
const buttons = new Discord.MessageActionRow()
.addComponents(
new Discord.MessageButton()
.setCustomId('list')
.setEmoji(client.messageEmojis["list"])
.setStyle('SECONDARY')
)
.addComponents(
new Discord.MessageButton()
.setCustomId('prev')
.setEmoji(client.messageEmojis["prev"])
.setStyle('SECONDARY')
.setDisabled(true)
)
.addComponents(
new Discord.MessageButton()
.setCustomId('stop')
.setEmoji(client.messageEmojis["stop"])
.setStyle('SECONDARY')
)
.addComponents(
new Discord.MessageButton()
.setCustomId('next')
.setEmoji(client.messageEmojis["next"])
.setStyle('SECONDARY')
.setDisabled(true)
)
.addComponents(
new Discord.MessageButton()
.setCustomId('statistics')
.setEmoji(client.messageEmojis["statistics"])
.setStyle('SECONDARY')
);
if(!radio.message){
radio.message = await radio.textChannel.send({ embeds: [embed], components: [buttons] });
} else {
radio.message.edit({ embeds: [embed], components: [buttons] });
}
message.play = client.messages.play.replace("%radio.station.name%", radio.station.name);
interaction.reply({
content: client.messageEmojis["play"] + message.play,
ephemeral: true
});
}
function searchStation(key, client) {
if (client.stations === null) return false;
let foundStations = [];
if (!key) return false;
if (key == "radio") return false;
client.stations
.filter(
x => x.name.toUpperCase().includes(key.toUpperCase()) || x === key
)
.forEach(x =>
foundStations.push({ station: x, name: x.name, probability: 100 })
);
if (key.startsWith("radio ")) key = key.slice(6);
const probabilityIncrement = 100 / key.split(" ").length / 2;
for (let i = 0; i < key.split(" ").length; i++) {
client.stations
.filter(
x => x.name.toUpperCase().includes(key.split(" ")[i].toUpperCase()) || x === key
)
.forEach(x =>
foundStations.push({ station: x, name: x.name, probability: probabilityIncrement })
);
}
if (foundStations.length === 0) return false;
for (let i = 0; i < foundStations.length; i++) {
for (let j = 0; j < foundStations.length; j++) {
if (foundStations[i] === foundStations[j] && i !== j) foundStations.splice(i, 1);
}
}
for (let i = 0; i < foundStations.length; i++) {
if (foundStations[i].name.length > key.length) {
foundStations[i].probability -=
(foundStations[i].name.split(" ").length - key.split(" ").length) *
(probabilityIncrement * 0.5);
} else if (foundStations[i].name.length === key.length) {
foundStations[i].probability += probabilityIncrement * 0.9;
}
for (let j = 0; j < key.split(" ").length; j++) {
if (!foundStations[i].name.toUpperCase().includes(key.toUpperCase().split(" ")[j])) {
foundStations[i].probability -= probabilityIncrement * 0.5;
}
}
}
let highestProbabilityStation;
for (let i = 0; i < foundStations.length; i++) {
if (
!highestProbabilityStation ||
highestProbabilityStation.probability < foundStations[i].probability
)
highestProbabilityStation = foundStations[i];
if (
highestProbabilityStation &&
highestProbabilityStation.probability === foundStations[i].probability
) {
highestProbabilityStation = foundStations[i].station;
}
}
return highestProbabilityStation;
}

View File

@ -0,0 +1,39 @@
module.exports = {
name: 'prev',
description: 'Previous Station',
category: 'radio',
async execute(interaction, client, command) {
if (client.funcs.check(client, interaction, command)) {
const radio = client.radio.get(interaction.guild.id);
let index = client.stations.findIndex(station => station.name == radio.station.name) - 1;
if(index == -1) index = client.stations.length - 1;
let station = client.stations[index];
if(!station) return interaction.reply({
content: client.messageEmojis["error"] + client.messages.noSearchResults,
ephemeral: true
});
let url = station.stream[station.stream.default];
client.funcs.statisticsUpdate(client, interaction.guild, radio);
radio.audioPlayer.stop();
let date = new Date();
radio.station = station;
radio.textChannel = interaction.channel;
radio.startTime = date.getTime();
if(interaction.isCommand()) {
client.funcs.play(interaction, interaction.guild, client, url);
}
if(interaction.isButton()) {
interaction.deferUpdate();
client.funcs.play(null, interaction.guild, client, url);
}
}
}
}

View File

@ -1,29 +1,37 @@
import Discord from "discord.js";
module.exports = {
name: 'statistics',
alias: 'stats',
usage: '',
description: 'Show statistics',
permission: 'none',
category: 'info',
execute(interaction, client, Discord, command) {
execute(interaction, client) {
let message = {};
let stations = client.stations;
let currentGuild = client.datastore.getEntry(interaction.guild.id);
let global = client.datastore.getEntry("global");
let statistics = "";
if(!client.stations) {
message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace("%client.config.supportGuild%", client.config.supportGuild);
return interaction.reply(client.messageEmojis["error"] + message.errorToGetPlaylist);
return interaction.reply({
content: client.messageEmojis["error"] + message.errorToGetPlaylist,
ephemeral: true
});
}
if(!currentGuild || currentGuild && !currentGuild.statistics){
statistics = "You have not listened any radio station";
statistics = "You have not listened any radio stations";
} else {
Object.keys(stations).forEach(function(station) {
if(currentGuild.statistics[stations[station].name] && currentGuild.statistics[stations[station].name].time && parseInt(currentGuild.statistics[stations[station].name].time) > 0 && currentGuild.statistics[stations[station].name].used && parseInt(currentGuild.statistics[stations[station].name].used) > 0){
statistics += `**${parseInt(station) + 1}** ` + stations[station].name + " \n";
statistics += "Time: " + client.funcs.msToTime(currentGuild.statistics[stations[station].name].time) + "\n";
statistics += "Used: " + currentGuild.statistics[stations[station].name].used + "\n";
statistics += `**${parseInt(station) + 1}. ` + stations[station].name + "** \n";
if(global && global.statistics[stations[station].name] && global.statistics[stations[station].name].time && parseInt(global.statistics[stations[station].name].time) > 0 && global.statistics[stations[station].name].used && parseInt(global.statistics[stations[station].name].used) > 0){
statistics += "Guild Time: " + client.funcs.msToTime(currentGuild.statistics[stations[station].name].time) + " (" + ((currentGuild.statistics[stations[station].name].time / global.statistics[stations[station].name].time) * 100).toFixed(0) + "%" + ")" + " / " + "Used: " + currentGuild.statistics[stations[station].name].used + " (" + ((currentGuild.statistics[stations[station].name].used / global.statistics[stations[station].name].used) * 100).toFixed(0) + "%" + ")" + "\n";
statistics += "Global Time: " + client.funcs.msToTime(global.statistics[stations[station].name].time) + " / " + "Used: " + global.statistics[stations[station].name].used + "\n\n";
} else {
statistics += "Time: " + client.funcs.msToTime(currentGuild.statistics[stations[station].name].time) + " / " + "Used: " + currentGuild.statistics[stations[station].name].used + "\n\n";
}
}
});
}

View File

@ -1,11 +1,10 @@
import Discord from "discord.js";
module.exports = {
name: 'status',
alias: 'st',
usage: '',
description: 'Bot Status',
permission: 'none',
category: 'info',
async execute(interaction, client, Discord, command) {
async execute(interaction, client) {
let message = {};
message.statusTitle = client.messages.statusTitle.replace("%client.user.username%", client.user.username);

View File

@ -1,11 +1,10 @@
import Discord from "discord.js";
module.exports = {
name: 'stop',
description: 'Stop radio',
alias: 's',
usage: '',
permission: 'none',
category: 'radio',
async execute(interaction, client, Discord, command) {
async execute(interaction, client, command) {
const radio = client.radio.get(interaction.guild.id);
if (client.funcs.check(client, interaction, command)) {
client.funcs.statisticsUpdate(client, interaction.guild, radio);

View File

@ -1,65 +1,18 @@
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const { token, version } = require('../../config.js');
module.exports = {
name: 'SIGINT',
async execute(client) {
execute(client) {
client.user.setStatus('dnd');
console.log("\n");
client.funcs.logger("Bot", "Closing");
console.log("\n");
setTimeout(async function () {
let message = {};
if (!client.stations) return process.exit();
let currentRadios = client.radio.keys();
let radio = currentRadios.next();
while (!radio.done) {
let currentRadio = client.radio.get(radio.value);
currentRadio.guild = client.datastore.getEntry(radio.value).guild;
if (currentRadio) {
await client.funcs.statisticsUpdate(client, currentRadio.guild, currentRadio);
await client.funcs.saveState(client, currentRadio.guild, currentRadio);
currentRadio.connection?.destroy();
currentRadio.audioPlayer?.stop();
currentRadio.message?.delete();
client.radio.delete(radio.value);
}
radio = currentRadios.next();
}
const rest = new REST({ version: '9' }).setToken(token);
if(version.includes("-dev")){
await rest.put(
Routes.applicationCommands(client.user.id),
{ body: [] },
);
let guilds = await client.guilds.fetch();
guilds.forEach(async guild => {
try {
await rest.put(
Routes.applicationGuildCommands(client.user.id, guild.id),
{ body: [] },
);
} catch (DiscordAPIError) {
}
});
}
client.funcs.saveRadios(client);
setInterval(() => {
if(radio.done){
if(client.radio.size == 0){
process.exit();
}
}, 1000);
}, 5000);
}, 500);
}
}

View File

@ -1,6 +1,6 @@
module.exports = {
name: 'SIGTERM',
async execute(client) {
execute(client) {
process.emit('SIGINT');
}
}

View File

@ -1,11 +1,14 @@
import Discord from "discord.js";
module.exports = {
name: 'interactionCreate',
async execute(client, interaction) {
const permissions = interaction.channel.permissionsFor(interaction.client.user);
if (!permissions.has('EMBED_LINKS')) return interaction.send(client.messages.noPermsEmbed);
if (!permissions.has('VIEW_CHANNEL')) return;
if (!permissions.has('EMBED_LINKS')) return interaction.reply({
content: client.messages.noPermsEmbed,
ephemeral: true
});
if(interaction.isCommand()){
const commandName = interaction.commandName;
@ -13,7 +16,7 @@ module.exports = {
if (!command) return;
try {
command.execute(interaction, client, Discord, command);
command.execute(interaction, client);
} catch (error) {
interaction.reply({
content: client.messages.runningCommandFailed,
@ -27,7 +30,7 @@ module.exports = {
if (!command) return;
try {
command.execute(interaction, client, Discord, command);
command.execute(interaction, client, command);
} catch (error) {
interaction.reply({
content: client.messages.runningCommandFailed,

View File

@ -22,7 +22,7 @@ module.exports = {
if (!args[0]) return;
const commandName = args[0].toLowerCase();
if (commandName === 'none') return;
const command = client.commands.get(commandName) || client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName)) || client.commandAliases.get(commandName);
const command = client.commands.get(commandName) || client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));
if (!command && message.content !== `${prefix}`) return;
const permissions = message.channel.permissionsFor(message.client.user);
if (!permissions.has('EMBED_LINKS')) return message.channel.send(client.messages.noPermsEmbed);

View File

@ -94,8 +94,8 @@ module.exports = {
require(`../commands.js`).execute(client);
setTimeout(function () {
/*RESTORE RADIO*/
require(`../restoreradio.js`).execute(client, guilds);
/*RESTORE RADIOS*/
client.funcs.restoreRadios(client, guilds);
}, 5000);
}

View File

@ -0,0 +1,7 @@
module.exports = {
name: 'uncaughtException',
execute(client, error) {
console.log(error.stack);
process.emit('SIGINT');
}
}

View File

@ -2,6 +2,14 @@ module.exports = function (client, interaction, command) {
let message = {};
const radio = client.radio.get(interaction.guild.id);
const permissions = interaction.channel.permissionsFor(interaction.user);
if(!client.stations) {
message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace("%client.config.supportGuild%", client.config.supportGuild);
interaction.reply({
content: client.messageEmojis["error"] + message.errorToGetPlaylist,
ephemeral: true
});
return false;
}
if (!radio) {
interaction.reply({
content: client.messageEmojis["error"] + client.messages.notPlaying,
@ -16,14 +24,6 @@ module.exports = function (client, interaction, command) {
});
return false;
}
if(!command.permission == 'none'){
if (!permissions.has(command.permission)) {
message.noPerms = client.messages.noPerms.replace("%command.permission%", command.permission);
interaction.reply({
content: client.messageEmojis["error"] + message.noPerms,
ephemeral: true
});
return false;
} else return true;
} else return true;
return true;
};

View File

@ -0,0 +1,33 @@
import Discord from "discord.js";
module.exports = function (client, interaction){
let stations = new Array();
let options = new Array();
stations = client.stations.forEach(station => {
if(station.name == "GrooveFM") return;
station = {
label: station.name,
description: station.owner,
value: station.name
};
options.push(station);
});
const menu = new Discord.MessageActionRow()
.addComponents(
new Discord.MessageSelectMenu()
.setCustomId('play')
.setPlaceholder('Nothing selected')
.addOptions(options)
);
stations = null;
options = null;
return interaction.reply({
content: '**Select station:**',
components: [menu],
ephemeral: true
});
}

96
src/client/funcs/play.js Normal file
View File

@ -0,0 +1,96 @@
import Discord from "discord.js";
const {
createAudioResource
} = require("@discordjs/voice");
module.exports = async function play(interaction, guild, client, url) {
let message = {};
const radio = client.radio.get(guild.id);
const resource = createAudioResource(url);
radio.connection.subscribe(radio.audioPlayer);
radio.audioPlayer.play(resource);
resource.playStream
.on("readable", () => {
client.funcs.logger('Radio', 'Stream started' + " / " + guild.id + " / " + radio.station.name);
})
.on("finish", () => {
client.funcs.logger('Radio', 'Stream finished' + " / " + guild.id);
client.funcs.statisticsUpdate(client, guild, radio);
radio.connection?.destroy();
radio.audioPlayer?.stop();
client.radio.delete(guild.id);
return;
})
.on("error", error => {
client.funcs.logger('Radio', 'Stream errored');
console.error(error);
radio.connection?.destroy();
radio.audioPlayer?.stop();
client.radio.delete(guild.id);
return interaction.reply({
content: client.messages.errorPlaying,
ephemeral: true
});
});
message.nowplayingDescription = client.messages.nowplayingDescription.replace("%radio.station.name%", radio.station.name);
message.nowplayingDescription = message.nowplayingDescription.replace("%radio.station.owner%", radio.station.owner);
message.nowplayingDescription = message.nowplayingDescription.replace("%client.funcs.msToTime(completed)%", "");
message.nowplayingDescription = message.nowplayingDescription.replace("Owner: ", "");
message.nowplayingDescription = message.nowplayingDescription.replace("**", "");
message.nowplayingDescription = message.nowplayingDescription.replace("**", "");
const embed = new Discord.MessageEmbed()
.setTitle(client.user.username)
.setThumbnail((radio.station.logo || "https://cdn.discordapp.com/emojis/" + client.messageEmojis["play"].replace(/[^0-9]+/g, '')))
.setColor(client.config.embedColor)
.addField(client.messages.nowplayingTitle, message.nowplayingDescription, true)
.setImage('https://waren.io/berriabot-temp-sa7a36a9xm6837br/images/empty-3.png')
.setFooter(client.messages.footerText, "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, ''));
const buttons = new Discord.MessageActionRow()
.addComponents(
new Discord.MessageButton()
.setCustomId('list')
.setEmoji(client.messageEmojis["list"])
.setStyle('SECONDARY')
)
.addComponents(
new Discord.MessageButton()
.setCustomId('prev')
.setEmoji(client.messageEmojis["prev"])
.setStyle('SECONDARY')
)
.addComponents(
new Discord.MessageButton()
.setCustomId('stop')
.setEmoji(client.messageEmojis["stop"])
.setStyle('SECONDARY')
)
.addComponents(
new Discord.MessageButton()
.setCustomId('next')
.setEmoji(client.messageEmojis["next"])
.setStyle('SECONDARY')
)
.addComponents(
new Discord.MessageButton()
.setCustomId('statistics')
.setEmoji(client.messageEmojis["statistics"])
.setStyle('SECONDARY')
);
if(!radio.message){
radio.message = await radio.textChannel.send({ embeds: [embed], components: [buttons] });
} else {
radio.message.edit({ embeds: [embed], components: [buttons] });
}
message.play = client.messages.play.replace("%radio.station.name%", radio.station.name);
interaction?.reply({
content: client.messageEmojis["play"] + message.play,
ephemeral: true
});
}

View File

@ -0,0 +1,62 @@
import Discord from "discord.js";
const {
createAudioPlayer,
getVoiceConnection,
joinVoiceChannel
} = require("@discordjs/voice");
module.exports = async function restoreRadios(client, guilds) {
if(!client.stations) return;
guilds.forEach(async guild => {
let state = client.funcs.loadState(client, guild);
if(!state) return;
if(!state.station || !state.channels.voice || !state.channels.text) return;
let voiceChannel = client.channels.cache.get(state.channels.voice);
if(!voiceChannel) return;
if(voiceChannel.members.size === 0) return;
const sstation = await client.funcs.searchStation(state.station.name, client);
let url = sstation.stream[sstation.stream.default];
let station = sstation;
const construct = {
textChannel: client.channels.cache.get(state.channels.text),
voiceChannel: client.channels.cache.get(state.channels.voice),
connection: null,
message: null,
audioPlayer: createAudioPlayer(),
station: station
};
client.radio.set(guild.id, construct);
try {
const connection =
getVoiceConnection(guild.id) ??
joinVoiceChannel({
channelId: voiceChannel.id,
guildId: voiceChannel.guild.id,
adapterCreator: voiceChannel.guild.voiceAdapterCreator
});
construct.connection = connection;
let date = new Date();
construct.startTime = date.getTime();
client.funcs.play(null, guild, client, url, Discord);
client.datastore.checkEntry(guild.id);
construct.datastore = client.datastore.getEntry(guild.id);
if (!construct.datastore.statistics[construct.station.name]) {
construct.datastore.statistics[construct.station.name] = {};
construct.datastore.statistics[construct.station.name].time = 0;
construct.datastore.statistics[construct.station.name].used = 0;
client.datastore.updateEntry(guild, construct.datastore);
}
} catch (error) {
console.log(error);
}
});
}

View File

@ -0,0 +1,20 @@
module.exports = function saveRadios(client) {
let currentRadios = client.radio.keys();
let radio = currentRadios.next();
while (!radio.done) {
let currentRadio = client.radio.get(radio.value);
currentRadio.guild = client.datastore.getEntry(radio.value).guild;
if (currentRadio) {
client.funcs.statisticsUpdate(client, currentRadio.guild, currentRadio);
client.funcs.saveState(client, currentRadio.guild, currentRadio);
currentRadio.connection?.destroy();
currentRadio.audioPlayer?.stop();
currentRadio.message?.delete();
client.radio.delete(radio.value);
}
radio = currentRadios.next();
}
}

View File

@ -0,0 +1,62 @@
module.exports = function searchStation(key, client) {
if (client.stations === null) return false;
let foundStations = [];
if (!key) return false;
if (key == "radio") return false;
client.stations
.filter(
x => x.name.toUpperCase().includes(key.toUpperCase()) || x === key
)
.forEach(x =>
foundStations.push({ station: x, name: x.name, probability: 100 })
);
if (key.startsWith("radio ")) key = key.slice(6);
const probabilityIncrement = 100 / key.split(" ").length / 2;
for (let i = 0; i < key.split(" ").length; i++) {
client.stations
.filter(
x => x.name.toUpperCase().includes(key.split(" ")[i].toUpperCase()) || x === key
)
.forEach(x =>
foundStations.push({ station: x, name: x.name, probability: probabilityIncrement })
);
}
if (foundStations.length === 0) return false;
for (let i = 0; i < foundStations.length; i++) {
for (let j = 0; j < foundStations.length; j++) {
if (foundStations[i] === foundStations[j] && i !== j) foundStations.splice(i, 1);
}
}
for (let i = 0; i < foundStations.length; i++) {
if (foundStations[i].name.length > key.length) {
foundStations[i].probability -=
(foundStations[i].name.split(" ").length - key.split(" ").length) *
(probabilityIncrement * 0.5);
} else if (foundStations[i].name.length === key.length) {
foundStations[i].probability += probabilityIncrement * 0.9;
}
for (let j = 0; j < key.split(" ").length; j++) {
if (!foundStations[i].name.toUpperCase().includes(key.toUpperCase().split(" ")[j])) {
foundStations[i].probability -= probabilityIncrement * 0.5;
}
}
}
let highestProbabilityStation;
for (let i = 0; i < foundStations.length; i++) {
if (
!highestProbabilityStation ||
highestProbabilityStation.probability < foundStations[i].probability
)
highestProbabilityStation = foundStations[i];
if (
highestProbabilityStation &&
highestProbabilityStation.probability === foundStations[i].probability
) {
highestProbabilityStation = foundStations[i].station;
}
}
return highestProbabilityStation;
}

View File

@ -1,210 +0,0 @@
import Discord from "discord.js";
const {
createAudioPlayer,
createAudioResource,
getVoiceConnection,
joinVoiceChannel
} = require("@discordjs/voice");
module.exports = {
async execute(client, guilds) {
if(!client.stations) return;
guilds.forEach(async guild => {
let state = client.funcs.loadState(client, guild);
if(!state) return;
if(!state.station || !state.channels.voice || !state.channels.text) return;
const sstation = await searchStation(state.station.name, client);
let url = sstation.stream[sstation.stream.default];
let station = sstation;
const construct = {
textChannel: client.channels.cache.get(state.channels.text),
voiceChannel: client.channels.cache.get(state.channels.voice),
connection: null,
message: null,
audioPlayer: createAudioPlayer(),
station: station
};
client.radio.set(guild.id, construct);
try {
let voiceChannel = client.channels.cache.get(state.channels.voice);
const connection =
getVoiceConnection(guild.id) ??
joinVoiceChannel({
channelId: voiceChannel.id,
guildId: voiceChannel.guild.id,
adapterCreator: voiceChannel.guild.voiceAdapterCreator
});
construct.connection = connection;
let date = new Date();
construct.startTime = date.getTime();
play(null, guild, client, url, Discord);
client.datastore.checkEntry(guild.id);
construct.datastore = client.datastore.getEntry(guild.id);
if (!construct.datastore.statistics[construct.station.name]) {
construct.datastore.statistics[construct.station.name] = {};
construct.datastore.statistics[construct.station.name].time = 0;
construct.datastore.statistics[construct.station.name].used = 0;
client.datastore.updateEntry(guild, construct.datastore);
}
} catch (error) {
console.log(error);
}
});
}
}
async function play(interaction, guild, client, url, Discord) {
let message = {};
const radio = client.radio.get(guild.id);
const resource = createAudioResource(url);
radio.connection.subscribe(radio.audioPlayer);
radio.audioPlayer.play(resource);
resource.playStream
.on("readable", () => {
client.funcs.logger('Radio', 'Stream started' + " / " + guild.id + " / " + radio.station.name);
})
.on("finish", () => {
client.funcs.logger('Radio', 'Stream finished' + " / " + guild.id);
client.funcs.statisticsUpdate(client, guild, radio);
radio.connection?.destroy();
radio.audioPlayer?.stop();
client.radio.delete(guild.id);
return;
})
.on("error", error => {
client.funcs.logger('Radio', 'Stream errored');
console.error(error);
radio.connection?.destroy();
radio.audioPlayer?.stop();
client.radio.delete(guild.id);
});
message.nowplayingDescription = client.messages.nowplayingDescription.replace("%radio.station.name%", radio.station.name);
message.nowplayingDescription = message.nowplayingDescription.replace("%radio.station.owner%", radio.station.owner);
message.nowplayingDescription = message.nowplayingDescription.replace("%client.funcs.msToTime(completed)%", "");
message.nowplayingDescription = message.nowplayingDescription.replace("Owner: ", "");
message.nowplayingDescription = message.nowplayingDescription.replace("**", "");
message.nowplayingDescription = message.nowplayingDescription.replace("**", "");
const embed = new Discord.MessageEmbed()
.setTitle(client.user.username)
.setThumbnail((radio.station.logo || "https://cdn.discordapp.com/emojis/" + client.messageEmojis["play"].replace(/[^0-9]+/g, '')))
.setColor(client.config.embedColor)
.addField(client.messages.nowplayingTitle, message.nowplayingDescription, true)
.setImage('https://waren.io/berriabot-temp-sa7a36a9xm6837br/images/empty-3.png')
.setFooter(client.messages.footerText, "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, ''));
const buttons = new Discord.MessageActionRow()
.addComponents(
new Discord.MessageButton()
.setCustomId('list')
.setEmoji(client.messageEmojis["list"])
.setStyle('SECONDARY')
)
.addComponents(
new Discord.MessageButton()
.setCustomId('prev')
.setEmoji(client.messageEmojis["prev"])
.setStyle('SECONDARY')
.setDisabled(true)
)
.addComponents(
new Discord.MessageButton()
.setCustomId('stop')
.setEmoji(client.messageEmojis["stop"])
.setStyle('SECONDARY')
)
.addComponents(
new Discord.MessageButton()
.setCustomId('next')
.setEmoji(client.messageEmojis["next"])
.setStyle('SECONDARY')
.setDisabled(true)
)
.addComponents(
new Discord.MessageButton()
.setCustomId('statistics')
.setEmoji(client.messageEmojis["statistics"])
.setStyle('SECONDARY')
);
if(!radio.message){
radio.message = await radio.textChannel.send({ embeds: [embed], components: [buttons] });
} else {
radio.message.edit({ embeds: [embed], components: [buttons] });
}
message.play = client.messages.play.replace("%radio.station.name%", radio.station.name);
}
function searchStation(key, client) {
if (client.stations === null) return false;
let foundStations = [];
if (!key) return false;
if (key == "radio") return false;
client.stations
.filter(
x => x.name.toUpperCase().includes(key.toUpperCase()) || x === key
)
.forEach(x =>
foundStations.push({ station: x, name: x.name, probability: 100 })
);
if (key.startsWith("radio ")) key = key.slice(6);
const probabilityIncrement = 100 / key.split(" ").length / 2;
for (let i = 0; i < key.split(" ").length; i++) {
client.stations
.filter(
x => x.name.toUpperCase().includes(key.split(" ")[i].toUpperCase()) || x === key
)
.forEach(x =>
foundStations.push({ station: x, name: x.name, probability: probabilityIncrement })
);
}
if (foundStations.length === 0) return false;
for (let i = 0; i < foundStations.length; i++) {
for (let j = 0; j < foundStations.length; j++) {
if (foundStations[i] === foundStations[j] && i !== j) foundStations.splice(i, 1);
}
}
for (let i = 0; i < foundStations.length; i++) {
if (foundStations[i].name.length > key.length) {
foundStations[i].probability -=
(foundStations[i].name.split(" ").length - key.split(" ").length) *
(probabilityIncrement * 0.5);
} else if (foundStations[i].name.length === key.length) {
foundStations[i].probability += probabilityIncrement * 0.9;
}
for (let j = 0; j < key.split(" ").length; j++) {
if (!foundStations[i].name.toUpperCase().includes(key.toUpperCase().split(" ")[j])) {
foundStations[i].probability -= probabilityIncrement * 0.5;
}
}
}
let highestProbabilityStation;
for (let i = 0; i < foundStations.length; i++) {
if (
!highestProbabilityStation ||
highestProbabilityStation.probability < foundStations[i].probability
)
highestProbabilityStation = foundStations[i];
if (
highestProbabilityStation &&
highestProbabilityStation.probability === foundStations[i].probability
) {
highestProbabilityStation = foundStations[i].station;
}
}
return highestProbabilityStation;
}