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