Skip to content

Commit

Permalink
chore: Update pnpm-lock.yaml and util/embed.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Fyphen1223 authored May 27, 2024
1 parent 84c0c5b commit af0fb71
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 49 deletions.
48 changes: 13 additions & 35 deletions commands/music/pause.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
const config = require('../../config.json');

const { getLocale } = require('../../lang/lang.js');
const { createMessageEmbed } = require('../../util/embed.js');
const { parseTimeToSeconds } = require('../../util/time.js');
const {
createMessageEmbed,
createMusicEmbed,
createButton,
} = require('../../util/embed.js');

const guilds = require('../../data/guilds.json');

const {
SlashCommandBuilder,
ButtonBuilder,
ButtonStyle,
ActionRowBuilder,
EmbedBuilder,
} = require('discord.js');
const { SlashCommandBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder().setName('pause').setDescription('Pause music'),
async execute(interaction) {
await interaction.deferReply();

const guildId = interaction.guild.id;
if (!interaction.member.voice.channelId || !globalThis.queue[guildId]) {
const noValidVCEmbed = createMessageEmbed(
Expand All @@ -43,36 +39,18 @@ module.exports = {
}
}

const time = interaction.options.getString('time');

const seconds = parseTimeToSeconds(time);
if (!seconds) {
const invalidTimeEmbed = createMessageEmbed(
getLocale(guilds[guildId].locale).vc.invalidFormat,
interaction
);
await interaction.editReply({ embeds: [invalidTimeEmbed] });
return;
}
await globalThis.queue[guildId].player.get();
if (
seconds >
globalThis.queue[guildId].queue[globalThis.queue[guildId].index].data.info
.length
) {
const embed = createMessageEmbed(
getLocale(guilds[guildId].locale).vc.outOfLength,
interaction
);
await interaction.editReply({ embeds: [embed] });
return;
}
globalThis.queue[guildId].player.seek(seconds * 1000);
await globalThis.queue[guildId].player.pause();
const embed = createMessageEmbed(
getLocale(guilds[guildId].locale).vc.seeked.replace('{time}', time),
getLocale(guilds[guildId].locale).vc.paused,
interaction
);
await interaction.editReply({ embeds: [embed] });
const panel = await createMusicEmbed(guildId);
await globalThis.queue[guildId].panel.edit({
embeds: [panel],
components: createButton('pause'),
});
return;
},
};
13 changes: 0 additions & 13 deletions commands/music/play.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,11 @@ module.exports = {
async execute(interaction) {
const guildId = interaction.guild.id;

//Add guild queue to the global queue and node
if (!globalThis.queue[interaction.guild.id]) {
globalThis.queue.add(interaction.guild.id);
globalThis.queue[guildId].node = globalThis.Tsumi.getIdealNode();
}

// Check if the user is in a voice channel
if (!interaction.member.voice.channelId) {
const noValidVCEmbed = createMessageEmbed(
getLocale(guilds[guildId].locale).vc.noVC,
Expand All @@ -113,7 +111,6 @@ module.exports = {

const query = interaction.options.getString('query');

//Join channel first
if (!globalThis.queue[guildId].voiceChannel) {
globalThis.queue[guildId].textChannel = interaction.channel;
globalThis.queue[guildId].voiceChannel = interaction.member.voice.channel;
Expand All @@ -130,7 +127,6 @@ module.exports = {
listenEvents(guildId);
}

//そもそもVCに未参加
if (!query && globalThis.queue[guildId].isEmpty()) {
const noQueryEmbed = createMessageEmbed(
getLocale(guilds[guildId].locale).vc.joined,
Expand All @@ -140,15 +136,6 @@ module.exports = {
return;
}

/*
1. そもそもVCに未参加
2. キューがないかつクエリがない
3. キューがあるかつクエリがない
4. キューがあるかつクエリがある
5. キューがないかつクエリがある
*/

// クエリが無いがキューは空ではない
if (!query && !globalThis.queue[guildId].isEmpty()) {
globalThis.queue[guildId].index = 0;
globalThis.queue[guildId].player.play({
Expand Down
54 changes: 54 additions & 0 deletions commands/music/resume.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const { getLocale } = require('../../lang/lang.js');
const {
createMessageEmbed,
createMusicEmbed,
createButton,
} = require('../../util/embed.js');

const guilds = require('../../data/guilds.json');

const { SlashCommandBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder().setName('resume').setDescription('Resume music'),
async execute(interaction) {
await interaction.deferReply();
const guildId = interaction.guild.id;
if (!interaction.member.voice.channelId || !globalThis.queue[guildId]) {
const noValidVCEmbed = createMessageEmbed(
getLocale(guilds[guildId].locale).vc.noVC,
interaction
);
await interaction.editReply({ embeds: [noValidVCEmbed] });
return;
}

if (globalThis.queue[guildId].voiceChannel) {
if (
globalThis.queue[guildId].voiceChannel.id !==
interaction.member.voice.channelId
) {
const differentVCEmbed = createMessageEmbed(
getLocale(guilds[guildId].locale).vc.differentVC,
interaction
);
await interaction.editReply({ embeds: [differentVCEmbed] });
return;
}
}

await globalThis.queue[guildId].player.get();
await globalThis.queue[guildId].player.resume();
const embed = createMessageEmbed(
getLocale(guilds[guildId].locale).vc.resumed,
interaction
);
await interaction.editReply({ embeds: [embed] });
const panel = await createMusicEmbed(guildId);
await globalThis.queue[guildId].panel.edit({
embeds: [panel],
components: createButton('resume'),
});
return;
},
};
4 changes: 3 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
"skipped": "⏭️ - Skipped the current song.",
"noMoreToBack": "🚫 - There are no more songs to go back.",
"backed": "⏮️ - Went back to the previous song.",
"queueStarted": "⏯ - Queue has started."
"queueStarted": "⏯ - Queue has started.",
"paused": "⏸️ - Paused the music.",
"resumed": "▶️ - Resumed the music."
},
"ping": "Pong! Current Ping is {ping}ms."
}

0 comments on commit af0fb71

Please sign in to comment.