-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(music): initilize module with
@necord/lavalink
Commands - play - join - leave - stop - pause - resume
- Loading branch information
1 parent
cfaa648
commit 1aee1ea
Showing
38 changed files
with
1,539 additions
and
21 deletions.
There are no files selected for viewing
Submodule Lavalink
updated
6 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
version: "3.8" | ||
|
||
services: | ||
bot: | ||
container_name: ndbot | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { Injectable } from "@nestjs/common"; | ||
import { | ||
ChannelType, | ||
Client, | ||
GuildMember, | ||
PermissionResolvable, | ||
} from "discord.js"; | ||
import { Context, ContextOf, On } from "necord"; | ||
|
||
@Injectable() | ||
export class VoiceStateUpdateEvents { | ||
public constructor(private readonly client: Client) {} | ||
|
||
@On("voiceChannelJoin") | ||
public async onVoiceChannelJoin( | ||
@Context() [member, channel]: ContextOf<"voiceChannelJoin">, | ||
) { | ||
if ( | ||
this.checkMember(member) && | ||
this.checkPermission(member, "DeafenMembers") | ||
) { | ||
await member.voice.setDeaf(true); | ||
} | ||
|
||
if ( | ||
channel.type === ChannelType.GuildStageVoice && | ||
this.checkPermission(member, "Speak") | ||
) { | ||
await member.voice.setSuppressed(false); | ||
} | ||
} | ||
|
||
// TODO: Auto leave if everyone leaves or is deafened | ||
@On("voiceChannelLeave") | ||
public async onVoiceChannelLeave( | ||
@Context() [member, channel]: ContextOf<"voiceChannelLeave">, | ||
) { | ||
if (this.checkMember(member) && !channel) { | ||
} | ||
} | ||
|
||
// TODO: Anti undeafen | ||
@On("voiceChannelUndeaf") | ||
public async onVoiceChannelUndeaf( | ||
@Context() [member, type]: ContextOf<"voiceChannelUndeaf">, | ||
) { | ||
console.log("undeaf"); | ||
if (this.checkMember(member)) { | ||
console.log("undeaf bot"); | ||
member.voice.setDeaf(true); | ||
} | ||
} | ||
|
||
private checkMember(member: GuildMember): boolean { | ||
return member.id === this.client.user?.id; | ||
} | ||
|
||
private checkPermission( | ||
member: GuildMember, | ||
permission: PermissionResolvable, | ||
): boolean { | ||
return member.permissions.has(permission); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export * from "./Gateway"; | ||
export * from "./Guild"; | ||
export * from "./NDC"; | ||
export * from "./Thread"; | ||
export * from "./VoiceStateUpdate"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { localizationMapByKey } from "@necord/localization"; | ||
import { createCommandGroupDecorator } from "necord"; | ||
|
||
export const MusicCommand = createCommandGroupDecorator({ | ||
name: "music", | ||
description: "Category 🎵 Music", | ||
nameLocalizations: localizationMapByKey("Music.category.name"), | ||
descriptionLocalizations: localizationMapByKey("Music.category.description"), | ||
dmPermission: false, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
import { | ||
LOCALIZATION_ADAPTER, | ||
NestedLocalizationAdapter, | ||
} from "@necord/localization"; | ||
import { Inject, Injectable } from "@nestjs/common"; | ||
import { | ||
Client, | ||
EmbedBuilder, | ||
Guild, | ||
VoiceChannel, | ||
channelMention, | ||
} from "discord.js"; | ||
import { IMusicEmbeds } from "./interfaces"; | ||
|
||
@Injectable() | ||
export class MusicEmbeds implements IMusicEmbeds { | ||
public constructor( | ||
@Inject(LOCALIZATION_ADAPTER) | ||
private readonly translate: NestedLocalizationAdapter, | ||
private readonly client: Client, | ||
) {} | ||
|
||
public async PlayerCreateEmbed( | ||
guild: Guild, | ||
textChannelId: string, | ||
voiceChannelId: string, | ||
): Promise<EmbedBuilder> { | ||
return new EmbedBuilder() | ||
.setAuthor({ | ||
name: guild.name, | ||
iconURL: guild.iconURL(), | ||
}) | ||
.setColor("#00c26f") | ||
.setTitle( | ||
this.translate.getTranslation( | ||
"Events.PlayerEvents.playerCreate.Embed.Title", | ||
guild.preferredLocale, | ||
), | ||
) | ||
.setFields([ | ||
{ | ||
name: this.translate.getTranslation( | ||
"Events.PlayerEvents.playerCreate.Embed.Fields.1", | ||
guild.preferredLocale, | ||
), | ||
value: this.translate.getTranslation( | ||
"Events.PlayerEvents.playerCreate.Embed.Fields.Content.1", | ||
guild.preferredLocale, | ||
{ TEXT: channelMention(textChannelId) }, | ||
), | ||
inline: true, | ||
}, | ||
{ | ||
name: this.translate.getTranslation( | ||
"Events.PlayerEvents.playerCreate.Embed.Fields.3", | ||
guild.preferredLocale, | ||
), | ||
value: this.translate.getTranslation( | ||
"Events.PlayerEvents.playerCreate.Embed.Fields.Content.3", | ||
guild.preferredLocale, | ||
{ VOICE: channelMention(voiceChannelId) }, | ||
), | ||
}, | ||
]) | ||
.setFooter({ | ||
text: this.translate.getTranslation( | ||
"Events.PlayerEvents.playerCreate.Embed.Footer", | ||
guild.preferredLocale, | ||
), | ||
iconURL: this.client.user.displayAvatarURL(), | ||
}) | ||
.setTimestamp(); | ||
} | ||
|
||
public async PlayerMoveKickEmbed( | ||
guildLocale: string, | ||
voiceChannelId: string, | ||
): Promise<EmbedBuilder> { | ||
const voiceChannel = (await this.client.channels.fetch( | ||
voiceChannelId, | ||
)) as VoiceChannel; | ||
return new EmbedBuilder() | ||
.setAuthor({ | ||
name: this.client.user.tag, | ||
url: this.client.user.displayAvatarURL(), | ||
}) | ||
.setColor("#00c26f") | ||
.setTitle( | ||
this.translate.getTranslation( | ||
"Events/PlayerEvents:playerMove:KickEmbed:Title", | ||
guildLocale, | ||
), | ||
) | ||
.setDescription( | ||
this.translate.getTranslation( | ||
"Events/PlayerEvents:playerMove:KickEmbed:Description", | ||
guildLocale, | ||
{ CHANNEL: voiceChannel.name }, | ||
), | ||
) | ||
.setFooter({ | ||
text: this.translate.getTranslation( | ||
"Events/PlayerEvents:playerMove:KickEmbed:Footer", | ||
guildLocale, | ||
), | ||
}) | ||
.setTimestamp(); | ||
} | ||
|
||
public async QueueEndAutoLeaveEmbed( | ||
guildLocale: string, | ||
voiceChannelId: string, | ||
timer: string, | ||
): Promise<EmbedBuilder> { | ||
const voiceChannel = (await this.client.channels.fetch( | ||
voiceChannelId, | ||
)) as VoiceChannel; | ||
return new EmbedBuilder() | ||
.setAuthor({ | ||
name: this.client.user.tag, | ||
url: this.client.user.displayAvatarURL(), | ||
}) | ||
.setColor("#00c26f") | ||
.setTitle( | ||
this.translate.getTranslation( | ||
"Events.PlayerEvents.playerMove.queueEnd.Title", | ||
guildLocale, | ||
), | ||
) | ||
.setDescription( | ||
this.translate.getTranslation( | ||
"Events.PlayerEvents.playerMove.queueEnd.Description", | ||
guildLocale, | ||
{ CHANNEL: voiceChannel.name, Timer: timer }, | ||
), | ||
) | ||
.setFooter({ | ||
text: this.translate.getTranslation( | ||
"Events.PlayerEvents.playerMove.queueEnd.Footer", | ||
guildLocale, | ||
{ TIMER: timer }, | ||
), | ||
}) | ||
.setTimestamp(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Global, Module } from "@nestjs/common"; | ||
import * as CommandsMap from "./commands"; | ||
import * as EventsMap from "./events"; | ||
import * as ProvidersMap from "./types/providers"; | ||
const Commands = Object.values(CommandsMap); | ||
const Events = Object.values(EventsMap); | ||
const Providers = Object.values(ProvidersMap); | ||
|
||
@Global() | ||
@Module({ | ||
providers: [...Commands, ...Events, ...Providers], | ||
}) | ||
export class MusicModule {} |
Oops, something went wrong.