mirror of
https://github.com/kirameki-cafe/Yumi.git
synced 2026-09-13 10:49:20 +00:00
Formatted code
This commit is contained in:
@@ -29,8 +29,8 @@
|
||||
"title": "🔧 Maintenance",
|
||||
"description": "{bot_username} will be down for maintenance\nThe maintenance includes feature improvement to bug fixes\n\nDuring the maintenance, {bot_username}'s commands and features will be unavailable",
|
||||
"fields": [
|
||||
{ "name": "Start", "value": "<t:1812519286:R>", "inline": true},
|
||||
{ "name": "End", "value": "<t:3390442486:R>", "inline": true}
|
||||
{ "name": "Start", "value": "<t:1812519286:R>", "inline": true },
|
||||
{ "name": "End", "value": "<t:3390442486:R>", "inline": true }
|
||||
],
|
||||
"thumbnail": {
|
||||
"url": "bot_avatar"
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import HTTP_STATUS from "../../../libs/HTTPStatus";
|
||||
import Environment from "../../../providers/Environment";
|
||||
import App from "../../../providers/App";
|
||||
import HTTP_STATUS from '../../../libs/HTTPStatus';
|
||||
import Environment from '../../../providers/Environment';
|
||||
import App from '../../../providers/App';
|
||||
|
||||
class HealthCheck {
|
||||
public static async perform(req: any, res: any, next: any) {
|
||||
Promise.resolve().then(async () => {
|
||||
Promise.resolve()
|
||||
.then(async () => {
|
||||
return res.status(HTTP_STATUS.OK).json({
|
||||
status: "OK",
|
||||
status: 'OK',
|
||||
environment: Environment.get().NODE_ENV,
|
||||
version: App.versionNumber,
|
||||
uptime: process.uptime(),
|
||||
@@ -15,7 +16,8 @@ class HealthCheck {
|
||||
pid: process.pid,
|
||||
ppid: process.ppid
|
||||
});
|
||||
}).catch(next);
|
||||
})
|
||||
.catch(next);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,11 +9,7 @@ import {
|
||||
} from 'discord.js';
|
||||
|
||||
import DiscordModule, { HybridInteractionMessage } from '../../utils/DiscordModule';
|
||||
import {
|
||||
makeInfoEmbed,
|
||||
makeErrorEmbed,
|
||||
sendHybridInteractionMessageResponse
|
||||
} from '../../utils/DiscordMessage';
|
||||
import { makeInfoEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse } from '../../utils/DiscordMessage';
|
||||
|
||||
import DiscordMusicPlayer from '../../providers/DiscordMusicPlayer';
|
||||
import Users from '../../services/Users';
|
||||
@@ -140,34 +136,26 @@ export default class Debug extends DiscordModule {
|
||||
},
|
||||
activeMusicPlayer: async (data: HybridInteractionMessage) => {
|
||||
await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [
|
||||
EMBEDS.ACTIVE_MUSIC_PLAYERS(data, DiscordMusicPlayer.GuildQueue)
|
||||
]
|
||||
embeds: [EMBEDS.ACTIVE_MUSIC_PLAYERS(data, DiscordMusicPlayer.GuildQueue)]
|
||||
});
|
||||
},
|
||||
myData: async (data: HybridInteractionMessage) => {
|
||||
const userData = await Cache.getCachedUser(user.id);
|
||||
await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [
|
||||
EMBEDS.YOUR_USER_DATA(data, userData)
|
||||
]
|
||||
embeds: [EMBEDS.YOUR_USER_DATA(data, userData)]
|
||||
});
|
||||
},
|
||||
guildData: async (data: HybridInteractionMessage) => {
|
||||
const guildData = await Cache.getCachedGuild(guild.id);
|
||||
await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [
|
||||
EMBEDS.GUILD_DATA(data, guildData)
|
||||
]
|
||||
embeds: [EMBEDS.GUILD_DATA(data, guildData)]
|
||||
});
|
||||
},
|
||||
invalidInteraction: async (data: HybridInteractionMessage) => {
|
||||
const row = new ActionRowBuilder<ButtonBuilder>().addComponents([
|
||||
new ButtonBuilder()
|
||||
.setEmoji('😥')
|
||||
.setLabel(
|
||||
' Make invalid interaction (Wait 7 seconds, check error in console or logs)'
|
||||
)
|
||||
.setLabel(' Make invalid interaction (Wait 7 seconds, check error in console or logs)')
|
||||
.setCustomId('dev_make_invalid_interaction')
|
||||
.setStyle(ButtonStyle.Primary)
|
||||
]);
|
||||
|
||||
@@ -53,17 +53,14 @@ const EMBEDS = {
|
||||
|
||||
if (!payload.timestamp) payload.timestamp = Date.now();
|
||||
|
||||
if (payload.thumbnail?.url === 'bot_avatar')
|
||||
payload.thumbnail.url = `${user?.displayAvatarURL()}?size=4096`;
|
||||
if (payload.thumbnail?.url === 'bot_avatar') payload.thumbnail.url = `${user?.displayAvatarURL()}?size=4096`;
|
||||
|
||||
if (payload.image?.url === 'bot_avatar')
|
||||
payload.image.url = `${user?.displayAvatarURL()}?size=4096`;
|
||||
if (payload.image?.url === 'bot_avatar') payload.image.url = `${user?.displayAvatarURL()}?size=4096`;
|
||||
|
||||
if (payload.description)
|
||||
payload.description = payload.description.replaceAll('{bot_username}', user?.username!);
|
||||
|
||||
if (payload.color && isNaN(payload.color))
|
||||
payload.color = hexToDecimal(payload.color.toString());
|
||||
if (payload.color && isNaN(payload.color)) payload.color = hexToDecimal(payload.color.toString());
|
||||
|
||||
return new EmbedBuilder(payload);
|
||||
},
|
||||
@@ -145,9 +142,7 @@ export default class ServiceAnnouncement extends DiscordModule {
|
||||
async Init() {
|
||||
if (fs.existsSync(path.join(process.cwd(), 'configs/ServiceAnnouncement.json'))) {
|
||||
try {
|
||||
const rawData = fs.readFileSync(
|
||||
path.join(process.cwd(), 'configs/ServiceAnnouncement.json')
|
||||
);
|
||||
const rawData = fs.readFileSync(path.join(process.cwd(), 'configs/ServiceAnnouncement.json'));
|
||||
const jsonData = JSON.parse(rawData.toString());
|
||||
Announcements = jsonData;
|
||||
} catch (err) {
|
||||
@@ -177,9 +172,7 @@ export default class ServiceAnnouncement extends DiscordModule {
|
||||
reload: async (data: HybridInteractionMessage) => {
|
||||
if (fs.existsSync(path.join(process.cwd(), 'configs/ServiceAnnouncement.json'))) {
|
||||
try {
|
||||
const rawData = fs.readFileSync(
|
||||
path.join(process.cwd(), 'configs/ServiceAnnouncement.json')
|
||||
);
|
||||
const rawData = fs.readFileSync(path.join(process.cwd(), 'configs/ServiceAnnouncement.json'));
|
||||
const jsonData = JSON.parse(rawData.toString());
|
||||
Announcements = jsonData;
|
||||
} catch (err: any) {
|
||||
@@ -264,9 +257,7 @@ export default class ServiceAnnouncement extends DiscordModule {
|
||||
let Guild: Guild = element[0];
|
||||
let Channel: TextChannel = element[1];
|
||||
try {
|
||||
const guildObject = DiscordProvider.client.guilds.cache.get(
|
||||
Guild.id
|
||||
);
|
||||
const guildObject = DiscordProvider.client.guilds.cache.get(Guild.id);
|
||||
if (!guildObject) throw new Error('Guild not found');
|
||||
Logger.info(
|
||||
`Sending Service Announcement to ${guildObject?.name} (${guildObject.id}) #${Channel.name} (${Channel.id})`
|
||||
@@ -276,9 +267,7 @@ export default class ServiceAnnouncement extends DiscordModule {
|
||||
});
|
||||
} catch (err) {
|
||||
withError = true;
|
||||
const guildObject = DiscordProvider.client.guilds.cache.get(
|
||||
Guild.id
|
||||
);
|
||||
const guildObject = DiscordProvider.client.guilds.cache.get(Guild.id);
|
||||
if (guildObject)
|
||||
Logger.info(
|
||||
`Unable to send Service Announcement to ${guildObject?.name} (${guildObject.id}) #${Channel.name} (${Channel.id})`
|
||||
@@ -296,28 +285,20 @@ export default class ServiceAnnouncement extends DiscordModule {
|
||||
|
||||
if (withError) {
|
||||
if (data && data.isMessage() && placeholder && placeholder.isMessage())
|
||||
return placeholder
|
||||
.getMessage()
|
||||
.edit({
|
||||
embeds: [
|
||||
EMBEDS.SERVICE_ANNOUNCEMENT_SENT_WITH_ERRORS(data)
|
||||
]
|
||||
return placeholder.getMessage().edit({
|
||||
embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_SENT_WITH_ERRORS(data)]
|
||||
});
|
||||
else if (data.isApplicationCommand())
|
||||
return await sendHybridInteractionMessageResponse(
|
||||
data,
|
||||
{
|
||||
embeds: [
|
||||
EMBEDS.SERVICE_ANNOUNCEMENT_SENT_WITH_ERRORS(data)
|
||||
]
|
||||
embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_SENT_WITH_ERRORS(data)]
|
||||
},
|
||||
true
|
||||
);
|
||||
} else {
|
||||
if (data && data.isMessage() && placeholder && placeholder.isMessage())
|
||||
return placeholder
|
||||
.getMessage()
|
||||
.edit({ embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_SENT(data)] });
|
||||
return placeholder.getMessage().edit({ embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_SENT(data)] });
|
||||
else if (data.isApplicationCommand())
|
||||
return await sendHybridInteractionMessageResponse(
|
||||
data,
|
||||
|
||||
+4
-4
@@ -17,10 +17,10 @@ const EMBEDS = {
|
||||
let _e = makeInfoEmbed({
|
||||
icon: '💌',
|
||||
title: locale.__('help.title', { BOT_NAME: bot.username }),
|
||||
description: `\u200b\n🏷️ **${locale.__('help.prefix_title')}**\n${locale.__(
|
||||
'help.prefix_description',
|
||||
{PREFIX: prefix.replaceAll('`', '`'), PREFIX_MENTION: `<@${bot.id}>`}
|
||||
)}\n\n💻 **${locale.__('help.available_commands')}**`,
|
||||
description: `\u200b\n🏷️ **${locale.__('help.prefix_title')}**\n${locale.__('help.prefix_description', {
|
||||
PREFIX: prefix.replaceAll('`', '`'),
|
||||
PREFIX_MENTION: `<@${bot.id}>`
|
||||
})}\n\n💻 **${locale.__('help.available_commands')}**`,
|
||||
fields: [
|
||||
{
|
||||
name: `☕ ${locale.__('help.general')}`,
|
||||
|
||||
@@ -108,9 +108,7 @@ export default class InteractionManager extends DiscordModule {
|
||||
await unregisterAllGuildsCommands();
|
||||
|
||||
if (data && data.isMessage() && placeholder && placeholder.isMessage())
|
||||
return placeholder
|
||||
.getMessage()
|
||||
.edit({ embeds: [EMBEDS.UNLOADALL_SUCCESS(data)] });
|
||||
return placeholder.getMessage().edit({ embeds: [EMBEDS.UNLOADALL_SUCCESS(data)] });
|
||||
else if (data.isApplicationCommand())
|
||||
return await sendHybridInteractionMessageResponse(
|
||||
data,
|
||||
@@ -119,9 +117,7 @@ export default class InteractionManager extends DiscordModule {
|
||||
);
|
||||
} catch (err) {
|
||||
if (data && data.isMessage() && placeholder && placeholder.isMessage())
|
||||
return placeholder
|
||||
.getMessage()
|
||||
.edit({ embeds: [EMBEDS.UNLOADALL_ERROR(data, err)] });
|
||||
return placeholder.getMessage().edit({ embeds: [EMBEDS.UNLOADALL_ERROR(data, err)] });
|
||||
else if (data.isApplicationCommand())
|
||||
return await sendHybridInteractionMessageResponse(
|
||||
data,
|
||||
@@ -143,9 +139,7 @@ export default class InteractionManager extends DiscordModule {
|
||||
await registerAllGlobalCommands();
|
||||
|
||||
if (data && data.isMessage() && placeholder && placeholder.isMessage())
|
||||
return placeholder
|
||||
.getMessage()
|
||||
.edit({ embeds: [EMBEDS.RELOADALL_SUCCESS(data)] });
|
||||
return placeholder.getMessage().edit({ embeds: [EMBEDS.RELOADALL_SUCCESS(data)] });
|
||||
else if (data.isApplicationCommand())
|
||||
return await sendHybridInteractionMessageResponse(
|
||||
data,
|
||||
@@ -154,9 +148,7 @@ export default class InteractionManager extends DiscordModule {
|
||||
);
|
||||
} catch (err) {
|
||||
if (data && data.isMessage() && placeholder && placeholder.isMessage())
|
||||
return placeholder
|
||||
.getMessage()
|
||||
.edit({ embeds: [EMBEDS.RELOADALL_ERROR(data, err)] });
|
||||
return placeholder.getMessage().edit({ embeds: [EMBEDS.RELOADALL_ERROR(data, err)] });
|
||||
else if (data.isApplicationCommand())
|
||||
return await sendHybridInteractionMessageResponse(
|
||||
data,
|
||||
@@ -178,9 +170,7 @@ export default class InteractionManager extends DiscordModule {
|
||||
await registerAllGuildsCommands();
|
||||
|
||||
if (data && data.isMessage() && placeholder && placeholder.isMessage())
|
||||
return placeholder
|
||||
.getMessage()
|
||||
.edit({ embeds: [EMBEDS.RELOADALL_SUCCESS(data)] });
|
||||
return placeholder.getMessage().edit({ embeds: [EMBEDS.RELOADALL_SUCCESS(data)] });
|
||||
else if (data.isApplicationCommand())
|
||||
return await sendHybridInteractionMessageResponse(
|
||||
data,
|
||||
@@ -189,9 +179,7 @@ export default class InteractionManager extends DiscordModule {
|
||||
);
|
||||
} catch (err) {
|
||||
if (data && data.isMessage() && placeholder && placeholder.isMessage())
|
||||
return placeholder
|
||||
.getMessage()
|
||||
.edit({ embeds: [EMBEDS.RELOADALL_ERROR(data, err)] });
|
||||
return placeholder.getMessage().edit({ embeds: [EMBEDS.RELOADALL_ERROR(data, err)] });
|
||||
else if (data.isApplicationCommand())
|
||||
return await sendHybridInteractionMessageResponse(
|
||||
data,
|
||||
|
||||
@@ -21,7 +21,7 @@ const EMBEDS = {
|
||||
|
||||
return makeInfoEmbed({
|
||||
title: `Invite`,
|
||||
description: message || locale.__('invite.private', { BOT_NAME: DiscordProvider.client.user!.username}),
|
||||
description: message || locale.__('invite.private', { BOT_NAME: DiscordProvider.client.user!.username }),
|
||||
user
|
||||
});
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
PermissionsBitField,
|
||||
EmbedBuilder,
|
||||
ButtonStyle,
|
||||
ActionRowBuilder,
|
||||
ActionRowBuilder
|
||||
} from 'discord.js';
|
||||
|
||||
import DiscordProvider from '../providers/Discord';
|
||||
@@ -114,16 +114,14 @@ const EMBEDS = {
|
||||
MANAGED_ROLE: (data: Message | BaseInteraction, role: Role) => {
|
||||
return makeErrorEmbed({
|
||||
title: 'You cannot use this role',
|
||||
description:
|
||||
'``' + role.name + '``' + ' is managed by external service and cannot be used',
|
||||
description: '``' + role.name + '``' + ' is managed by external service and cannot be used',
|
||||
user: data instanceof BaseInteraction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
CONFIGURED_ROLE: (data: Message | BaseInteraction, role: Role) => {
|
||||
return makeSuccessEmbed({
|
||||
title: 'Configured Membership Screening Role',
|
||||
description:
|
||||
'New member will be given a ' + '``' + role.name + '``' + ' role after approval',
|
||||
description: 'New member will be given a ' + '``' + role.name + '``' + ' role after approval',
|
||||
user: data instanceof BaseInteraction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
@@ -146,17 +144,10 @@ const EMBEDS = {
|
||||
user: data instanceof BaseInteraction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
INVALID_CHANNEL_THREAD: (
|
||||
data: Message | BaseInteraction,
|
||||
channel: GuildChannel | ThreadChannel
|
||||
) => {
|
||||
INVALID_CHANNEL_THREAD: (data: Message | BaseInteraction, channel: GuildChannel | ThreadChannel) => {
|
||||
return makeErrorEmbed({
|
||||
title: 'Thread channel is not supported',
|
||||
description:
|
||||
'``' +
|
||||
channel.name +
|
||||
'``' +
|
||||
' is a thread channel. Please use a regular text channel',
|
||||
description: '``' + channel.name + '``' + ' is a thread channel. Please use a regular text channel',
|
||||
user: data instanceof BaseInteraction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
@@ -225,11 +216,7 @@ export default class MembershipScreening extends DiscordModule {
|
||||
if (!this.isJsonValid(interaction.customId)) return;
|
||||
const payload = JSON.parse(interaction.customId);
|
||||
|
||||
if (
|
||||
typeof payload.m === 'undefined' ||
|
||||
typeof payload.a === 'undefined' ||
|
||||
payload.m !== 'MembershipScreening'
|
||||
)
|
||||
if (typeof payload.m === 'undefined' || typeof payload.a === 'undefined' || payload.m !== 'MembershipScreening')
|
||||
return;
|
||||
|
||||
const message = await channel.messages.fetch(interaction.message.id);
|
||||
@@ -261,9 +248,7 @@ export default class MembershipScreening extends DiscordModule {
|
||||
const role = (await guild.roles.fetch()).find(
|
||||
(role) => role.id === PrismaGuild.MembershipScreening_GivenRole
|
||||
);
|
||||
const requesterMember = (await guild.members.fetch()).find(
|
||||
(member) => member.id === payload.d.requester
|
||||
);
|
||||
const requesterMember = (await guild.members.fetch()).find((member) => member.id === payload.d.requester);
|
||||
|
||||
if (!role)
|
||||
return await interaction.reply({
|
||||
@@ -466,7 +451,8 @@ export default class MembershipScreening extends DiscordModule {
|
||||
});
|
||||
|
||||
if (
|
||||
!guild.members.me?.permissionsIn(TargetChannel)
|
||||
!guild.members.me
|
||||
?.permissionsIn(TargetChannel)
|
||||
.has([PermissionsBitField.Flags.SendMessages, PermissionsBitField.Flags.ViewChannel])
|
||||
)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
@@ -556,17 +542,14 @@ export default class MembershipScreening extends DiscordModule {
|
||||
fields: [
|
||||
{
|
||||
name: 'Account Information',
|
||||
value: `Account age: <t:${Math.round(
|
||||
member.user.createdAt.getTime() / 1000
|
||||
)}:R>`
|
||||
value: `Account age: <t:${Math.round(member.user.createdAt.getTime() / 1000)}:R>`
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
embed.setThumbnail(`${member.user.displayAvatarURL()}?size=4096`);
|
||||
|
||||
const row = new ActionRowBuilder<ButtonBuilder>()
|
||||
.addComponents([
|
||||
const row = new ActionRowBuilder<ButtonBuilder>().addComponents([
|
||||
new ButtonBuilder()
|
||||
.setCustomId(
|
||||
JSON.stringify({
|
||||
@@ -606,8 +589,7 @@ export default class MembershipScreening extends DiscordModule {
|
||||
.setEmoji('🔪')
|
||||
.setLabel(' Vision Hunt Decree (Ban)')
|
||||
.setStyle(ButtonStyle.Danger)
|
||||
]
|
||||
);
|
||||
]);
|
||||
|
||||
await channel.send({ content: '\u200b', embeds: [embed], components: [row] });
|
||||
}
|
||||
|
||||
@@ -80,7 +80,6 @@ const EMBEDS = {
|
||||
});
|
||||
},
|
||||
NOW_PLAYING: async (data: HybridInteractionMessage, locale: I18n, track: ValidTracks) => {
|
||||
|
||||
const title = TrackUtils.getTitle(track);
|
||||
const thumbnails = await TrackUtils.getThumbnails(track);
|
||||
|
||||
@@ -97,7 +96,6 @@ const EMBEDS = {
|
||||
return embed;
|
||||
},
|
||||
NOW_REPEATING: async (data: HybridInteractionMessage, locale: I18n, track: ValidTracks) => {
|
||||
|
||||
const title = TrackUtils.getTitle(track);
|
||||
const thumbnails = await TrackUtils.getThumbnails(track);
|
||||
|
||||
@@ -142,7 +140,16 @@ export async function joinVoiceChannelProcedure(
|
||||
|
||||
const locale = await Locale.getGuildLocale(guild.id);
|
||||
|
||||
if(!await checkBotPermissionsInChannel({ guild, data, locale, channel: memberVoiceChannel, permissions: [PermissionsBitField.Flags.ViewChannel, PermissionsBitField.Flags.Connect]})) return;
|
||||
if (
|
||||
!(await checkBotPermissionsInChannel({
|
||||
guild,
|
||||
data,
|
||||
locale,
|
||||
channel: memberVoiceChannel,
|
||||
permissions: [PermissionsBitField.Flags.ViewChannel, PermissionsBitField.Flags.Connect]
|
||||
}))
|
||||
)
|
||||
return;
|
||||
|
||||
// If already in VoiceChannel
|
||||
if (bot.voice.channelId) {
|
||||
@@ -231,7 +238,7 @@ export async function joinVoiceChannelProcedure(
|
||||
else if (event.instance.queue.track[0] === previousTrack && isLoopMessageSent) return;
|
||||
|
||||
const row = new ActionRowBuilder<ButtonBuilder>();
|
||||
if(event.instance.queue.track[0] instanceof SpotifyTrack)
|
||||
if (event.instance.queue.track[0] instanceof SpotifyTrack)
|
||||
row.addComponents([
|
||||
new ButtonBuilder()
|
||||
.setEmoji('🟢')
|
||||
@@ -239,14 +246,21 @@ export async function joinVoiceChannelProcedure(
|
||||
.setURL(encodeURI(`https://open.spotify.com/track/${event.instance.queue.track[0].id}`))
|
||||
.setStyle(ButtonStyle.Link)
|
||||
]);
|
||||
if(event.instance.queue.track[0] instanceof YouTubeVideo || event.instance.queue.track[0] instanceof SpotifyTrack) {
|
||||
if (
|
||||
event.instance.queue.track[0] instanceof YouTubeVideo ||
|
||||
event.instance.queue.track[0] instanceof SpotifyTrack
|
||||
) {
|
||||
const actualPlaybackURL = event.instance.getActualPlaybackURL();
|
||||
if(event.instance.queue.track[0] instanceof SpotifyTrack && !actualPlaybackURL) return;
|
||||
if (event.instance.queue.track[0] instanceof SpotifyTrack && !actualPlaybackURL) return;
|
||||
row.addComponents([
|
||||
new ButtonBuilder()
|
||||
.setEmoji('🔴')
|
||||
.setLabel(' Open in YouTube')
|
||||
.setURL(event.instance.queue.track[0] instanceof YouTubeVideo ? encodeURI(`https://www.youtube.com/watch?v=${event.instance.queue.track[0].id}`) : encodeURI(event.instance.getActualPlaybackURL()!))
|
||||
.setURL(
|
||||
event.instance.queue.track[0] instanceof YouTubeVideo
|
||||
? encodeURI(`https://www.youtube.com/watch?v=${event.instance.queue.track[0].id}`)
|
||||
: encodeURI(event.instance.getActualPlaybackURL()!)
|
||||
)
|
||||
.setStyle(ButtonStyle.Link)
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { I18n } from "i18n";
|
||||
import { Message, CommandInteraction } from "discord.js";
|
||||
import { I18n } from 'i18n';
|
||||
import { Message, CommandInteraction } from 'discord.js';
|
||||
|
||||
import DiscordMusicPlayer from "../../providers/DiscordMusicPlayer";
|
||||
import Locale from "../../services/Locale";
|
||||
import DiscordMusicPlayer from '../../providers/DiscordMusicPlayer';
|
||||
import Locale from '../../services/Locale';
|
||||
|
||||
import { makeSuccessEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse } from "../../utils/DiscordMessage";
|
||||
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
|
||||
import { makeSuccessEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse } from '../../utils/DiscordMessage';
|
||||
import DiscordModule, { HybridInteractionMessage } from '../../utils/DiscordModule';
|
||||
|
||||
const EMBEDS = {
|
||||
VOICECHANNEL_LEFT: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
@@ -32,13 +32,12 @@ const EMBEDS = {
|
||||
user: data.getUser()
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default class Leave extends DiscordModule {
|
||||
|
||||
public id = "Discord_MusicPlayer_Leave";
|
||||
public commands = ["leave", "disconnect", "dc"];
|
||||
public commandInteractionName = "leave";
|
||||
public id = 'Discord_MusicPlayer_Leave';
|
||||
public commands = ['leave', 'disconnect', 'dc'];
|
||||
public commandInteractionName = 'leave';
|
||||
|
||||
async GuildOnModuleCommand(args: any, message: Message) {
|
||||
await this.run(new HybridInteractionMessage(message), args);
|
||||
@@ -49,28 +48,32 @@ export default class Leave extends DiscordModule {
|
||||
}
|
||||
|
||||
async run(data: HybridInteractionMessage, args: any) {
|
||||
|
||||
const guild = data.getGuild();
|
||||
const member = data.getMember();
|
||||
|
||||
if(!guild || !member) return;
|
||||
if (!guild || !member) return;
|
||||
|
||||
const locale = await Locale.getGuildLocale(guild.id);
|
||||
const voiceChannel = member.voice.channel;
|
||||
|
||||
if (!voiceChannel)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data, locale)] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data, locale)]
|
||||
});
|
||||
|
||||
let instance = DiscordMusicPlayer.getGuildInstance(guild.id);
|
||||
if(!instance)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)] });
|
||||
|
||||
if(instance.voiceChannel.id !== voiceChannel.id)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data, locale)] });
|
||||
if (!instance)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)]
|
||||
});
|
||||
|
||||
if (instance.voiceChannel.id !== voiceChannel.id)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data, locale)]
|
||||
});
|
||||
|
||||
DiscordMusicPlayer.destoryGuildInstance(guild.id);
|
||||
await sendHybridInteractionMessageResponse(data, { embeds:[EMBEDS.VOICECHANNEL_LEFT(data, locale)] });
|
||||
await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.VOICECHANNEL_LEFT(data, locale)] });
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
import { I18n } from "i18n";
|
||||
import { Message, CommandInteraction } from "discord.js";
|
||||
import { I18n } from 'i18n';
|
||||
import { Message, CommandInteraction } from 'discord.js';
|
||||
|
||||
import DiscordMusicPlayer, { DiscordMusicPlayerLoopMode } from "../../providers/DiscordMusicPlayer";
|
||||
import Locale from "../../services/Locale";
|
||||
import DiscordMusicPlayer, { DiscordMusicPlayerLoopMode } from '../../providers/DiscordMusicPlayer';
|
||||
import Locale from '../../services/Locale';
|
||||
|
||||
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
|
||||
import { makeErrorEmbed, makeSuccessEmbed, sendHybridInteractionMessageResponse, makeInfoEmbed } from "../../utils/DiscordMessage";
|
||||
import DiscordModule, { HybridInteractionMessage } from '../../utils/DiscordModule';
|
||||
import {
|
||||
makeErrorEmbed,
|
||||
makeSuccessEmbed,
|
||||
sendHybridInteractionMessageResponse,
|
||||
makeInfoEmbed
|
||||
} from '../../utils/DiscordMessage';
|
||||
const EMBEDS = {
|
||||
INVALID_LOOP_MODE: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
return makeErrorEmbed({
|
||||
@@ -50,12 +55,11 @@ const EMBEDS = {
|
||||
user: data.getUser()
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
export default class Loop extends DiscordModule {
|
||||
|
||||
public id = "Discord_MusicPlayer_Loop";
|
||||
public commands = ["loop", "repeat"];
|
||||
public commandInteractionName = "loop";
|
||||
public id = 'Discord_MusicPlayer_Loop';
|
||||
public commands = ['loop', 'repeat'];
|
||||
public commandInteractionName = 'loop';
|
||||
|
||||
async GuildOnModuleCommand(args: any, message: Message) {
|
||||
await this.run(new HybridInteractionMessage(message), args);
|
||||
@@ -66,7 +70,6 @@ export default class Loop extends DiscordModule {
|
||||
}
|
||||
|
||||
async run(data: HybridInteractionMessage, args: any) {
|
||||
|
||||
const guild = data.getGuild();
|
||||
const user = data.getUser();
|
||||
const member = data.getMember();
|
||||
@@ -78,39 +81,52 @@ export default class Loop extends DiscordModule {
|
||||
let query;
|
||||
|
||||
if (data.isMessage()) {
|
||||
if (args.length !== 0)
|
||||
query = args.join(' ');
|
||||
}
|
||||
else if (data.isApplicationCommand())
|
||||
query = args.getSubcommand();
|
||||
if (args.length !== 0) query = args.join(' ');
|
||||
} else if (data.isApplicationCommand()) query = args.getSubcommand();
|
||||
|
||||
const voiceChannel = member.voice.channel;
|
||||
|
||||
if (!voiceChannel)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data, locale)] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data, locale)]
|
||||
});
|
||||
|
||||
const instance = DiscordMusicPlayer.getGuildInstance(guild.id);
|
||||
|
||||
if (!instance)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)]
|
||||
});
|
||||
|
||||
if (instance.voiceChannel.id !== voiceChannel.id)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data, locale)] }, true);
|
||||
return await sendHybridInteractionMessageResponse(
|
||||
data,
|
||||
{ embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data, locale)] },
|
||||
true
|
||||
);
|
||||
|
||||
if (instance.queue.track.length === 0)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)]
|
||||
});
|
||||
|
||||
if (!query)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.LOOP_STATUS(data, locale, instance.getLoopMode())] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.LOOP_STATUS(data, locale, instance.getLoopMode())]
|
||||
});
|
||||
|
||||
let enumKey = Object.keys(DiscordMusicPlayerLoopMode)[Object.values(DiscordMusicPlayerLoopMode).indexOf(query.toLowerCase())];
|
||||
let enumKey =
|
||||
Object.keys(DiscordMusicPlayerLoopMode)[
|
||||
Object.values(DiscordMusicPlayerLoopMode).indexOf(query.toLowerCase())
|
||||
];
|
||||
|
||||
if(enumKey) {
|
||||
if (enumKey) {
|
||||
instance.setLoopMode(DiscordMusicPlayerLoopMode[enumKey as keyof typeof DiscordMusicPlayerLoopMode]);
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.LOOP_SET(data, locale, instance.getLoopMode())] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.LOOP_SET(data, locale, instance.getLoopMode())]
|
||||
});
|
||||
}
|
||||
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.INVALID_LOOP_MODE(data, locale)] });
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,17 +1,16 @@
|
||||
import { Message, CommandInteraction, ActionRowBuilder, ButtonBuilder, ButtonStyle } from "discord.js";
|
||||
import { I18n } from "i18n";
|
||||
import { SpotifyTrack, YouTubeVideo } from "play-dl";
|
||||
import { Message, CommandInteraction, ActionRowBuilder, ButtonBuilder, ButtonStyle } from 'discord.js';
|
||||
import { I18n } from 'i18n';
|
||||
import { SpotifyTrack, YouTubeVideo } from 'play-dl';
|
||||
|
||||
import DiscordProvider from "../../providers/Discord";
|
||||
import DiscordMusicPlayer, { TrackUtils, ValidTracks } from "../../providers/DiscordMusicPlayer";
|
||||
import Locale from "../../services/Locale";
|
||||
import DiscordProvider from '../../providers/Discord';
|
||||
import DiscordMusicPlayer, { TrackUtils, ValidTracks } from '../../providers/DiscordMusicPlayer';
|
||||
import Locale from '../../services/Locale';
|
||||
|
||||
import { makeErrorEmbed, makeInfoEmbed, sendHybridInteractionMessageResponse } from "../../utils/DiscordMessage";
|
||||
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
|
||||
import { makeErrorEmbed, makeInfoEmbed, sendHybridInteractionMessageResponse } from '../../utils/DiscordMessage';
|
||||
import DiscordModule, { HybridInteractionMessage } from '../../utils/DiscordModule';
|
||||
|
||||
const EMBEDS = {
|
||||
NOW_PLAYING: async (data: HybridInteractionMessage, locale: I18n, track: ValidTracks) => {
|
||||
|
||||
const title = TrackUtils.getTitle(track);
|
||||
const thumbnails = await TrackUtils.getThumbnails(track);
|
||||
|
||||
@@ -33,13 +32,12 @@ const EMBEDS = {
|
||||
user: data.getUser()
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default class NowPlaying extends DiscordModule {
|
||||
|
||||
public id = "Discord_MusicPlayer_NowPlaying";
|
||||
public commands = ["nowplaying", "np"];
|
||||
public commandInteractionName = "nowplaying";
|
||||
public id = 'Discord_MusicPlayer_NowPlaying';
|
||||
public commands = ['nowplaying', 'np'];
|
||||
public commandInteractionName = 'nowplaying';
|
||||
|
||||
async GuildOnModuleCommand(args: any, message: Message) {
|
||||
await this.run(new HybridInteractionMessage(message), args);
|
||||
@@ -50,35 +48,44 @@ export default class NowPlaying extends DiscordModule {
|
||||
}
|
||||
|
||||
async run(data: HybridInteractionMessage, args: any) {
|
||||
|
||||
const guild = data.getGuild();
|
||||
if(!guild) return;
|
||||
if (!guild) return;
|
||||
|
||||
const locale = await Locale.getGuildLocale(guild.id);
|
||||
const instance = DiscordMusicPlayer.getGuildInstance(guild.id);
|
||||
if(!instance || !instance.queue.track[0]) return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)] });
|
||||
if (!instance || !instance.queue.track[0])
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)]
|
||||
});
|
||||
|
||||
const row = new ActionRowBuilder<ButtonBuilder>();
|
||||
|
||||
if(instance.queue.track[0] instanceof SpotifyTrack)
|
||||
if (instance.queue.track[0] instanceof SpotifyTrack)
|
||||
row.addComponents([
|
||||
new ButtonBuilder()
|
||||
.setEmoji('🟢')
|
||||
.setLabel(' Open in Spotify')
|
||||
.setURL(encodeURI(`https://open.spotify.com/track/${instance.queue.track[0].id}`))
|
||||
.setStyle(ButtonStyle.Link),
|
||||
.setStyle(ButtonStyle.Link)
|
||||
]);
|
||||
if(instance.queue.track[0] instanceof YouTubeVideo || instance.queue.track[0] instanceof SpotifyTrack) {
|
||||
if (instance.queue.track[0] instanceof YouTubeVideo || instance.queue.track[0] instanceof SpotifyTrack) {
|
||||
const actualPlaybackURL = instance.getActualPlaybackURL();
|
||||
if(instance.queue.track[0] instanceof SpotifyTrack && !actualPlaybackURL) return;
|
||||
if (instance.queue.track[0] instanceof SpotifyTrack && !actualPlaybackURL) return;
|
||||
row.addComponents([
|
||||
new ButtonBuilder()
|
||||
.setEmoji('🔴')
|
||||
.setLabel(' Open in YouTube')
|
||||
.setURL(instance.queue.track[0] instanceof YouTubeVideo ? encodeURI(`https://www.youtube.com/watch?v=${instance.queue.track[0].id}`) : encodeURI(instance.getActualPlaybackURL()!))
|
||||
.setStyle(ButtonStyle.Link),
|
||||
.setURL(
|
||||
instance.queue.track[0] instanceof YouTubeVideo
|
||||
? encodeURI(`https://www.youtube.com/watch?v=${instance.queue.track[0].id}`)
|
||||
: encodeURI(instance.getActualPlaybackURL()!)
|
||||
)
|
||||
.setStyle(ButtonStyle.Link)
|
||||
]);
|
||||
}
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [await EMBEDS.NOW_PLAYING(data, locale, instance.queue.track[0])], components: [row] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [await EMBEDS.NOW_PLAYING(data, locale, instance.queue.track[0])],
|
||||
components: [row]
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,17 @@
|
||||
import { Message, CommandInteraction, Interaction } from "discord.js";
|
||||
import { I18n } from "i18n";
|
||||
import { Message, CommandInteraction, Interaction } from 'discord.js';
|
||||
import { I18n } from 'i18n';
|
||||
|
||||
import DiscordMusicPlayer from "../../providers/DiscordMusicPlayer";
|
||||
import Locale from "../../services/Locale";
|
||||
import DiscordMusicPlayer from '../../providers/DiscordMusicPlayer';
|
||||
import Locale from '../../services/Locale';
|
||||
|
||||
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
|
||||
import DiscordModule, { HybridInteractionMessage } from '../../utils/DiscordModule';
|
||||
|
||||
import { makeSuccessEmbed, makeInfoEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse } from "../../utils/DiscordMessage";
|
||||
import {
|
||||
makeSuccessEmbed,
|
||||
makeInfoEmbed,
|
||||
makeErrorEmbed,
|
||||
sendHybridInteractionMessageResponse
|
||||
} from '../../utils/DiscordMessage';
|
||||
|
||||
const EMBEDS = {
|
||||
PAUSED: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
@@ -39,13 +44,12 @@ const EMBEDS = {
|
||||
user: data.getUser()
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default class Pause extends DiscordModule{
|
||||
|
||||
public id = "Discord_MusicPlayer_Pause";
|
||||
public commands = ["pause"];
|
||||
public commandInteractionName = "pause";
|
||||
export default class Pause extends DiscordModule {
|
||||
public id = 'Discord_MusicPlayer_Pause';
|
||||
public commands = ['pause'];
|
||||
public commandInteractionName = 'pause';
|
||||
|
||||
async GuildOnModuleCommand(args: any, message: Message) {
|
||||
await this.run(new HybridInteractionMessage(message), args);
|
||||
@@ -56,7 +60,6 @@ export default class Pause extends DiscordModule{
|
||||
}
|
||||
|
||||
async run(data: HybridInteractionMessage, args: any) {
|
||||
|
||||
const guild = data.getGuild();
|
||||
const member = data.getMember();
|
||||
|
||||
@@ -66,20 +69,30 @@ export default class Pause extends DiscordModule{
|
||||
const voiceChannel = member.voice.channel;
|
||||
|
||||
if (!voiceChannel)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data, locale)] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data, locale)]
|
||||
});
|
||||
|
||||
const instance = DiscordMusicPlayer.getGuildInstance(guild.id);
|
||||
|
||||
if(!instance)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)] });
|
||||
if (!instance)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)]
|
||||
});
|
||||
|
||||
if(instance.voiceChannel.id !== voiceChannel.id)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data, locale)] }, true);
|
||||
if (instance.voiceChannel.id !== voiceChannel.id)
|
||||
return await sendHybridInteractionMessageResponse(
|
||||
data,
|
||||
{ embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data, locale)] },
|
||||
true
|
||||
);
|
||||
|
||||
if(instance.queue.track.length === 0)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)] });
|
||||
if (instance.queue.track.length === 0)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)]
|
||||
});
|
||||
|
||||
if(instance.isPaused())
|
||||
if (instance.isPaused())
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.ALREADY_PAUSED(data, locale)] });
|
||||
|
||||
instance.pausePlayer();
|
||||
|
||||
@@ -42,7 +42,6 @@ const EMBEDS = {
|
||||
});
|
||||
},
|
||||
ADDED_QUEUE: async (data: HybridInteractionMessage, locale: I18n, track: ValidTracks) => {
|
||||
|
||||
const title = TrackUtils.getTitle(track);
|
||||
const thumbnails = await TrackUtils.getThumbnails(track);
|
||||
|
||||
@@ -354,7 +353,15 @@ export default class Play extends DiscordModule {
|
||||
|
||||
if (!result) return;
|
||||
|
||||
if (data.isMessage() && data.getMessage().embeds.length > 0 && await checkBotPermissionsInChannel({ guild, channel, permissions: [PermissionsBitField.Flags.ManageMessages]})) {
|
||||
if (
|
||||
data.isMessage() &&
|
||||
data.getMessage().embeds.length > 0 &&
|
||||
(await checkBotPermissionsInChannel({
|
||||
guild,
|
||||
channel,
|
||||
permissions: [PermissionsBitField.Flags.ManageMessages]
|
||||
}))
|
||||
) {
|
||||
data.getMessage().suppressEmbeds(true);
|
||||
}
|
||||
|
||||
@@ -373,8 +380,7 @@ export default class Play extends DiscordModule {
|
||||
)
|
||||
.setLabel(' Add the remaining songs in the playlist')
|
||||
.setStyle(ButtonStyle.Primary)
|
||||
]
|
||||
);
|
||||
]);
|
||||
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [await EMBEDS.ADDED_QUEUE(data, locale, result)],
|
||||
@@ -389,11 +395,15 @@ export default class Play extends DiscordModule {
|
||||
|
||||
if (linkData.type === 'playlist' || linkData.type === 'album') {
|
||||
let playlist = await DiscordMusicPlayer.getSpotifySongsInPlayList(query).catch((err) => {
|
||||
sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.LOOKUP_ERROR(data, locale, err)] }, true);
|
||||
sendHybridInteractionMessageResponse(
|
||||
data,
|
||||
{ embeds: [EMBEDS.LOOKUP_ERROR(data, locale, err)] },
|
||||
true
|
||||
);
|
||||
return null;
|
||||
});
|
||||
|
||||
if(!playlist) return;
|
||||
if (!playlist) return;
|
||||
const songs = await playlist.all_tracks();
|
||||
|
||||
for (const song of songs) {
|
||||
@@ -414,7 +424,15 @@ export default class Play extends DiscordModule {
|
||||
|
||||
if (!result) return;
|
||||
|
||||
if (data.isMessage() && data.getMessage().embeds.length > 0 && await checkBotPermissionsInChannel({ guild, channel, permissions: [PermissionsBitField.Flags.ManageMessages]})) {
|
||||
if (
|
||||
data.isMessage() &&
|
||||
data.getMessage().embeds.length > 0 &&
|
||||
(await checkBotPermissionsInChannel({
|
||||
guild,
|
||||
channel,
|
||||
permissions: [PermissionsBitField.Flags.ManageMessages]
|
||||
}))
|
||||
) {
|
||||
data.getMessage().suppressEmbeds(true);
|
||||
}
|
||||
|
||||
@@ -423,7 +441,6 @@ export default class Play extends DiscordModule {
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [await EMBEDS.ADDED_QUEUE(data, locale, result)]
|
||||
});
|
||||
|
||||
} else {
|
||||
let result = await DiscordMusicPlayer.searchYouTubeByQuery(query);
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { I18n } from "i18n";
|
||||
import { Message, CommandInteraction, ActivityType, ActionRowBuilder, ButtonBuilder, ButtonStyle } from "discord.js";
|
||||
import { I18n } from 'i18n';
|
||||
import { Message, CommandInteraction, ActivityType, ActionRowBuilder, ButtonBuilder, ButtonStyle } from 'discord.js';
|
||||
|
||||
import DiscordMusicPlayer, { TrackUtils, ValidTracks } from "../../providers/DiscordMusicPlayer";
|
||||
import Locale from "../../services/Locale";
|
||||
import DiscordMusicPlayer, { TrackUtils, ValidTracks } from '../../providers/DiscordMusicPlayer';
|
||||
import Locale from '../../services/Locale';
|
||||
|
||||
import { makeSuccessEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse } from "../../utils/DiscordMessage";
|
||||
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
|
||||
import { joinVoiceChannelProcedure } from "./Join";
|
||||
import { makeSuccessEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse } from '../../utils/DiscordMessage';
|
||||
import DiscordModule, { HybridInteractionMessage } from '../../utils/DiscordModule';
|
||||
import { joinVoiceChannelProcedure } from './Join';
|
||||
|
||||
const EMBEDS = {
|
||||
NOT_DETECTED: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
@@ -28,7 +28,6 @@ const EMBEDS = {
|
||||
});
|
||||
},
|
||||
ADDED_QUEUE: async (data: HybridInteractionMessage, locale: I18n, track: ValidTracks) => {
|
||||
|
||||
const title = TrackUtils.getTitle(track);
|
||||
const thumbnails = await TrackUtils.getThumbnails(track);
|
||||
|
||||
@@ -43,13 +42,12 @@ const EMBEDS = {
|
||||
|
||||
return embed;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default class PlayMy extends DiscordModule {
|
||||
|
||||
public id = "Discord_MusicPlayer_PlayMy";
|
||||
public commands = ["playmy"];
|
||||
public commandInteractionName = "playmy";
|
||||
public id = 'Discord_MusicPlayer_PlayMy';
|
||||
public commands = ['playmy'];
|
||||
public commandInteractionName = 'playmy';
|
||||
|
||||
async GuildOnModuleCommand(args: any, message: Message) {
|
||||
await this.run(new HybridInteractionMessage(message), args);
|
||||
@@ -60,11 +58,10 @@ export default class PlayMy extends DiscordModule {
|
||||
}
|
||||
|
||||
async run(data: HybridInteractionMessage, args: any) {
|
||||
|
||||
const guild = data.getGuild();
|
||||
const member = data.getMember();
|
||||
|
||||
if(!guild || !member) return;
|
||||
if (!guild || !member) return;
|
||||
|
||||
const locale = await Locale.getGuildLocale(guild.id);
|
||||
|
||||
@@ -94,21 +91,19 @@ export default class PlayMy extends DiscordModule {
|
||||
instance = DiscordMusicPlayer.getGuildInstance(guild.id);
|
||||
}
|
||||
|
||||
if(!instance) return;
|
||||
if(!member.presence) return;
|
||||
if(!member.presence.activities) return;
|
||||
if (!instance) return;
|
||||
if (!member.presence) return;
|
||||
if (!member.presence.activities) return;
|
||||
|
||||
let query;
|
||||
let found = false;
|
||||
for (const activity of member.presence.activities) {
|
||||
if(activity.type === ActivityType.Listening) {
|
||||
if(!activity.details) continue;
|
||||
if (activity.type === ActivityType.Listening) {
|
||||
if (!activity.details) continue;
|
||||
found = true;
|
||||
|
||||
if(activity.name == "Spotify")
|
||||
query = `${activity.state} - ${activity.details}`
|
||||
else
|
||||
query = `${activity.state} - ${activity.details}` // TODO: Find better query formula
|
||||
if (activity.name == 'Spotify') query = `${activity.state} - ${activity.details}`;
|
||||
else query = `${activity.state} - ${activity.details}`; // TODO: Find better query formula
|
||||
|
||||
const result = await DiscordMusicPlayer.searchYouTubeByQuery(query);
|
||||
if (!result) continue;
|
||||
@@ -141,7 +136,7 @@ export default class PlayMy extends DiscordModule {
|
||||
]);
|
||||
}
|
||||
|
||||
if(!row)
|
||||
if (!row)
|
||||
await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [await EMBEDS.ADDED_QUEUE(data, locale, result[0])]
|
||||
});
|
||||
@@ -153,8 +148,7 @@ export default class PlayMy extends DiscordModule {
|
||||
}
|
||||
}
|
||||
|
||||
if(!found)
|
||||
await sendHybridInteractionMessageResponse(data, { embeds:[EMBEDS.NOT_DETECTED(data, locale)] });
|
||||
if (!found) await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NOT_DETECTED(data, locale)] });
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -133,10 +133,14 @@ export default class QueueCommand extends DiscordModule {
|
||||
switch (query.toLowerCase()) {
|
||||
case 'clear':
|
||||
instance.clearQueue();
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.QUEUE_CLEARED(data, locale)] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.QUEUE_CLEARED(data, locale)]
|
||||
});
|
||||
case 'shuffle':
|
||||
instance.shuffleQueue();
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.QUEUE_SHUFFLED(data, locale)] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.QUEUE_SHUFFLED(data, locale)]
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
import { Message, CommandInteraction, Interaction } from "discord.js";
|
||||
import { I18n } from "i18n";
|
||||
import { Message, CommandInteraction, Interaction } from 'discord.js';
|
||||
import { I18n } from 'i18n';
|
||||
|
||||
import DiscordMusicPlayer from "../../providers/DiscordMusicPlayer";
|
||||
import DiscordMusicPlayer from '../../providers/DiscordMusicPlayer';
|
||||
|
||||
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
|
||||
import { makeSuccessEmbed, makeInfoEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse } from "../../utils/DiscordMessage";
|
||||
import Locale from "../../services/Locale";
|
||||
import DiscordModule, { HybridInteractionMessage } from '../../utils/DiscordModule';
|
||||
import {
|
||||
makeSuccessEmbed,
|
||||
makeInfoEmbed,
|
||||
makeErrorEmbed,
|
||||
sendHybridInteractionMessageResponse
|
||||
} from '../../utils/DiscordMessage';
|
||||
import Locale from '../../services/Locale';
|
||||
|
||||
const EMBEDS = {
|
||||
RESUMED: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
@@ -38,13 +43,12 @@ const EMBEDS = {
|
||||
user: data.getUser()
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default class Resume extends DiscordModule{
|
||||
|
||||
public id = "Discord_MusicPlayer_Resume";
|
||||
public commands = ["resume"];
|
||||
public commandInteractionName = "resume";
|
||||
export default class Resume extends DiscordModule {
|
||||
public id = 'Discord_MusicPlayer_Resume';
|
||||
public commands = ['resume'];
|
||||
public commandInteractionName = 'resume';
|
||||
|
||||
async GuildOnModuleCommand(args: any, message: Message) {
|
||||
await this.run(new HybridInteractionMessage(message), args);
|
||||
@@ -55,7 +59,6 @@ export default class Resume extends DiscordModule{
|
||||
}
|
||||
|
||||
async run(data: HybridInteractionMessage, args: any) {
|
||||
|
||||
const guild = data.getGuild();
|
||||
const member = data.getMember();
|
||||
|
||||
@@ -66,20 +69,30 @@ export default class Resume extends DiscordModule{
|
||||
const voiceChannel = member.voice.channel;
|
||||
|
||||
if (!voiceChannel)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data, locale)] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data, locale)]
|
||||
});
|
||||
|
||||
const instance = DiscordMusicPlayer.getGuildInstance(guild.id);
|
||||
|
||||
if(!instance)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)] });
|
||||
if (!instance)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)]
|
||||
});
|
||||
|
||||
if(instance.voiceChannel.id !== voiceChannel.id)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data, locale)] }, true);
|
||||
if (instance.voiceChannel.id !== voiceChannel.id)
|
||||
return await sendHybridInteractionMessageResponse(
|
||||
data,
|
||||
{ embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data, locale)] },
|
||||
true
|
||||
);
|
||||
|
||||
if(instance.queue.track.length === 0)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)] });
|
||||
if (instance.queue.track.length === 0)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)]
|
||||
});
|
||||
|
||||
if(!instance.isPaused())
|
||||
if (!instance.isPaused())
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NOT_PAUSED(data, locale)] });
|
||||
|
||||
instance.resumePlayer();
|
||||
|
||||
@@ -1,13 +1,20 @@
|
||||
import { Message, CommandInteraction, ActionRowBuilder, ButtonInteraction, SelectMenuBuilder, SelectMenuComponentOptionData } from "discord.js";
|
||||
import { I18n } from "i18n";
|
||||
import {
|
||||
Message,
|
||||
CommandInteraction,
|
||||
ActionRowBuilder,
|
||||
ButtonInteraction,
|
||||
SelectMenuBuilder,
|
||||
SelectMenuComponentOptionData
|
||||
} from 'discord.js';
|
||||
import { I18n } from 'i18n';
|
||||
|
||||
import { joinVoiceChannelProcedure } from "./Join";
|
||||
import { joinVoiceChannelProcedure } from './Join';
|
||||
|
||||
import DiscordMusicPlayer, { TrackUtils, ValidTracks } from "../../providers/DiscordMusicPlayer";
|
||||
import Locale from "../../services/Locale";
|
||||
import DiscordMusicPlayer, { TrackUtils, ValidTracks } from '../../providers/DiscordMusicPlayer';
|
||||
import Locale from '../../services/Locale';
|
||||
|
||||
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
|
||||
import { makeErrorEmbed, sendHybridInteractionMessageResponse, makeInfoEmbed } from "../../utils/DiscordMessage";
|
||||
import DiscordModule, { HybridInteractionMessage } from '../../utils/DiscordModule';
|
||||
import { makeErrorEmbed, sendHybridInteractionMessageResponse, makeInfoEmbed } from '../../utils/DiscordMessage';
|
||||
|
||||
const EMBEDS = {
|
||||
SEARCH_INFO: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
@@ -17,7 +24,7 @@ const EMBEDS = {
|
||||
fields: [
|
||||
{
|
||||
name: locale.__('common.available_args'),
|
||||
value: locale.__('musicplayer_search.valid_args'),
|
||||
value: locale.__('musicplayer_search.valid_args')
|
||||
}
|
||||
],
|
||||
user: data.getUser()
|
||||
@@ -28,7 +35,7 @@ const EMBEDS = {
|
||||
title: locale.__('musicplayer_search.title_result'),
|
||||
description: `${locale.__('musicplayer_search.x_results_found', {
|
||||
COUNT: result.length.toString()
|
||||
})}\n\n${result.map(track => `- [${TrackUtils.getTitle(track)}](${track.url})`).join('\n')}`,
|
||||
})}\n\n${result.map((track) => `- [${TrackUtils.getTitle(track)}](${track.url})`).join('\n')}`,
|
||||
user: data.getUser()
|
||||
});
|
||||
},
|
||||
@@ -44,12 +51,11 @@ const EMBEDS = {
|
||||
user: data.getUser()
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
export default class Search extends DiscordModule {
|
||||
|
||||
public id = "Discord_MusicPlayer_Search";
|
||||
public commands = ["search"];
|
||||
public commandInteractionName = "search";
|
||||
public id = 'Discord_MusicPlayer_Search';
|
||||
public commands = ['search'];
|
||||
public commandInteractionName = 'search';
|
||||
|
||||
async GuildOnModuleCommand(args: any, message: Message) {
|
||||
await this.run(new HybridInteractionMessage(message), args);
|
||||
@@ -70,16 +76,18 @@ export default class Search extends DiscordModule {
|
||||
data.q stands for data.query
|
||||
*/
|
||||
|
||||
if (typeof payload.m === 'undefined' ||
|
||||
if (
|
||||
typeof payload.m === 'undefined' ||
|
||||
typeof payload.a === 'undefined' ||
|
||||
payload.m !== 'MP_S' ||
|
||||
payload.a !== 'search') return;
|
||||
payload.a !== 'search'
|
||||
)
|
||||
return;
|
||||
|
||||
await this.run(new HybridInteractionMessage(interaction), payload.d.q);
|
||||
}
|
||||
|
||||
async run(data: HybridInteractionMessage, args: any) {
|
||||
|
||||
const guild = data.getGuild();
|
||||
const user = data.getUser();
|
||||
const member = data.getMember();
|
||||
@@ -95,19 +103,18 @@ export default class Search extends DiscordModule {
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SEARCH_INFO(data, locale)] });
|
||||
|
||||
query = args.join(' ');
|
||||
}
|
||||
else if (data.isApplicationCommand())
|
||||
} else if (data.isApplicationCommand())
|
||||
query = data.getSlashCommand().options.get('query', true).value?.toString();
|
||||
else if (data.isButton())
|
||||
query = args;
|
||||
else if (data.isButton()) query = args;
|
||||
|
||||
if (!query) return;
|
||||
|
||||
const voiceChannel = member.voice.channel;
|
||||
|
||||
if (!voiceChannel)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data, locale)] });
|
||||
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data, locale)]
|
||||
});
|
||||
|
||||
if (!DiscordMusicPlayer.isGuildInstanceExists(guild.id))
|
||||
await joinVoiceChannelProcedure(data, null, voiceChannel);
|
||||
@@ -116,7 +123,9 @@ export default class Search extends DiscordModule {
|
||||
if (!instance) return;
|
||||
|
||||
if (instance.voiceChannel.id !== voiceChannel.id)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data, locale)] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data, locale)]
|
||||
});
|
||||
|
||||
if (!instance.isConnected()) {
|
||||
await joinVoiceChannelProcedure(data, instance!, voiceChannel);
|
||||
@@ -136,14 +145,16 @@ export default class Search extends DiscordModule {
|
||||
data.r stands for data.requester
|
||||
data.v stands for data.voiceChannel
|
||||
*/
|
||||
messageSelectMenu.setCustomId(JSON.stringify({
|
||||
messageSelectMenu.setCustomId(
|
||||
JSON.stringify({
|
||||
m: 'MP_SM',
|
||||
a: 'play',
|
||||
d: {
|
||||
r: user.id,
|
||||
v: voiceChannel.id
|
||||
}
|
||||
}))
|
||||
})
|
||||
);
|
||||
messageSelectMenu.setPlaceholder('Nothing selected');
|
||||
|
||||
for (let song of result) {
|
||||
@@ -160,21 +171,21 @@ export default class Search extends DiscordModule {
|
||||
const row = new ActionRowBuilder<SelectMenuBuilder>();
|
||||
row.addComponents([messageSelectMenu]);
|
||||
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SEARCH_RESULT(data, locale, result)], components: [row] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.SEARCH_RESULT(data, locale, result)],
|
||||
components: [row]
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
isJsonValid(jsonString: string) {
|
||||
try {
|
||||
let o = JSON.parse(jsonString);
|
||||
if (o && typeof o === "object") {
|
||||
if (o && typeof o === 'object') {
|
||||
return true;
|
||||
//return o;
|
||||
}
|
||||
}
|
||||
catch (e) { }
|
||||
} catch (e) {}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
|
||||
import DiscordModule, { HybridInteractionMessage } from '../../utils/DiscordModule';
|
||||
|
||||
import { Message, CommandInteraction } from "discord.js";
|
||||
import { makeSuccessEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse } from "../../utils/DiscordMessage";
|
||||
import { Message, CommandInteraction } from 'discord.js';
|
||||
import { makeSuccessEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse } from '../../utils/DiscordMessage';
|
||||
|
||||
import DiscordMusicPlayer from "../../providers/DiscordMusicPlayer";
|
||||
import { I18n } from "i18n";
|
||||
import Locale from "../../services/Locale";
|
||||
import DiscordMusicPlayer from '../../providers/DiscordMusicPlayer';
|
||||
import { I18n } from 'i18n';
|
||||
import Locale from '../../services/Locale';
|
||||
|
||||
const EMBEDS = {
|
||||
SKIPPED: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
@@ -38,13 +38,12 @@ const EMBEDS = {
|
||||
user: data.getUser()
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default class Skip extends DiscordModule{
|
||||
|
||||
public id = "Discord_MusicPlayer_Skip";
|
||||
public commands = ["skip"];
|
||||
public commandInteractionName = "skip";
|
||||
export default class Skip extends DiscordModule {
|
||||
public id = 'Discord_MusicPlayer_Skip';
|
||||
public commands = ['skip'];
|
||||
public commandInteractionName = 'skip';
|
||||
|
||||
async GuildOnModuleCommand(args: any, message: Message) {
|
||||
await this.run(new HybridInteractionMessage(message), args);
|
||||
@@ -55,7 +54,6 @@ export default class Skip extends DiscordModule{
|
||||
}
|
||||
|
||||
async run(data: HybridInteractionMessage, args: any) {
|
||||
|
||||
const guild = data.getGuild();
|
||||
const member = data.getMember();
|
||||
|
||||
@@ -65,24 +63,35 @@ export default class Skip extends DiscordModule{
|
||||
const voiceChannel = member.voice.channel;
|
||||
|
||||
if (!voiceChannel)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data, locale)] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data, locale)]
|
||||
});
|
||||
|
||||
const instance = DiscordMusicPlayer.getGuildInstance(guild.id);
|
||||
|
||||
if(!instance)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)] });
|
||||
if (!instance)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)]
|
||||
});
|
||||
|
||||
if(instance.voiceChannel.id !== voiceChannel.id)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data, locale)] }, true);
|
||||
if (instance.voiceChannel.id !== voiceChannel.id)
|
||||
return await sendHybridInteractionMessageResponse(
|
||||
data,
|
||||
{ embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data, locale)] },
|
||||
true
|
||||
);
|
||||
|
||||
if(instance.queue.track.length === 0)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)] });
|
||||
if (instance.queue.track.length === 0)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)]
|
||||
});
|
||||
|
||||
instance.skipTrack();
|
||||
|
||||
if(instance.queue.track.length === 0)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SKIPPED_LASTSONG(data, locale)] });
|
||||
else
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SKIPPED(data, locale)] });
|
||||
if (instance.queue.track.length === 0)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.SKIPPED_LASTSONG(data, locale)]
|
||||
});
|
||||
else return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SKIPPED(data, locale)] });
|
||||
}
|
||||
}
|
||||
+12
-20
@@ -10,11 +10,7 @@ import Environment from '../providers/Environment';
|
||||
import Locale from '../services/Locale';
|
||||
|
||||
import DiscordModule, { HybridInteractionMessage } from '../utils/DiscordModule';
|
||||
import {
|
||||
makeSuccessEmbed,
|
||||
makeProcessingEmbed,
|
||||
sendHybridInteractionMessageResponse
|
||||
} from '../utils/DiscordMessage';
|
||||
import { makeSuccessEmbed, makeProcessingEmbed, sendHybridInteractionMessageResponse } from '../utils/DiscordMessage';
|
||||
|
||||
enum MeasureType {
|
||||
Ping = 'ping',
|
||||
@@ -57,14 +53,14 @@ export default class Ping extends DiscordModule {
|
||||
const guild = data.getGuild();
|
||||
const member = data.getMember();
|
||||
|
||||
if(!guild || !member) return;
|
||||
if (!guild || !member) return;
|
||||
|
||||
const locale = await Locale.getGuildLocale(guild.id);
|
||||
|
||||
let placeholder: HybridInteractionMessage | undefined;
|
||||
let beforeEditDate = Date.now();
|
||||
let _placeholder = await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.PINGING(data, locale)],
|
||||
embeds: [EMBEDS.PINGING(data, locale)]
|
||||
});
|
||||
if (_placeholder) placeholder = new HybridInteractionMessage(_placeholder);
|
||||
|
||||
@@ -86,23 +82,17 @@ export default class Ping extends DiscordModule {
|
||||
return finalString.push(stringCurrent);
|
||||
}
|
||||
|
||||
if (
|
||||
res.avg === 'unknown' ||
|
||||
res.min === 'unknown' ||
|
||||
res.max === 'unknown'
|
||||
) {
|
||||
if (res.avg === 'unknown' || res.min === 'unknown' || res.max === 'unknown') {
|
||||
stringCurrent += 'Failed';
|
||||
return finalString.push(stringCurrent);
|
||||
}
|
||||
|
||||
stringCurrent += `${parseFloat(res.avg).toFixed(1)}ms (${parseFloat(
|
||||
res.min
|
||||
).toFixed(1)}ms - ${parseFloat(res.max).toFixed(1)}ms)`;
|
||||
stringCurrent += `${parseFloat(res.avg).toFixed(1)}ms (${parseFloat(res.min).toFixed(
|
||||
1
|
||||
)}ms - ${parseFloat(res.max).toFixed(1)}ms)`;
|
||||
finalString.push(stringCurrent);
|
||||
} else if (entry.type === MeasureType.DiscordWebsocket) {
|
||||
stringCurrent += `${Math.round(DiscordProvider.client.ws.ping).toFixed(
|
||||
1
|
||||
)}ms`;
|
||||
stringCurrent += `${Math.round(DiscordProvider.client.ws.ping).toFixed(1)}ms`;
|
||||
finalString.push(stringCurrent);
|
||||
} else if (entry.type === MeasureType.DiscordHTTPPing) {
|
||||
stringCurrent += `${Math.abs(afterEditDate - beforeEditDate).toFixed(1)}ms`;
|
||||
@@ -117,9 +107,11 @@ export default class Ping extends DiscordModule {
|
||||
|
||||
finalString.push('');
|
||||
finalString.push(
|
||||
`💻 ${locale.__('ping.running_on', {HOST: os.hostname()})} ` +
|
||||
`💻 ${locale.__('ping.running_on', { HOST: os.hostname() })} ` +
|
||||
`${
|
||||
Environment.get().NODE_ENV === 'development' ? ` / ${locale.__('ping.development_environment')}` : ''
|
||||
Environment.get().NODE_ENV === 'development'
|
||||
? ` / ${locale.__('ping.development_environment')}`
|
||||
: ''
|
||||
}`
|
||||
);
|
||||
|
||||
|
||||
+3
-5
@@ -27,11 +27,9 @@ const EMBEDS = {
|
||||
NO_PERMISSION: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
return makeErrorEmbed({
|
||||
title: locale.__('common.no_permissions'),
|
||||
description: locale.__(
|
||||
'common.no_permissions_description', {
|
||||
description: locale.__('common.no_permissions_description', {
|
||||
PERMISSIONS: 'VIEW_CHANNEL, SEND_MESSAGES, MANAGE_CHANNELS'
|
||||
}
|
||||
),
|
||||
}),
|
||||
user: data.getUser()
|
||||
});
|
||||
},
|
||||
@@ -80,7 +78,7 @@ export default class Say extends DiscordModule {
|
||||
!message.member.permissions.has([
|
||||
PermissionsBitField.Flags.ViewChannel,
|
||||
PermissionsBitField.Flags.SendMessages,
|
||||
PermissionsBitField.Flags.ManageChannels,
|
||||
PermissionsBitField.Flags.ManageChannels
|
||||
])
|
||||
)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
|
||||
@@ -53,7 +53,14 @@ export default async (data: HybridInteractionMessage, args: any, guild: Guild, l
|
||||
if (!GuildCache) return;
|
||||
const language = GuildCache.locale;
|
||||
|
||||
if (!(await checkMemberPermissionsInGuild({ member, data, locale, permissions: [PermissionsBitField.Flags.ManageGuild] })))
|
||||
if (
|
||||
!(await checkMemberPermissionsInGuild({
|
||||
member,
|
||||
data,
|
||||
locale,
|
||||
permissions: [PermissionsBitField.Flags.ManageGuild]
|
||||
}))
|
||||
)
|
||||
return;
|
||||
|
||||
let newLanguage: string | null | undefined;
|
||||
|
||||
@@ -19,7 +19,7 @@ import { checkMemberPermissionsInGuild } from '../../utils/DiscordPermission';
|
||||
const EMBEDS = {
|
||||
PREFIX_INFO: (data: HybridInteractionMessage, locale: I18n, currentPrefix: string) => {
|
||||
return makeInfoEmbed({
|
||||
title: locale.__('settings_prefix.info', { PREFIX: currentPrefix}),
|
||||
title: locale.__('settings_prefix.info', { PREFIX: currentPrefix }),
|
||||
description: locale.__('settings_prefix.info_description'),
|
||||
user: data.getUser()
|
||||
});
|
||||
@@ -55,7 +55,14 @@ export default async (data: HybridInteractionMessage, args: any, guild: Guild, l
|
||||
if (!GuildCache) return;
|
||||
const prefix = GuildCache.prefix;
|
||||
|
||||
if (!(await checkMemberPermissionsInGuild({ member, data, locale, permissions: [PermissionsBitField.Flags.ManageGuild] })))
|
||||
if (
|
||||
!(await checkMemberPermissionsInGuild({
|
||||
member,
|
||||
data,
|
||||
locale,
|
||||
permissions: [PermissionsBitField.Flags.ManageGuild]
|
||||
}))
|
||||
)
|
||||
return;
|
||||
|
||||
let newPrefix: string | null | undefined;
|
||||
@@ -70,7 +77,8 @@ export default async (data: HybridInteractionMessage, args: any, guild: Guild, l
|
||||
__name.shift();
|
||||
_name = __name.join(' ');
|
||||
newPrefix = _name;
|
||||
} else if (data.isApplicationCommand()) newPrefix = data.getSlashCommand().options.get('prefix', true).value?.toString();
|
||||
} else if (data.isApplicationCommand())
|
||||
newPrefix = data.getSlashCommand().options.get('prefix', true).value?.toString();
|
||||
|
||||
if (!newPrefix)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
@@ -82,7 +90,10 @@ export default async (data: HybridInteractionMessage, args: any, guild: Guild, l
|
||||
embeds: [EMBEDS.PREFIX_TOO_LONG(data, locale)]
|
||||
});
|
||||
|
||||
if (newPrefix.startsWith(`<@!${DiscordProvider.client.user?.id}>`) || newPrefix.startsWith(`<@${DiscordProvider.client.user?.id}>`))
|
||||
if (
|
||||
newPrefix.startsWith(`<@!${DiscordProvider.client.user?.id}>`) ||
|
||||
newPrefix.startsWith(`<@${DiscordProvider.client.user?.id}>`)
|
||||
)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.PREFIX_IS_MENTION(data, locale)]
|
||||
});
|
||||
|
||||
@@ -104,29 +104,49 @@ export const setEnableServiceAnnouncement = async (
|
||||
let member = data.getMember();
|
||||
if (!member) return;
|
||||
|
||||
if (!(await checkMemberPermissionsInGuild({ member, data, locale, permissions: [PermissionsBitField.Flags.Administrator] })))
|
||||
if (
|
||||
!(await checkMemberPermissionsInGuild({
|
||||
member,
|
||||
data,
|
||||
locale,
|
||||
permissions: [PermissionsBitField.Flags.Administrator]
|
||||
}))
|
||||
)
|
||||
return;
|
||||
|
||||
let GuildCache = await Cache.getCachedGuild(guild.id);
|
||||
if(!GuildCache) return;
|
||||
if (!GuildCache) return;
|
||||
|
||||
let newStatus: string | null | undefined;
|
||||
if (data.isMessage()) {
|
||||
let _name: string;
|
||||
if (typeof args[1] === 'undefined')
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [await EMBEDS.NO_SERVICE_ANNOUNCEMENT_STATUS_PROVIDED(data, locale, GuildCache.ServiceAnnouncement_Enabled)]
|
||||
embeds: [
|
||||
await EMBEDS.NO_SERVICE_ANNOUNCEMENT_STATUS_PROVIDED(
|
||||
data,
|
||||
locale,
|
||||
GuildCache.ServiceAnnouncement_Enabled
|
||||
)
|
||||
]
|
||||
});
|
||||
|
||||
let __name = args;
|
||||
__name.shift();
|
||||
_name = __name.join(' ');
|
||||
newStatus = _name;
|
||||
} else if (data.isApplicationCommand()) newStatus = data.getSlashCommand().options.get('status', true).value?.toString();
|
||||
} else if (data.isApplicationCommand())
|
||||
newStatus = data.getSlashCommand().options.get('status', true).value?.toString();
|
||||
|
||||
if (!newStatus)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [await EMBEDS.NO_SERVICE_ANNOUNCEMENT_STATUS_PROVIDED(data, locale, GuildCache.ServiceAnnouncement_Enabled)]
|
||||
embeds: [
|
||||
await EMBEDS.NO_SERVICE_ANNOUNCEMENT_STATUS_PROVIDED(
|
||||
data,
|
||||
locale,
|
||||
GuildCache.ServiceAnnouncement_Enabled
|
||||
)
|
||||
]
|
||||
});
|
||||
|
||||
if (!['true', 'false', 'yes', 'no', 'y', 'n', 'enable', 'disable'].includes(newStatus.toLowerCase()))
|
||||
@@ -182,7 +202,14 @@ export const setServiceAnnouncementChannel = async (
|
||||
let member = data.getMember();
|
||||
if (!member) return;
|
||||
|
||||
if (!(await checkMemberPermissionsInGuild({ member, data, locale, permissions: [PermissionsBitField.Flags.Administrator] })))
|
||||
if (
|
||||
!(await checkMemberPermissionsInGuild({
|
||||
member,
|
||||
data,
|
||||
locale,
|
||||
permissions: [PermissionsBitField.Flags.Administrator]
|
||||
}))
|
||||
)
|
||||
return;
|
||||
|
||||
let channel;
|
||||
@@ -213,7 +240,9 @@ export const setServiceAnnouncementChannel = async (
|
||||
});
|
||||
|
||||
if (
|
||||
!data.getGuild()?.members.me?.permissionsIn(TargetChannel)
|
||||
!data
|
||||
.getGuild()
|
||||
?.members.me?.permissionsIn(TargetChannel)
|
||||
.has([PermissionsBitField.Flags.SendMessages, PermissionsBitField.Flags.ViewChannel])
|
||||
)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
import {
|
||||
Message,
|
||||
CommandInteraction,
|
||||
Guild,
|
||||
PermissionsBitField,
|
||||
PermissionResolvable
|
||||
} from 'discord.js';
|
||||
import { Message, CommandInteraction, Guild, PermissionsBitField, PermissionResolvable } from 'discord.js';
|
||||
import { I18n } from 'i18n';
|
||||
|
||||
import DiscordProvider from '../../providers/Discord';
|
||||
@@ -24,26 +18,26 @@ import * as ServiceAnnouncementModule from './ServiceAnnouncement';
|
||||
|
||||
export const COMMON_EMBEDS = {
|
||||
MEMBER_NO_PERMISSION: (data: HybridInteractionMessage, locale: I18n, permissions: PermissionResolvable[]) => {
|
||||
|
||||
let allPermissions = [];
|
||||
for(const value of permissions) {
|
||||
for (const value of permissions) {
|
||||
allPermissions.push(new PermissionsBitField(value).toArray());
|
||||
}
|
||||
return makeErrorEmbed({
|
||||
title: locale.__('common.member_no_permissions'),
|
||||
description: locale.__('common.member_no_permissions_description', { PERMISSIONS: allPermissions.join(', ')}),
|
||||
description: locale.__('common.member_no_permissions_description', {
|
||||
PERMISSIONS: allPermissions.join(', ')
|
||||
}),
|
||||
user: data.getUser()
|
||||
});
|
||||
},
|
||||
BOT_NO_PERMISSION: (data: HybridInteractionMessage, locale: I18n, permissions: PermissionResolvable[]) => {
|
||||
|
||||
let allPermissions = [];
|
||||
for(const value of permissions) {
|
||||
for (const value of permissions) {
|
||||
allPermissions.push(new PermissionsBitField(value).toArray());
|
||||
}
|
||||
return makeErrorEmbed({
|
||||
title: locale.__('common.bot_no_permissions'),
|
||||
description: locale.__('common.bot_no_permissions_description', { PERMISSIONS: allPermissions.join(', ')}),
|
||||
description: locale.__('common.bot_no_permissions_description', { PERMISSIONS: allPermissions.join(', ') }),
|
||||
user: data.getUser()
|
||||
});
|
||||
},
|
||||
@@ -55,7 +49,7 @@ export const COMMON_EMBEDS = {
|
||||
user: data.getUser()
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const EMBEDS = {
|
||||
SETTINGS_INFO: (data: HybridInteractionMessage, locale: I18n, guild: Guild) => {
|
||||
@@ -68,7 +62,7 @@ const EMBEDS = {
|
||||
fields: [
|
||||
{
|
||||
name: locale.__('common.available_args'),
|
||||
value: locale.__('settings.valid_args'),
|
||||
value: locale.__('settings.valid_args')
|
||||
}
|
||||
],
|
||||
user: data.getUser()
|
||||
|
||||
@@ -23,15 +23,16 @@ const EMBEDS = {
|
||||
{
|
||||
name: `🌐 ${locale.__('stats.users')}`,
|
||||
value: `${locale.__('stats.x_servers', { COUNT: totalServers.toString() })}\n${locale.__(
|
||||
'stats.x_users', { COUNT: totalUsers.toString()}
|
||||
'stats.x_users',
|
||||
{ COUNT: totalUsers.toString() }
|
||||
)}`,
|
||||
inline: true
|
||||
},
|
||||
{
|
||||
name: `🟢 ${locale.__('stats.uptime_since')}`,
|
||||
value: `${locale.__('stats.server_uptime_x', {TIME: `<t:${systemUptime.toString()}:R>`})}\n${locale.__(
|
||||
'stats.process_uptime_x', { TIME: `<t:${processUptime.toString()}:R>`}
|
||||
)}`,
|
||||
value: `${locale.__('stats.server_uptime_x', {
|
||||
TIME: `<t:${systemUptime.toString()}:R>`
|
||||
})}\n${locale.__('stats.process_uptime_x', { TIME: `<t:${processUptime.toString()}:R>` })}`,
|
||||
inline: true
|
||||
}
|
||||
],
|
||||
|
||||
@@ -13,11 +13,15 @@ const EMBEDS = {
|
||||
const user = data.getUser();
|
||||
let message;
|
||||
if (Environment.get().SUPPORT_URL)
|
||||
message = locale.__('support.info', { BOT_NAME: DiscordProvider.client.user!.username, LINK: Environment.get().SUPPORT_URL});
|
||||
message = locale.__('support.info', {
|
||||
BOT_NAME: DiscordProvider.client.user!.username,
|
||||
LINK: Environment.get().SUPPORT_URL
|
||||
});
|
||||
|
||||
return makeInfoEmbed({
|
||||
title: locale.__('support.title'),
|
||||
description: message || locale.__('support.not_available', { BOT_NAME: DiscordProvider.client.user!.username}),
|
||||
description:
|
||||
message || locale.__('support.not_available', { BOT_NAME: DiscordProvider.client.user!.username }),
|
||||
user
|
||||
});
|
||||
}
|
||||
@@ -46,7 +50,7 @@ export default class Support extends DiscordModule {
|
||||
embeds: [EMBEDS.SUPPORT_INFO(data, locale)]
|
||||
});
|
||||
|
||||
if(Environment.get().SUPPORT_URL)
|
||||
if (Environment.get().SUPPORT_URL)
|
||||
await sendHybridInteractionMessageResponse(data, {
|
||||
content: Environment.get().SUPPORT_URL
|
||||
});
|
||||
|
||||
+18
-8
@@ -74,7 +74,8 @@ const EMBEDS = {
|
||||
if (user.presence?.activities) {
|
||||
for (let activity of user.presence?.activities) {
|
||||
if (activity.type === ActivityType.Custom)
|
||||
embed.addFields([{
|
||||
embed.addFields([
|
||||
{
|
||||
name: `✨ ${locale.__('userinfo.custom_status')}`,
|
||||
value: `${
|
||||
!activity.emoji
|
||||
@@ -89,7 +90,8 @@ const EMBEDS = {
|
||||
} ${activity.state === null ? '' : activity.state}
|
||||
\u200b`,
|
||||
inline: false
|
||||
}]);
|
||||
}
|
||||
]);
|
||||
else {
|
||||
let title = '';
|
||||
switch (activity.type) {
|
||||
@@ -111,27 +113,34 @@ const EMBEDS = {
|
||||
}
|
||||
const startTime = activity.timestamps?.start;
|
||||
const endTime = activity.timestamps?.end;
|
||||
embed.addFields([{
|
||||
embed.addFields([
|
||||
{
|
||||
name: `${title}`,
|
||||
value: `${activity.details === null ? '' : activity.details}
|
||||
${activity.state === null ? '' : activity.state}
|
||||
${
|
||||
startTime
|
||||
? `${locale.__('userinfo.since', {TIME: `<t:${Math.round(startTime.getTime() / 1000)}:R>` })}`
|
||||
? `${locale.__('userinfo.since', {
|
||||
TIME: `<t:${Math.round(startTime.getTime() / 1000)}:R>`
|
||||
})}`
|
||||
: ''
|
||||
}${
|
||||
endTime
|
||||
? `\n${locale.__('userinfo.end', {TIME: `<t:${Math.round(endTime.getTime() / 1000)}:R>` })}`
|
||||
? `\n${locale.__('userinfo.end', {
|
||||
TIME: `<t:${Math.round(endTime.getTime() / 1000)}:R>`
|
||||
})}`
|
||||
: ''
|
||||
}
|
||||
\u200b`,
|
||||
inline: false
|
||||
}]);
|
||||
}
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
embed.addFields([{
|
||||
embed.addFields([
|
||||
{
|
||||
name: `📰 ${locale.__('userinfo.user_guild_info')}`,
|
||||
value: `${
|
||||
user.joinedAt === null
|
||||
@@ -142,7 +151,8 @@ const EMBEDS = {
|
||||
}
|
||||
${user.isGuildOwner ? `${locale.__('userinfo.guild_owner')}` : ''}
|
||||
`
|
||||
}]);
|
||||
}
|
||||
]);
|
||||
|
||||
embed.setThumbnail(user.displayAvatarURL + '?size=4096');
|
||||
embed.setAuthor({
|
||||
|
||||
+2
-14
@@ -1,11 +1,4 @@
|
||||
import {
|
||||
Message,
|
||||
ActionRowBuilder,
|
||||
ButtonBuilder,
|
||||
CommandInteraction,
|
||||
BaseInteraction,
|
||||
ButtonStyle
|
||||
} from 'discord.js';
|
||||
import { Message, ActionRowBuilder, ButtonBuilder, CommandInteraction, BaseInteraction, ButtonStyle } from 'discord.js';
|
||||
import validator from 'validator';
|
||||
import countryLookup from 'country-code-lookup';
|
||||
import { countryCodeEmoji } from 'country-code-emoji';
|
||||
@@ -14,11 +7,7 @@ import Prisma from '../providers/Prisma';
|
||||
import osuAPI from '../providers/osuAPI';
|
||||
|
||||
import DiscordModule, { HybridInteractionMessage } from '../utils/DiscordModule';
|
||||
import {
|
||||
makeInfoEmbed,
|
||||
makeErrorEmbed,
|
||||
sendHybridInteractionMessageResponse
|
||||
} from '../utils/DiscordMessage';
|
||||
import { makeInfoEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse } from '../utils/DiscordMessage';
|
||||
|
||||
const EMBEDS = {
|
||||
osu_INFO: (data: HybridInteractionMessage) => {
|
||||
@@ -99,7 +88,6 @@ export default class osu extends DiscordModule {
|
||||
const Guild = await Prisma.client.guild.findFirst({ where: { id: data.getGuild()!.id } });
|
||||
if (!Guild) return;
|
||||
|
||||
|
||||
if (!osuAPI.client)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.NOT_INITIALIZED(data)]
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
import HTTP_STATUS from "../libs/HTTPStatus";
|
||||
import Logger from "../libs/Logger";
|
||||
import { ServiceError } from "./Errors";
|
||||
import HTTP_STATUS from '../libs/HTTPStatus';
|
||||
import Logger from '../libs/Logger';
|
||||
import { ServiceError } from './Errors';
|
||||
|
||||
class ExpressExceptionHandler {
|
||||
public static errorLogger(error: any, req: any, res: any, next: any) {
|
||||
if(error instanceof ServiceError) {
|
||||
if (error instanceof ServiceError) {
|
||||
res.status(error.statusCode).json({
|
||||
error: error.message
|
||||
})
|
||||
}
|
||||
else {
|
||||
});
|
||||
} else {
|
||||
res.status(HTTP_STATUS.INTERNAL_SERVER_ERROR).json({
|
||||
error: "Internal server error"
|
||||
})
|
||||
error: 'Internal server error'
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,11 +36,7 @@ class Configuration {
|
||||
const dir = path.join(process.cwd(), 'configs/');
|
||||
if (!fs.existsSync(path.join(dir, file))) {
|
||||
fs.copyFileSync(
|
||||
path.join(
|
||||
process.cwd(),
|
||||
'configs_example/',
|
||||
`${file.replace('.json', '.example.json')}`
|
||||
),
|
||||
path.join(process.cwd(), 'configs_example/', `${file.replace('.json', '.example.json')}`),
|
||||
path.join(dir, file)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,17 @@
|
||||
import { Guild, Client, GuildMember, IntentsBitField, Interaction, Message, TextChannel, BaseGuildTextChannel, TextBasedChannelMixin, ChannelType, BaseGuildVoiceChannel, InteractionType } from 'discord.js';
|
||||
import {
|
||||
Guild,
|
||||
Client,
|
||||
GuildMember,
|
||||
IntentsBitField,
|
||||
Interaction,
|
||||
Message,
|
||||
TextChannel,
|
||||
BaseGuildTextChannel,
|
||||
TextBasedChannelMixin,
|
||||
ChannelType,
|
||||
BaseGuildVoiceChannel,
|
||||
InteractionType
|
||||
} from 'discord.js';
|
||||
|
||||
import Logger from '../libs/Logger';
|
||||
import Environment from './Environment';
|
||||
@@ -131,7 +144,11 @@ class Discord {
|
||||
if (interaction.guild) {
|
||||
thisModule.GuildInteractionCreate(interaction);
|
||||
|
||||
if (interaction.type === InteractionType.ApplicationCommand && interaction.commandName && thisModule.commandInteractionName) {
|
||||
if (
|
||||
interaction.type === InteractionType.ApplicationCommand &&
|
||||
interaction.commandName &&
|
||||
thisModule.commandInteractionName
|
||||
) {
|
||||
thisModule.GuildCommandInteractionCreate(interaction);
|
||||
if (interaction.commandName.toLowerCase() === thisModule.commandInteractionName)
|
||||
thisModule.GuildModuleCommandInteractionCreate(interaction);
|
||||
@@ -164,7 +181,8 @@ class Discord {
|
||||
|
||||
// Handling guild commands
|
||||
this.client.on('messageCreate', async (message: Message) => {
|
||||
if (!(message.channel instanceof BaseGuildTextChannel || message.channel instanceof BaseGuildVoiceChannel)) return;
|
||||
if (!(message.channel instanceof BaseGuildTextChannel || message.channel instanceof BaseGuildVoiceChannel))
|
||||
return;
|
||||
if (message.author.bot) return;
|
||||
if (typeof message.guild?.id === 'undefined') return;
|
||||
|
||||
@@ -265,7 +283,8 @@ class Discord {
|
||||
// Handling mentions
|
||||
this.client.on('messageCreate', async (message: Message) => {
|
||||
// TODO: Handle DMs commands soon
|
||||
if (!(message.channel instanceof BaseGuildTextChannel || message.channel instanceof BaseGuildVoiceChannel)) return;
|
||||
if (!(message.channel instanceof BaseGuildTextChannel || message.channel instanceof BaseGuildVoiceChannel))
|
||||
return;
|
||||
if (message.author.bot) return;
|
||||
|
||||
if (typeof message.guild?.id === 'undefined') return;
|
||||
|
||||
@@ -67,16 +67,21 @@ let tokenObject: TokenOptions = {};
|
||||
if (Environment.get().YOUTUBE_COOKIE_BASE64) {
|
||||
tokenObject.youtube = {
|
||||
cookie: Buffer.from(Environment.get().YOUTUBE_COOKIE_BASE64, 'base64').toString()
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (Environment.get().SPOTIFY_CLIENT_ID && Environment.get().SPOTIFY_CLIENT_SECRET && Environment.get().SPOTIFY_REFRESH_TOKEN && Environment.get().SPOTIFY_CLIENT_MARKET) {
|
||||
if (
|
||||
Environment.get().SPOTIFY_CLIENT_ID &&
|
||||
Environment.get().SPOTIFY_CLIENT_SECRET &&
|
||||
Environment.get().SPOTIFY_REFRESH_TOKEN &&
|
||||
Environment.get().SPOTIFY_CLIENT_MARKET
|
||||
) {
|
||||
tokenObject.spotify = {
|
||||
client_id: Environment.get().SPOTIFY_CLIENT_ID,
|
||||
client_secret: Environment.get().SPOTIFY_CLIENT_SECRET,
|
||||
refresh_token: Environment.get().SPOTIFY_REFRESH_TOKEN,
|
||||
market: Environment.get().SPOTIFY_CLIENT_MARKET
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
playdl.setToken(tokenObject);
|
||||
@@ -86,11 +91,10 @@ export class TrackUtils {
|
||||
if (track instanceof YouTubeVideo) {
|
||||
return track.title;
|
||||
} else if (track instanceof SpotifyTrack) {
|
||||
let artistNames = "";
|
||||
for(let artist of track.artists)
|
||||
artistNames += artist.name + " ";
|
||||
let artistNames = '';
|
||||
for (let artist of track.artists) artistNames += artist.name + ' ';
|
||||
|
||||
return `${artistNames} - ${track.name}`;;
|
||||
return `${artistNames} - ${track.name}`;
|
||||
} else {
|
||||
throw new Error('Invalid track type');
|
||||
}
|
||||
@@ -99,22 +103,20 @@ export class TrackUtils {
|
||||
if (track instanceof YouTubeVideo) {
|
||||
return track.thumbnails;
|
||||
} else if (track instanceof SpotifyTrack) {
|
||||
if (track.thumbnail)
|
||||
return [track.thumbnail];
|
||||
if (track.thumbnail) return [track.thumbnail];
|
||||
else {
|
||||
// Try to find the thumbnail again
|
||||
const result = await DiscordMusicPlayer_Instance.searchSpotifyBySpotifyLink(track);
|
||||
if(!result) return null;
|
||||
if(result.thumbnail)
|
||||
return [result.thumbnail];
|
||||
if (!result) return null;
|
||||
if (result.thumbnail) return [result.thumbnail];
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
throw new Error('Invalid track type');
|
||||
}
|
||||
}
|
||||
public static getHighestResolutionThumbnail(thumbnails: (YouTubeThumbnail[] | SpotifyThumbnail[] | null)) {
|
||||
if(!thumbnails) return null;
|
||||
public static getHighestResolutionThumbnail(thumbnails: YouTubeThumbnail[] | SpotifyThumbnail[] | null) {
|
||||
if (!thumbnails) return null;
|
||||
|
||||
return (thumbnails as any[]).reduce((prev: any, current: any) =>
|
||||
prev.height * prev.width > current.height * current.width ? prev : current
|
||||
@@ -141,7 +143,7 @@ export class SpotifyLink {
|
||||
public type: 'track' | 'playlist' | 'album';
|
||||
public url: string;
|
||||
|
||||
constructor(id: string, type: ('track' | 'playlist' | 'album'), url: string) {
|
||||
constructor(id: string, type: 'track' | 'playlist' | 'album', url: string) {
|
||||
this.id = id;
|
||||
this.type = type;
|
||||
this.url = url;
|
||||
@@ -237,7 +239,10 @@ export class DiscordMusicPlayerInstance {
|
||||
});
|
||||
}
|
||||
|
||||
public joinVoiceChannel(voiceChannel: VoiceChannel | StageChannel, textChannel?: BaseGuildTextChannel | BaseGuildVoiceChannel) {
|
||||
public joinVoiceChannel(
|
||||
voiceChannel: VoiceChannel | StageChannel,
|
||||
textChannel?: BaseGuildTextChannel | BaseGuildVoiceChannel
|
||||
) {
|
||||
const permissions = voiceChannel.permissionsFor(DiscordProvider.client.user!);
|
||||
|
||||
if (!permissions || !voiceChannel.joinable || !permissions.has(PermissionsBitField.Flags.Connect))
|
||||
@@ -269,7 +274,7 @@ export class DiscordMusicPlayerInstance {
|
||||
(oldState: VoiceConnectionState, newState: VoiceConnectionState) => {
|
||||
setTimeout(async () => {
|
||||
let guild = DiscordProvider.client.guilds.cache.get(voiceChannel.guildId);
|
||||
if(guild) {
|
||||
if (guild) {
|
||||
if (!guild?.members.me?.voice.channelId) {
|
||||
this.events.emit('disconnect', new VoiceDisconnectedEvent(this));
|
||||
}
|
||||
@@ -314,9 +319,8 @@ export class DiscordMusicPlayerInstance {
|
||||
if (!this.voiceConnection) throw new Error('No voice connection');
|
||||
|
||||
try {
|
||||
|
||||
let resource;
|
||||
if(track instanceof YouTubeVideo) {
|
||||
if (track instanceof YouTubeVideo) {
|
||||
const stream = await playdl.stream(track.url);
|
||||
resource = createAudioResource(stream.stream, {
|
||||
inputType: stream.type
|
||||
@@ -324,8 +328,7 @@ export class DiscordMusicPlayerInstance {
|
||||
this.actualPlaybackURL = track.url;
|
||||
} else {
|
||||
const search = await DiscordMusicPlayer_Instance.searchYouTubeBySpotifyLink(track);
|
||||
if(!search)
|
||||
throw new Error('Unable to find Spotify track on YouTube');
|
||||
if (!search) throw new Error('Unable to find Spotify track on YouTube');
|
||||
|
||||
const stream = await playdl.stream(search.url);
|
||||
resource = createAudioResource(stream.stream, {
|
||||
@@ -359,7 +362,7 @@ export class DiscordMusicPlayerInstance {
|
||||
public clearQueue() {
|
||||
if (!this.voiceConnection) throw new Error('No voice connection');
|
||||
|
||||
if(!this.queue.track || this.queue.track.length === 0) return;
|
||||
if (!this.queue.track || this.queue.track.length === 0) return;
|
||||
this.queue.track = [this.queue.track[0]];
|
||||
}
|
||||
|
||||
@@ -367,17 +370,17 @@ export class DiscordMusicPlayerInstance {
|
||||
if (!this.voiceConnection) throw new Error('No voice connection');
|
||||
|
||||
const shuffleFixedFirst = (queue: ValidTracks[]) => {
|
||||
if(queue.length <= 2) return queue;
|
||||
if (queue.length <= 2) return queue;
|
||||
|
||||
const fixedFirst = queue.shift();
|
||||
if(!fixedFirst) return queue;
|
||||
if (!fixedFirst) return queue;
|
||||
|
||||
queue.sort(() => Math.random() - 0.5);
|
||||
queue.unshift(fixedFirst);
|
||||
return queue;
|
||||
}
|
||||
};
|
||||
|
||||
if(!this.queue.track || this.queue.track.length === 0) return;
|
||||
if (!this.queue.track || this.queue.track.length === 0) return;
|
||||
this.queue.track = shuffleFixedFirst(this.queue.track);
|
||||
}
|
||||
|
||||
@@ -475,32 +478,31 @@ class DiscordMusicPlayer {
|
||||
}
|
||||
|
||||
public async searchYouTubeBySpotifyLink(spotifyLink: SpotifyLink) {
|
||||
|
||||
const track = await this.searchSpotifyBySpotifyLink(spotifyLink);
|
||||
if(!track) return;
|
||||
if (!track) return;
|
||||
|
||||
let artistNames = "";
|
||||
for(let artist of track.artists)
|
||||
artistNames += artist.name + " ";
|
||||
let artistNames = '';
|
||||
for (let artist of track.artists) artistNames += artist.name + ' ';
|
||||
|
||||
const ytSearchResult = await this.searchYouTubeByQuery(`${artistNames} ${track.name}`);
|
||||
if(!ytSearchResult) return null;
|
||||
if (!ytSearchResult) return null;
|
||||
|
||||
return ytSearchResult[0];
|
||||
}
|
||||
|
||||
public async searchSpotifyBySpotifyLink(spotifyLink: SpotifyLink) {
|
||||
if(playdl.is_expired())
|
||||
await playdl.refreshToken();
|
||||
if (playdl.is_expired()) await playdl.refreshToken();
|
||||
|
||||
if(spotifyLink.type != 'track') return;
|
||||
if (spotifyLink.type != 'track') return;
|
||||
|
||||
// Fetch data from spotify
|
||||
const searched: Spotify = await playdl.spotify("https://open.spotify.com/track/" + spotifyLink.id).catch((err) => {
|
||||
const searched: Spotify = await playdl
|
||||
.spotify('https://open.spotify.com/track/' + spotifyLink.id)
|
||||
.catch((err) => {
|
||||
Logger.error(err.message);
|
||||
throw new Error('Error while searching on Spotify');
|
||||
});
|
||||
if(!(searched instanceof SpotifyTrack)) return;
|
||||
if (!(searched instanceof SpotifyTrack)) return;
|
||||
|
||||
if (!searched) return null;
|
||||
const track = searched as unknown as SpotifyTrack;
|
||||
@@ -570,16 +572,14 @@ class DiscordMusicPlayer {
|
||||
}
|
||||
|
||||
public async getSpotifySongsInPlayList(spotifyLink: string) {
|
||||
if(playdl.is_expired())
|
||||
await playdl.refreshToken();
|
||||
if (playdl.is_expired()) await playdl.refreshToken();
|
||||
|
||||
const result = await playdl.spotify(spotifyLink).catch((err) => {
|
||||
Logger.error(err.message);
|
||||
throw new Error('Error while searching on Spotify');
|
||||
});
|
||||
|
||||
if(!(result.type == 'playlist' || result.type == 'album'))
|
||||
throw new Error("Not a spotify playlist");
|
||||
if (!(result.type == 'playlist' || result.type == 'album')) throw new Error('Not a spotify playlist');
|
||||
|
||||
return result as unknown as SpotifyPlaylist;
|
||||
}
|
||||
@@ -647,24 +647,21 @@ class DiscordMusicPlayer {
|
||||
type: 'track',
|
||||
url: query.split(/[?#]/)[0]
|
||||
};
|
||||
}
|
||||
else if (query.startsWith('https://open.spotify.com/album/')) {
|
||||
} else if (query.startsWith('https://open.spotify.com/album/')) {
|
||||
let id = query.split('/')[4].split(/[?#]/)[0];
|
||||
return {
|
||||
id: id,
|
||||
type: 'album',
|
||||
url: query.split(/[?#]/)[0]
|
||||
};
|
||||
}
|
||||
else if (query.startsWith('https://open.spotify.com/playlist/')) {
|
||||
} else if (query.startsWith('https://open.spotify.com/playlist/')) {
|
||||
let id = query.split('/')[4].split(/[?#]/)[0];
|
||||
return {
|
||||
id: id,
|
||||
type: 'playlist',
|
||||
url: query.split(/[?#]/)[0]
|
||||
};
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw new Error('Spotify link is invalid');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,11 @@ class Environment {
|
||||
throw new Error('.env SUPPORT_URL is not a valid URL');
|
||||
|
||||
// WEB_HOST Checks
|
||||
if (this.get().WEB_HOST && this.get().WEB_HOST.toLowerCase() != 'localhost' && !validator.isIP(this.get().WEB_HOST))
|
||||
if (
|
||||
this.get().WEB_HOST &&
|
||||
this.get().WEB_HOST.toLowerCase() != 'localhost' &&
|
||||
!validator.isIP(this.get().WEB_HOST)
|
||||
)
|
||||
throw new Error('.env WEB_HOST must be either localhost or a valid IP address');
|
||||
|
||||
// WEB_PORT Checks
|
||||
@@ -68,9 +72,9 @@ class Environment {
|
||||
const YOUTUBE_COOKIE_BASE64 = process.env.YOUTUBE_COOKIE_BASE64;
|
||||
|
||||
const SPOTIFY_CLIENT_ID = process.env.SPOTIFY_CLIENT_ID;
|
||||
const SPOTIFY_CLIENT_SECRET= process.env.SPOTIFY_CLIENT_SECRET;
|
||||
const SPOTIFY_REFRESH_TOKEN= process.env.SPOTIFY_REFRESH_TOKEN;
|
||||
const SPOTIFY_CLIENT_MARKET= process.env.SPOTIFY_CLIENT_MARKET;
|
||||
const SPOTIFY_CLIENT_SECRET = process.env.SPOTIFY_CLIENT_SECRET;
|
||||
const SPOTIFY_REFRESH_TOKEN = process.env.SPOTIFY_REFRESH_TOKEN;
|
||||
const SPOTIFY_CLIENT_MARKET = process.env.SPOTIFY_CLIENT_MARKET;
|
||||
|
||||
return {
|
||||
NODE_ENV,
|
||||
|
||||
+10
-13
@@ -1,53 +1,50 @@
|
||||
import express from 'express';
|
||||
import cors from 'cors';
|
||||
|
||||
import Logger from "../libs/Logger";
|
||||
import Environment from "./Environment";
|
||||
import Logger from '../libs/Logger';
|
||||
import Environment from './Environment';
|
||||
|
||||
import ExpressException from '../exception/ExpressException';
|
||||
import Routes from './Routes';
|
||||
|
||||
class Express {
|
||||
|
||||
public server: any;
|
||||
public express: express.Application;
|
||||
|
||||
constructor () {
|
||||
constructor() {
|
||||
this.server = null;
|
||||
this.express = express();
|
||||
}
|
||||
|
||||
public init(): void {
|
||||
|
||||
this.mountMiddlewares();
|
||||
this.mountRoutes();
|
||||
this.express = this.express.use(ExpressException.errorLogger);
|
||||
|
||||
this.server = this.express.listen(Environment.get().WEB_PORT, Environment.get().WEB_HOST, () => {
|
||||
Logger.log('info', `Express Webserver listening at ${Environment.get().WEB_HOST}:${Environment.get().WEB_PORT}`);
|
||||
Logger.log(
|
||||
'info',
|
||||
`Express Webserver listening at ${Environment.get().WEB_HOST}:${Environment.get().WEB_PORT}`
|
||||
);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public end(): void {
|
||||
if(this.server)
|
||||
this.server.close();
|
||||
if (this.server) this.server.close();
|
||||
}
|
||||
|
||||
private mountRoutes (): void {
|
||||
private mountRoutes(): void {
|
||||
this.express = Routes.mountAPI(this.express);
|
||||
this.express = Routes.mountWeb(this.express);
|
||||
}
|
||||
|
||||
private mountMiddlewares (): void {
|
||||
|
||||
private mountMiddlewares(): void {
|
||||
//this.express = RateLimit.init(this.express);
|
||||
this.express = this.express.use(cors());
|
||||
|
||||
//This always have to be at the bottom!
|
||||
this.express = this.express.use(express.json());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default new Express();
|
||||
@@ -3,7 +3,6 @@ import Logger from '../libs/Logger';
|
||||
import apiv1Router from '../routes/API/v1';
|
||||
|
||||
class Routes {
|
||||
|
||||
public mountWeb(_express: express.Application): Application {
|
||||
Logger.log('info', 'Mounting Web routes');
|
||||
return _express;
|
||||
@@ -16,7 +15,6 @@ class Routes {
|
||||
|
||||
return _express;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default new Routes;
|
||||
export default new Routes();
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
import * as express from 'express';
|
||||
import Environment from '../../providers/Environment'
|
||||
import Environment from '../../providers/Environment';
|
||||
|
||||
import HealthCheck from '../../controllers/API/v1/HealthCheck';
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
let isDevEnv = (req: any, res: any, next: any) => {
|
||||
if(Environment.get().NODE_ENV == 'development') {
|
||||
if (Environment.get().NODE_ENV == 'development') {
|
||||
return next();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return res.sendStatus(403);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
router.get('/health', HealthCheck.perform);
|
||||
|
||||
export default router;
|
||||
@@ -6,7 +6,7 @@ import Locale from '../providers/Locale';
|
||||
|
||||
export async function getGuildLocale(id: Snowflake): Promise<I18n> {
|
||||
const cachedGuild = await Cache.getCachedGuild(id);
|
||||
if (!cachedGuild) return Locale.getLocaleProvider("en");
|
||||
if (!cachedGuild) return Locale.getLocaleProvider('en');
|
||||
|
||||
const LocaleProvider = Locale.getLocaleProvider(cachedGuild.locale);
|
||||
return LocaleProvider;
|
||||
@@ -14,4 +14,4 @@ export async function getGuildLocale(id: Snowflake): Promise<I18n> {
|
||||
|
||||
export default {
|
||||
getGuildLocale
|
||||
}
|
||||
};
|
||||
|
||||
@@ -3,9 +3,7 @@ import Environment from '../providers/Environment';
|
||||
|
||||
class Users {
|
||||
public static isDeveloper(user: User | Snowflake) {
|
||||
|
||||
if(!Environment.get().DEVELOPERS)
|
||||
return false;
|
||||
if (!Environment.get().DEVELOPERS) return false;
|
||||
|
||||
const developers: Snowflake[] = Environment.get().DEVELOPER_IDS.split(',');
|
||||
let userID;
|
||||
|
||||
@@ -44,13 +44,9 @@ export default class DiscordModule {
|
||||
GuildModuleInteractionCreate(interaction: Interaction): void | Promise<void | any> {}
|
||||
|
||||
GuildCommandInteractionCreate(interaction: CommandInteraction): void | Promise<void | any> {}
|
||||
GuildModuleCommandInteractionCreate(
|
||||
interaction: CommandInteraction
|
||||
): void | Promise<void | any> {}
|
||||
GuildModuleCommandInteractionCreate(interaction: CommandInteraction): void | Promise<void | any> {}
|
||||
|
||||
GuildSelectMenuInteractionCreate(
|
||||
interaction: SelectMenuInteraction
|
||||
): void | Promise<void | any> {}
|
||||
GuildSelectMenuInteractionCreate(interaction: SelectMenuInteraction): void | Promise<void | any> {}
|
||||
|
||||
GuildButtonInteractionCreate(interaction: ButtonInteraction): void | Promise<void | any> {}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ export async function checkBotPermissionsInGuild({
|
||||
locale?: I18n;
|
||||
}): Promise<boolean> {
|
||||
const member = guild.members.me;
|
||||
if(!member) return false;
|
||||
if (!member) return false;
|
||||
|
||||
const hasPermissions = member.permissions.has(permissions);
|
||||
|
||||
@@ -86,7 +86,7 @@ export async function checkBotPermissionsInChannel({
|
||||
locale?: I18n;
|
||||
}): Promise<boolean> {
|
||||
const member = guild.members.me;
|
||||
if(!member) return false;
|
||||
if (!member) return false;
|
||||
|
||||
const hasPermissions = member.permissionsIn(channel).has(permissions);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user