Merge pull request #47 from warengroup/develop

Version 0.3.6
This commit is contained in:
Christer Warén 2021-09-06 22:39:05 +03:00 committed by GitHub
commit 8b5933749d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 254 additions and 108 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. 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 ## 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` 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 ## Join our Discord Server

44
package-lock.json generated
View File

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

View File

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

View File

@ -85,6 +85,10 @@ class RadioClient extends Client {
process.on('SIGTERM', () => { process.on('SIGTERM', () => {
require(`${events}SIGTERM`).execute(this); require(`${events}SIGTERM`).execute(this);
}); });
process.on('uncaughtException', (error) => {
require(`${events}uncaughtException`).execute(this, error);
});
this.on("error", error => { this.on("error", error => {
console.error(error); console.error(error);

View File

@ -3,7 +3,6 @@ import Discord from "discord.js";
module.exports = { module.exports = {
name: 'bug', name: 'bug',
description: 'Report a bug', description: 'Report a bug',
permission: 'none',
category: 'info', category: 'info',
async execute(interaction, client) { async execute(interaction, client) {
let message = {}; let message = {};

View File

@ -3,7 +3,6 @@ import Discord from "discord.js";
module.exports = { module.exports = {
name: 'help', name: 'help',
description: 'Get help using bot', description: 'Get help using bot',
permission: 'none',
category: 'info', category: 'info',
execute(interaction, client) { execute(interaction, client) {
let message = {}; let message = {};

View File

@ -3,7 +3,6 @@ import Discord from "discord.js";
module.exports = { module.exports = {
name: 'invite', name: 'invite',
description: 'Invite Bot', description: 'Invite Bot',
permission: 'none',
category: 'info', category: 'info',
execute(interaction, client) { execute(interaction, client) {
let message = {}; let message = {};

View File

@ -3,13 +3,15 @@ import Discord from "discord.js";
module.exports = { module.exports = {
name: 'list', name: 'list',
description: 'List radio stations', description: 'List radio stations',
permission: 'none',
category: 'radio', category: 'radio',
execute(interaction, client) { execute(interaction, client) {
let message = {}; let message = {};
if(!client.stations) { if(!client.stations) {
message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace("%client.config.supportGuild%", client.config.supportGuild); 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); const radio = client.radio.get(interaction.guild.id);

View File

@ -1,9 +1,9 @@
import Discord from "discord.js"; import Discord from "discord.js";
import fetch from "node-fetch";
module.exports = { module.exports = {
name: 'maintenance', name: 'maintenance',
description: 'Bot Maintenance', description: 'Bot Maintenance',
permission: 'none',
category: 'info', category: 'info',
options: [ options: [
{ type: "NUMBER", name: "action", description: "Select action", required: false} { type: "NUMBER", name: "action", description: "Select action", required: false}
@ -11,7 +11,10 @@ module.exports = {
async execute(interaction, client) { async execute(interaction, client) {
let message = {}; 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]; let action = interaction.options?.getNumber("action") ?? interaction.values?.[0];
const options = new Array( const options = new Array(
{ {
@ -38,6 +41,12 @@ module.exports = {
description: "", description: "",
value: "6" value: "6"
}, },
{
emoji: "<:RadioXList:688541155519889482>",
label: "Reload Stations",
description: "",
value: "7"
},
{ {
emoji: "<:dnd:746069698139127831>", emoji: "<:dnd:746069698139127831>",
label: "Enable Maintenance Mode", label: "Enable Maintenance Mode",
@ -87,17 +96,13 @@ module.exports = {
break; break;
case "4": case "4":
client.user.setStatus('idle'); client.user.setStatus('idle');
setTimeout(function () { client.funcs.saveRadios(client);
client.funcs.saveRadios(client);
}, 5000);
client.user.setStatus('online'); client.user.setStatus('online');
break; break;
case "5": case "5":
client.user.setStatus('idle'); client.user.setStatus('idle');
let guilds = await client.guilds.fetch(); let guilds = await client.guilds.fetch();
setTimeout(function () { client.funcs.restoreRadios(client, guilds);
client.funcs.restoreRadios(client, guilds);
}, 5000);
client.user.setStatus('online'); client.user.setStatus('online');
break; break;
case "6": case "6":
@ -105,6 +110,18 @@ module.exports = {
require(`../commands.js`).execute(client); require(`../commands.js`).execute(client);
client.user.setStatus('online'); client.user.setStatus('online');
break; 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": case "8":
client.user.setStatus('dnd'); client.user.setStatus('dnd');
break; break;

View File

@ -1,7 +1,6 @@
module.exports = { module.exports = {
name: 'next', name: 'next',
description: 'Next Station', description: 'Next Station',
permission: 'none',
category: 'radio', category: 'radio',
async execute(interaction, client, command) { async execute(interaction, client, command) {
if (client.funcs.check(client, interaction, command)) { if (client.funcs.check(client, interaction, command)) {
@ -17,8 +16,6 @@ module.exports = {
ephemeral: true ephemeral: true
}); });
interaction.deferUpdate();
let url = station.stream[station.stream.default]; let url = station.stream[station.stream.default];
client.funcs.statisticsUpdate(client, interaction.guild, radio); client.funcs.statisticsUpdate(client, interaction.guild, radio);
@ -28,7 +25,14 @@ module.exports = {
radio.station = station; radio.station = station;
radio.textChannel = interaction.channel; radio.textChannel = interaction.channel;
radio.startTime = date.getTime(); radio.startTime = date.getTime();
client.funcs.play(null, interaction.guild, client, url);
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

@ -3,7 +3,6 @@ import Discord from "discord.js";
module.exports = { module.exports = {
name: 'nowplaying', name: 'nowplaying',
description: 'Current Radio Station', description: 'Current Radio Station',
permission: 'none',
category: 'radio', category: 'radio',
async execute(interaction, client, command) { async execute(interaction, client, command) {
if (client.funcs.check(client, interaction, command)) { if (client.funcs.check(client, interaction, command)) {

View File

@ -11,13 +11,15 @@ module.exports = {
options: [ options: [
{ type: "STRING", name: "query", description: "Select station", required: false} { type: "STRING", name: "query", description: "Select station", required: false}
], ],
permission: "none",
category: "radio", category: "radio",
async execute(interaction, client) { async execute(interaction, client) {
let message = {}; let message = {};
if(!client.stations) { if(!client.stations) {
message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace("%client.config.supportGuild%", client.config.supportGuild); 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
});
} }
let query = interaction.options?.getString("query") ?? interaction.values?.[0]; let query = interaction.options?.getString("query") ?? interaction.values?.[0];
@ -27,26 +29,32 @@ module.exports = {
let url = query ? query.replace(/<(.+)>/g, "$1") : ""; let url = query ? query.replace(/<(.+)>/g, "$1") : "";
const radio = client.radio.get(interaction.guild.id); const radio = client.radio.get(interaction.guild.id);
const voiceChannel = interaction.member.voice.channel; const voiceChannel = interaction.member.voice.channel;
if (!radio) { if (!voiceChannel) return interaction.reply({
if (!interaction.member.voice.channel) content: client.messageEmojis["error"] + client.messages.noVoiceChannel,
return interaction.reply({ ephemeral: true
content: client.messageEmojis["error"] + client.messages.noVoiceChannel, });
ephemeral: true if (radio) {
}); if (voiceChannel !== radio.voiceChannel) return interaction.reply({
} else { content: client.messageEmojis["error"] + client.messages.wrongVoiceChannel,
if (voiceChannel !== radio.voiceChannel) ephemeral: true
return interaction.reply({ });
content: client.messageEmojis["error"] + client.messages.wrongVoiceChannel,
ephemeral: true
});
} }
if (!query) return interaction.reply(client.messages.noQuery); if (!query) return interaction.reply({
content: client.messages.noQuery,
ephemeral: true
});
const permissions = voiceChannel.permissionsFor(interaction.client.user); const permissions = voiceChannel.permissionsFor(interaction.client.user);
if (!permissions.has("CONNECT")) { 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")) { 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; let station;
const number = parseInt(query - 1); const number = parseInt(query - 1);
@ -66,17 +74,15 @@ module.exports = {
station = client.stations[number]; station = client.stations[number];
} }
} else { } else {
if (query.length < 3) if (query.length < 3) return interaction.reply({
return interaction.reply({ content: client.messageEmojis["error"] + client.messages.tooShortSearch,
content: client.messageEmojis["error"] + client.messages.tooShortSearch, ephemeral: true
ephemeral: true });
});
const sstation = await client.funcs.searchStation(query, client); const sstation = await client.funcs.searchStation(query, client);
if (!sstation) if (!sstation) return interaction.reply({
return interaction.reply({ content: client.messageEmojis["error"] + client.messages.noSearchResults,
content: client.messageEmojis["error"] + client.messages.noSearchResults, ephemeral: true
ephemeral: true });
});
url = sstation.stream[sstation.stream.default]; url = sstation.stream[sstation.stream.default];
station = sstation; station = sstation;
} }
@ -129,7 +135,10 @@ module.exports = {
} catch (error) { } catch (error) {
console.log(error); console.log(error);
client.radio.delete(interaction.guild.id); 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
});
} }
} }
}; };

View File

@ -1,7 +1,6 @@
module.exports = { module.exports = {
name: 'prev', name: 'prev',
description: 'Previous Station', description: 'Previous Station',
permission: 'none',
category: 'radio', category: 'radio',
async execute(interaction, client, command) { async execute(interaction, client, command) {
if (client.funcs.check(client, interaction, command)) { if (client.funcs.check(client, interaction, command)) {
@ -17,8 +16,6 @@ module.exports = {
ephemeral: true ephemeral: true
}); });
interaction.deferUpdate();
let url = station.stream[station.stream.default]; let url = station.stream[station.stream.default];
client.funcs.statisticsUpdate(client, interaction.guild, radio); client.funcs.statisticsUpdate(client, interaction.guild, radio);
@ -28,7 +25,14 @@ module.exports = {
radio.station = station; radio.station = station;
radio.textChannel = interaction.channel; radio.textChannel = interaction.channel;
radio.startTime = date.getTime(); radio.startTime = date.getTime();
client.funcs.play(null, interaction.guild, client, url);
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

@ -4,7 +4,6 @@ import Discord from "discord.js";
module.exports = { module.exports = {
name: 'statistics', name: 'statistics',
description: 'Show statistics', description: 'Show statistics',
permission: 'none',
category: 'info', category: 'info',
execute(interaction, client) { execute(interaction, client) {
let message = {}; let message = {};
@ -15,7 +14,10 @@ module.exports = {
if(!client.stations) { if(!client.stations) {
message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace("%client.config.supportGuild%", client.config.supportGuild); 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){ if(!currentGuild || currentGuild && !currentGuild.statistics){

View File

@ -3,7 +3,6 @@ import Discord from "discord.js";
module.exports = { module.exports = {
name: 'status', name: 'status',
description: 'Bot Status', description: 'Bot Status',
permission: 'none',
category: 'info', category: 'info',
async execute(interaction, client) { async execute(interaction, client) {
let message = {}; let message = {};

View File

@ -3,7 +3,6 @@ import Discord from "discord.js";
module.exports = { module.exports = {
name: 'stop', name: 'stop',
description: 'Stop radio', description: 'Stop radio',
permission: 'none',
category: 'radio', category: 'radio',
async execute(interaction, client, command) { async execute(interaction, client, command) {
const radio = client.radio.get(interaction.guild.id); const radio = client.radio.get(interaction.guild.id);

View File

@ -1,23 +1,18 @@
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const { token, version } = require('../../config.js');
module.exports = { module.exports = {
name: 'SIGINT', name: 'SIGINT',
async execute(client) { execute(client) {
client.user.setStatus('dnd'); client.user.setStatus('dnd');
console.log("\n"); console.log("\n");
client.funcs.logger("Bot", "Closing"); client.funcs.logger("Bot", "Closing");
console.log("\n"); console.log("\n");
client.funcs.saveRadios(client);
setTimeout(async function () { setInterval(() => {
let message = {}; if(client.radio.size == 0){
process.exit();
if (!client.stations) return process.exit(); }
}, 500);
await client.funcs.saveRadios(client);
await process.exit();
}, 5000);
} }
} }

View File

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

View File

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

View File

@ -24,14 +24,6 @@ module.exports = function (client, interaction, command) {
}); });
return false; return false;
} }
if(!command.permission == 'none'){
if (!permissions.has(command.permission)) { return true;
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;
}; };

View File

@ -27,7 +27,10 @@ module.exports = async function play(interaction, guild, client, url) {
radio.connection?.destroy(); radio.connection?.destroy();
radio.audioPlayer?.stop(); radio.audioPlayer?.stop();
client.radio.delete(guild.id); client.radio.delete(guild.id);
return interaction.reply(client.messages.errorPlaying); return interaction.reply({
content: client.messages.errorPlaying,
ephemeral: true
});
}); });
message.nowplayingDescription = client.messages.nowplayingDescription.replace("%radio.station.name%", radio.station.name); message.nowplayingDescription = client.messages.nowplayingDescription.replace("%radio.station.name%", radio.station.name);

View File

@ -1,4 +1,4 @@
module.exports = async function saveRadios(client) { module.exports = function saveRadios(client) {
let currentRadios = client.radio.keys(); let currentRadios = client.radio.keys();
let radio = currentRadios.next(); let radio = currentRadios.next();
@ -7,8 +7,8 @@ module.exports = async function saveRadios(client) {
currentRadio.guild = client.datastore.getEntry(radio.value).guild; currentRadio.guild = client.datastore.getEntry(radio.value).guild;
if (currentRadio) { if (currentRadio) {
await client.funcs.statisticsUpdate(client, currentRadio.guild, currentRadio); client.funcs.statisticsUpdate(client, currentRadio.guild, currentRadio);
await client.funcs.saveState(client, currentRadio.guild, currentRadio); client.funcs.saveState(client, currentRadio.guild, currentRadio);
currentRadio.connection?.destroy(); currentRadio.connection?.destroy();
currentRadio.audioPlayer?.stop(); currentRadio.audioPlayer?.stop();
currentRadio.message?.delete(); currentRadio.message?.delete();