mirror of
https://github.com/warengroup/eximiabots-radiox.git
synced 2025-07-01 15:03:37 +00:00
Compare commits
248 Commits
Author | SHA1 | Date | |
---|---|---|---|
1d8ddc6084 | |||
1fcbe8dc98 | |||
145e23cc91 | |||
7f791e0075 | |||
e229b91812 | |||
8d66dcb4ae | |||
21743b8383 | |||
d7587f4d71 | |||
eb131a405f | |||
2891ceee0d | |||
3c49d3ccec | |||
88a171d4e5 | |||
a289da13e0 | |||
8f0d73ba29 | |||
0adffbd240 | |||
90600b12f8 | |||
5181a2a419 | |||
c1ee0f4bc6 | |||
4bc4ac65db | |||
b7ae0db444 | |||
ab9b5fc32f | |||
d04610ba48 | |||
26a220b366 | |||
09991a0080 | |||
d67fa68445 | |||
93a4f3e0c4 | |||
3d29a7c2ff | |||
92b262bbd7 | |||
5dfb79e2d7 | |||
524107bc94 | |||
0479e21015 | |||
bf1b2a9d31 | |||
2e077f639b | |||
16f91fa3f1 | |||
db32310b44 | |||
10b94e1d62 | |||
8476c7d484 | |||
8b7747a914 | |||
32ed9edce5 | |||
74298deaf4 | |||
1a36e7481b | |||
5e6c3f0cec | |||
8e7ceac8c2 | |||
c5be6ef112 | |||
45d37c1f39 | |||
8842e8e684 | |||
0da7568f50 | |||
dc9caba870 | |||
d0939c8a95 | |||
d585b1c619 | |||
62096ea2d5 | |||
c1dd67c4a9 | |||
2e82e13e12 | |||
86befc7c59 | |||
688bfb5b0a | |||
7fc1aafb64 | |||
c30e1892f6 | |||
20a2b3829e | |||
ea54541f6a | |||
419f5639bf | |||
b6b96fb7a6 | |||
13fedb1e28 | |||
7b816ce538 | |||
5c8f31dbc0 | |||
9b512a3d27 | |||
eadba47c2c | |||
1c2aae3ea3 | |||
5eb79a77f5 | |||
725ac8a9fc | |||
87e3a58e36 | |||
0cf66571ae | |||
5513ace425 | |||
8ff2013333 | |||
d683e7e0df | |||
dd8551dacc | |||
aa623d6b13 | |||
5708349f67 | |||
14bbd9de7c | |||
5b98a70ce2 | |||
b174cf1456 | |||
8031737e2f | |||
42fa7fed57 | |||
5d3b0e48e4 | |||
9a775b3fe9 | |||
d5316cde06 | |||
39d3b4df42 | |||
66a0e0c80d | |||
2746ecc588 | |||
7c64d0069d | |||
1005a37c48 | |||
58b99daa48 | |||
e04b73ea94 | |||
8359737828 | |||
706b5c0841 | |||
aefc7b2334 | |||
7133fada59 | |||
12289f2493 | |||
a1d5038ab0 | |||
b65388cb68 | |||
8f9220231a | |||
caab59e5f0 | |||
9de0ce42df | |||
fe9cd0d5f4 | |||
cd9dccd766 | |||
ac750996b9 | |||
6854faa66b | |||
d8b1c99132 | |||
3e023f17eb | |||
437a6e9892 | |||
348ee5d7b8 | |||
2b58c25027 | |||
23aa8de334 | |||
1a7af434fa | |||
f16ee0a357 | |||
4255802027 | |||
8680a90f8e | |||
098f874757 | |||
1ad9e93d8f | |||
91b1098c58 | |||
3873e6e8c1 | |||
5945ab95ae | |||
b1e9ebd291 | |||
545bacf25b | |||
2859f8af51 | |||
3541cd1870 | |||
1160895f9e | |||
3db736d3f3 | |||
22bb8c7467 | |||
12db2c5fcc | |||
51a038096a | |||
53fda7c401 | |||
a7f3029be0 | |||
9f373368b3 | |||
0945c7c26c | |||
871cb475f9 | |||
57aaf92947 | |||
dc7b14b11a | |||
0f5022df15 | |||
8f256d9bc3 | |||
b686afba98 | |||
f08eeb435c | |||
7a8c10c6d4 | |||
b38dfa039d | |||
b07f0d4942 | |||
788216c373 | |||
ead52decf2 | |||
7757788f99 | |||
ddff397fe4 | |||
8fc441c1b3 | |||
0ee3ca5e08 | |||
214dff29d5 | |||
cc3b2a50cf | |||
ee08232128 | |||
f9d5be189e | |||
a8513ce514 | |||
9ecdbc2bee | |||
5ee30b1782 | |||
4bf74f15a2 | |||
ccb386e3b3 | |||
dbedb83104 | |||
b34120e688 | |||
90c7c667e4 | |||
062a163a11 | |||
1f4c3a08d0 | |||
acc7ab1727 | |||
c7ddc6ec5b | |||
6d22dda0ae | |||
bfba8304e4 | |||
7d38170ba6 | |||
348b540c06 | |||
330c33b3d7 | |||
dfa9548b59 | |||
b351bbebed | |||
469374f25e | |||
72c1609503 | |||
8d5291cbb0 | |||
ebf1d0759e | |||
c829f70418 | |||
341bddd4cd | |||
460a5415e5 | |||
a4d984f19c | |||
09ae458ff1 | |||
00f6ee71e0 | |||
126d5e9ba2 | |||
d64b0ac0cb | |||
bfb27e7359 | |||
48445afdd5 | |||
4854e622b3 | |||
9d9c8a6a07 | |||
7040300b3e | |||
24478b6320 | |||
a43a788e15 | |||
2892913caa | |||
930d481fcf | |||
81a9d7be7c | |||
45e5019b28 | |||
b76b7a107c | |||
87295d10c1 | |||
d03b8cdb1d | |||
fd8c1ec31b | |||
720d356d1f | |||
4b0efe7491 | |||
a20e7a1c8e | |||
88fdad4ab9 | |||
3ed49f88ab | |||
752bd07c5d | |||
b08de94c64 | |||
892c5f9902 | |||
3029a8a653 | |||
86510a8871 | |||
e85b864170 | |||
727f8f5177 | |||
ad9a2f8f19 | |||
803bc20fb7 | |||
7d479b4c5f | |||
ffa9c8abb0 | |||
49475212a7 | |||
824d4042c1 | |||
0c76c137b9 | |||
accff3fa60 | |||
1cfa62802f | |||
9019741146 | |||
095b6ad775 | |||
a043cde46e | |||
bfec178de7 | |||
12f3948e40 | |||
0bc26f8895 | |||
b66a60ebe9 | |||
b4a24de8cd | |||
9517ba1fa9 | |||
73d330d1e2 | |||
13ae6c2716 | |||
645ea3e197 | |||
fcf6f15be9 | |||
3d066435b4 | |||
26eda76b23 | |||
05905e6e6d | |||
1533ae46a4 | |||
2b72f87256 | |||
8bf79c2744 | |||
45923319a6 | |||
d8daacf80e | |||
24eaf3a7e2 | |||
57f63c3838 | |||
b9e1945719 | |||
0b8fb4977c | |||
a5eec44b8e | |||
e2ebe6a36e |
@ -1,2 +1,5 @@
|
|||||||
DISCORD_TOKEN=
|
DISCORD_TOKEN=
|
||||||
RADIOX_STATIONSLISTURL=https://gitea.cwinfo.org/cwchristerw/radio/raw/branch/master/playlist.json
|
RADIOX_STATIONSLISTURL=https://git.cwinfo.net/cwchristerw/radio/raw/branch/master/playlist.json
|
||||||
|
DEV_MODE=false
|
||||||
|
DEBUG_MODE=false
|
||||||
|
STREAMER_MODE=manual
|
||||||
|
2
.github/workflows/typescript-build.yml
vendored
2
.github/workflows/typescript-build.yml
vendored
@ -10,7 +10,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v1
|
||||||
- name: install node v16
|
- name: install node v16
|
||||||
uses: actions/setup-node@v2.4.0
|
uses: actions/setup-node@v2.4.1
|
||||||
with:
|
with:
|
||||||
node-version: 16
|
node-version: 16
|
||||||
- name: npm install
|
- name: npm install
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
# RadioX by EximiaBots
|
# RadioX by EximiaBots
|
||||||
Internet Radio to your Discord guild
|
Internet Radio to your Discord guild
|
||||||
|
|
||||||
## [Radio Stations List](https://gitea.cwinfo.org/cwchristerw/radio)
|
## [Radio Stations List](https://git.cwinfo.net/cwchristerw/radio)
|
||||||
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://git.cwinfo.net/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 . --pull`
|
1. `docker build -t warengroup/eximiabots-radiox . --pull`
|
||||||
|
2463
package-lock.json
generated
2463
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
34
package.json
34
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "eximiabots-radiox",
|
"name": "eximiabots-radiox",
|
||||||
"version": "0.3.8",
|
"version": "0.3.12",
|
||||||
"description": "Internet Radio to your Discord guild",
|
"description": "Internet Radio to your Discord guild",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@ -18,34 +18,34 @@
|
|||||||
"url": "https://github.com/warengroup/eximiabots-radiox/issues"
|
"url": "https://github.com/warengroup/eximiabots-radiox/issues"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@discordjs/builders": "^0.6.0",
|
"@discordjs/builders": "^0.8.2",
|
||||||
"@discordjs/opus": "^0.6.0",
|
"@discordjs/opus": "^0.7.0",
|
||||||
"@discordjs/rest": "^0.1.1-canary.0",
|
"@discordjs/rest": "^0.1.1-canary.0",
|
||||||
"@discordjs/voice": "^0.6.0",
|
"@discordjs/voice": "^0.7.5",
|
||||||
"discord-api-types": "^0.23.1",
|
"discord-api-types": "^0.24.0",
|
||||||
"discord.js": "^13.1.0",
|
"discord.js": "^13.2.0",
|
||||||
"dotenv": "^10.0.0",
|
"dotenv": "^10.0.0",
|
||||||
"libsodium-wrappers": "^0.7.9",
|
"libsodium-wrappers": "^0.7.9",
|
||||||
"node-fetch": "^3.0.0",
|
"node-fetch": "^3.1.0",
|
||||||
"path": "^0.12.7"
|
"path": "^0.12.7"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^16.9.0",
|
"@types/node": "^16.11.10",
|
||||||
"@types/ws": "^7.4.7",
|
"@types/ws": "^8.2.0",
|
||||||
"@typescript-eslint/eslint-plugin": "^4.31.0",
|
"@typescript-eslint/eslint-plugin": "^5.4.0",
|
||||||
"@typescript-eslint/parser": "^4.31.0",
|
"@typescript-eslint/parser": "^5.4.0",
|
||||||
"eslint": "^7.32.0",
|
"eslint": "^8.3.0",
|
||||||
"eslint-config-prettier": "^8.3.0",
|
"eslint-config-prettier": "^8.3.0",
|
||||||
"eslint-plugin-prettier": "^4.0.0",
|
"eslint-plugin-prettier": "^4.0.0",
|
||||||
"nodemon": "^2.0.12",
|
"nodemon": "^2.0.15",
|
||||||
"prettier": "^2.3.2",
|
"prettier": "^2.5.0",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"ts-node": "^10.2.1",
|
"ts-node": "^10.4.0",
|
||||||
"tsc-watch": "^4.5.0",
|
"tsc-watch": "^4.5.0",
|
||||||
"typescript": "^4.4.2"
|
"typescript": "^4.5.2"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16.8.0",
|
"node": ">=16.9.1",
|
||||||
"npm": ">=7.0.0"
|
"npm": ">=7.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
import Discord, { Client, Collection } from "discord.js";
|
import Discord, { Client, Collection } from "discord.js";
|
||||||
|
import Datastore from "./client/classes/Datastore.js";
|
||||||
|
import Radio from "./client/classes/Radio.js";
|
||||||
|
import Stations from "./client/classes/Stations.js";
|
||||||
|
import Streamer from "./client/classes/Streamer.js";
|
||||||
|
import Statistics from "./client/classes/Statistics.js";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import Datastore from "./client/datastore.js";
|
|
||||||
import { command, radio } from "./client/utils/typings.js";
|
import { command, radio } from "./client/utils/typings.js";
|
||||||
import config from "./config.js";
|
import config from "./config.js";
|
||||||
import messages from "./client/messages.js";
|
import messages from "./client/messages.js";
|
||||||
@ -17,33 +21,34 @@ GatewayIntents.add(
|
|||||||
|
|
||||||
class RadioClient extends Client {
|
class RadioClient extends Client {
|
||||||
readonly commands: Collection<string, command>;
|
readonly commands: Collection<string, command>;
|
||||||
readonly radio: Map<string, radio>;
|
|
||||||
public funcs: any;
|
public funcs: any;
|
||||||
readonly config = config;
|
readonly config = config;
|
||||||
readonly messages = messages;
|
readonly messages = messages;
|
||||||
public datastore: Datastore | null;
|
public datastore: Datastore | null;
|
||||||
|
public stations: Stations | null;
|
||||||
|
public streamer: Streamer | null;
|
||||||
|
public statistics: Statistics | null;
|
||||||
|
public radio: Radio | null;
|
||||||
constructor() {
|
constructor() {
|
||||||
super({
|
super({
|
||||||
intents: GatewayIntents
|
intents: GatewayIntents
|
||||||
});
|
});
|
||||||
this.commands = new Collection();
|
this.commands = new Collection();
|
||||||
this.radio = new Map();
|
|
||||||
this.datastore = null;
|
this.datastore = null;
|
||||||
|
this.stations = null;
|
||||||
|
this.streamer = null;
|
||||||
|
this.statistics = null;
|
||||||
|
this.radio = null;
|
||||||
|
|
||||||
this.funcs = {};
|
this.funcs = {};
|
||||||
this.funcs.check = require("./client/funcs/check.js");
|
this.funcs.check = require("./client/funcs/check.js");
|
||||||
this.funcs.checkFetchStatus = require("./client/funcs/checkFetchStatus.js");
|
|
||||||
this.funcs.isDev = require("./client/funcs/isDev.js");
|
this.funcs.isDev = require("./client/funcs/isDev.js");
|
||||||
this.funcs.logger = require("./client/funcs/logger.js");
|
this.funcs.logger = require("./client/funcs/logger.js");
|
||||||
this.funcs.msToTime = require("./client/funcs/msToTime.js");
|
this.funcs.msToTime = require("./client/funcs/msToTime.js");
|
||||||
this.funcs.statisticsUpdate = require("./client/funcs/statisticsUpdate.js");
|
|
||||||
this.funcs.saveState = require("./client/funcs/saveState.js");
|
this.funcs.saveState = require("./client/funcs/saveState.js");
|
||||||
this.funcs.loadState = require("./client/funcs/loadState.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.play = require("./client/funcs/play.js");
|
||||||
this.funcs.listStations = require("./client/funcs/listStations.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('RadioX ' + this.config.version);
|
||||||
console.log('Internet Radio to your Discord guild');
|
console.log('Internet Radio to your Discord guild');
|
||||||
@ -53,13 +58,7 @@ class RadioClient extends Client {
|
|||||||
this.funcs.logger("Bot", "Starting");
|
this.funcs.logger("Bot", "Starting");
|
||||||
|
|
||||||
this.funcs.logger("Maintenance Mode", "Enabled");
|
this.funcs.logger("Maintenance Mode", "Enabled");
|
||||||
this.config.maintenance = true;
|
this.config.maintenanceMode = true;
|
||||||
|
|
||||||
const commandFiles = fs.readdirSync(path.join("./src/client/commands")).filter(f => f.endsWith(".js"));
|
|
||||||
for (const file of commandFiles) {
|
|
||||||
const command = require(`./client/commands/${file}`);
|
|
||||||
this.commands.set(command.name, command);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.on("ready", () => {
|
this.on("ready", () => {
|
||||||
require(`${events}ready`).execute(this);
|
require(`${events}ready`).execute(this);
|
||||||
|
@ -8,15 +8,15 @@ module.exports = class {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadData() {
|
loadData() {
|
||||||
const dir = path.join(path.dirname(__dirname), '../datastore');
|
const dir = path.join(path.dirname(__dirname), '../../datastore');
|
||||||
if (!fs.existsSync(dir)) {
|
if (!fs.existsSync(dir)) {
|
||||||
fs.mkdirSync(dir);
|
fs.mkdirSync(dir);
|
||||||
}
|
}
|
||||||
//console.log("");
|
//console.log("");
|
||||||
const dataFiles = fs.readdirSync(path.join(path.dirname(__dirname), '../datastore')).filter(f => f.endsWith('.json'));
|
const dataFiles = fs.readdirSync(path.join(path.dirname(__dirname), '../../datastore')).filter(f => f.endsWith('.json'));
|
||||||
for (const file of dataFiles) {
|
for (const file of dataFiles) {
|
||||||
try {
|
try {
|
||||||
const json = require(`../../datastore/${file}`);
|
const json = require(`../../../datastore/${file}`);
|
||||||
this.map.set(json.guild.id, json);
|
this.map.set(json.guild.id, json);
|
||||||
//console.log('[LOADED] ' + file + " (" + json.guild.id + ")");
|
//console.log('[LOADED] ' + file + " (" + json.guild.id + ")");
|
||||||
//console.log(JSON.stringify(json, null, 4));
|
//console.log(JSON.stringify(json, null, 4));
|
||||||
@ -27,46 +27,8 @@ module.exports = class {
|
|||||||
//console.log("");
|
//console.log("");
|
||||||
}
|
}
|
||||||
|
|
||||||
calculateGlobal(client){
|
|
||||||
let guilds = this.map.keys();
|
|
||||||
let stations = client.stations;
|
|
||||||
var statistics = {};
|
|
||||||
|
|
||||||
if(!client.stations) return;
|
|
||||||
|
|
||||||
let calculation = guilds.next();
|
|
||||||
|
|
||||||
while (!calculation.done) {
|
|
||||||
let currentGuild = this.getEntry(calculation.value);
|
|
||||||
if(calculation.value != 'global'){
|
|
||||||
if(stations){
|
|
||||||
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){
|
|
||||||
if(!statistics[stations[station].name]){
|
|
||||||
statistics[stations[station].name] = {};
|
|
||||||
statistics[stations[station].name].time = 0;
|
|
||||||
statistics[stations[station].name].used = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
statistics[stations[station].name].time = parseInt(statistics[stations[station].name].time)+parseInt(currentGuild.statistics[stations[station].name].time);
|
|
||||||
statistics[stations[station].name].used = parseInt(statistics[stations[station].name].used)+parseInt(currentGuild.statistics[stations[station].name].used);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
calculation = guilds.next();
|
|
||||||
}
|
|
||||||
|
|
||||||
let newData = {};
|
|
||||||
newData.guild = {};
|
|
||||||
newData.guild.id = "global";
|
|
||||||
newData.guild.name = "global";
|
|
||||||
newData.statistics = statistics;
|
|
||||||
this.updateEntry(newData.guild, newData);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
checkEntry(id){
|
checkEntry(id){
|
||||||
|
this.loadEntry(id);
|
||||||
if(!this.map.has(id)){
|
if(!this.map.has(id)){
|
||||||
this.createEntry(id);
|
this.createEntry(id);
|
||||||
//this.showEntry(this.getEntry(id));
|
//this.showEntry(this.getEntry(id));
|
||||||
@ -85,6 +47,14 @@ module.exports = class {
|
|||||||
this.saveEntry(id, newData);
|
this.saveEntry(id, newData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loadEntry(id){
|
||||||
|
try {
|
||||||
|
const json = require(`../../../datastore/` + id + '.json');
|
||||||
|
this.map.set(id, json);
|
||||||
|
} catch (error) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
getEntry(id){
|
getEntry(id){
|
||||||
return this.map.get(id);
|
return this.map.get(id);
|
||||||
}
|
}
|
||||||
@ -127,7 +97,7 @@ module.exports = class {
|
|||||||
saveEntry(file, data) {
|
saveEntry(file, data) {
|
||||||
data = JSON.stringify(data, null, 4);
|
data = JSON.stringify(data, null, 4);
|
||||||
|
|
||||||
fs.writeFile(path.join(path.dirname(__dirname), '../datastore') + "/" + file + ".json", data, 'utf8', function(err) {
|
fs.writeFile(path.join(path.dirname(__dirname), '../../datastore') + "/" + file + ".json", data, 'utf8', function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
//console.log(err);
|
//console.log(err);
|
||||||
}
|
}
|
78
src/client/classes/Radio.js
Normal file
78
src/client/classes/Radio.js
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
const {
|
||||||
|
getVoiceConnection,
|
||||||
|
joinVoiceChannel
|
||||||
|
} = require("@discordjs/voice");
|
||||||
|
|
||||||
|
module.exports = class Radio extends Map {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
save(client) {
|
||||||
|
let currentRadios = this.keys();
|
||||||
|
let radio = currentRadios.next();
|
||||||
|
|
||||||
|
while (!radio.done) {
|
||||||
|
let currentRadio = this.get(radio.value);
|
||||||
|
|
||||||
|
if (currentRadio) {
|
||||||
|
currentRadio.guild = client.datastore.getEntry(radio.value).guild;
|
||||||
|
|
||||||
|
client.statistics.update(client, currentRadio.guild, currentRadio);
|
||||||
|
client.funcs.saveState(client, currentRadio.guild, currentRadio);
|
||||||
|
currentRadio.connection?.destroy();
|
||||||
|
currentRadio.message?.delete();
|
||||||
|
this.delete(radio.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
radio = currentRadios.next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
restore(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.filter(member => !member.user.bot).size === 0) return;
|
||||||
|
|
||||||
|
|
||||||
|
const sstation = await client.stations.search(state.station.name, "direct");
|
||||||
|
let station = sstation;
|
||||||
|
|
||||||
|
if(!station) return;
|
||||||
|
|
||||||
|
const construct = {
|
||||||
|
textChannel: client.channels.cache.get(state.channels.text),
|
||||||
|
voiceChannel: client.channels.cache.get(state.channels.voice),
|
||||||
|
connection: null,
|
||||||
|
message: null,
|
||||||
|
station: station
|
||||||
|
};
|
||||||
|
this.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.datastore.checkEntry(guild.id);
|
||||||
|
client.funcs.play(client, null, guild, station);
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
138
src/client/classes/Stations.js
Normal file
138
src/client/classes/Stations.js
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
const _importDynamic = new Function('modulePath', 'return import(modulePath)');
|
||||||
|
const fetch = (...args) => _importDynamic('node-fetch').then(({default: fetch}) => fetch(...args));
|
||||||
|
|
||||||
|
module.exports = class Stations extends Array {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
this.logger = require("../funcs/logger.js");
|
||||||
|
}
|
||||||
|
|
||||||
|
async fetch(options){
|
||||||
|
try {
|
||||||
|
this.logger('Stations', 'Started fetching list – ' + options.url);
|
||||||
|
let list = await fetch(options.url)
|
||||||
|
.then(this.checkFetchStatus)
|
||||||
|
.then(response => response.json());
|
||||||
|
|
||||||
|
if(list){
|
||||||
|
this.length = 0;
|
||||||
|
list.forEach(station => {
|
||||||
|
try {
|
||||||
|
this.push(station);
|
||||||
|
} catch (error) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if(options.show){
|
||||||
|
this.logger('Stations');
|
||||||
|
list.forEach(station => {
|
||||||
|
console.log("- " + station.name);
|
||||||
|
});
|
||||||
|
console.log("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
list.forEach(async station => {
|
||||||
|
try {
|
||||||
|
let stationTest = await fetch(station.stream[station.stream.default]);
|
||||||
|
if(stationTest.ok === true) return;
|
||||||
|
this.splice(this.indexOf(station),1);
|
||||||
|
} catch (error) {
|
||||||
|
this.splice(this.indexOf(station),1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger('Stations', 'Successfully fetched list');
|
||||||
|
} catch (error) {
|
||||||
|
this.logger('Stations', 'Fetching list failed');
|
||||||
|
console.error(error + "\n");
|
||||||
|
|
||||||
|
if(this.length == 0) this.fetch(options);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
checkFetchStatus(response) {
|
||||||
|
if (response.ok) { // res.status >= 200 && res.status < 300
|
||||||
|
return response;
|
||||||
|
} else {
|
||||||
|
throw new Error(response.status + " " + response.statusText);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
search(key, type) {
|
||||||
|
if (this === null) return false;
|
||||||
|
if (!key) return false;
|
||||||
|
if (!type) return false;
|
||||||
|
|
||||||
|
if(type == "direct"){
|
||||||
|
let foundStation;
|
||||||
|
this.forEach(station => {
|
||||||
|
if(station.name != key) return false;
|
||||||
|
foundStation = station;
|
||||||
|
});
|
||||||
|
|
||||||
|
return foundStation;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
let foundStations = [];
|
||||||
|
if (key == "radio") return false;
|
||||||
|
|
||||||
|
this
|
||||||
|
.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++) {
|
||||||
|
this
|
||||||
|
.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
70
src/client/classes/Statistics.js
Normal file
70
src/client/classes/Statistics.js
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
module.exports = class {
|
||||||
|
constructor() {
|
||||||
|
this.map = new Map();
|
||||||
|
}
|
||||||
|
|
||||||
|
update(client, guild, radio) {
|
||||||
|
|
||||||
|
client.datastore.checkEntry(guild.id);
|
||||||
|
|
||||||
|
radio.datastore = client.datastore.getEntry(guild.id);
|
||||||
|
|
||||||
|
if(!radio.datastore.statistics[radio.station.name]){
|
||||||
|
radio.datastore.statistics[radio.station.name] = {};
|
||||||
|
radio.datastore.statistics[radio.station.name].time = 0;
|
||||||
|
radio.datastore.statistics[radio.station.name].used = 0;
|
||||||
|
client.datastore.updateEntry(guild, radio.datastore);
|
||||||
|
}
|
||||||
|
|
||||||
|
let date = new Date();
|
||||||
|
radio.currentTime = date.getTime();
|
||||||
|
radio.playTime = parseInt(radio.currentTime)-parseInt(radio.startTime);
|
||||||
|
radio.datastore.statistics[radio.station.name].time = parseInt(radio.datastore.statistics[radio.station.name].time)+parseInt(radio.playTime);
|
||||||
|
|
||||||
|
radio.datastore.statistics[radio.station.name].used = parseInt(radio.datastore.statistics[radio.station.name].used)+1;
|
||||||
|
client.datastore.updateEntry(guild, radio.datastore);
|
||||||
|
this.calculateGlobal(client);
|
||||||
|
}
|
||||||
|
|
||||||
|
calculateGlobal(client){
|
||||||
|
if(!client.stations) return;
|
||||||
|
if(!client.datastore.map) return;
|
||||||
|
|
||||||
|
let guilds = client.datastore.map.keys();
|
||||||
|
let stations = client.stations;
|
||||||
|
let statistics = {};
|
||||||
|
|
||||||
|
if(!client.stations) return;
|
||||||
|
|
||||||
|
let calculation = guilds.next();
|
||||||
|
|
||||||
|
while (!calculation.done) {
|
||||||
|
let currentGuild = client.datastore.getEntry(calculation.value);
|
||||||
|
if(calculation.value != 'global'){
|
||||||
|
if(stations){
|
||||||
|
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){
|
||||||
|
if(!statistics[stations[station].name]){
|
||||||
|
statistics[stations[station].name] = {};
|
||||||
|
statistics[stations[station].name].time = 0;
|
||||||
|
statistics[stations[station].name].used = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
statistics[stations[station].name].time = parseInt(statistics[stations[station].name].time)+parseInt(currentGuild.statistics[stations[station].name].time);
|
||||||
|
statistics[stations[station].name].used = parseInt(statistics[stations[station].name].used)+parseInt(currentGuild.statistics[stations[station].name].used);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
calculation = guilds.next();
|
||||||
|
}
|
||||||
|
|
||||||
|
let newData = {};
|
||||||
|
newData.guild = {};
|
||||||
|
newData.guild.id = "global";
|
||||||
|
newData.guild.name = "global";
|
||||||
|
newData.statistics = statistics;
|
||||||
|
client.datastore.updateEntry(newData.guild, newData);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
133
src/client/classes/Streamer.js
Normal file
133
src/client/classes/Streamer.js
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
const {
|
||||||
|
createAudioPlayer,
|
||||||
|
createAudioResource,
|
||||||
|
AudioPlayerStatus,
|
||||||
|
NoSubscriberBehavior
|
||||||
|
} = require("@discordjs/voice");
|
||||||
|
|
||||||
|
module.exports = class {
|
||||||
|
constructor() {
|
||||||
|
this.map = new Map();
|
||||||
|
this.mode = null;
|
||||||
|
this.logger = require("../funcs/logger.js");
|
||||||
|
}
|
||||||
|
|
||||||
|
init(client){
|
||||||
|
if(!client.config.streamerMode) return;
|
||||||
|
|
||||||
|
switch(client.config.streamerMode){
|
||||||
|
case "manual":
|
||||||
|
this.mode = "manual";
|
||||||
|
break;
|
||||||
|
case "auto":
|
||||||
|
this.mode = "auto";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
this.mode = "manual";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(this.mode == "auto"){
|
||||||
|
if(!client.stations) return;
|
||||||
|
|
||||||
|
client.stations.forEach(station => {
|
||||||
|
this.play(station);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
refresh(client){
|
||||||
|
this.init(client);
|
||||||
|
|
||||||
|
let streamers = this.map.keys();
|
||||||
|
streamers.forEach(streamer => {
|
||||||
|
if(client.stations.findIndex(station => station.name == streamer) == -1){
|
||||||
|
this.stop(streamer);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
play(station) {
|
||||||
|
let audioPlayer = this.map.get(station.name);
|
||||||
|
if(!audioPlayer) {
|
||||||
|
if(this.mode == "auto"){
|
||||||
|
audioPlayer = createAudioPlayer({
|
||||||
|
behaviors: {
|
||||||
|
noSubscriber: NoSubscriberBehavior.Play,
|
||||||
|
maxMissedFrames: Math.round(5000 / 20),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if(this.mode == "manual"){
|
||||||
|
audioPlayer = createAudioPlayer({
|
||||||
|
behaviors: {
|
||||||
|
noSubscriber: NoSubscriberBehavior.Stop,
|
||||||
|
maxMissedFrames: Math.round(5000 / 20),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
this.map.set(station.name, audioPlayer);
|
||||||
|
}
|
||||||
|
const url = station.stream[station.stream.default];
|
||||||
|
const resource = createAudioResource(url);
|
||||||
|
audioPlayer.play(resource);
|
||||||
|
resource.playStream
|
||||||
|
.on("readable", () => {
|
||||||
|
this.logger('Streamer', station.name + " / " + "Readable");
|
||||||
|
})
|
||||||
|
.on("finish", () => {
|
||||||
|
this.logger('Streamer', station.name + " / " + "Finished");
|
||||||
|
})
|
||||||
|
.on("error", error => {
|
||||||
|
this.logger('Streamer', station.name + " / " + "Error" + "\n" + error);
|
||||||
|
});
|
||||||
|
|
||||||
|
audioPlayer
|
||||||
|
.on('playing', () => {
|
||||||
|
this.logger('Streamer', station.name + " / " + "Playing");
|
||||||
|
})
|
||||||
|
.on('idle', () => {
|
||||||
|
this.logger('Streamer', station.name + " / " + "Idle");
|
||||||
|
audioPlayer.removeAllListeners();
|
||||||
|
this.play(station);
|
||||||
|
})
|
||||||
|
.on('paused', () => {
|
||||||
|
this.logger('Streamer', station.name + " / " + "Paused");
|
||||||
|
})
|
||||||
|
.on('buffering', () => {
|
||||||
|
this.logger('Streamer', station.name + " / " + "Buffering");
|
||||||
|
})
|
||||||
|
.on('autopaused', () => {
|
||||||
|
this.logger('Streamer', station.name + " / " + "AutoPaused");
|
||||||
|
})
|
||||||
|
.on('error', error => {
|
||||||
|
this.logger('Streamer', station.name + " / " + "Error" + "\n" + error);
|
||||||
|
});
|
||||||
|
return audioPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
stop(station){
|
||||||
|
let audioPlayer = this.map.get(station.name);
|
||||||
|
if(audioPlayer){
|
||||||
|
this.logger('Streamer', station.name + " / " + "Stop");
|
||||||
|
audioPlayer.removeAllListeners();
|
||||||
|
audioPlayer.stop();
|
||||||
|
}
|
||||||
|
this.map.delete(station.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
listen(station) {
|
||||||
|
let audioPlayer = this.map.get(station.name);
|
||||||
|
if(!audioPlayer){
|
||||||
|
audioPlayer = this.play(station);
|
||||||
|
}
|
||||||
|
return audioPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
leave(client) {
|
||||||
|
if(!client.stations) return;
|
||||||
|
|
||||||
|
client.stations.forEach(station => {
|
||||||
|
this.stop(station);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
@ -1,17 +1,19 @@
|
|||||||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||||
const { REST } = require('@discordjs/rest');
|
const { REST } = require('@discordjs/rest');
|
||||||
const { Routes } = require('discord-api-types/v9');
|
const { Routes } = require('discord-api-types/v9');
|
||||||
const { token, version } = require('../config.js');
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require ('path');
|
const path = require ('path');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
async execute(client) {
|
async execute(client) {
|
||||||
|
|
||||||
const commands = [];
|
const commands = [];
|
||||||
const commandFiles = fs.readdirSync(path.join("./src/client/commands")).filter(f => f.endsWith(".js"));
|
const commandFiles = fs.readdirSync(path.join("./src/client/commands")).filter(f => f.endsWith(".js"));
|
||||||
|
|
||||||
for (const file of commandFiles) {
|
for (const file of commandFiles) {
|
||||||
const command = require(`./commands/${file}`);
|
const command = require(`./commands/${file}`);
|
||||||
|
client.commands.set(command.name, command);
|
||||||
|
|
||||||
command.data = new SlashCommandBuilder()
|
command.data = new SlashCommandBuilder()
|
||||||
.setName(command.name)
|
.setName(command.name)
|
||||||
.setDescription(command.description);
|
.setDescription(command.description);
|
||||||
@ -28,13 +30,13 @@ module.exports = {
|
|||||||
commands.push(command.data);
|
commands.push(command.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
const rest = new REST({ version: '9' }).setToken(token);
|
const rest = new REST({ version: '9' }).setToken(client.config.token);
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
client.funcs.logger('Slash Commands', 'Started refreshing application (/) commands.');
|
client.funcs.logger('Slash Commands', 'Started refreshing application (/) commands.');
|
||||||
|
|
||||||
if(version.includes("-dev")){
|
if(client.config.devMode){
|
||||||
await rest.put(
|
await rest.put(
|
||||||
Routes.applicationCommands(client.user.id),
|
Routes.applicationCommands(client.user.id),
|
||||||
{ body: [] },
|
{ body: [] },
|
||||||
|
@ -17,7 +17,7 @@ module.exports = {
|
|||||||
|
|
||||||
const radio = client.radio.get(interaction.guild.id);
|
const radio = client.radio.get(interaction.guild.id);
|
||||||
|
|
||||||
if(radio && !client.config.maintenance){
|
if(radio && !client.config.maintenanceMode){
|
||||||
client.funcs.listStations(client, interaction);
|
client.funcs.listStations(client, interaction);
|
||||||
} else {
|
} else {
|
||||||
let stations = `${client.stations.map(s => `**#** ${s.name}`).join('\n')}`
|
let stations = `${client.stations.map(s => `**#** ${s.name}`).join('\n')}`
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import Discord from "discord.js";
|
import Discord from "discord.js";
|
||||||
|
import Streamer from "../classes/Streamer.js";
|
||||||
const _importDynamic = new Function('modulePath', 'return import(modulePath)');
|
const _importDynamic = new Function('modulePath', 'return import(modulePath)');
|
||||||
const fetch = (...args) => _importDynamic('node-fetch').then(({default: fetch}) => fetch(...args));
|
const fetch = (...args) => _importDynamic('node-fetch').then(({default: fetch}) => fetch(...args));
|
||||||
|
|
||||||
@ -6,9 +7,6 @@ module.exports = {
|
|||||||
name: 'maintenance',
|
name: 'maintenance',
|
||||||
description: 'Bot Maintenance',
|
description: 'Bot Maintenance',
|
||||||
category: 'info',
|
category: 'info',
|
||||||
options: [
|
|
||||||
{ type: "NUMBER", name: "action", description: "Select action", required: false}
|
|
||||||
],
|
|
||||||
async execute(interaction, client) {
|
async execute(interaction, client) {
|
||||||
let message = {};
|
let message = {};
|
||||||
|
|
||||||
@ -59,6 +57,18 @@ module.exports = {
|
|||||||
label: "Disable Maintenance Mode",
|
label: "Disable Maintenance Mode",
|
||||||
description: "",
|
description: "",
|
||||||
value: "9"
|
value: "9"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
emoji: "💤",
|
||||||
|
label: "Streamer Mode – Manual",
|
||||||
|
description: "",
|
||||||
|
value: "10"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
emoji: "📡",
|
||||||
|
label: "Streamer Mode – Auto",
|
||||||
|
description: "",
|
||||||
|
value: "11"
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -91,47 +101,102 @@ module.exports = {
|
|||||||
ephemeral: true
|
ephemeral: true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let guilds = await client.guilds.fetch();
|
||||||
|
|
||||||
switch(action){
|
switch(action){
|
||||||
case "0":
|
case "0":
|
||||||
|
client.config.maintenanceMode = true;
|
||||||
process.emit('SIGINT');
|
process.emit('SIGINT');
|
||||||
break;
|
break;
|
||||||
case "4":
|
case "4":
|
||||||
|
client.config.maintenanceMode = true;
|
||||||
client.user.setStatus('idle');
|
client.user.setStatus('idle');
|
||||||
client.funcs.saveRadios(client);
|
client.radio.save(client);
|
||||||
client.user.setStatus('online');
|
client.user.setStatus('online');
|
||||||
|
client.config.maintenanceMode = false;
|
||||||
break;
|
break;
|
||||||
case "5":
|
case "5":
|
||||||
|
client.config.maintenanceMode = true;
|
||||||
client.user.setStatus('idle');
|
client.user.setStatus('idle');
|
||||||
let guilds = await client.guilds.fetch();
|
client.radio.restore(client, guilds);
|
||||||
client.funcs.restoreRadios(client, guilds);
|
|
||||||
client.user.setStatus('online');
|
client.user.setStatus('online');
|
||||||
|
client.config.maintenanceMode = false;
|
||||||
break;
|
break;
|
||||||
case "6":
|
case "6":
|
||||||
|
client.config.maintenanceMode = true;
|
||||||
client.user.setStatus('idle');
|
client.user.setStatus('idle');
|
||||||
require(`../commands.js`).execute(client);
|
require(`../commands.js`).execute(client);
|
||||||
client.user.setStatus('online');
|
client.user.setStatus('online');
|
||||||
|
client.config.maintenanceMode = false;
|
||||||
break;
|
break;
|
||||||
case "7":
|
case "7":
|
||||||
try {
|
try {
|
||||||
client.funcs.logger('Stations', 'Started fetching list – ' + client.config.stationslistUrl);
|
client.stations.fetch({
|
||||||
client.stations = await fetch(client.config.stationslistUrl)
|
url: client.config.stationslistUrl
|
||||||
.then(client.funcs.checkFetchStatus)
|
});
|
||||||
.then(response => response.json());
|
client.streamer.refresh(client);
|
||||||
|
|
||||||
client.funcs.logger('Stations', 'Successfully fetched list');
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
client.funcs.logger('Stations', 'Fetching list failed');
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "8":
|
case "8":
|
||||||
client.user.setStatus('dnd');
|
client.user.setStatus('dnd');
|
||||||
client.funcs.logger("Maintenance Mode", "Enabled");
|
client.funcs.logger("Maintenance Mode", "Enabled");
|
||||||
client.config.maintenance = false;
|
client.config.maintenanceMode = true;
|
||||||
break;
|
break;
|
||||||
case "9":
|
case "9":
|
||||||
client.user.setStatus('online');
|
client.user.setStatus('online');
|
||||||
client.funcs.logger("Maintenance Mode", "Disabled");
|
client.funcs.logger("Maintenance Mode", "Disabled");
|
||||||
client.config.maintenance = false;
|
client.config.maintenanceMode = false;
|
||||||
|
break;
|
||||||
|
case "10":
|
||||||
|
client.config.streamerMode = "manual";
|
||||||
|
client.config.maintenanceMode = true;
|
||||||
|
|
||||||
|
client.user.setStatus('idle');
|
||||||
|
client.radio.save(client);
|
||||||
|
|
||||||
|
setInterval(() => {
|
||||||
|
if(client.radio.size == 0 && client.config.streamerMode == "manual" && client.config.maintenanceMode){
|
||||||
|
client.streamer.leave(client);
|
||||||
|
client.streamer = new Streamer();
|
||||||
|
client.streamer.init(client);
|
||||||
|
|
||||||
|
client.radio.restore(client, guilds);
|
||||||
|
client.user.setStatus('online');
|
||||||
|
client.config.maintenanceMode = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!client.config.maintenanceMode){
|
||||||
|
clearInterval();
|
||||||
|
}
|
||||||
|
}, 500);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case "11":
|
||||||
|
client.config.streamerMode = "auto";
|
||||||
|
client.config.maintenanceMode = true;
|
||||||
|
|
||||||
|
client.user.setStatus('idle');
|
||||||
|
client.radio.save(client);
|
||||||
|
|
||||||
|
setInterval(() => {
|
||||||
|
if(client.radio.size == 0 && client.config.streamerMode == "auto" && client.config.maintenanceMode){
|
||||||
|
client.streamer.leave(client);
|
||||||
|
client.streamer = new Streamer();
|
||||||
|
client.streamer.init(client);
|
||||||
|
|
||||||
|
client.radio.restore(client, guilds);
|
||||||
|
client.user.setStatus('online');
|
||||||
|
client.config.maintenanceMode = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!client.config.maintenanceMode){
|
||||||
|
clearInterval();
|
||||||
|
}
|
||||||
|
}, 500);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
||||||
|
@ -16,10 +16,7 @@ module.exports = {
|
|||||||
ephemeral: true
|
ephemeral: true
|
||||||
});
|
});
|
||||||
|
|
||||||
let url = station.stream[station.stream.default];
|
client.statistics.update(client, interaction.guild, radio);
|
||||||
|
|
||||||
client.funcs.statisticsUpdate(client, interaction.guild, radio);
|
|
||||||
radio.audioPlayer.stop();
|
|
||||||
|
|
||||||
let date = new Date();
|
let date = new Date();
|
||||||
radio.station = station;
|
radio.station = station;
|
||||||
@ -27,13 +24,12 @@ module.exports = {
|
|||||||
radio.startTime = date.getTime();
|
radio.startTime = date.getTime();
|
||||||
|
|
||||||
if(interaction.isCommand()) {
|
if(interaction.isCommand()) {
|
||||||
client.funcs.play(interaction, interaction.guild, client, url);
|
client.funcs.play(client, interaction, interaction.guild, station);
|
||||||
}
|
}
|
||||||
if(interaction.isButton()) {
|
if(interaction.isButton()) {
|
||||||
interaction.deferUpdate();
|
interaction.deferUpdate();
|
||||||
client.funcs.play(null, interaction.guild, client, url);
|
client.funcs.play(client, null, interaction.guild, station);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ module.exports = {
|
|||||||
const completed = (radio.playTime);
|
const completed = (radio.playTime);
|
||||||
|
|
||||||
message.nowplayingDescription = client.messages.nowplayingDescription.replace("%radio.station.name%", radio.station.name);
|
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("%radio.station.owner%" + "\n", radio.station.name != radio.station.owner ? radio.station.owner + "\n" : "");
|
||||||
message.nowplayingDescription = message.nowplayingDescription.replace("%client.funcs.msToTime(completed)%", client.funcs.msToTime(completed));
|
message.nowplayingDescription = message.nowplayingDescription.replace("%client.funcs.msToTime(completed)%", client.funcs.msToTime(completed));
|
||||||
|
|
||||||
const embed = new Discord.MessageEmbed()
|
const embed = new Discord.MessageEmbed()
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
const {
|
const {
|
||||||
createAudioPlayer,
|
|
||||||
getVoiceConnection,
|
getVoiceConnection,
|
||||||
joinVoiceChannel
|
joinVoiceChannel
|
||||||
} = require("@discordjs/voice");
|
} = require("@discordjs/voice");
|
||||||
@ -15,12 +14,11 @@ module.exports = {
|
|||||||
async execute(interaction, client) {
|
async execute(interaction, client) {
|
||||||
let message = {};
|
let message = {};
|
||||||
|
|
||||||
if(client.config.maintenance){
|
if(client.config.maintenanceMode){
|
||||||
interaction.reply({
|
return interaction.reply({
|
||||||
content: client.messageEmojis["error"] + client.messages.maintenance,
|
content: client.messageEmojis["error"] + client.messages.maintenance,
|
||||||
ephemeral: true
|
ephemeral: true
|
||||||
});
|
});
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!client.stations) {
|
if(!client.stations) {
|
||||||
@ -79,7 +77,6 @@ module.exports = {
|
|||||||
ephemeral: true
|
ephemeral: true
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
url = client.stations[number].stream[client.stations[number].stream.default];
|
|
||||||
station = client.stations[number];
|
station = client.stations[number];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -87,24 +84,31 @@ module.exports = {
|
|||||||
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);
|
|
||||||
|
let type = "";
|
||||||
|
|
||||||
|
if(interaction.values?.[0]){
|
||||||
|
type = "direct";
|
||||||
|
} else {
|
||||||
|
type = "text";
|
||||||
|
}
|
||||||
|
|
||||||
|
const sstation = await client.stations.search(query, type);
|
||||||
if (!sstation) return interaction.reply({
|
if (!sstation) 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];
|
|
||||||
station = sstation;
|
station = sstation;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (radio) {
|
if (radio) {
|
||||||
client.funcs.statisticsUpdate(client, interaction.guild, radio);
|
client.statistics.update(client, interaction.guild, radio);
|
||||||
radio.audioPlayer.stop();
|
|
||||||
|
|
||||||
let date = new Date();
|
let date = new Date();
|
||||||
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(interaction, interaction.guild, client, url);
|
client.funcs.play(client, interaction, interaction.guild, station);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -114,7 +118,6 @@ module.exports = {
|
|||||||
voiceChannel: voiceChannel,
|
voiceChannel: voiceChannel,
|
||||||
connection: null,
|
connection: null,
|
||||||
message: null,
|
message: null,
|
||||||
audioPlayer: createAudioPlayer(),
|
|
||||||
station: station
|
station: station
|
||||||
};
|
};
|
||||||
client.radio.set(interaction.guild.id, construct);
|
client.radio.set(interaction.guild.id, construct);
|
||||||
@ -130,17 +133,8 @@ module.exports = {
|
|||||||
construct.connection = connection;
|
construct.connection = connection;
|
||||||
let date = new Date();
|
let date = new Date();
|
||||||
construct.startTime = date.getTime();
|
construct.startTime = date.getTime();
|
||||||
client.funcs.play(interaction, interaction.guild, client, url);
|
|
||||||
|
|
||||||
client.datastore.checkEntry(interaction.guild.id);
|
client.datastore.checkEntry(interaction.guild.id);
|
||||||
construct.currentGuild = client.datastore.getEntry(interaction.guild.id);
|
client.funcs.play(client, interaction, interaction.guild, station);
|
||||||
|
|
||||||
if (!construct.currentGuild.statistics[construct.station.name]) {
|
|
||||||
construct.currentGuild.statistics[construct.station.name] = {};
|
|
||||||
construct.currentGuild.statistics[construct.station.name].time = 0;
|
|
||||||
construct.currentGuild.statistics[construct.station.name].used = 0;
|
|
||||||
client.datastore.updateEntry(interaction.guild, construct.currentGuild);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
client.radio.delete(interaction.guild.id);
|
client.radio.delete(interaction.guild.id);
|
||||||
|
@ -16,10 +16,7 @@ module.exports = {
|
|||||||
ephemeral: true
|
ephemeral: true
|
||||||
});
|
});
|
||||||
|
|
||||||
let url = station.stream[station.stream.default];
|
client.statistics.update(client, interaction.guild, radio);
|
||||||
|
|
||||||
client.funcs.statisticsUpdate(client, interaction.guild, radio);
|
|
||||||
radio.audioPlayer.stop();
|
|
||||||
|
|
||||||
let date = new Date();
|
let date = new Date();
|
||||||
radio.station = station;
|
radio.station = station;
|
||||||
@ -27,11 +24,11 @@ module.exports = {
|
|||||||
radio.startTime = date.getTime();
|
radio.startTime = date.getTime();
|
||||||
|
|
||||||
if(interaction.isCommand()) {
|
if(interaction.isCommand()) {
|
||||||
client.funcs.play(interaction, interaction.guild, client, url);
|
client.funcs.play(client, interaction, interaction.guild, station);
|
||||||
}
|
}
|
||||||
if(interaction.isButton()) {
|
if(interaction.isButton()) {
|
||||||
interaction.deferUpdate();
|
interaction.deferUpdate();
|
||||||
client.funcs.play(null, interaction.guild, client, url);
|
client.funcs.play(client, null, interaction.guild, station);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,11 +14,11 @@ module.exports = {
|
|||||||
.setTitle(message.statusTitle)
|
.setTitle(message.statusTitle)
|
||||||
.setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["logo"].replace(/[^0-9]+/g, ''))
|
.setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["logo"].replace(/[^0-9]+/g, ''))
|
||||||
.setColor(client.config.embedColor)
|
.setColor(client.config.embedColor)
|
||||||
.addField(client.messages.statusField1, Date.now() - interaction.createdTimestamp + "ms", true)
|
.addField(client.messages.statusField1, uptime, false)
|
||||||
.addField(client.messages.statusField2, client.ws.ping + "ms", true)
|
.addField(client.messages.statusField2, client.config.version, false)
|
||||||
.addField(client.messages.statusField3, uptime, true)
|
.addField(client.messages.statusField3, Date.now() - interaction.createdTimestamp + "ms", false)
|
||||||
.addField(client.messages.statusField4, client.config.version, true)
|
.addField(client.messages.statusField4, client.ws.ping + "ms", false)
|
||||||
.addField(client.messages.statusField5, client.config.hostedBy, true)
|
.addField(client.messages.statusField5, client.config.hostedBy, false)
|
||||||
.setImage('https://waren.io/berriabot-temp-sa7a36a9xm6837br/images/empty-3.png')
|
.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, ''));
|
.setFooter(client.messages.footerText, "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, ''));
|
||||||
|
|
||||||
|
@ -7,10 +7,9 @@ module.exports = {
|
|||||||
async execute(interaction, client, command) {
|
async execute(interaction, client, command) {
|
||||||
if (client.funcs.check(client, interaction, command)) {
|
if (client.funcs.check(client, interaction, command)) {
|
||||||
const radio = client.radio.get(interaction.guild.id);
|
const radio = client.radio.get(interaction.guild.id);
|
||||||
client.funcs.statisticsUpdate(client, interaction.guild, radio);
|
client.statistics.update(client, interaction.guild, radio);
|
||||||
radio.connection?.destroy();
|
radio.connection?.destroy();
|
||||||
radio.audioPlayer?.stop();
|
client.funcs.logger('Radio', interaction.guild.id + " / " + 'Stop');
|
||||||
client.funcs.logger('Radio', 'Stream stopped' + " / " + interaction.guild.id);
|
|
||||||
|
|
||||||
const embed = new Discord.MessageEmbed()
|
const embed = new Discord.MessageEmbed()
|
||||||
.setTitle(client.user.username)
|
.setTitle(client.user.username)
|
||||||
@ -23,7 +22,11 @@ module.exports = {
|
|||||||
if(!radio.message){
|
if(!radio.message){
|
||||||
radio.message = radio.textChannel.send({ embeds: [embed], components: [] });
|
radio.message = radio.textChannel.send({ embeds: [embed], components: [] });
|
||||||
} else {
|
} else {
|
||||||
|
if(radio.textChannel.id == radio.message.channel.id){
|
||||||
radio.message.edit({ embeds: [embed], components: [] });
|
radio.message.edit({ embeds: [embed], components: [] });
|
||||||
|
} else {
|
||||||
|
radio.message?.delete();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(async function() {
|
setTimeout(async function() {
|
||||||
|
@ -3,7 +3,8 @@ module.exports = {
|
|||||||
execute(client) {
|
execute(client) {
|
||||||
client.user.setStatus('dnd');
|
client.user.setStatus('dnd');
|
||||||
|
|
||||||
client.funcs.saveRadios(client);
|
client.streamer.leave(client);
|
||||||
|
client.radio.save(client);
|
||||||
|
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
if(client.radio.size == 0){
|
if(client.radio.size == 0){
|
||||||
|
@ -6,7 +6,7 @@ module.exports = {
|
|||||||
if (!permissions.has('VIEW_CHANNEL')) return;
|
if (!permissions.has('VIEW_CHANNEL')) return;
|
||||||
|
|
||||||
if (!permissions.has('EMBED_LINKS')) return interaction.reply({
|
if (!permissions.has('EMBED_LINKS')) return interaction.reply({
|
||||||
content: client.messages.noPermsEmbed,
|
content: client.messageEmojis["error"] + client.messages.noPermsEmbed,
|
||||||
ephemeral: true
|
ephemeral: true
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ module.exports = {
|
|||||||
command.execute(interaction, client);
|
command.execute(interaction, client);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
interaction.reply({
|
interaction.reply({
|
||||||
content: client.messages.runningCommandFailed,
|
content: client.messageEmojis["error"] + client.messages.runningCommandFailed,
|
||||||
ephemeral: true
|
ephemeral: true
|
||||||
});
|
});
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@ -33,7 +33,7 @@ module.exports = {
|
|||||||
command.execute(interaction, client, command);
|
command.execute(interaction, client, command);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
interaction.reply({
|
interaction.reply({
|
||||||
content: client.messages.runningCommandFailed,
|
content: client.messageEmojis["error"] + client.messages.runningCommandFailed,
|
||||||
ephemeral: true
|
ephemeral: true
|
||||||
});
|
});
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import Datastore from "../datastore.js";
|
import Datastore from "../classes/Datastore.js";
|
||||||
const _importDynamic = new Function('modulePath', 'return import(modulePath)');
|
import Radio from "../classes/Radio.js";
|
||||||
const fetch = (...args) => _importDynamic('node-fetch').then(({default: fetch}) => fetch(...args));
|
import Stations from "../classes/Stations.js";
|
||||||
|
import Streamer from "../classes/Streamer.js";
|
||||||
|
import Statistics from "../classes/Statistics.js";
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'ready',
|
name: 'ready',
|
||||||
@ -37,38 +39,23 @@ module.exports = {
|
|||||||
console.log("\n");
|
console.log("\n");
|
||||||
|
|
||||||
/*STATIONS*/
|
/*STATIONS*/
|
||||||
try {
|
client.stations = new Stations();
|
||||||
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');
|
await client.stations.fetch({
|
||||||
client.stations.forEach(station => {
|
url: client.config.stationslistUrl,
|
||||||
console.log("- " + station.name);
|
show: true
|
||||||
});
|
});
|
||||||
console.log("\n");
|
|
||||||
|
|
||||||
client.funcs.logger('Stations', 'Successfully fetched list');
|
|
||||||
} catch (error) {
|
|
||||||
client.funcs.logger('Stations', 'Fetching list failed');
|
|
||||||
console.error(error + "\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
setInterval(async () => {
|
setInterval(async () => {
|
||||||
try {
|
await client.stations.fetch({
|
||||||
client.funcs.logger('Stations', 'Started fetching list – ' + client.config.stationslistUrl);
|
url: client.config.stationslistUrl,
|
||||||
client.stations = await fetch(client.config.stationslistUrl)
|
show: false
|
||||||
.then(client.funcs.checkFetchStatus)
|
});
|
||||||
.then(response => response.json());
|
|
||||||
|
|
||||||
client.funcs.logger('Stations', 'Successfully fetched list');
|
|
||||||
} catch (error) {
|
|
||||||
client.funcs.logger('Stations', 'Fetching list failed');
|
|
||||||
//console.error(error);
|
|
||||||
}
|
|
||||||
}, 3600000);
|
}, 3600000);
|
||||||
|
|
||||||
|
client.streamer = new Streamer();
|
||||||
|
client.streamer.init(client);
|
||||||
|
|
||||||
if(!client.stations) {
|
if(!client.stations) {
|
||||||
client.user.setStatus('dnd');
|
client.user.setStatus('dnd');
|
||||||
}
|
}
|
||||||
@ -86,7 +73,8 @@ module.exports = {
|
|||||||
client.funcs.logger('Guilds', 'Successfully fetched list');
|
client.funcs.logger('Guilds', 'Successfully fetched list');
|
||||||
|
|
||||||
/*STATISTICS*/
|
/*STATISTICS*/
|
||||||
client.datastore.calculateGlobal(client);
|
client.statistics = new Statistics();
|
||||||
|
client.statistics.calculateGlobal(client);
|
||||||
|
|
||||||
/*EMOJIS*/
|
/*EMOJIS*/
|
||||||
require(`../emojis.js`).execute(client);
|
require(`../emojis.js`).execute(client);
|
||||||
@ -94,15 +82,20 @@ module.exports = {
|
|||||||
/*COMMANDS*/
|
/*COMMANDS*/
|
||||||
require(`../commands.js`).execute(client);
|
require(`../commands.js`).execute(client);
|
||||||
|
|
||||||
|
/*RADIO*/
|
||||||
|
client.radio = new Radio();
|
||||||
|
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
/*RESTORE RADIOS*/
|
/*RESTORE RADIOS*/
|
||||||
client.funcs.restoreRadios(client, guilds);
|
client.radio.restore(client, guilds);
|
||||||
}, 5000);
|
}, 5000);
|
||||||
|
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
|
if(client.stations) {
|
||||||
/*MAINTENANCE MODE*/
|
/*MAINTENANCE MODE*/
|
||||||
client.funcs.logger("Maintenance Mode", "Disabled");
|
client.funcs.logger("Maintenance Mode", "Disabled");
|
||||||
client.config.maintenance = false;
|
client.config.maintenanceMode = false;
|
||||||
|
}
|
||||||
}, 10000);
|
}, 10000);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,11 +14,10 @@ module.exports = {
|
|||||||
if (newState.member.id === client.user.id && oldState.member.id === client.user.id) {
|
if (newState.member.id === client.user.id && oldState.member.id === client.user.id) {
|
||||||
|
|
||||||
if (newState.channel === null) {
|
if (newState.channel === null) {
|
||||||
client.funcs.statisticsUpdate(client, newState.guild, radio);
|
client.statistics.update(client, newState.guild, radio);
|
||||||
radio.connection?.destroy();
|
radio.connection?.destroy();
|
||||||
radio.audioPlayer?.stop();
|
|
||||||
radio.message?.delete();
|
radio.message?.delete();
|
||||||
client.funcs.logger('Radio', 'Stream stopped' + " / " + newState.guild.id);
|
client.funcs.logger('Radio', newState.guild.id + " / " + 'Stop');
|
||||||
return client.radio.delete(newState.guild.id);
|
return client.radio.delete(newState.guild.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,11 +36,10 @@ module.exports = {
|
|||||||
1000
|
1000
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
client.funcs.statisticsUpdate(client, newState.guild, radio);
|
client.statistics.update(client, newState.guild, radio);
|
||||||
radio.connection?.destroy();
|
radio.connection?.destroy();
|
||||||
radio.audioPlayer?.stop();
|
|
||||||
radio.message?.delete();
|
radio.message?.delete();
|
||||||
client.funcs.logger('Radio', 'Stream stopped' + " / " + newState.guild.id);
|
client.funcs.logger('Radio', newState.guild.id + " / " + 'Stop');
|
||||||
client.radio.delete(oldState.guild.id);
|
client.radio.delete(oldState.guild.id);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -53,18 +51,17 @@ module.exports = {
|
|||||||
//radio.connection = await newState.channel.join();
|
//radio.connection = await newState.channel.join();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((oldState.channel.members.size === 1 && oldState.channel === radio.voiceChannel) || change) {
|
if ((oldState.channel.members.filter(member => !member.user.bot).size === 0 && oldState.channel === radio.voiceChannel) || change) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (!radio || !radio.connection || !radio.connection === null) return;
|
if (!radio || !radio.connection || !radio.connection === null) return;
|
||||||
if (radio.voiceChannel.members.size === 1) {
|
if (radio.voiceChannel.members.filter(member => !member.user.bot).size === 0) {
|
||||||
client.funcs.statisticsUpdate(client, newState.guild, radio);
|
client.statistics.update(client, newState.guild, radio);
|
||||||
radio.connection?.destroy();
|
radio.connection?.destroy();
|
||||||
radio.audioPlayer?.stop();
|
|
||||||
radio.message?.delete();
|
radio.message?.delete();
|
||||||
client.funcs.logger('Radio', 'Stream stopped' + " / " + newState.guild.id);
|
client.funcs.logger('Radio', newState.guild.id + " / " + 'Stop');
|
||||||
client.radio.delete(newState.guild.id);
|
client.radio.delete(newState.guild.id);
|
||||||
}
|
}
|
||||||
}, 60000);
|
}, 5000);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
module.exports = function (client, interaction, command) {
|
module.exports = function check(client, interaction, command) {
|
||||||
let message = {};
|
let message = {};
|
||||||
const radio = client.radio.get(interaction.guild.id);
|
const radio = client.radio.get(interaction.guild.id);
|
||||||
const permissions = interaction.channel.permissionsFor(interaction.user);
|
const permissions = interaction.channel.permissionsFor(interaction.user);
|
||||||
if(client.config.maintenance){
|
if(client.config.maintenanceMode){
|
||||||
interaction.reply({
|
interaction.reply({
|
||||||
content: client.messageEmojis["error"] + client.messages.maintenance,
|
content: client.messageEmojis["error"] + client.messages.maintenance,
|
||||||
ephemeral: true
|
ephemeral: true
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
module.exports = function (response) {
|
|
||||||
if (response.ok) { // res.status >= 200 && res.status < 300
|
|
||||||
return response;
|
|
||||||
} else {
|
|
||||||
throw new Error(response.status + " " + response.statusText);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
module.exports = function (devList, authorID){
|
module.exports = function isDev(devList, authorID){
|
||||||
let response = false;
|
let response = false;
|
||||||
Object.keys(devList).forEach(function(oneDev) {
|
Object.keys(devList).forEach(function(oneDev) {
|
||||||
let devID = devList[oneDev];
|
let devID = devList[oneDev];
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import Discord from "discord.js";
|
import Discord from "discord.js";
|
||||||
|
|
||||||
module.exports = function (client, interaction){
|
module.exports = function listStations(client, interaction){
|
||||||
let stations = new Array();
|
let stations = new Array();
|
||||||
let options = new Array();
|
let options = new Array();
|
||||||
|
|
||||||
|
@ -4,6 +4,8 @@ module.exports = function loadState(client, guild){
|
|||||||
let state;
|
let state;
|
||||||
|
|
||||||
state = data.state;
|
state = data.state;
|
||||||
|
if(!state) return;
|
||||||
|
|
||||||
data.state = {};
|
data.state = {};
|
||||||
client.datastore.updateEntry(guild, data);
|
client.datastore.updateEntry(guild, data);
|
||||||
return state;
|
return state;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
module.exports = function (area, text){
|
module.exports = function logger(area, text){
|
||||||
let date = new Date();
|
let date = new Date();
|
||||||
console.log('[' + area + '] – ' + date.toISOString());
|
console.log('[' + area + '] – ' + date.toISOString());
|
||||||
if(text) console.log(text + '\n');
|
if(text) console.log(text + '\n');
|
||||||
|
@ -1,42 +1,15 @@
|
|||||||
import Discord from "discord.js";
|
import Discord from "discord.js";
|
||||||
const {
|
|
||||||
createAudioResource
|
|
||||||
} = require("@discordjs/voice");
|
|
||||||
|
|
||||||
module.exports = async function play(interaction, guild, client, url) {
|
module.exports = async function play(client, interaction, guild, station) {
|
||||||
let message = {};
|
let message = {};
|
||||||
const radio = client.radio.get(guild.id);
|
const radio = client.radio.get(guild.id);
|
||||||
const resource = createAudioResource(url);
|
const audioPlayer = client.streamer.listen(station);
|
||||||
radio.connection.subscribe(radio.audioPlayer);
|
radio.connection.subscribe(audioPlayer);
|
||||||
radio.audioPlayer.play(resource);
|
client.funcs.logger('Radio', guild.id + " / " + "Play" + " / " + radio.station.name);
|
||||||
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 = 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("%radio.station.owner%", radio.station.name != radio.station.owner ? radio.station.owner + "\n" : "");
|
||||||
message.nowplayingDescription = message.nowplayingDescription.replace("%client.funcs.msToTime(completed)%", "");
|
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("**", "");
|
||||||
message.nowplayingDescription = message.nowplayingDescription.replace("**", "");
|
message.nowplayingDescription = message.nowplayingDescription.replace("**", "");
|
||||||
|
|
||||||
@ -83,7 +56,12 @@ module.exports = async function play(interaction, guild, client, url) {
|
|||||||
if(!radio.message){
|
if(!radio.message){
|
||||||
radio.message = await radio.textChannel.send({ embeds: [embed], components: [buttons] });
|
radio.message = await radio.textChannel.send({ embeds: [embed], components: [buttons] });
|
||||||
} else {
|
} else {
|
||||||
|
if(radio.textChannel.id == radio.message.channel.id){
|
||||||
radio.message.edit({ embeds: [embed], components: [buttons] });
|
radio.message.edit({ embeds: [embed], components: [buttons] });
|
||||||
|
} else {
|
||||||
|
radio.message?.delete();
|
||||||
|
radio.message = await radio.textChannel.send({ embeds: [embed], components: [buttons] });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
message.play = client.messages.play.replace("%radio.station.name%", radio.station.name);
|
message.play = client.messages.play.replace("%radio.station.name%", radio.station.name);
|
||||||
|
@ -1,62 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,62 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
module.exports = function statisticsUpdate(client, guild, radio) {
|
|
||||||
|
|
||||||
client.datastore.checkEntry(guild.id);
|
|
||||||
|
|
||||||
radio.datastore = client.datastore.getEntry(guild.id);
|
|
||||||
|
|
||||||
if(!radio.datastore.statistics[radio.station.name]){
|
|
||||||
radio.datastore.statistics[radio.station.name] = {};
|
|
||||||
radio.datastore.statistics[radio.station.name].time = 0;
|
|
||||||
radio.datastore.statistics[radio.station.name].used = 0;
|
|
||||||
client.datastore.updateEntry(guild, radio.datastore);
|
|
||||||
}
|
|
||||||
|
|
||||||
let date = new Date();
|
|
||||||
radio.currentTime = date.getTime();
|
|
||||||
radio.playTime = parseInt(radio.currentTime)-parseInt(radio.startTime);
|
|
||||||
radio.datastore.statistics[radio.station.name].time = parseInt(radio.datastore.statistics[radio.station.name].time)+parseInt(radio.playTime);
|
|
||||||
|
|
||||||
radio.datastore.statistics[radio.station.name].used = parseInt(radio.datastore.statistics[radio.station.name].used)+1;
|
|
||||||
client.datastore.updateEntry(guild, radio.datastore);
|
|
||||||
client.datastore.calculateGlobal(client);
|
|
||||||
}
|
|
@ -11,7 +11,7 @@ module.exports = {
|
|||||||
inviteTitle: "Invite %client.user.username% to your Discord server!",
|
inviteTitle: "Invite %client.user.username% to your Discord server!",
|
||||||
listTitle: "Radio Stations",
|
listTitle: "Radio Stations",
|
||||||
nowplayingTitle: "Now Playing",
|
nowplayingTitle: "Now Playing",
|
||||||
nowplayingDescription: "**%radio.station.name%**" + "\n" + "Owner: %radio.station.owner%" + "\n" + "%client.funcs.msToTime(completed)%",
|
nowplayingDescription: "**%radio.station.name%**" + "\n" + "%radio.station.owner%" + "\n" + "%client.funcs.msToTime(completed)%",
|
||||||
noVoiceChannel: "You need to be in a voice channel to play radio!",
|
noVoiceChannel: "You need to be in a voice channel to play radio!",
|
||||||
noQuery: "You need to use a number or search for a supported station!",
|
noQuery: "You need to use a number or search for a supported station!",
|
||||||
noPermsConnect: "I cannot connect to your voice channel.",
|
noPermsConnect: "I cannot connect to your voice channel.",
|
||||||
@ -29,11 +29,11 @@ module.exports = {
|
|||||||
sendedMaintenanceMessage: "This bot is going to be under maintenance!",
|
sendedMaintenanceMessage: "This bot is going to be under maintenance!",
|
||||||
footerText: "EximiaBots by Warén Group",
|
footerText: "EximiaBots by Warén Group",
|
||||||
statusTitle: "%client.user.username% Status",
|
statusTitle: "%client.user.username% Status",
|
||||||
statusField1: "Bot Latency",
|
statusField1: ":clock1: Bot Uptime",
|
||||||
statusField2: "API Latency",
|
statusField2: ":floppy_disk: Bot Version",
|
||||||
statusField3: "Uptime",
|
statusField3: ":heartbeat: WebSocket Ping",
|
||||||
statusField4: "Version",
|
statusField4: ":hourglass: Latency",
|
||||||
statusField5: "Hosted by",
|
statusField5: ":globe_with_meridians: Hosted by",
|
||||||
errorStationURL: "Station can't be URL",
|
errorStationURL: "Station can't be URL",
|
||||||
messageCommandsDeprecatedTitle: "%client.user.username%",
|
messageCommandsDeprecatedTitle: "%client.user.username%",
|
||||||
messageCommandsDeprecatedDescription: "We recommend you to reauthorize our bot by clicking the invite link down below, because Discord is planning to remove message content from verified bots [Read More](https://support-dev.discord.com/hc/en-us/articles/4404772028055)" + "\n\n" + "**Invite Bot**" + "\n" + "https://wgi.fi/radiox_invite" + "\n\n" + "This bot now supports slash commands, you should start using them instead. Type / into the message box and select the bot you wish to use. Remember to be careful as there are a few bugs here and there on Discord." + "\n\n" + "We will remove this deprecation message in March of 2022 when RadioX 1.0.0 is released.",
|
messageCommandsDeprecatedDescription: "We recommend you to reauthorize our bot by clicking the invite link down below, because Discord is planning to remove message content from verified bots [Read More](https://support-dev.discord.com/hc/en-us/articles/4404772028055)" + "\n\n" + "**Invite Bot**" + "\n" + "https://wgi.fi/radiox_invite" + "\n\n" + "This bot now supports slash commands, you should start using them instead. Type / into the message box and select the bot you wish to use. Remember to be careful as there are a few bugs here and there on Discord." + "\n\n" + "We will remove this deprecation message in March of 2022 when RadioX 1.0.0 is released.",
|
||||||
|
@ -6,7 +6,7 @@ module.exports = {
|
|||||||
token: process.env.DISCORD_TOKEN,
|
token: process.env.DISCORD_TOKEN,
|
||||||
|
|
||||||
//radio stations
|
//radio stations
|
||||||
stationslistUrl: process.env.RADIOX_STATIONSLISTURL || "https://gitea.cwinfo.org/cwchristerw/radio/raw/branch/master/playlist.json",
|
stationslistUrl: process.env.RADIOX_STATIONSLISTURL || "https://git.cwinfo.net/cwchristerw/radio/raw/branch/master/playlist.json",
|
||||||
|
|
||||||
//support
|
//support
|
||||||
supportGuild: "https://discord.gg/rRA65Mn",
|
supportGuild: "https://discord.gg/rRA65Mn",
|
||||||
@ -20,7 +20,9 @@ module.exports = {
|
|||||||
hostedBy: "[Warén Group](https://waren.io)",
|
hostedBy: "[Warén Group](https://waren.io)",
|
||||||
|
|
||||||
//Settings
|
//Settings
|
||||||
version: process.env.RADIOX_VERSION || process.env.npm_package_version,
|
version: process.env.DEV_MODE ? process.env.npm_package_version + "-dev" : process.env.npm_package_version,
|
||||||
debug: process.env.DEBUG_MODE || false,
|
debug: process.env.DEBUG_MODE || false,
|
||||||
maintenance: false
|
devMode: process.env.DEV_MODE || false,
|
||||||
|
maintenanceMode: false,
|
||||||
|
streamerMode: process.env.STREAMER_MODE || "manual"
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user