Skip to content

Commit

Permalink
feat: styling and more commands
Browse files Browse the repository at this point in the history
  • Loading branch information
SrIzan10 committed Oct 27, 2022
1 parent 7171d76 commit 0f2479b
Show file tree
Hide file tree
Showing 15 changed files with 1,632 additions and 111 deletions.
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"tabWidth": 2,
"useTabs": true,
"singleQuote": true
}
68 changes: 40 additions & 28 deletions commands/music/loop.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,49 @@
import { commandModule, CommandType, Context, SlashOptions } from '@sern/handler';
import { ApplicationCommandOptionType, Guild, GuildMember, GuildTextBasedChannel, messageLink, VoiceBasedChannel, VoiceChannel, VoiceState } from 'discord.js'
import { commandModule, CommandType } from '@sern/handler';
import { ApplicationCommandOptionType } from 'discord.js';
import { distube } from '../../index.js';
import { publish } from '../../src/plugins/publish.js';

export default commandModule({
type: CommandType.Slash,
plugins: [publish()],
description: 'Loop the song or queue',
options: [
{
name: 'type',
description: '0 for disable, 1 for song, 2 for queue',
type: ApplicationCommandOptionType.Number,
required: true,
min_value: 0,
max_value: 2
}
],
options: [
{
name: 'type',
description: '0 for disable, 1 for song, 2 for queue',
type: ApplicationCommandOptionType.Number,
required: true,
min_value: 0,
max_value: 2,
},
],
//alias : [],
execute: async (ctx) => {
const queue = distube.getQueue(ctx.guild.id)
queue?.setRepeatMode(ctx.interaction.options.getNumber('type') as number)
switch (ctx.interaction.options.getNumber('type') as number) {
case 0:
await ctx.reply({content: "Looping has been disabled.", ephemeral: true});
break;
case 1:
await ctx.reply({content: "From now on, the song playing will be looped!", ephemeral: true});
break;
case 2:
await ctx.reply({content: "From now on, all the queue will be looped!", ephemeral: true});
break;
}

execute: async (ctx) => {
if (ctx.guild.members.me?.voice.channelId) {
const queue = distube.getQueue(ctx.guild);
queue?.setRepeatMode(ctx.interaction.options.getNumber('type') as number);
switch (ctx.interaction.options.getNumber('type') as number) {
case 0:
await ctx.reply({
content: 'Looping has been disabled.',
ephemeral: true,
});
break;
case 1:
await ctx.reply({
content: 'From now on, the song playing will be looped!',
ephemeral: true,
});
break;
case 2:
await ctx.reply({
content: 'From now on, all the queue will be looped!',
ephemeral: true,
});
break;
}
} else {
ctx.reply({ content: "There's no queue!", ephemeral: true });
}
},
});
});
36 changes: 36 additions & 0 deletions commands/music/lyrics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { commandModule, CommandType } from '@sern/handler';
import { EmbedBuilder } from 'discord.js'
import { distube } from '../../index.js';
import { publish } from '../../src/plugins/publish.js';
import Genius from "genius-lyrics";
const genius = new Genius.Client()

export default commandModule({
type: CommandType.Slash,
plugins: [publish()],
description: 'Loop the song or queue',
options: [],
//alias : [],
execute: async (ctx) => {
await ctx.interaction.deferReply({ephemeral: true})
if (ctx.guild.members.me?.voice.channelId) {
const queue = distube.getQueue(ctx.guild)
const search = await genius.songs.search(queue!.songs[0].name as string)
const song = search[0]
let lyrics
try {
lyrics = await song.lyrics()
} catch (error) {
lyrics = "Lyrics not found!"
}
const embed = new EmbedBuilder()
.setColor('Random')
.setAuthor({name: ctx.user.username, iconURL: ctx.user.displayAvatarURL()})
.setTitle(`Lyrics of ${queue!.songs[0].name}`)
.setDescription(lyrics)
await ctx.interaction.editReply({embeds: [embed]})
} else {
await ctx.interaction.editReply({content: "There's no queue!"})
}
},
});
15 changes: 15 additions & 0 deletions commands/music/pause.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { commandModule, CommandType } from '@sern/handler';
import { distube } from '../../index.js';
import { publish } from '../../src/plugins/publish.js';

