TypeScript types

This commit is contained in:
Christer Warén 2023-06-04 05:48:42 +03:00
parent 9303c4fcc9
commit 3fc7337d0f
36 changed files with 131 additions and 119 deletions

View File

@ -4,11 +4,9 @@ import Radio from "./client/classes/Radio";
import Stations from "./client/classes/Stations"; import Stations from "./client/classes/Stations";
import Streamer from "./client/classes/Streamer"; import Streamer from "./client/classes/Streamer";
import Statistics from "./client/classes/Statistics"; import Statistics from "./client/classes/Statistics";
import fs from "fs"; import { command } from "./client/utils/typings";
import { command, radio } from "./client/utils/typings";
import config from "./config"; import config from "./config";
import messages from "./client/messages"; import messages from "./client/messages";
import path from "path";
const events = "./client/events/"; const events = "./client/events/";
@ -19,7 +17,7 @@ GatewayIntents.add(
1 << 9 // GUILD_MESSAGES 1 << 9 // GUILD_MESSAGES
); );
class RadioClient extends Client { export default class RadioClient extends Client {
readonly commands: Collection<string, command>; readonly commands: Collection<string, command>;
public funcs: any; public funcs: any;
readonly config = config; readonly config = config;
@ -109,5 +107,3 @@ class RadioClient extends Client {
}); });
} }
} }
export default RadioClient

View File

