Skip to content

Commit

Permalink
fix: build failed in some devices
Browse files Browse the repository at this point in the history
add: initial support for /radio command (not usable)
  • Loading branch information
RainyXeon committed Sep 11, 2024
1 parent 2127711 commit 8ef39ae
Show file tree
Hide file tree
Showing 7 changed files with 439 additions and 6 deletions.
125 changes: 125 additions & 0 deletions src/commands/Music/Radio.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import { ActionRowBuilder, ApplicationCommandOptionType, ComponentType, EmbedBuilder, StringSelectMenuBuilder, StringSelectMenuOptionBuilder } from 'discord.js'
import { Manager } from '../../manager.js'
import { Accessableby, Command } from '../../structures/Command.js'
import { CommandHandler } from '../../structures/CommandHandler.js'
import { RadioStationNewInterface } from '../../utilities/RadioStations.js'

// Main code
export default class implements Command {
public name = ['radio']
public description = 'Play radio in voice channel'
public category = 'Music'
public accessableby = [Accessableby.Member]
public usage = '<radio_number>'
public aliases = ['ra']
public lavalink = false
public playerCheck = false
public usingInteraction = true
public sameVoiceCheck = false
public permissions = []
public options = [
{
name: "number",
description: "The number of radio to choose the radio station",
type: ApplicationCommandOptionType.Number,
required: false,
},
];

public async execute(client: Manager, handler: CommandHandler) {
await handler.deferReply()
const radioList = RadioStationNewInterface()
const radioListKeys = Object.keys(radioList)

const pages: EmbedBuilder[] = []
for (let i = 0; i < radioListKeys.length; i++) {
const radioListKey = radioListKeys[i];
const stringArray = radioList[radioListKey]
const converted = this.stringConverter(stringArray)

const embed = new EmbedBuilder()
.setAuthor({
name: `List all radio avaliable in ${radioListKey}`,
iconURL: handler.user?.displayAvatarURL(),
})
.setColor(client.color)
.addFields(converted)

pages.push(embed)
}

const providerSelector = (disable: boolean) => new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(
new StringSelectMenuBuilder()
.setCustomId('provider')
.setPlaceholder('Choose a provider / country to get radio id list')
.addOptions(this.getOptionBuilder(radioListKeys))
.setDisabled(disable)
)

const msg = await handler.editReply({
embeds: [pages[0]],
components: [providerSelector(false)]
})

const collector = msg.createMessageComponentCollector({
componentType: ComponentType.StringSelect,
time: 60000
})

collector.on('collect', async (message): Promise<void> => {
const providerId = Number(message.values[0])
const providerName = radioListKeys[providerId]
const getEmbed = pages[providerId]
await msg.edit({ embeds: [getEmbed] })

const replyEmbed = new EmbedBuilder()
.setColor(client.color)
.setDescription(`\`✅\` | Moved to **${providerName}**`)

const msgReply = await message
.reply({
embeds: [replyEmbed],
ephemeral: true
})
.catch(() => {})
if (msgReply)
setTimeout(() => msgReply.delete().catch(() => {}), client.config.utilities.DELETE_MSG_TIMEOUT)
})

collector.on('end', async () => {
// @ts-ignore
collector.removeAllListeners()
await msg.edit({
components: [providerSelector(false)]
})
})
}

protected getOptionBuilder(radioListKeys: string[]) {
const result = []
for (let i = 0; i < radioListKeys.length; i++) {
const key = radioListKeys[i];
result.push(
new StringSelectMenuOptionBuilder()
.setLabel(key)
.setValue(String(i))
)
}
return result
}

protected stringConverter(array: { no: number, name: string, link: string}[]) {
const radioStrings = []
for (let i = 0; i < array.length; i++) {
const radio = array[i]
radioStrings.push(
{
name: `**${String(radio.no).padEnd(3)}** ${radio.name}`,
value: " ",
inline: true
}
)
}
return radioStrings
}
}
4 changes: 2 additions & 2 deletions src/commands/Premium/Generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export default class implements Command {

const plan = name

let time
let time: number | 'lifetime'
switch (plan) {
case 'daily':
time = Date.now() + 86400000
Expand Down Expand Up @@ -138,7 +138,7 @@ export default class implements Command {
codes_length: String(codes.length),
codes: codes.join('\n'),
plan: String(plan),
expires: time == 'lifetime' ? 'lifetime' : `<t:${(time / 1000 ?? 0).toFixed()}:F>`,
expires: time == 'lifetime' ? 'lifetime' : `<t:${(time / 1000).toFixed()}:F>`,
})}`
)
.setTimestamp()
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Premium/GuildProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default class implements Command {
expires:
PremiumPlan!.expiresAt == 'lifetime'
? 'lifetime'
: `<t:${(PremiumPlan.expiresAt / 1000 ?? 0).toFixed()}:F>`,
: `<t:${(PremiumPlan.expiresAt / 1000).toFixed()}:F>`,
})}`
)
.setColor(client.color)
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Premium/Profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default class implements Command {
expires:
PremiumPlan!.expiresAt == 'lifetime'
? 'lifetime'
: `<t:${(PremiumPlan.expiresAt / 1000 ?? 0).toFixed()}:F>`,
: `<t:${(PremiumPlan.expiresAt / 1000).toFixed()}:F>`,
})}`
)
.setColor(client.color)
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Premium/Redeem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export default class implements Command {
`${client.i18n.get(handler.language, 'command.premium', 'redeem_desc', {
expires:
premium.expiresAt !== 'lifetime'
? `<t:${(premium.expiresAt / 1000 ?? 0).toFixed()}:F>`
? `<t:${(premium.expiresAt / 1000).toFixed()}:F>`
: 'lifetime',
plan: premium.plan,
})}`
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/loadPlayerEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class PlayerEventLoader {

async loader() {
await chillout.forEach(['player', 'track', 'node'], async (path) => {
let eventsPath = resolve(join(__dirname, '..', '..', 'events', path))
let eventsPath = resolve(join(__dirname, '..', 'events', path))
let eventsFile = await readdirRecursive(eventsPath)
await this.registerPath(eventsFile)
})
Expand Down
Loading

0 comments on commit 8ef39ae

Please sign in to comment.