export default commandModule({
type: CommandType.Slash,
plugins: [publish()],
description: 'Pause the song',
options: [],
execute: async (ctx, options) => {
const queue = distube.getQueue(ctx.guild.id)
queue?.pause()
await ctx.reply({content: `The queue was paused correctly!`, ephemeral: true})
},
});
4 changes: 2 additions & 2 deletions commands/music/play.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { commandModule, CommandType, Context, SlashOptions } from '@sern/handler';
import { ApplicationCommandOptionType, Guild, GuildMember, GuildTextBasedChannel, messageLink, VoiceBasedChannel, VoiceChannel, VoiceState } from 'discord.js'
import { commandModule, CommandType } from '@sern/handler';
import { ApplicationCommandOptionType, GuildMember, GuildTextBasedChannel, VoiceBasedChannel } from 'discord.js'
import { distube } from '../../index.js';
import { publish } from '../../src/plugins/publish.js';

Expand Down
21 changes: 21 additions & 0 deletions commands/music/queue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { commandModule, CommandType } from '@sern/handler';
import { EmbedBuilder } from 'discord.js';
import { Song } from 'distube';
import { distube } from '../../index.js';
import { publish } from '../../src/plugins/publish.js';

export default commandModule({
type: CommandType.Slash,
plugins: [publish()],
description: 'See the current queue',
options: [],
execute: async (ctx, options) => {
const queue = distube.getQueue(ctx.guild.id)
const embed = new EmbedBuilder()
.setAuthor({name: ctx.user.username, iconURL: ctx.user.displayAvatarURL()})
.setColor('Random')
.setTitle('Current queue')
.setDescription(`${queue!.songs.map((song: Song, id: number) => `**${id + 1}**. [${song.name}](${song.url}) - \`${song.formattedDuration}\``)}`)
await ctx.reply({embeds: [embed], ephemeral: true})
},
});
15 changes: 15 additions & 0 deletions commands/music/resume.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { commandModule, CommandType } from '@sern/handler';
import { distube } from '../../index.js';
import { publish } from '../../src/plugins/publish.js';

export default commandModule({
type: CommandType.Slash,
plugins: [publish()],
description: 'Resume the song',
options: [],
execute: async (ctx, options) => {
const queue = distube.getQueue(ctx.guild.id)
queue?.resume()
await ctx.reply({content: `The queue was resumed correctly!`, ephemeral: true})
},
});
15 changes: 15 additions & 0 deletions commands/music/shuffle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { commandModule, CommandType } from '@sern/handler';
import { distube } from '../../index.js';
import { publish } from '../../src/plugins/publish.js';

export default commandModule({
type: CommandType.Slash,
plugins: [publish()],
description: 'Shuffle the queue',
options: [],
execute: async (ctx, options) => {
const queue = distube.getQueue(ctx.guild.id)
await queue?.shuffle()
await ctx.reply({content: `The queue was shuffled correctly!`, ephemeral: true})
},
});
15 changes: 15 additions & 0 deletions commands/music/stop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { commandModule, CommandType } from '@sern/handler';
import { distube } from '../../index.js';
import { publish } from '../../src/plugins/publish.js';

export default commandModule({
type: CommandType.Slash,
plugins: [publish()],
description: 'Stop the song',
options: [],
execute: async (ctx, options) => {
const queue = distube.getQueue(ctx.guild.id)
await queue?.stop()
await ctx.reply({content: `The queue was stopped correctly!`, ephemeral: true})
},
});
6 changes: 3 additions & 3 deletions events/distube/addSong.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { eventModule, EventType } from "@sern/handler";
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, ComponentType, GuildMember, TextChannel } from "discord.js";
import { GuildMember, TextChannel } from "discord.js";
import { Queue, Song } from "distube";

export default eventModule({
type: EventType.External,
emitter: 'DisTube',
execute: async (queue: Queue, song: Song, member: GuildMember) => {
await (queue.textChannel as TextChannel).send({content: `[${song.name}](${song.url}) was added to the queue by ${member}`})
execute: async (queue: Queue, song: Song) => {
await (queue.textChannel as TextChannel).send({content: `${song.name} (<${song.url}>) was added to the queue by ${song.member?.user}!`})
}
})
Loading

0 comments on commit 0f2479b

Please sign in to comment.