Typescript Continue

This commit is contained in:
Christer Warén
2023-06-06 01:39:35 +03:00
parent 7acabe411b
commit 2d17c33d21
32 changed files with 233 additions and 149 deletions

View File

@ -6,6 +6,11 @@ export default {
description: 'Report a bug',
category: 'info',
async execute(interaction: ChatInputCommandInteraction, client: RadioClient) {
if(!client.user) return interaction.reply({
content: client.messageEmojis["error"] + client.messages.maintenance,
ephemeral: true
});
let message : any = {};
message.bugTitle = client.messages.bugTitle.replace("%client.user.username%", client.user.username);

View File

@ -6,6 +6,12 @@ export default {
description: 'Get help using bot',
category: 'info',
execute(interaction: ChatInputCommandInteraction, client: RadioClient) {
if(!client.user) return interaction.reply({
content: client.messageEmojis["error"] + client.messages.maintenance,
ephemeral: true
});
let message: any = {};
const categories : any= [];
@ -14,10 +20,10 @@ export default {
}
let commands = '';
for (let i = 0; i < categories.length; i++) {
commands += `**» ${categories[i].toUpperCase()}**\n${client.commands.filter((x: { category: any; omitFromHelp: any; }) => x.category === categories[i] && !x.omitFromHelp).map((x: { name: any; }) => `\`${x.name}\``).join(', ')}\n`;
commands += `**» ${categories[i].toUpperCase()}**\n${client.commands.filter(x => x.category === categories[i]).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 || "-");
message.helpDescription = client.messages.helpDescription.replace("%commands%", commands);
const embed = new EmbedBuilder()

View File

@ -6,6 +6,12 @@ export default {
description: 'Invite Bot',
category: 'info',
execute(interaction: ChatInputCommandInteraction, client: RadioClient) {
if(!client.user) return interaction.reply({
content: client.messageEmojis["error"] + client.messages.maintenance,
ephemeral: true
});
let message: any = {};
message.inviteTitle = client.messages.inviteTitle.replace("%client.user.username%", client.user.username);
const embed = new EmbedBuilder()

View File

@ -16,7 +16,7 @@ export default {
});
}
const radio = client.radio?.get(interaction.guild.id);
const radio = client.radio?.get(interaction.guild?.id);
if(radio && !client.config.maintenanceMode){
client.funcs.listStations(client, interaction);

View File

@ -1,4 +1,4 @@
import { ActionRowBuilder, ButtonInteraction, ChatInputCommandInteraction, ColorResolvable, EmbedBuilder, StringSelectMenuBuilder, StringSelectMenuInteraction } from "discord.js";
import { ActionRowBuilder, AnyComponentBuilder, APIActionRowComponent, APISelectMenuOption, ButtonInteraction, ChatInputCommandInteraction, ColorResolvable, EmbedBuilder, StringSelectMenuBuilder, StringSelectMenuInteraction } from "discord.js";
import RadioClient from "../../Client";
import Streamer from "../classes/Streamer";
import commands from "../commands";
@ -17,62 +17,95 @@ export default {
content: client.messageEmojis["error"] + client.messages.notAllowed,
ephemeral: true
});
let action = interaction.options?.getNumber("action") ?? interaction.values?.[0];
const options: any = new Array(
let action : number | string | null = null;
if(interaction.isChatInputCommand()){
action = interaction.options?.getNumber("action");
}
if(interaction.isStringSelectMenu()){
action = interaction.values?.[0];
}
const options: APISelectMenuOption[] = new Array(
{
emoji: "🌀",
emoji: {
"name": "🌀",
},
label: "Restart Bot",
value: "0"
},
{
emoji: "<:RadioXStop:688541155377414168>",
emoji: {
id: "688541155377414168",
name: "RadioXStop",
},
label: "Save Radios",
value: "4"
},
{
emoji: "<:RadioXPlay:688541155712827458>",
emoji: {
id: "688541155712827458",
name: "RadioXPlay",
},
label: "Restore Radios",
value: "5"
},
{
emoji: "#️⃣",
emoji: {
name: "#️⃣",
},
label: "Reload Commands",
value: "6"
},
{
emoji: "<:RadioXList:688541155519889482>",
emoji: {
id: "688541155519889482",
name: "RadioXList",
},
label: "Reload Stations",
value: "7"
},
{
emoji: "<:dnd:746069698139127831>",
emoji: {
id: "746069698139127831",
name: "dnd",
},
label: "Enable Maintenance Mode",
value: "8"
},
{
emoji: "<:online:746069731836035098>",
emoji: {
id: "746069731836035098",
name: "online",
},
label: "Disable Maintenance Mode",
value: "9"
},
{
emoji: "💤",
emoji: {
name: "💤",
},
label: "Streamer Mode - Manual",
value: "10"
},
{
emoji: "📡",
emoji: {
name: "📡",
},
label: "Streamer Mode - Auto",
value: "11"
}
);
const menu = new ActionRowBuilder()
.addComponents(
new StringSelectMenuBuilder()
.setCustomId('maintenance')
.setPlaceholder('Select action')
.addOptions(options)
);
const menu : ActionRowBuilder<any> = new ActionRowBuilder()
.addComponents(
new StringSelectMenuBuilder()
.setCustomId('maintenance')
.setPlaceholder('Select action')
.addOptions(options)
);
if(!action){
return interaction.reply({
@ -82,12 +115,12 @@ export default {
});
}
client.funcs.logger('Maintenance', options.find((option: { value: any; }) => option.value == action).label);
client.funcs.logger('Maintenance', options.find((option: APISelectMenuOption) => option.value == action)?.label);
const embed = new EmbedBuilder()
.setTitle(client.messages.maintenanceTitle)
.setColor(client.config.embedColor as ColorResolvable)
.setDescription(options.find((option: { value: any; }) => option.value == action).label)
.setDescription(options.find((option: APISelectMenuOption) => option.value == action)?.label || "-")
.setFooter({
text: client.messages.footerText,
iconURL: "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, '')
@ -107,43 +140,43 @@ export default {
break;
case "4":
client.config.maintenanceMode = true;
client.user.setStatus('idle');
client.radio.save(client);
client.user.setStatus('online');
client.user?.setStatus('idle');
client.radio?.save(client);
client.user?.setStatus('online');
client.config.maintenanceMode = false;
break;
case "5":
client.config.maintenanceMode = true;
client.user.setStatus('idle');
client.radio.restore(client, guilds);
client.user.setStatus('online');
client.user?.setStatus('idle');
client.radio?.restore(client, guilds);
client.user?.setStatus('online');
client.config.maintenanceMode = false;
break;
case "6":
client.config.maintenanceMode = true;
client.user.setStatus('idle');
client.user?.setStatus('idle');
commands.execute(client);
client.user.setStatus('online');
client.user?.setStatus('online');
client.config.maintenanceMode = false;
break;
case "7":
try {
client.stations.fetch({
client.stations?.fetch({
url: client.config.stationslistUrl
});
client.streamer.refresh(client);
client.streamer?.refresh(client);
} catch (error) {
}
break;
case "8":
client.user.setStatus('dnd');
client.user?.setStatus('dnd');
client.funcs.logger("Maintenance Mode", "Enabled");
client.config.maintenanceMode = true;
break;
case "9":
client.user.setStatus('online');
client.user?.setStatus('online');
client.funcs.logger("Maintenance Mode", "Disabled");
client.config.maintenanceMode = false;
break;
@ -151,17 +184,17 @@ export default {
client.config.streamerMode = "manual";
client.config.maintenanceMode = true;
client.user.setStatus('idle');
client.radio.save(client);
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);
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.radio?.restore(client, guilds);
client.user?.setStatus('online');
client.config.maintenanceMode = false;
}
@ -175,17 +208,17 @@ export default {
client.config.streamerMode = "auto";
client.config.maintenanceMode = true;
client.user.setStatus('idle');
client.radio.save(client);
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);
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.user?.setStatus('online');
client.config.maintenanceMode = false;
}

View File

@ -1,5 +1,6 @@
import { ButtonInteraction, ChatInputCommandInteraction, StringSelectMenuInteraction } from "discord.js";
import RadioClient from "../../Client";
import { station } from "../classes/Stations"
export default {
name: 'next',
@ -7,10 +8,15 @@ export default {
category: 'radio',
async execute(interaction: ButtonInteraction | ChatInputCommandInteraction | StringSelectMenuInteraction, client: RadioClient, command: any) {
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: { name: any; }) => station.name == radio.station.name) + 1;
if(index == client.stations.length) index = 0;
if(!client.stations) return interaction.reply({
content: client.messageEmojis["error"] + client.messages.maintenance,
ephemeral: true
});
let index: number = client.stations.findIndex((station: station) => station.name == radio.station.name) + 1;
if(index == client.stations?.length) index = 0;
let station = client.stations[index];
@ -19,7 +25,7 @@ export default {
ephemeral: true
});
client.statistics.update(client, interaction.guild, radio);
client.statistics?.update(client, interaction.guild, radio);
let date = new Date();
radio.station = station;

View File

@ -6,9 +6,9 @@ export default {
description: 'Current Radio Station',
category: 'radio',
async execute(interaction: ButtonInteraction | ChatInputCommandInteraction | StringSelectMenuInteraction, client: RadioClient, command: any) {
if (client.funcs.check(client, interaction, command)) {
if(client.funcs.check(client, interaction, command)) {
let message: any = {};
const radio = client.radio?.get(interaction.guild.id);
const radio = client.radio?.get(interaction.guild?.id);
let date = new Date();
radio.currentTime = date.getTime();

View File

@ -1,4 +1,4 @@
import { ApplicationCommandOptionType, ButtonInteraction, ChatInputCommandInteraction, PermissionFlagsBits, StringSelectMenuInteraction } from "discord.js";
import { ApplicationCommandOptionType, ChatInputCommandInteraction, GuildMember, PermissionFlagsBits, StringSelectMenuInteraction } from "discord.js";
import { getVoiceConnection, joinVoiceChannel } from "@discordjs/voice";
import RadioClient from "../../Client";
@ -10,16 +10,9 @@ export default {
{ type: ApplicationCommandOptionType.String, name: "query", description: "Select station", required: false}
],
category: "radio",
async execute(interaction: ButtonInteraction | ChatInputCommandInteraction | StringSelectMenuInteraction, client: RadioClient) {
async execute(interaction: ChatInputCommandInteraction | StringSelectMenuInteraction, client: RadioClient) {
let message: any = {};
if(client.config.maintenanceMode){
return interaction.reply({
content: client.messageEmojis["error"] + client.messages.maintenance,
ephemeral: true
});
}
if(!client.stations) {
message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace("%client.config.supportGuild%", client.config.supportGuild);
return interaction.reply({
@ -28,13 +21,23 @@ export default {
});
}
let query = interaction.options?.getString("query") ?? interaction.values?.[0];
let query : number | string | null = null;
if(interaction.isChatInputCommand()){
query = interaction.options?.getNumber("query");
}
if(interaction.isStringSelectMenu()){
query = interaction.values?.[0];
}
if(!query){
return client.funcs.listStations(client, interaction);
}
const radio = client.radio.get(interaction.guild.id);
const voiceChannel = interaction.member.voice.channel;
const radio = client.radio?.get(interaction.guild?.id);
if(!(interaction.member instanceof GuildMember)) return;
const voiceChannel = interaction.member?.voice.channel;
if (!voiceChannel) return interaction.reply({
content: client.messageEmojis["error"] + client.messages.noVoiceChannel,
ephemeral: true
@ -50,13 +53,13 @@ export default {
ephemeral: true
});
const permissions = voiceChannel.permissionsFor(interaction.client.user);
if (!permissions.has(PermissionFlagsBits.Connect)) {
if (!permissions?.has(PermissionFlagsBits.Connect)) {
return interaction.reply({
content: client.messageEmojis["error"] + client.messages.noPermsConnect,
ephemeral: true
});
}
if (!permissions.has(PermissionFlagsBits.Speak)) {
if (!permissions?.has(PermissionFlagsBits.Speak)) {
return interaction.reply({
content: client.messageEmojis["error"] + client.messages.noPermsSpeak,
ephemeral: true
@ -64,7 +67,7 @@ export default {
}
let station;
if (!isNaN(query)) {
if (typeof query === 'number') {
const number = parseInt((query - 1) as unknown as string);
if (number > client.stations.length - 1) {
return interaction.reply({
@ -75,17 +78,20 @@ export default {
station = client.stations[number];
}
} else {
if (query.length < 3) return interaction.reply({
if(!(typeof query === 'string')) return;
if(query.length < 3) return interaction.reply({
content: client.messageEmojis["error"] + client.messages.tooShortSearch,
ephemeral: true
});
let type = "";
if(interaction.values?.[0]){
type = "direct";
} else {
type = "text";
if(interaction.isStringSelectMenu()){
if(interaction.values?.[0]){
type = "direct";
} else {
type = "text";
}
}
const sstation = await client.stations.search(query, type);
@ -97,7 +103,7 @@ export default {
}
if (radio) {
client.statistics.update(client, interaction.guild, radio);
client.statistics?.update(client, interaction.guild, radio);
let date = new Date();
radio.station = station;
@ -117,7 +123,7 @@ export default {
station: station,
startTime: date.getTime()
};
client.radio.set(interaction.guild.id, construct);
client.radio?.set(interaction.guild?.id, construct);
try {
const connection =
@ -130,11 +136,11 @@ export default {
construct.connection = connection;
let date = new Date();
construct.startTime = date.getTime();
client.datastore.checkEntry(interaction.guild.id);
client.datastore?.checkEntry(interaction.guild?.id);
client.funcs.play(client, interaction, interaction.guild, station);
} catch (error) {
console.log(error);
client.radio.delete(interaction.guild.id);
client.radio?.delete(interaction.guild?.id);
return interaction.reply({
content: client.messageEmojis["error"] + `An error occured: ${error}`,
ephemeral: true

View File

@ -1,6 +1,7 @@
import { ButtonInteraction, ChatInputCommandInteraction, StringSelectMenuInteraction } from "discord.js";
import RadioClient from "../../Client";
import { command } from "../commands";
import { station } from "../classes/Stations"
export default {
name: 'prev',
@ -8,9 +9,14 @@ export default {
category: 'radio',
async execute(interaction: ButtonInteraction | ChatInputCommandInteraction | StringSelectMenuInteraction, client: RadioClient, command: 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: { name: any; }) => station.name == radio.station.name) - 1;
if(!client.stations) return interaction.reply({
content: client.messageEmojis["error"] + client.messages.maintenance,
ephemeral: true
});
let index = client.stations.findIndex((station: station) => station.name == radio.station.name) - 1;
if(index == -1) index = client.stations.length - 1;
let station = client.stations[index];
@ -20,7 +26,7 @@ export default {
ephemeral: true
});
client.statistics.update(client, interaction.guild, radio);
client.statistics?.update(client, interaction.guild, radio);
let date = new Date();
radio.station = station;

View File

@ -8,6 +8,12 @@ export default {
category: 'info',
execute(interaction: ButtonInteraction | ChatInputCommandInteraction | StringSelectMenuInteraction, client: RadioClient) {
let message: any = {};
if(!interaction.guild) return interaction.reply({
content: client.messageEmojis["error"] + client.messages.maintenance,
ephemeral: true
});
let stations = client.stations;
let currentGuild = client.datastore?.getEntry(interaction.guild.id);
let global = client.datastore?.getEntry("global");

View File

@ -8,20 +8,25 @@ export default {
async execute(interaction: any, client: RadioClient) {
let message: any = {};
if(!client.user) return interaction.reply({
content: client.messageEmojis["error"] + client.messages.maintenance,
ephemeral: true
});
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 || 0);
const embed = new EmbedBuilder()
.setTitle(message.statusTitle)
.setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["logo"].replace(/[^0-9]+/g, ''))
.setColor(client.config.embedColor as ColorResolvable)
.addFields(
.addFields([
{ name: client.messages.statusField1, value: uptime },
{ name: client.messages.statusField2, value: client.config.version },
{ name: client.messages.statusField3, value: Date.now() - interaction.createdTimestamp + "ms" },
{ name: client.messages.statusField4, value: client.ws.ping.toString() },
{ name: client.messages.statusField5, value: client.config.hostedBy }
)
])
.setImage('https://waren.io/berriabot-temp-sa7a36a9xm6837br/images/empty-3.png')
.setFooter({
text: client.messages.footerText,

View File

@ -7,13 +7,13 @@ export default {
category: 'radio',
async execute(interaction: ButtonInteraction | ChatInputCommandInteraction | StringSelectMenuInteraction, client: RadioClient, command: any) {
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);
radio.connection?.destroy();
client.funcs.logger('Radio', interaction.guild.id + " / " + 'Stop');
client.funcs.logger('Radio', interaction.guild?.id + " / " + 'Stop');
const embed = new EmbedBuilder()
.setTitle(client.user.username)
.setTitle(client.user?.username || "-")
.setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["stop"].replace(/[^0-9]+/g, ''))
.setColor(client.config.embedColor as ColorResolvable)
.addFields({
@ -40,7 +40,7 @@ export default {
await radio.message?.delete();
}, 5000);
client.radio?.delete(interaction.guild.id);
client.radio?.delete(interaction.guild?.id);
interaction.reply({
content: client.messageEmojis["stop"] + client.messages.stop,