switch.ts
1 import { AmethystCommand, log4js, preconditions } from "amethystjs"; 2 import { buildLocalizations, getRandomStation, resolveName } from "../utils/functions"; 3 import playing from "../preconditions/playing"; 4 import adminIfNotAlone from "../preconditions/adminIfNotAlone"; 5 import { ApplicationCommandOptionType } from "discord.js"; 6 import { stations } from "../cache/stations"; 7 import { players, playlists } from "../cache/players"; 8 import { buildResource } from "../utils/playerUtils"; 9 10 const locals = buildLocalizations('switch') 11 export default new AmethystCommand({ 12 name: 'switch', 13 description: "Switch to another music station", 14 preconditions: [preconditions.GuildOnly, playing, adminIfNotAlone], 15 options: [ 16 { 17 name: 'station', 18 description: "Station to switch to", 19 required: false, 20 type: ApplicationCommandOptionType.String, 21 autocomplete: true, 22 nameLocalizations: locals.options.station.name, 23 descriptionLocalizations: locals.options.station.description 24 } 25 ], 26 nameLocalizations: locals.name, 27 descriptionLocalizations: locals.description 28 }).setChatInputRun(async({ interaction, client, options }) => { 29 await interaction.deferReply().catch(log4js.trace); 30 const station = stations[options.getString('station')] ?? getRandomStation(); 31 32 const queue = players.get(interaction.guild.id); 33 34 const pl = playlists.get(interaction.guild.id) ?? [] 35 const newPlaylist = [station, ...pl]; 36 37 playlists.set(interaction.guild.id, newPlaylist); 38 queue.player.stop(true); 39 40 interaction.editReply(client.langs.getText(interaction, 'switch', 'switched', { 41 stationName: resolveName(station), 42 stationEmoji: station.emoji, 43 stationUrl: station.url 44 })).catch(log4js.trace); 45 })