Skip to content

Commit

Permalink
๐Ÿชง added constant Embeds
Browse files Browse the repository at this point in the history
  • Loading branch information
Nich87 committed Dec 3, 2023
1 parent 736567e commit 2c21bd8
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 104 deletions.
9 changes: 2 additions & 7 deletions src/Events/onMessageCreate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Builder } from '../Utils/Builder';
import { commands } from '../commands';
import { embeds } from '../embeds';
import { Message, Awaitable } from 'discord.js';

const prefix = 'ts!';
Expand Down Expand Up @@ -56,12 +56,7 @@ export async function onMessageCreate(message: Message): Promise<Awaitable<void>
commands.nowplaying(message);
break;
default:
message.reply(
new Builder()
.addFields({ name: 'Error', value: 'ไธๆ˜Žใชใ‚ณใƒžใƒณใƒ‰ใ‹ใ‚ณใƒžใƒณใƒ‰ใŒๆŒ‡ๅฎšใ•ใ‚Œใฆใ„ใพใ›ใ‚“ใ€‚' })
.setColor('Red')
.build()
);
message.reply(embeds.unknownCommand);
break;
}
}
5 changes: 3 additions & 2 deletions src/commands/debug.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { songResolver } from '../Utils/songResolver';
import { embeds } from '../embeds';
import { Message } from 'discord.js';
import ytdl from 'ytdl-core';

export async function debugCommand(message: Message) {
const url = message.content.split(' ')[1];
if (!url) {
return message.reply({ content: 'URLใ‚’ๆŒ‡ๅฎšใ—ใฆใใ ใ•ใ„ใ€‚' });
return message.reply(embeds.noUrl);
}
if (!ytdl.validateURL(url)) {
return message.reply({ content: '็„กๅŠนใชURLใงใ™ใ€‚' });
return message.reply(embeds.invaildUrl);
}
const info = await ytdl.getInfo(url);
console.table(songResolver(info));
Expand Down
19 changes: 2 additions & 17 deletions src/commands/help.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
import { Builder } from '../Utils/Builder';
import { embeds } from '../embeds';
import { Message } from 'discord.js';

export async function helpCommand(message: Message): Promise<void> {
message.reply(
new Builder()
.setTitle('Help')
.setColor('Blue')
.addFields(
{ name: 'play', value: '้Ÿณๆฅฝใ‚’ๅ†็”Ÿใ—ใพใ™ใ€‚' },
{ name: 'queue', value: 'ใ‚ญใƒฅใƒผใ‚’่กจ็คบใ—ใพใ™ใ€‚' },
{ name: 'loop', value: 'ใƒซใƒผใƒ—ใ‚’ใ‚ชใƒณ/ใ‚ชใƒ•ใซใ—ใพใ™ใ€‚' },
{ name: 'skip', value: '็พๅœจใฎๆ›ฒใ‚’ใ‚นใ‚ญใƒƒใƒ—ใ—ใพใ™ใ€‚' },
{ name: 'stop', value: 'ๅ†็”Ÿใ‚’ๅœๆญขใ—ใพใ™ใ€‚' },
{ name: 'pause', value: 'ๅ†็”Ÿใ‚’ไธ€ๆ™‚ๅœๆญขใ—ใพใ™ใ€‚' },
{ name: 'resume', value: 'ๅ†็”Ÿใ‚’ๅ†้–‹ใ—ใพใ™ใ€‚' },
{ name: 'help', value: 'ใ“ใฎใƒกใƒƒใ‚ปใƒผใ‚ธใ‚’่กจ็คบใ—ใพใ™ใ€‚' }
)
.build()
);
message.reply(embeds.help);
}
10 changes: 4 additions & 6 deletions src/commands/loop.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Builder } from '../Utils/Builder';
import { queueManager, Queue } from '../classes/queue';
import { embeds } from '../embeds';
import { player } from './play';
import { Message } from 'discord.js';

