Skip to content

Commit

Permalink
✨ add some commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Nich87 committed Dec 3, 2023
1 parent a2e0e4d commit ef93b21
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Events/onMessageCreate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { changeVolumeCommand } from '../commands/changeVolume';
import { helpCommand } from '../commands/help';
import { loopCommand } from '../commands/loop';
import { nowplayingCommand } from '../commands/nowplaying';
import { pauseCommand } from '../commands/pause';
import { playCommand } from '../commands/play';
import { queueCommand } from '../commands/queue';
Expand Down Expand Up @@ -41,6 +43,12 @@ export async function onMessageCreate(message: Message) {
case 'help':
helpCommand(message);
break;
case 'volume':
changeVolumeCommand(message);
break;
case 'nowplaying':
nowplayingCommand(message);
break;
default:
message.reply({
embeds: [
Expand Down
18 changes: 18 additions & 0 deletions src/Utils/songResolver.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { format_count, seconds_to_time } from '../Utils/NumberUtil';
import { EmbedBuilder } from 'discord.js';
import ytdl from 'ytdl-core';

export function songResolver(info: ytdl.videoInfo, requestedBy?: string, requestedByAvatar?: string) {
Expand All @@ -14,3 +15,20 @@ export function songResolver(info: ytdl.videoInfo, requestedBy?: string, request
requestedByAvatar: requestedByAvatar ?? ''
};
}

export async function getSongInfo(url: string) {
const info = await ytdl.getInfo(url);
const song = songResolver(info);

const embed = new EmbedBuilder()
.setTitle(song.title)
.setURL(song.url)
.setThumbnail(song.thumbnail)
.addFields(
{ name: '投稿者', value: `[${song.author}](${song.authorUrl})` },
{ name: '再生時間', value: song.duration, inline: true },
{ name: '再生回数', value: song.views, inline: true }
);

return { embeds: [embed] };
}
19 changes: 19 additions & 0 deletions src/commands/changeVolume.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { player } from './play';
import { Message } from 'discord.js';

export async function changeVolumeCommand(message: Message) {
if (typeof player === 'undefined') return message.reply({ content: '動画が再生されていません。' });
if (!message.content.split(' ')[1]) return message.reply({ content: `現在の音量は${player.volume}です。` });
if (Number(message.content.split(' ')[1]) > 100) {
player.changeVolume(100 / 10);
return message.reply({ content: 'ボリュームを最大に設定しました。' });
}

if (Number(message.content.split(' ')[1]) < 0) {
player.changeVolume(0 / 10);
return message.reply({ content: 'ミュートに設定しました。' });
}

player.changeVolume(Number(message.content.split(' ')[1]) / 10);
return message.reply({ content: `ボリュームを${player.volume * 10}に変更しました。` });
}
12 changes: 12 additions & 0 deletions src/commands/nowplaying.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { getSongInfo } from '../Utils/songResolver';
import { queueManager, Queue } from '../classes/queue';
import { player } from './play';
import { Message } from 'discord.js';

export async function nowplayingCommand(message: Message) {
if (typeof player === 'undefined') return message.reply({ content: '動画が再生されていません。' });
const queue = queueManager.getQueue(message.guild?.id as string) as Queue<string>;
if (!queue.currentSong) return message.reply({ content: 'キューに曲がありません。' });
const info = await getSongInfo(queue.currentSong);
return message.reply(info);
}

0 comments on commit ef93b21

Please sign in to comment.