39 lines
1.5 KiB
TypeScript
39 lines
1.5 KiB
TypeScript
import { ButtonInteraction, Guild } from "discord.js";
|
|
import { lavalinkManager } from "../../index";
|
|
import { checkTextChannelAndMsg, getTextChannelAndMsg } from "./Channel";
|
|
import { default_content, default_embed, default_image, getButtons } from "./Config";
|
|
import { DB } from "../Database";
|
|
|
|
export const buttonInteraction = (interaction: ButtonInteraction, args: string[]) => {
|
|
if (!interaction.guild) return;
|
|
let player = lavalinkManager.getPlayer(interaction.guild.id);
|
|
if (player) {
|
|
if (args[0] === "pause") player.setPause();
|
|
if (args[0] === "stop") player.stop();
|
|
if (args[0] === "skip") player.skip();
|
|
if (args[0] === "shuffle") player.setShuffle();
|
|
if (args[0] === "recommend") player.setRecommend();
|
|
} else {
|
|
if (args[0] === "recommend") buttonRecommend(interaction.guild);
|
|
}
|
|
return interaction.deferUpdate().catch(() => {});
|
|
}
|
|
|
|
const buttonRecommend = async (guild: Guild) => {
|
|
const gdb = DB.guild.get(guild.id);
|
|
const change = gdb ? DB.guild.update({...gdb, options: { ...gdb.options, recommend: !gdb.options.recommend }}) : false;
|
|
if (!change) return;
|
|
const { channel: getChannel, msg: getMsg, reason } = await getTextChannelAndMsg(guild);
|
|
if (reason || !getChannel || !getMsg) return;
|
|
const { msg, check } = await checkTextChannelAndMsg(guild, getChannel, getMsg);
|
|
if (!check) return;
|
|
await msg.edit({
|
|
content: default_content,
|
|
embeds: [ default_embed(guild.id) ],
|
|
components: [ getButtons() ],
|
|
files: [ default_image ],
|
|
}).catch((err) => {
|
|
console.error(err);
|
|
return null;
|
|
});
|
|
} |