export async function loopCommand(message: Message, args: string[]) {
if (typeof player === 'undefined') return message.reply({ content: 'ๅ‹•็”ปใŒๅ†็”Ÿใ•ใ‚Œใฆใ„ใพใ›ใ‚“ใ€‚' });
if (typeof player === 'undefined') return message.reply(embeds.videoNotPlaying);
const queue = queueManager.queues.get(message.guildId!) as Queue;
args = args.filter((arg) => arg !== '');
if (args.length === 0) {
Expand All @@ -21,12 +21,10 @@ export async function loopCommand(message: Message, args: string[]) {
queue?.setLoop('track');
break;
default:
message.reply(
new Builder().addFields({ name: 'Error', value: 'ใ‚ณใƒžใƒณใƒ‰ใŒ่ฆ‹ใคใ‹ใ‚Šใพใ›ใ‚“ใงใ—ใŸใ€‚' }).setColor('Red').build()
);
message.reply(embeds.commandNotFound);
break;
}
}

message.reply(new Builder().addFields({ name: 'Looping', value: queue.loop! }).setColor('Green').build());
message.reply(embeds.embed.addFields({ name: 'Looping', value: queue.loop! }).setColor('Green').build());
}
5 changes: 3 additions & 2 deletions src/commands/nowplaying.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { getSongInfo } from '../Utils/songResolver';
import { queueManager, Queue } from '../classes/queue';
import { embeds } from '../embeds';
import { player } from './play';
import { Message } from 'discord.js';

export async function nowplayingCommand(message: Message) {
if (typeof player === 'undefined') return message.reply({ content: 'ๅ‹•็”ปใŒๅ†็”Ÿใ•ใ‚Œใฆใ„ใพใ›ใ‚“ใ€‚' });
if (typeof player === 'undefined') return message.reply(embeds.videoNotPlaying);
const queue = queueManager.getQueue(message.guild?.id as string) as Queue;
if (!queue.currentSong) return message.reply({ content: 'ใ‚ญใƒฅใƒผใซๆ›ฒใŒใ‚ใ‚Šใพใ›ใ‚“ใ€‚' });
if (!queue.currentSong) return message.reply(embeds.queueEmpty);
const info = await getSongInfo(queue.currentSong);
return message.reply(info);
}
16 changes: 5 additions & 11 deletions src/commands/pause.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
import { Builder } from '../Utils/Builder';
import { embeds } from '../embeds';
import { player } from './play';
import { AudioPlayerStatus } from '@discordjs/voice';
import { Message } from 'discord.js';

export async function pauseCommand(message: Message) {
if (typeof player === 'undefined') return message.reply({ content: 'ๅ‹•็”ปใŒๅ†็”Ÿใ•ใ‚Œใฆใ„ใพใ›ใ‚“ใ€‚' });
if (typeof player === 'undefined') return message.reply(embeds.videoNotPlaying);

if (player.player.state.status === AudioPlayerStatus.Playing) {
player.pause();
message.reply(
new Builder().addFields({ name: 'Success', value: 'ๅ‹•็”ปใ‚’ไธ€ๆ™‚ๅœๆญขใ—ใพใ—ใŸใ€‚' }).setColor('Green').build()
);
message.reply(embeds.videoPaused);
} else if (player.player.state.status === AudioPlayerStatus.Paused) {
player.resume();
message.reply(
new Builder().addFields({ name: 'Success', value: 'ๅ‹•็”ปใ‚’ๅ†้–‹ใ—ใพใ—ใŸใ€‚' }).setColor('Green').build()
);
message.reply(embeds.videoResumed);
} else {
message.reply(
new Builder().addFields({ name: 'Info', value: 'ๅ‹•็”ปใŒๅ†็”Ÿใ•ใ‚Œใฆใ„ใพใ›ใ‚“ใ€‚' }).setColor('Yellow').build()
);
message.reply(embeds.videoNotPlaying);
}
}
36 changes: 8 additions & 28 deletions src/commands/play.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Builder } from '../Utils/Builder';
import { YTPlayer } from '../classes/player';
import { Queue, queueManager } from '../classes/queue';
import { embeds } from '../embeds';
import { Message, ChannelType, VoiceBasedChannel } from 'discord.js';
import ytdl from 'ytdl-core';

Expand All @@ -22,38 +22,18 @@ export async function playCommand(message: Message) {
}
url = message.content.split(' ')[1];
const channel = message.member?.voice.channel;
if (!url)
return message.reply(
new Builder().addFields({ name: 'Error', value: 'URLใ‚’ๆŒ‡ๅฎšใ—ใฆใใ ใ•ใ„' }).setColor('Red').build()
);