@ -2,6 +2,7 @@ const fs = require('fs');
const path = require('path'); const path = require('path');
export default class { export default class {
map: Map<any, any>;
constructor() { constructor() {
this.map = new Map(); this.map = new Map();
this.loadData(); this.loadData();
@ -27,7 +28,7 @@ export default class {
//console.log(""); //console.log("");
} }
checkEntry(id){ checkEntry(id: string){
this.loadEntry(id); this.loadEntry(id);
if(!this.map.has(id)){ if(!this.map.has(id)){
this.createEntry(id); this.createEntry(id);
@ -37,8 +38,8 @@ export default class {
} }
} }
createEntry(id){ createEntry(id: string){
let newData = {}; let newData: any = {};
newData.guild = {}; newData.guild = {};
newData.guild.id = id; newData.guild.id = id;
newData.statistics = {}; newData.statistics = {};
@ -47,7 +48,7 @@ export default class {
this.saveEntry(id, newData); this.saveEntry(id, newData);
} }
loadEntry(id){ loadEntry(id: any){
try { try {
const json = require(`../../../datastore/` + id + '.json'); const json = require(`../../../datastore/` + id + '.json');
this.map.set(id, json); this.map.set(id, json);
@ -55,11 +56,11 @@ export default class {
} }
} }
getEntry(id){ getEntry(id: string){
return this.map.get(id); return this.map.get(id);
} }
updateEntry(guild, newData) { updateEntry(guild: any, newData: any) {
newData.guild.name = guild.name; newData.guild.name = guild.name;
let date = new Date(); let date = new Date();
@ -70,7 +71,7 @@ export default class {
//this.showEntry(this.getEntry(guild.id)); //this.showEntry(this.getEntry(guild.id));
} }
showEntry(data){ showEntry(data : any){
console.log(data); console.log(data);
} }
@ -94,10 +95,10 @@ export default class {
this.updateEntry(newData.guild, newData); this.updateEntry(newData.guild, newData);
} }
saveEntry(file, data) { saveEntry(file: string, data: any) {
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: any) {
if (err) { if (err) {
//console.log(err); //console.log(err);
} }

View File

@ -4,11 +4,12 @@ const {
} = require("@discordjs/voice"); } = require("@discordjs/voice");
export default class Radio extends Map { export default class Radio extends Map {
constructor() { constructor() {
super(); super();
} }
save(client) { save(client: any) {
let currentRadios = this.keys(); let currentRadios = this.keys();
let radio = currentRadios.next(); let radio = currentRadios.next();
@ -29,16 +30,16 @@ export default class Radio extends Map {
} }
} }
restore(client, guilds) { restore(client: any, guilds: any) {
if(!client.stations) return; if(!client.stations) return;
guilds.forEach(async guild => { guilds.forEach(async (guild: { id: any; }) => {
let state = client.funcs.loadState(client, guild); let state = client.funcs.loadState(client, guild);
if(!state) return; if(!state) return;
if(!state.station || !state.channels.voice || !state.channels.text) return; if(!state.station || !state.channels.voice || !state.channels.text) return;
let voiceChannel = client.channels.cache.get(state.channels.voice); let voiceChannel = client.channels.cache.get(state.channels.voice);
if(!voiceChannel) return; if(!voiceChannel) return;
if(voiceChannel.members.filter(member => !member.user.bot).size === 0) return; if(voiceChannel.members.filter((member: { user: { bot: any; }; }) => !member.user.bot).size === 0) return;
const sstation = await client.stations.search(state.station.name, "direct"); const sstation = await client.stations.search(state.station.name, "direct");

View File

@ -1,22 +1,24 @@
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: any) => _importDynamic('node-fetch').then(({default: fetch}) => fetch(...args));
export default class Stations extends Array { export default class Stations extends Array {
logger: any;
constructor() { constructor() {
super(); super();
this.logger = require("../funcs/logger.js"); this.logger = require("../funcs/logger.js");
} }
async fetch(options){ async fetch(options: any){
try { try {
this.logger('Stations', 'Started fetching list ' + options.url); this.logger('Stations', 'Started fetching list ' + options.url);
let list = await fetch(options.url) let list = await fetch(options.url)
.then(this.checkFetchStatus) .then(this.checkFetchStatus)
.then(response => response.json()); .then((response: { json: () => any; }) => response.json());
if(list){ if(list){
this.length = 0; this.length = 0;
list.forEach(station => { list.forEach((station: any) => {
try { try {
this.push(station); this.push(station);
} catch (error) { } catch (error) {
@ -25,12 +27,12 @@ export default class Stations extends Array {
}); });
if(options.show){ if(options.show){
list.forEach(station => { list.forEach((station: { name: any; }) => {
this.logger('Stations', station.name); this.logger('Stations', station.name);
}); });
} }
list.forEach(async station => { list.forEach(async (station: { stream: { [x: string]: any; default: string | number; }; }) => {
try { try {
let stationTest = await fetch(station.stream[station.stream.default]); let stationTest = await fetch(station.stream[station.stream.default]);
if(stationTest.ok === true) return; if(stationTest.ok === true) return;
@ -50,7 +52,7 @@ export default class Stations extends Array {
} }
} }
checkFetchStatus(response) { checkFetchStatus(response: any) {
if (response.ok) { // res.status >= 200 && res.status < 300 if (response.ok) { // res.status >= 200 && res.status < 300
return response; return response;
} else { } else {
@ -58,7 +60,7 @@ export default class Stations extends Array {
} }
} }
search(key, type) { search(key: string, type: string) {
if (this === null) return false; if (this === null) return false;
if (!key) return false; if (!key) return false;
if (!type) return false; if (!type) return false;
@ -73,7 +75,7 @@ export default class Stations extends Array {
return foundStation; return foundStation;
} else { } else {
let foundStations = []; let foundStations : any[] = [];
if (key == "radio") return false; if (key == "radio") return false;
this this

View File

@ -1,9 +1,13 @@
import { Guild } from "discord.js";
export default class Statistics { export default class Statistics {
map: any;
constructor() { constructor() {
this.map = new Map(); this.map = new Map();
} }
update(client, guild, radio) { update(client: any, guild: Guild, radio: any) {
client.datastore.checkEntry(guild.id); client.datastore.checkEntry(guild.id);
@ -26,13 +30,13 @@ export default class Statistics {
this.calculateGlobal(client); this.calculateGlobal(client);
} }
calculateGlobal(client){ calculateGlobal(client: any){
if(!client.stations) return; if(!client.stations) return;
if(!client.datastore.map) return; if(!client.datastore.map) return;
let guilds = client.datastore.map.keys(); let guilds = client.datastore.map.keys();
let stations = client.stations; let stations = client.stations;
let statistics = {}; let statistics : any = {};
if(!client.stations) return; if(!client.stations) return;
@ -59,7 +63,7 @@ export default class Statistics {
calculation = guilds.next(); calculation = guilds.next();
} }
let newData = {}; let newData : any = {};
newData.guild = {}; newData.guild = {};
newData.guild.id = "global"; newData.guild.id = "global";
newData.guild.name = "global"; newData.guild.name = "global";

View File

@ -1,18 +1,21 @@
const { const {
createAudioPlayer, createAudioPlayer,
createAudioResource, createAudioResource,
AudioPlayerStatus,
NoSubscriberBehavior NoSubscriberBehavior
} = require("@discordjs/voice"); } = require("@discordjs/voice");
export default class Streamer { export default class Streamer {
map: any;
mode: any | null;
logger: any;
constructor() { constructor() {
this.map = new Map(); this.map = new Map();
this.mode = null; this.mode = null;
this.logger = require("../funcs/logger"); this.logger = require("../funcs/logger");
} }
init(client){ init(client: any){
if(!client.config.streamerMode) return; if(!client.config.streamerMode) return;
switch(client.config.streamerMode){ switch(client.config.streamerMode){
@ -29,24 +32,24 @@ export default class Streamer {
if(this.mode == "auto"){ if(this.mode == "auto"){
if(!client.stations) return; if(!client.stations) return;
client.stations.forEach(station => { client.stations.forEach((station: any) => {
this.play(station); this.play(station);
}); });
} }
} }
refresh(client){ refresh(client: any){
this.init(client); this.init(client);
let streamers = this.map.keys(); let streamers = this.map.keys();
streamers.forEach(streamer => { streamers.forEach((streamer: any) => {
if(client.stations.findIndex(station => station.name == streamer) == -1){ if(client.stations.findIndex((station: { name: any; }) => station.name == streamer) == -1){
this.stop(streamer); this.stop(streamer);
} }
}); });
} }
play(station) { play(station: any) {
let audioPlayer = this.map.get(station.name); let audioPlayer = this.map.get(station.name);
if(!audioPlayer) { if(!audioPlayer) {
if(this.mode == "auto"){ if(this.mode == "auto"){
@ -89,13 +92,13 @@ export default class Streamer {
.on('autopaused', () => { .on('autopaused', () => {
this.logger('Streamer', station.name + " / " + "AutoPaused"); this.logger('Streamer', station.name + " / " + "AutoPaused");
}) })
.on('error', error => { .on('error', (error: string) => {
this.logger('Streamer', station.name + " / " + "Error" + "\n" + error); this.logger('Streamer', station.name + " / " + "Error" + "\n" + error);
}); });
return audioPlayer; return audioPlayer;
} }
stop(station){ stop(station: any){
let audioPlayer = this.map.get(station.name); let audioPlayer = this.map.get(station.name);
if(audioPlayer){ if(audioPlayer){
this.logger('Streamer', station.name + " / " + "Stop"); this.logger('Streamer', station.name + " / " + "Stop");
@ -105,15 +108,15 @@ export default class Streamer {
this.map.delete(station.name); this.map.delete(station.name);
} }
listen(station) { listen(station: any) {
let audioPlayer = this.map.get(station.name); let audioPlayer = this.map.get(station.name);
if(!audioPlayer || this.mode == "manual" && audioPlayer.subscribers.length == 0) audioPlayer = this.play(station); if(!audioPlayer || this.mode == "manual" && audioPlayer.subscribers.length == 0) audioPlayer = this.play(station);
return audioPlayer; return audioPlayer;
} }
leave(client) { leave(client: any) {
if(!client.stations) return; if(!client.stations) return;
client.stations.forEach(station => { client.stations.forEach((station: any) => {
this.stop(station); this.stop(station);
}); });
} }

View File

@ -5,10 +5,10 @@ const fs = require('fs');
const path = require ('path'); const path = require ('path');
export default { export default {
async execute(client) { async execute(client: any) {
const commands = []; const commands : any[] = [];
const commandFiles = fs.readdirSync(path.join("./src/client/commands")).filter(f => f.endsWith(".ts")); const commandFiles = fs.readdirSync(path.join("./src/client/commands")).filter((f: string) => f.endsWith(".ts"));
for (const file of commandFiles) { for (const file of commandFiles) {
const command = require(`./commands/${file}`); const command = require(`./commands/${file}`);
@ -20,7 +20,7 @@ export default {
command.data = command.data.toJSON(); command.data = command.data.toJSON();
if(command.options) { if(command.options) {
command.options.forEach(function(option) { command.options.forEach(function(option: { type: string | number; }) {
if(option.type == "STRING") option.type = 3; if(option.type == "STRING") option.type = 3;
if(option.type == "NUMBER") option.type = 10; if(option.type == "NUMBER") option.type = 10;
command.data.options.push(option); command.data.options.push(option);
@ -43,14 +43,14 @@ export default {
); );
let guilds = await client.guilds.fetch(); let guilds = await client.guilds.fetch();
guilds.forEach(async guild => { guilds.forEach(async (guild: { id: string; name: string; }) => {
try { try {
await rest.put( await rest.put(
Routes.applicationGuildCommands(client.user.id, guild.id), Routes.applicationGuildCommands(client.user.id, guild.id),
{ body: commands } { body: commands }
); );
client.funcs.logger('Slash Commands', 'Guild Applications Successful' + "\n" + guild.id + " / " + guild.name); client.funcs.logger('Slash Commands', 'Guild Applications Successful' + "\n" + guild.id + " / " + guild.name);
} catch (DiscordAPIError) { } catch (DiscordAPIError: any) {
client.funcs.logger('Slash Commands', 'Guild Applications Failed' + "\n" + guild.id + " / " + guild.name); client.funcs.logger('Slash Commands', 'Guild Applications Failed' + "\n" + guild.id + " / " + guild.name);
if(DiscordAPIError.name != "DiscordAPIError[50001]") console.error(DiscordAPIError.message + "\n\n"); if(DiscordAPIError.name != "DiscordAPIError[50001]") console.error(DiscordAPIError.message + "\n\n");
} }
@ -62,7 +62,7 @@ export default {
); );
let guilds = await client.guilds.fetch(); let guilds = await client.guilds.fetch();
guilds.forEach(async guild => { guilds.forEach(async (guild: { id: any; }) => {
try { try {
await rest.put( await rest.put(
Routes.applicationGuildCommands(client.user.id, guild.id), Routes.applicationGuildCommands(client.user.id, guild.id),

View File

@ -4,8 +4,8 @@ export default {
name: 'bug', name: 'bug',
description: 'Report a bug', description: 'Report a bug',
category: 'info', category: 'info',
async execute(interaction, client) { async execute(interaction: any, client: any) {
let message = {}; let message : any = {};
message.bugTitle = client.messages.bugTitle.replace("%client.user.username%", client.user.username); message.bugTitle = client.messages.bugTitle.replace("%client.user.username%", client.user.username);
message.bugDescription = client.messages.bugDescription.replace("%client.config.supportGuild%", client.config.supportGuild); message.bugDescription = client.messages.bugDescription.replace("%client.config.supportGuild%", client.config.supportGuild);

View File

@ -4,16 +4,16 @@ export default {
name: 'help', name: 'help',
description: 'Get help using bot', description: 'Get help using bot',
category: 'info', category: 'info',
execute(interaction, client) { execute(interaction: any, client: any) {
let message = {}; let message: any = {};
const categories = []; const categories : any= [];
for (let i = 0; i < client.commands.size; i++) { for (let i = 0; i < client.commands.size; i++) {
if (!categories.includes([...client.commands.values()][i].category)) categories.push([...client.commands.values()][i].category); if (!categories.includes([...client.commands.values()][i].category)) categories.push([...client.commands.values()][i].category);
} }
let commands = ''; let commands = '';
for (let i = 0; i < categories.length; i++) { for (let i = 0; i < categories.length; i++) {
commands += `**» ${categories[i].toUpperCase()}**\n${client.commands.filter(x => x.category === categories[i] && !x.omitFromHelp).map(x => `\`${x.name}\``).join(', ')}\n`; commands += `**» ${categories[i].toUpperCase()}**\n${client.commands.filter(x => x.category === categories[i] && !x.omitFromHelp).map((x: { name: any; }) => `\`${x.name}\``).join(', ')}\n`;
} }
message.helpTitle = client.messages.helpTitle.replace("%client.user.username%", client.user.username); message.helpTitle = client.messages.helpTitle.replace("%client.user.username%", client.user.username);

View File

@ -4,8 +4,8 @@ export default {
name: 'invite', name: 'invite',
description: 'Invite Bot', description: 'Invite Bot',
category: 'info', category: 'info',
execute(interaction, client) { execute(interaction: any, client: any) {
let message = {}; let message: any = {};
message.inviteTitle = client.messages.inviteTitle.replace("%client.user.username%", client.user.username); message.inviteTitle = client.messages.inviteTitle.replace("%client.user.username%", client.user.username);
const embed = new EmbedBuilder() const embed = new EmbedBuilder()
.setTitle(message.inviteTitle) .setTitle(message.inviteTitle)

View File

@ -4,8 +4,8 @@ export default {
name: 'list', name: 'list',
description: 'List radio stations', description: 'List radio stations',
category: 'radio', category: 'radio',
execute(interaction, client) { execute(interaction: any, client: any) {
let message = {}; let message: any = {};
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);
@ -20,7 +20,7 @@ export default {
if(radio && !client.config.maintenanceMode){ 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: { name: any; }) => `**#** ${s.name}`).join('\n')}`
const hashs = stations.split('**#**').length; const hashs = stations.split('**#**').length;
for (let i = 0; i < hashs; i++) { for (let i = 0; i < hashs; i++) {
stations = stations.replace('**#**', `**${i + 1}.**`); stations = stations.replace('**#**', `**${i + 1}.**`);

View File

@ -1,21 +1,21 @@
import { ActionRowBuilder, EmbedBuilder, StringSelectMenuBuilder } from "discord.js"; import { ActionRowBuilder, EmbedBuilder, StringSelectMenuBuilder } from "discord.js";
import Streamer from "../classes/Streamer"; import Streamer from "../classes/Streamer";
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: any) => _importDynamic('node-fetch').then(({default: fetch}) => fetch(...args));
export default { export default {
name: 'maintenance', name: 'maintenance',
description: 'Bot Maintenance', description: 'Bot Maintenance',
category: 'info', category: 'info',
async execute(interaction, client) { async execute(interaction: any, client: any) {
let message = {}; let message: any = {};
if(!client.funcs.isDev(client.config.devId, interaction.user.id)) return interaction.reply({ if(!client.funcs.isDev(client.config.devId, interaction.user.id)) return interaction.reply({
content: client.messageEmojis["error"] + client.messages.notAllowed, content: client.messageEmojis["error"] + client.messages.notAllowed,
ephemeral: true 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: any = new Array(
{ {
emoji: "🌀", emoji: "🌀",
label: "Restart Bot", label: "Restart Bot",
@ -79,12 +79,12 @@ export default {
}); });
} }
client.funcs.logger('Maintenance', options.find(option => option.value == action).label); client.funcs.logger('Maintenance', options.find((option: { value: any; }) => option.value == action).label);
const embed = new EmbedBuilder() const embed = new EmbedBuilder()
.setTitle(client.messages.maintenanceTitle) .setTitle(client.messages.maintenanceTitle)
.setColor(client.config.embedColor) .setColor(client.config.embedColor)
.setDescription(options.find(option => option.value == action).label) .setDescription(options.find((option: { value: any; }) => option.value == action).label)
.setFooter({ .setFooter({
text: client.messages.footerText, text: client.messages.footerText,
iconURL: "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, '') iconURL: "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, '')
@ -163,7 +163,7 @@ export default {
} }
if(!client.config.maintenanceMode){ if(!client.config.maintenanceMode){
clearInterval(); clearInterval(undefined);
} }
}, 500); }, 500);
@ -187,7 +187,7 @@ export default {
} }
if(!client.config.maintenanceMode){ if(!client.config.maintenanceMode){
clearInterval(); clearInterval(undefined);
} }
}, 500); }, 500);

View File

@ -2,11 +2,11 @@ export default {
name: 'next', name: 'next',
description: 'Next Station', description: 'Next Station',
category: 'radio', category: 'radio',
async execute(interaction, client, command) { async execute(interaction: any, client: any, command: any) {
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);
let index = client.stations.findIndex(station => station.name == radio.station.name) + 1; let index = client.stations.findIndex((station: { name: any; }) => station.name == radio.station.name) + 1;
if(index == client.stations.length) index = 0; if(index == client.stations.length) index = 0;
let station = client.stations[index]; let station = client.stations[index];

View File

@ -4,9 +4,9 @@ export default {
name: 'nowplaying', name: 'nowplaying',
description: 'Current Radio Station', description: 'Current Radio Station',
category: 'radio', category: 'radio',
async execute(interaction, client, command) { async execute(interaction: any, client: any, command: any) {
if (client.funcs.check(client, interaction, command)) { if (client.funcs.check(client, interaction, command)) {
let message = {}; let message: any = {};
const radio = client.radio.get(interaction.guild.id); const radio = client.radio.get(interaction.guild.id);
let date = new Date(); let date = new Date();

View File

@ -12,8 +12,8 @@ export default {
{ type: "STRING", name: "query", description: "Select station", required: false} { type: "STRING", name: "query", description: "Select station", required: false}
], ],
category: "radio", category: "radio",
async execute(interaction, client) { async execute(interaction: any, client: any) {
let message = {}; let message: any = {};
if(client.config.maintenanceMode){ if(client.config.maintenanceMode){
return interaction.reply({ return interaction.reply({
@ -119,7 +119,8 @@ export default {
voiceChannel: voiceChannel, voiceChannel: voiceChannel,
connection: null, connection: null,
message: null, message: null,
station: station station: station,
startTime: number
}; };
client.radio.set(interaction.guild.id, construct); client.radio.set(interaction.guild.id, construct);

View File

@ -2,11 +2,11 @@ export default {
name: 'prev', name: 'prev',
description: 'Previous Station', description: 'Previous Station',
category: 'radio', category: 'radio',
async execute(interaction, client, command) { async execute(interaction: any, client: any, command: any) {
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);
let index = client.stations.findIndex(station => station.name == radio.station.name) - 1; let index = client.stations.findIndex((station: { name: any; }) => station.name == radio.station.name) - 1;
if(index == -1) index = client.stations.length - 1; if(index == -1) index = client.stations.length - 1;
let station = client.stations[index]; let station = client.stations[index];

View File

@ -5,8 +5,8 @@ export default {
name: 'statistics', name: 'statistics',
description: 'Show statistics', description: 'Show statistics',
category: 'info', category: 'info',
execute(interaction, client) { execute(interaction: any, client: any) {
let message = {}; let message: any = {};
let stations = client.stations; let stations = client.stations;
let currentGuild = client.datastore.getEntry(interaction.guild.id); let currentGuild = client.datastore.getEntry(interaction.guild.id);
let global = client.datastore.getEntry("global"); let global = client.datastore.getEntry("global");

View File

@ -4,8 +4,8 @@ export default {
name: 'status', name: 'status',
description: 'Bot Status', description: 'Bot Status',
category: 'info', category: 'info',
async execute(interaction, client) { async execute(interaction: any, client: any) {
let message = {}; let message: any = {};
message.statusTitle = client.messages.statusTitle.replace("%client.user.username%", client.user.username); message.statusTitle = client.messages.statusTitle.replace("%client.user.username%", client.user.username);
let uptime = client.funcs.msToTime(client.uptime); let uptime = client.funcs.msToTime(client.uptime);

View File

@ -4,7 +4,7 @@ export default {
name: 'stop', name: 'stop',
description: 'Stop radio', description: 'Stop radio',
category: 'radio', category: 'radio',
async execute(interaction, client, command) { async execute(interaction: any, client: any, command: any) {
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.statistics.update(client, interaction.guild, radio); client.statistics.update(client, interaction.guild, radio);

View File

@ -1,7 +1,7 @@
export default { export default {
name: 'emojis', name: 'emojis',
async execute(client) { async execute(client: any): Promise<any> {
let customEmojis = { let customEmojis: any = {
logo: "<:RadioX:688765708808487072>", logo: "<:RadioX:688765708808487072>",
eximiabots: "<:EximiaBots:693277919929303132>", eximiabots: "<:EximiaBots:693277919929303132>",
list: "<:RadioXList:688541155519889482>", list: "<:RadioXList:688541155519889482>",
@ -14,7 +14,7 @@ export default {
next: "<:RadioXNext:882153637474893834>" next: "<:RadioXNext:882153637474893834>"
}; };
let fallbackEmojis = { let fallbackEmojis: any = {
logo: "RadioX", logo: "RadioX",
eximiabots: "EximiaBots", eximiabots: "EximiaBots",
list: "📜", list: "📜",

View File

@ -1,6 +1,6 @@
export default { export default {
name: 'SIGINT', name: 'SIGINT',
execute(client) { execute(client: any) {
client.user.setStatus('dnd'); client.user.setStatus('dnd');
client.streamer.leave(client); client.streamer.leave(client);

View File

@ -1,6 +1,6 @@
export default { export default {
name: 'SIGTERM', name: 'SIGTERM',
execute(client) { execute(client: any) {
process.emit('SIGINT'); process.emit('SIGINT');
} }
} }

View File

@ -2,7 +2,7 @@ import { PermissionFlagsBits } from "discord.js";
export default { export default {
name: 'interactionCreate', name: 'interactionCreate',
async execute(client, interaction) { async execute(client: any, interaction: any) {
const permissions = interaction.channel.permissionsFor(interaction.client.user); const permissions = interaction.channel.permissionsFor(interaction.client.user);
if (!permissions.has(PermissionFlagsBits.ViewChannel)) return; if (!permissions.has(PermissionFlagsBits.ViewChannel)) return;

View File

@ -1,6 +1,8 @@
import { Message } from "discord.js";
export default { export default {
name: 'messageDelete', name: 'messageDelete',
async execute(client, msg) { async execute(client: any, msg: Message) {
if(!msg.author.bot || !msg.guild) return; if(!msg.author.bot || !msg.guild) return;
const radio = client.radio.get(msg.guild.id); const radio = client.radio.get(msg.guild.id);
if(!radio) return; if(!radio) return;

View File

@ -6,7 +6,7 @@ import Statistics from "../classes/Statistics";
export default { export default {
name: 'ready', name: 'ready',
async execute(client) { async execute(client: any) {
client.funcs.logger("Bot", "Ready"); client.funcs.logger("Bot", "Ready");
@ -14,7 +14,7 @@ export default {
client.funcs.logger('Datastore', 'Initialize'); client.funcs.logger('Datastore', 'Initialize');
client.datastore = new Datastore(); client.datastore = new Datastore();
client.datastore.map.forEach(datastore => { client.datastore.map.forEach((datastore: { guild: { id: string; name: string; }; }) => {
client.funcs.logger('Datastore', datastore.guild.id + " / " + datastore.guild.name); client.funcs.logger('Datastore', datastore.guild.id + " / " + datastore.guild.name);
}); });
@ -22,7 +22,7 @@ export default {
/*DEVELOPERS*/ /*DEVELOPERS*/
client.developers = ""; client.developers = "";
let user = ""; let user : any= "";
for (let i = 0; i < client.config.devId.length; i++) { for (let i = 0; i < client.config.devId.length; i++) {
user = await client.users.fetch(client.config.devId[i]); user = await client.users.fetch(client.config.devId[i]);
client.funcs.logger('Developers', user.tag); client.funcs.logger('Developers', user.tag);
@ -59,7 +59,7 @@ export default {
client.funcs.logger('Guilds', 'Started fetching list'); client.funcs.logger('Guilds', 'Started fetching list');
let guilds = await client.guilds.fetch(); let guilds = await client.guilds.fetch();
guilds.forEach(guild => { guilds.forEach((guild: { id: string; name: string; }) => {
client.funcs.logger('Guilds', guild.id + " / " + guild.name); client.funcs.logger('Guilds', guild.id + " / " + guild.name);
}); });

View File

@ -1,6 +1,6 @@
export default { export default {
name: 'uncaughtException', name: 'uncaughtException',
execute(client, error) { execute(client: any, error: any) {
client.funcs.logger("Error"); client.funcs.logger("Error");
console.log(error.stack); console.log(error.stack);
console.log(''); console.log('');

View File

@ -1,4 +1,4 @@
import { PermissionFlagsBits } from "discord.js"; import { PermissionFlagsBits, VoiceState } from "discord.js";
const { const {
getVoiceConnection, getVoiceConnection,
joinVoiceChannel joinVoiceChannel
@ -6,13 +6,13 @@ const {
export default { export default {
name: "voiceStateUpdate", name: "voiceStateUpdate",
async execute(client, oldState, newState) { async execute(client: any, oldState: VoiceState, newState: VoiceState) {
if (oldState.channel === null) return; if (oldState.channel === null) return;
let change = false; let change = false;
const radio = client.radio?.get(newState.guild.id); const radio = client.radio?.get(newState.guild.id);
if (!radio) return; if (!radio) return;
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.statistics.update(client, newState.guild, radio); client.statistics.update(client, newState.guild, radio);
@ -23,14 +23,14 @@ export default {
} }
const newPermissions = newState.channel.permissionsFor(newState.client.user); const newPermissions = newState.channel.permissionsFor(newState.client.user);
if (!newPermissions.has(PermissionFlagsBits.Connect) || !newPermissions.has(PermissionFlagsBits.Speak) || !newPermissions.has(PermissionFlagsBits.ViewChannel)) { if (!newPermissions?.has(PermissionFlagsBits.Connect) || !newPermissions?.has(PermissionFlagsBits.Speak) || !newPermissions?.has(PermissionFlagsBits.ViewChannel)) {
try { try {
setTimeout( setTimeout(
async () => ( async () => (
radio.connection = joinVoiceChannel({ radio.connection = joinVoiceChannel({
channelId: oldState.channel.id, channelId: oldState.channel?.id,
guildId: oldState.channel.guild.id, guildId: oldState.channel?.guild.id,
adapterCreator: oldState.channel.guild.voiceAdapterCreator adapterCreator: oldState.channel?.guild.voiceAdapterCreator
}) })
//radio.connection = await oldState.channel.join() //radio.connection = await oldState.channel.join()
), ),
@ -55,7 +55,7 @@ export default {
if ((oldState.channel.members.filter(member => !member.user.bot).size === 0 && 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.filter(member => !member.user.bot).size === 0) { if (radio.voiceChannel.members.filter((member: { user: { bot: any; }; }) => !member.user.bot).size === 0) {
client.statistics.update(client, newState.guild, radio); client.statistics.update(client, newState.guild, radio);
radio.connection?.destroy(); radio.connection?.destroy();
radio.message?.delete(); radio.message?.delete();

View File

@ -1,6 +1,6 @@
export default { export default {
name: 'warning', name: 'warning',
execute(client, warning) { execute(client: any, warning: any) {
if(warning.name == "ExperimentalWarning" && warning.message.startsWith("stream/web")) return; if(warning.name == "ExperimentalWarning" && warning.message.startsWith("stream/web")) return;
client.funcs.logger("Warning"); client.funcs.logger("Warning");

View File

@ -1,5 +1,5 @@
export default function check(client, interaction, command) { export default function check(client: any, interaction: any, command: any) {
let message = {}; let message: any = {};
const radio = client.radio.get(interaction.guild.id); const radio = client.radio.get(interaction.guild.id);
if(client.config.maintenanceMode){ if(client.config.maintenanceMode){
interaction.reply({ interaction.reply({

View File

@ -1,4 +1,4 @@
export default function isDev(devList, authorID){ export default function isDev(devList : any, authorID : any){
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];

View File

@ -1,10 +1,10 @@
import { ActionRowBuilder, StringSelectMenuBuilder } from "discord.js"; import { ActionRowBuilder, Interaction, StringSelectMenuBuilder } from "discord.js";
export default function listStations(client, interaction){ export default function listStations(client: any, interaction: any){
let stations = new Array(); let stations: any = new Array();
let options = new Array(); let options: any = new Array();
stations = client.stations.forEach(station => { stations = client.stations.forEach((station: { name?: any; owner?: any; label?: any; description?: any; value?: any; }) => {
if(station.name == "GrooveFM") return; if(station.name == "GrooveFM") return;
station = { station = {
label: station.name, label: station.name,

View File

@ -1,4 +1,6 @@
export default function loadState(client, guild){ import { Guild } from "discord.js";
export default function loadState(client: any, guild: Guild){
let data = client.datastore.getEntry(guild.id); let data = client.datastore.getEntry(guild.id);
if(!data) return; if(!data) return;
let state; let state;

View File

@ -1,4 +1,4 @@
export default function logger(area, text){ export default function logger(area : string, text: string){
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');

View File

@ -1,4 +1,4 @@
export default function msToTime(duration) { export default function msToTime(duration : number) {
let seconds = Math.floor((duration / 1000) % 60), let seconds = Math.floor((duration / 1000) % 60),
minutes = Math.floor((duration / (1000 * 60)) % 60), minutes = Math.floor((duration / (1000 * 60)) % 60),
hours = Math.floor((duration / (1000 * 60 * 60)) % 24), hours = Math.floor((duration / (1000 * 60 * 60)) % 24),

View File

@ -1,7 +1,7 @@
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder } from "discord.js"; import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder } from "discord.js";
export default async function play(client, interaction, guild, station) { export default async function play(client: any, interaction: any, guild: any, station: any) {
let message = {}; let message: any = {};
const radio = client.radio.get(guild.id); const radio = client.radio.get(guild.id);
const audioPlayer = client.streamer.listen(station); const audioPlayer = client.streamer.listen(station);
radio.connection.subscribe(audioPlayer); radio.connection.subscribe(audioPlayer);

View File

@ -1,4 +1,4 @@
export default function saveState(client, guild, radio){ export default function saveState(client: any, guild: any, radio: any){
client.datastore.checkEntry(guild.id); client.datastore.checkEntry(guild.id);
let date = new Date(); let date = new Date();