if (!ytdl.validateURL(url))
return message.reply(new Builder().addFields({ name: 'Error', value: '็„กๅŠนใชURLใงใ™ใ€‚' }).setColor('Red').build());

if (!channel)
return message.reply(
new Builder()
.addFields({ name: 'Error', value: 'ใƒœใ‚คใ‚นใƒใƒฃใƒณใƒใƒซใซๅ‚ๅŠ ใ—ใฆใ‹ใ‚‰ๅฎŸ่กŒใ—ใฆใใ ใ•ใ„ใ€‚' })
.setColor('Red')
.build()
);

if (!url) return message.reply(embeds.noUrl);
if (!ytdl.validateURL(url)) return message.reply(embeds.invaildUrl);
if (!channel) return message.reply(embeds.voiceChannelJoin);
if (channel.type !== ChannelType.GuildVoice) return;
if (!channel.joinable)
return message.reply(
new Builder().addFields({ name: 'Error', value: 'ใ“ใฎใƒใƒฃใƒณใƒใƒซใซๅ‚ๅŠ ใงใใพใ›ใ‚“ใ€‚' }).setColor('Red').build()
);

if (!channel.speakable)
return message.reply(
new Builder().addFields({ name: 'Error', value: 'ใ“ใฎใƒใƒฃใƒณใƒใƒซใงๅ–‹ใ‚Œใพใ›ใ‚“ใ€‚' }).setColor('Red').build()
);
if (!channel.joinable) return message.reply(embeds.voiceChannnelJoined);
if (!channel.speakable) return message.reply(embeds.voiceChannnelPermission);

if (!queue.length || !player.isPlaying) {
queue.addSong(url);
const info = await ytdl.getInfo(url);
message.reply(
new Builder()
embeds.embed
.setTitle('Success')
.setDescription(`**[${info.videoDetails.title}](${info.videoDetails.video_url})ใ‚’ๅ†็”Ÿใ—ใพใ™ใ€‚**`)
.addFields({
Expand All @@ -69,7 +49,7 @@ export async function playCommand(message: Message) {
queue.addSong(url);
const info = await ytdl.getInfo(url);
message.reply(
new Builder()
embeds.embed
.setTitle('Info')
.setDescription(`**[${info.videoDetails.title}](${info.videoDetails.video_url})ใ‚’ใ‚ญใƒฅใƒผใซ่ฟฝๅŠ ใ—ใพใ—ใŸใ€‚**`)
.addFields({
Expand Down
13 changes: 5 additions & 8 deletions src/commands/queue.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import { Builder } from '../Utils/Builder';
import { songResolver } from '../Utils/songResolver';
import { Queue, queueManager } from '../classes/queue';
import { embeds } from '../embeds';
import { player } from './play';
import { Message } from 'discord.js';
import ytdl from 'ytdl-core';

export async function queueCommand(message: Message) {
if (typeof player === 'undefined') return message.reply({ content: 'ๅ‹•็”ปใŒๅ†็”Ÿใ•ใ‚Œใฆใ„ใพใ›ใ‚“ใ€‚' });
if (typeof player === 'undefined') return message.reply(embeds.videoNotPlaying);
const queue = queueManager.getQueue(message.guildId!) as Queue;
if (!queue.length) {
return message.reply(
new Builder().addFields({ name: 'Info', value: 'ใ‚ญใƒฅใƒผใŒ็ฉบใงใ™ใ€‚' }).setColor('Yellow').build()
);
}
const embed = new Builder().setTitle('Queue').setColor('Blue').setTimestamp();
if (!queue.length) return message.reply(embeds.queueEmpty);

const embed = embeds.embed.setTitle('Queue').setColor('Blue').setTimestamp();
for (let i = 0; i < queue.length; i++) {
const url = queue.store[i];
const info = await ytdl.getInfo(url);
Expand Down
16 changes: 5 additions & 11 deletions src/commands/resume.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
import { Builder } from '../Utils/Builder';
import { embeds } from '../embeds';
import { player } from './play';
import { AudioPlayerStatus } from '@discordjs/voice';
import { Message } from 'discord.js';

export async function resumeCommand(message: Message) {
if (typeof player === 'undefined') return message.reply({ content: 'ๅ‹•็”ปใŒๅ†็”Ÿใ•ใ‚Œใฆใ„ใพใ›ใ‚“ใ€‚' });
if (typeof player === 'undefined') return message.reply(embeds.videoNotPlaying);
if (player.player.state.status === AudioPlayerStatus.Paused) {
player.resume();
message.reply(
new Builder().addFields({ name: 'Success', value: 'ๅ‹•็”ปใ‚’ๅ†้–‹ใ—ใพใ—ใŸใ€‚' }).setColor('Green').build()
);
message.reply(embeds.videoResumed);
} else if (player.player.state.status === AudioPlayerStatus.Playing) {
message.reply(
new Builder().addFields({ name: 'Info', value: 'ๅ‹•็”ปใŒไธ€ๆ™‚ๅœๆญขใ•ใ‚Œใฆใ„ใพใ›ใ‚“ใ€‚' }).setColor('Yellow').build()
);
message.reply(embeds.videoNotPaused);
} else {
message.reply(
new Builder().addFields({ name: 'Info', value: 'ๅ‹•็”ปใŒๅ†็”Ÿใ•ใ‚Œใฆใ„ใพใ›ใ‚“ใ€‚' }).setColor('Yellow').build()
);
message.reply(embeds.videoNotPlaying);
}
}
11 changes: 3 additions & 8 deletions src/commands/skip.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import { Builder } from '../Utils/Builder';
import { Queue, queueManager } from '../classes/queue';
import { embeds } from '../embeds';
import { player } from './play';
import { Message } from 'discord.js';

export async function skipCommand(message: Message) {
if (typeof player === 'undefined') return message.reply({ content: 'ๅ‹•็”ปใŒๅ†็”Ÿใ•ใ‚Œใฆใ„ใพใ›ใ‚“ใ€‚' });
if (typeof player === 'undefined') return message.reply(embeds.videoNotPlaying);
const queue = queueManager.queues.get(message.guildId!) as Queue;

if (!queue.length) {
return message.reply(
new Builder().addFields({ name: 'Info', value: 'ใ‚ญใƒฅใƒผใŒ็ฉบใงใ™ใ€‚' }).setColor('Yellow').build()
);
}
if (!queue.length) return message.reply(embeds.queueEmpty);
player.skip();
}
6 changes: 2 additions & 4 deletions src/commands/stop.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { Builder } from '../Utils/Builder';
import { queueManager } from '../classes/queue';
import { embeds } from '../embeds';
import { Message } from 'discord.js';

export async function stopCommand(message: Message): Promise<void> {
if (message.guild?.members.me?.voice.channel) {
message.guild.members.me.voice.disconnect();
message.reply(
new Builder().addFields({ name: 'Success', value: 'ๅ†็”Ÿใ‚’ๅœๆญขใ—ใพใ—ใŸใ€‚' }).setColor('Green').build()
);
message.reply(embeds.videoStopped);
}

queueManager.queues.delete(message.guildId!);
Expand Down
59 changes: 59 additions & 0 deletions src/embeds/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Builder } from '../Utils/Builder';

export const embeds = {
embed: new Builder(),
help: new Builder()
.setTitle('Help')
.setColor('Blue')
.addFields(
{ name: 'play', value: '้Ÿณๆฅฝใ‚’ๅ†็”Ÿใ—ใพใ™ใ€‚' },
{ name: 'queue', value: 'ใ‚ญใƒฅใƒผใ‚’่กจ็คบใ—ใพใ™ใ€‚' },
{ name: 'loop', value: 'ใƒซใƒผใƒ—ใ‚’ใ‚ชใƒณ/ใ‚ชใƒ•ใซใ—ใพใ™ใ€‚' },
{ name: 'skip', value: '็พๅœจใฎๆ›ฒใ‚’ใ‚นใ‚ญใƒƒใƒ—ใ—ใพใ™ใ€‚' },
{ name: 'stop', value: 'ๅ†็”Ÿใ‚’ๅœๆญขใ—ใพใ™ใ€‚' },
{ name: 'pause', value: 'ๅ†็”Ÿใ‚’ไธ€ๆ™‚ๅœๆญขใ—ใพใ™ใ€‚' },
{ name: 'resume', value: 'ๅ†็”Ÿใ‚’ๅ†้–‹ใ—ใพใ™ใ€‚' },
{ name: 'help', value: 'ใ“ใฎใƒกใƒƒใ‚ปใƒผใ‚ธใ‚’่กจ็คบใ—ใพใ™ใ€‚' }
)
.build(),
videoNotPlaying: new Builder()
.addFields({ name: 'Info', value: 'ๅ‹•็”ปใŒๅ†็”Ÿใ•ใ‚Œใฆใ„ใพใ›ใ‚“ใ€‚' })
.setColor('Yellow')
.build(),
videoResumed: new Builder().addFields({ name: 'Success', value: 'ๅ‹•็”ปใ‚’ๅ†้–‹ใ—ใพใ—ใŸใ€‚' }).setColor('Green').build(),
videoPaused: new Builder()
.addFields({ name: 'Success', value: 'ๅ‹•็”ปใ‚’ไธ€ๆ™‚ๅœๆญขใ—ใพใ—ใŸใ€‚' })
.setColor('Green')
.build(),
videoNotPaused: new Builder()
.addFields({ name: 'Info', value: 'ๅ‹•็”ปใฏไธ€ๆ™‚ๅœๆญขใ•ใ‚Œใฆใ„ใพใ›ใ‚“ใ€‚' })
.setColor('Yellow')
.build(),
videoStopped: new Builder().addFields({ name: 'Success', value: 'ๅ‹•็”ปใ‚’ๅœๆญขใ—ใพใ—ใŸใ€‚' }).setColor('Green').build(),
noUrl: new Builder().addFields({ name: 'Error', value: 'URLใ‚’ๆŒ‡ๅฎšใ—ใฆใใ ใ•ใ„ใ€‚' }).setColor('Red').build(),
invaildUrl: new Builder()
.addFields({ name: 'Error', value: 'ๆœ‰ๅŠนใชURLใ‚’ๆŒ‡ๅฎšใ—ใฆใใ ใ•ใ„ใ€‚' })
.setColor('Red')
.build(),
voiceChannnelPermission: new Builder()
.addFields({ name: 'Error', value: 'ใƒœใ‚คใ‚นใƒใƒฃใƒณใƒใƒซใซๅ‚ๅŠ ใ™ใ‚‹ๆจฉ้™ใŒใ‚ใ‚Šใพใ›ใ‚“ใ€‚' })
.setColor('Red')
.build(),
voiceChannnelJoined: new Builder()
.addFields({ name: 'Error', value: 'ใƒœใ‚คใ‚นใƒใƒฃใƒณใƒใƒซใซๆ—ขใซๅ‚ๅŠ ใ—ใฆใ„ใพใ™ใ€‚' })
.setColor('Red')
.build(),
queueEmpty: new Builder().addFields({ name: 'Error', value: 'ใ‚ญใƒฅใƒผใŒ็ฉบใงใ™ใ€‚' }).setColor('Red').build(),
unknownCommand: new Builder()
.addFields({ name: 'Error', value: 'ไธๆ˜Žใชใ‚ณใƒžใƒณใƒ‰ใ‹ใ‚ณใƒžใƒณใƒ‰ใŒๆŒ‡ๅฎšใ•ใ‚Œใฆใ„ใพใ›ใ‚“ใ€‚' })
.setColor('Red')
.build(),
voiceChannelJoin: new Builder()
.addFields({ name: 'Error', value: 'ใƒœใ‚คใ‚นใƒใƒฃใƒณใƒใƒซใซๅ‚ๅŠ ใ—ใฆใ‹ใ‚‰ๅฎŸ่กŒใ—ใฆใใ ใ•ใ„ใ€‚' })
.setColor('Red')
.build(),
commandNotFound: new Builder()
.addFields({ name: 'Error', value: 'ใ‚ณใƒžใƒณใƒ‰ใŒ่ฆ‹ใคใ‹ใ‚Šใพใ›ใ‚“ใงใ—ใŸใ€‚' })
.setColor('Red')
.build()
};

0 comments on commit 2c21bd8

Please sign in to comment.