Formatted code

This commit is contained in:
2023-03-05 14:46:25 +07:00
parent 89744dcb10
commit b44e583834
47 changed files with 1240 additions and 1162 deletions
+5 -17
View File
@@ -9,11 +9,7 @@ import {
} from 'discord.js';
import DiscordModule, { HybridInteractionMessage } from '../../utils/DiscordModule';
import {
makeInfoEmbed,
makeErrorEmbed,
sendHybridInteractionMessageResponse
} from '../../utils/DiscordMessage';
import { makeInfoEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse } from '../../utils/DiscordMessage';
import DiscordMusicPlayer from '../../providers/DiscordMusicPlayer';
import Users from '../../services/Users';
@@ -140,34 +136,26 @@ export default class Debug extends DiscordModule {
},
activeMusicPlayer: async (data: HybridInteractionMessage) => {
await sendHybridInteractionMessageResponse(data, {
embeds: [
EMBEDS.ACTIVE_MUSIC_PLAYERS(data, DiscordMusicPlayer.GuildQueue)
]
embeds: [EMBEDS.ACTIVE_MUSIC_PLAYERS(data, DiscordMusicPlayer.GuildQueue)]
});
},
myData: async (data: HybridInteractionMessage) => {
const userData = await Cache.getCachedUser(user.id);
await sendHybridInteractionMessageResponse(data, {
embeds: [
EMBEDS.YOUR_USER_DATA(data, userData)
]
embeds: [EMBEDS.YOUR_USER_DATA(data, userData)]
});
},
guildData: async (data: HybridInteractionMessage) => {
const guildData = await Cache.getCachedGuild(guild.id);
await sendHybridInteractionMessageResponse(data, {
embeds: [
EMBEDS.GUILD_DATA(data, guildData)
]
embeds: [EMBEDS.GUILD_DATA(data, guildData)]
});
},
invalidInteraction: async (data: HybridInteractionMessage) => {
const row = new ActionRowBuilder<ButtonBuilder>().addComponents([
new ButtonBuilder()
.setEmoji('😥')
.setLabel(
'Make invalid interaction (Wait 7 seconds, check error in console or logs)'
)
.setLabel('Make invalid interaction (Wait 7 seconds, check error in console or logs)')
.setCustomId('dev_make_invalid_interaction')
.setStyle(ButtonStyle.Primary)
]);
+12 -31
View File
@@ -53,17 +53,14 @@ const EMBEDS = {
if (!payload.timestamp) payload.timestamp = Date.now();
if (payload.thumbnail?.url === 'bot_avatar')
payload.thumbnail.url = `${user?.displayAvatarURL()}?size=4096`;
if (payload.thumbnail?.url === 'bot_avatar') payload.thumbnail.url = `${user?.displayAvatarURL()}?size=4096`;
if (payload.image?.url === 'bot_avatar')
payload.image.url = `${user?.displayAvatarURL()}?size=4096`;
if (payload.image?.url === 'bot_avatar') payload.image.url = `${user?.displayAvatarURL()}?size=4096`;
if (payload.description)
payload.description = payload.description.replaceAll('{bot_username}', user?.username!);
if (payload.color && isNaN(payload.color))
payload.color = hexToDecimal(payload.color.toString());
if (payload.color && isNaN(payload.color)) payload.color = hexToDecimal(payload.color.toString());
return new EmbedBuilder(payload);
},
@@ -145,9 +142,7 @@ export default class ServiceAnnouncement extends DiscordModule {
async Init() {
if (fs.existsSync(path.join(process.cwd(), 'configs/ServiceAnnouncement.json'))) {
try {
const rawData = fs.readFileSync(
path.join(process.cwd(), 'configs/ServiceAnnouncement.json')
);
const rawData = fs.readFileSync(path.join(process.cwd(), 'configs/ServiceAnnouncement.json'));
const jsonData = JSON.parse(rawData.toString());
Announcements = jsonData;
} catch (err) {
@@ -177,9 +172,7 @@ export default class ServiceAnnouncement extends DiscordModule {
reload: async (data: HybridInteractionMessage) => {
if (fs.existsSync(path.join(process.cwd(), 'configs/ServiceAnnouncement.json'))) {
try {
const rawData = fs.readFileSync(
path.join(process.cwd(), 'configs/ServiceAnnouncement.json')
);
const rawData = fs.readFileSync(path.join(process.cwd(), 'configs/ServiceAnnouncement.json'));
const jsonData = JSON.parse(rawData.toString());
Announcements = jsonData;
} catch (err: any) {
@@ -264,9 +257,7 @@ export default class ServiceAnnouncement extends DiscordModule {
let Guild: Guild = element[0];
let Channel: TextChannel = element[1];
try {
const guildObject = DiscordProvider.client.guilds.cache.get(
Guild.id
);
const guildObject = DiscordProvider.client.guilds.cache.get(Guild.id);
if (!guildObject) throw new Error('Guild not found');
Logger.info(
`Sending Service Announcement to ${guildObject?.name} (${guildObject.id}) #${Channel.name} (${Channel.id})`
@@ -276,9 +267,7 @@ export default class ServiceAnnouncement extends DiscordModule {
});
} catch (err) {
withError = true;
const guildObject = DiscordProvider.client.guilds.cache.get(
Guild.id
);
const guildObject = DiscordProvider.client.guilds.cache.get(Guild.id);
if (guildObject)
Logger.info(
`Unable to send Service Announcement to ${guildObject?.name} (${guildObject.id}) #${Channel.name} (${Channel.id})`
@@ -296,28 +285,20 @@ export default class ServiceAnnouncement extends DiscordModule {
if (withError) {
if (data && data.isMessage() && placeholder && placeholder.isMessage())
return placeholder
.getMessage()
.edit({
embeds: [
EMBEDS.SERVICE_ANNOUNCEMENT_SENT_WITH_ERRORS(data)
]
});
return placeholder.getMessage().edit({
embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_SENT_WITH_ERRORS(data)]
});
else if (data.isApplicationCommand())
return await sendHybridInteractionMessageResponse(
data,
{
embeds: [
EMBEDS.SERVICE_ANNOUNCEMENT_SENT_WITH_ERRORS(data)
]
embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_SENT_WITH_ERRORS(data)]
},
true
);
} else {
if (data && data.isMessage() && placeholder && placeholder.isMessage())
return placeholder
.getMessage()
.edit({ embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_SENT(data)] });
return placeholder.getMessage().edit({ embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_SENT(data)] });
else if (data.isApplicationCommand())
return await sendHybridInteractionMessageResponse(
data,
+4 -4
View File
@@ -17,10 +17,10 @@ const EMBEDS = {
let _e = makeInfoEmbed({
icon: '💌',
title: locale.__('help.title', { BOT_NAME: bot.username }),
description: `\u200b\n🏷️**${locale.__('help.prefix_title')}**\n${locale.__(
'help.prefix_description',
{PREFIX: prefix.replaceAll('`', '`'), PREFIX_MENTION: `<@${bot.id}>`}
)}\n\n💻 **${locale.__('help.available_commands')}**`,
description: `\u200b\n🏷️**${locale.__('help.prefix_title')}**\n${locale.__('help.prefix_description', {
PREFIX: prefix.replaceAll('`', '`'),
PREFIX_MENTION: `<@${bot.id}>`
})}\n\n💻 **${locale.__('help.available_commands')}**`,
fields: [
{
name: `☕ ${locale.__('help.general')}`,
+6 -18
View File
@@ -108,9 +108,7 @@ export default class InteractionManager extends DiscordModule {
await unregisterAllGuildsCommands();
if (data && data.isMessage() && placeholder && placeholder.isMessage())
return placeholder
.getMessage()
.edit({ embeds: [EMBEDS.UNLOADALL_SUCCESS(data)] });
return placeholder.getMessage().edit({ embeds: [EMBEDS.UNLOADALL_SUCCESS(data)] });
else if (data.isApplicationCommand())
return await sendHybridInteractionMessageResponse(
data,
@@ -119,9 +117,7 @@ export default class InteractionManager extends DiscordModule {
);
} catch (err) {
if (data && data.isMessage() && placeholder && placeholder.isMessage())
return placeholder
.getMessage()
.edit({ embeds: [EMBEDS.UNLOADALL_ERROR(data, err)] });
return placeholder.getMessage().edit({ embeds: [EMBEDS.UNLOADALL_ERROR(data, err)] });
else if (data.isApplicationCommand())
return await sendHybridInteractionMessageResponse(
data,
@@ -143,9 +139,7 @@ export default class InteractionManager extends DiscordModule {
await registerAllGlobalCommands();
if (data && data.isMessage() && placeholder && placeholder.isMessage())
return placeholder
.getMessage()
.edit({ embeds: [EMBEDS.RELOADALL_SUCCESS(data)] });
return placeholder.getMessage().edit({ embeds: [EMBEDS.RELOADALL_SUCCESS(data)] });
else if (data.isApplicationCommand())
return await sendHybridInteractionMessageResponse(
data,
@@ -154,9 +148,7 @@ export default class InteractionManager extends DiscordModule {
);
} catch (err) {
if (data && data.isMessage() && placeholder && placeholder.isMessage())
return placeholder
.getMessage()
.edit({ embeds: [EMBEDS.RELOADALL_ERROR(data, err)] });
return placeholder.getMessage().edit({ embeds: [EMBEDS.RELOADALL_ERROR(data, err)] });
else if (data.isApplicationCommand())
return await sendHybridInteractionMessageResponse(
data,
@@ -178,9 +170,7 @@ export default class InteractionManager extends DiscordModule {
await registerAllGuildsCommands();
if (data && data.isMessage() && placeholder && placeholder.isMessage())
return placeholder
.getMessage()
.edit({ embeds: [EMBEDS.RELOADALL_SUCCESS(data)] });
return placeholder.getMessage().edit({ embeds: [EMBEDS.RELOADALL_SUCCESS(data)] });
else if (data.isApplicationCommand())
return await sendHybridInteractionMessageResponse(
data,
@@ -189,9 +179,7 @@ export default class InteractionManager extends DiscordModule {
);
} catch (err) {
if (data && data.isMessage() && placeholder && placeholder.isMessage())
return placeholder
.getMessage()
.edit({ embeds: [EMBEDS.RELOADALL_ERROR(data, err)] });
return placeholder.getMessage().edit({ embeds: [EMBEDS.RELOADALL_ERROR(data, err)] });
else if (data.isApplicationCommand())
return await sendHybridInteractionMessageResponse(
data,
+1 -1
View File
@@ -21,7 +21,7 @@ const EMBEDS = {
return makeInfoEmbed({
title: `Invite`,
description: message || locale.__('invite.private', { BOT_NAME: DiscordProvider.client.user!.username}),
description: message || locale.__('invite.private', { BOT_NAME: DiscordProvider.client.user!.username }),
user
});
}
+51 -69
View File
@@ -13,7 +13,7 @@ import {
PermissionsBitField,
EmbedBuilder,
ButtonStyle,
ActionRowBuilder,
ActionRowBuilder
} from 'discord.js';
import DiscordProvider from '../providers/Discord';
@@ -114,16 +114,14 @@ const EMBEDS = {
MANAGED_ROLE: (data: Message | BaseInteraction, role: Role) => {
return makeErrorEmbed({
title: 'You cannot use this role',
description:
'``' + role.name + '``' + ' is managed by external service and cannot be used',
description: '``' + role.name + '``' + ' is managed by external service and cannot be used',
user: data instanceof BaseInteraction ? data.user : data.author
});
},
CONFIGURED_ROLE: (data: Message | BaseInteraction, role: Role) => {
return makeSuccessEmbed({
title: 'Configured Membership Screening Role',
description:
'New member will be given a ' + '``' + role.name + '``' + ' role after approval',
description: 'New member will be given a ' + '``' + role.name + '``' + ' role after approval',
user: data instanceof BaseInteraction ? data.user : data.author
});
},
@@ -146,17 +144,10 @@ const EMBEDS = {
user: data instanceof BaseInteraction ? data.user : data.author
});
},
INVALID_CHANNEL_THREAD: (
data: Message | BaseInteraction,
channel: GuildChannel | ThreadChannel
) => {
INVALID_CHANNEL_THREAD: (data: Message | BaseInteraction, channel: GuildChannel | ThreadChannel) => {
return makeErrorEmbed({
title: 'Thread channel is not supported',
description:
'``' +
channel.name +
'``' +
' is a thread channel. Please use a regular text channel',
description: '``' + channel.name + '``' + ' is a thread channel. Please use a regular text channel',
user: data instanceof BaseInteraction ? data.user : data.author
});
},
@@ -225,11 +216,7 @@ export default class MembershipScreening extends DiscordModule {
if (!this.isJsonValid(interaction.customId)) return;
const payload = JSON.parse(interaction.customId);
if (
typeof payload.m === 'undefined' ||
typeof payload.a === 'undefined' ||
payload.m !== 'MembershipScreening'
)
if (typeof payload.m === 'undefined' || typeof payload.a === 'undefined' || payload.m !== 'MembershipScreening')
return;
const message = await channel.messages.fetch(interaction.message.id);
@@ -261,9 +248,7 @@ export default class MembershipScreening extends DiscordModule {
const role = (await guild.roles.fetch()).find(
(role) => role.id === PrismaGuild.MembershipScreening_GivenRole
);
const requesterMember = (await guild.members.fetch()).find(
(member) => member.id === payload.d.requester
);
const requesterMember = (await guild.members.fetch()).find((member) => member.id === payload.d.requester);
if (!role)
return await interaction.reply({
@@ -466,7 +451,8 @@ export default class MembershipScreening extends DiscordModule {
});
if (
!guild.members.me?.permissionsIn(TargetChannel)
!guild.members.me
?.permissionsIn(TargetChannel)
.has([PermissionsBitField.Flags.SendMessages, PermissionsBitField.Flags.ViewChannel])
)
return await sendHybridInteractionMessageResponse(data, {
@@ -556,58 +542,54 @@ export default class MembershipScreening extends DiscordModule {
fields: [
{
name: 'Account Information',
value: `Account age: <t:${Math.round(
member.user.createdAt.getTime() / 1000
)}:R>`
value: `Account age: <t:${Math.round(member.user.createdAt.getTime() / 1000)}:R>`
}
]
});
embed.setThumbnail(`${member.user.displayAvatarURL()}?size=4096`);
const row = new ActionRowBuilder<ButtonBuilder>()
.addComponents([
new ButtonBuilder()
.setCustomId(
JSON.stringify({
m: 'MembershipScreening',
a: 'approve',
d: {
requester: member.id
}
})
)
.setEmoji('✅')
.setLabel(' Approve')
.setStyle(ButtonStyle.Success),
new ButtonBuilder()
.setCustomId(
JSON.stringify({
m: 'MembershipScreening',
a: 'deny',
d: {
requester: member.id
}
})
)
.setEmoji('⛔')
.setLabel(' Deny and kick')
.setStyle(ButtonStyle.Danger),
new ButtonBuilder()
.setCustomId(
JSON.stringify({
m: 'MembershipScreening',
a: 'ban',
d: {
requester: member.id
}
})
)
.setEmoji('🔪')
.setLabel(' Vision Hunt Decree (Ban)')
.setStyle(ButtonStyle.Danger)
]
);
const row = new ActionRowBuilder<ButtonBuilder>().addComponents([
new ButtonBuilder()
.setCustomId(
JSON.stringify({
m: 'MembershipScreening',
a: 'approve',
d: {
requester: member.id
}
})
)
.setEmoji('✅')
.setLabel(' Approve')
.setStyle(ButtonStyle.Success),
new ButtonBuilder()
.setCustomId(
JSON.stringify({
m: 'MembershipScreening',
a: 'deny',
d: {
requester: member.id
}
})
)
.setEmoji('⛔')
.setLabel(' Deny and kick')
.setStyle(ButtonStyle.Danger),
new ButtonBuilder()
.setCustomId(
JSON.stringify({
m: 'MembershipScreening',
a: 'ban',
d: {
requester: member.id
}
})
)
.setEmoji('🔪')
.setLabel(' Vision Hunt Decree (Ban)')
.setStyle(ButtonStyle.Danger)
]);
await channel.send({ content: '\u200b', embeds: [embed], components: [row] });
}
+22 -8
View File
@@ -80,7 +80,6 @@ const EMBEDS = {
});
},
NOW_PLAYING: async (data: HybridInteractionMessage, locale: I18n, track: ValidTracks) => {
const title = TrackUtils.getTitle(track);
const thumbnails = await TrackUtils.getThumbnails(track);
@@ -97,7 +96,6 @@ const EMBEDS = {
return embed;
},
NOW_REPEATING: async (data: HybridInteractionMessage, locale: I18n, track: ValidTracks) => {
const title = TrackUtils.getTitle(track);
const thumbnails = await TrackUtils.getThumbnails(track);
@@ -141,8 +139,17 @@ export async function joinVoiceChannelProcedure(
if (!bot) return;
const locale = await Locale.getGuildLocale(guild.id);
if(!await checkBotPermissionsInChannel({ guild, data, locale, channel: memberVoiceChannel, permissions: [PermissionsBitField.Flags.ViewChannel, PermissionsBitField.Flags.Connect]})) return;
if (
!(await checkBotPermissionsInChannel({
guild,
data,
locale,
channel: memberVoiceChannel,
permissions: [PermissionsBitField.Flags.ViewChannel, PermissionsBitField.Flags.Connect]
}))
)
return;
// If already in VoiceChannel
if (bot.voice.channelId) {
@@ -231,7 +238,7 @@ export async function joinVoiceChannelProcedure(
else if (event.instance.queue.track[0] === previousTrack && isLoopMessageSent) return;
const row = new ActionRowBuilder<ButtonBuilder>();
if(event.instance.queue.track[0] instanceof SpotifyTrack)
if (event.instance.queue.track[0] instanceof SpotifyTrack)
row.addComponents([
new ButtonBuilder()
.setEmoji('🟢')
@@ -239,14 +246,21 @@ export async function joinVoiceChannelProcedure(
.setURL(encodeURI(`https://open.spotify.com/track/${event.instance.queue.track[0].id}`))
.setStyle(ButtonStyle.Link)
]);
if(event.instance.queue.track[0] instanceof YouTubeVideo || event.instance.queue.track[0] instanceof SpotifyTrack) {
if (
event.instance.queue.track[0] instanceof YouTubeVideo ||
event.instance.queue.track[0] instanceof SpotifyTrack
) {
const actualPlaybackURL = event.instance.getActualPlaybackURL();
if(event.instance.queue.track[0] instanceof SpotifyTrack && !actualPlaybackURL) return;
if (event.instance.queue.track[0] instanceof SpotifyTrack && !actualPlaybackURL) return;
row.addComponents([
new ButtonBuilder()
.setEmoji('🔴')
.setLabel('Open in YouTube')
.setURL(event.instance.queue.track[0] instanceof YouTubeVideo ? encodeURI(`https://www.youtube.com/watch?v=${event.instance.queue.track[0].id}`) : encodeURI(event.instance.getActualPlaybackURL()!))
.setURL(
event.instance.queue.track[0] instanceof YouTubeVideo
? encodeURI(`https://www.youtube.com/watch?v=${event.instance.queue.track[0].id}`)
: encodeURI(event.instance.getActualPlaybackURL()!)
)
.setStyle(ButtonStyle.Link)
]);
}
+27 -24
View File
@@ -1,11 +1,11 @@
import { I18n } from "i18n";
import { Message, CommandInteraction } from "discord.js";
import { I18n } from 'i18n';
import { Message, CommandInteraction } from 'discord.js';
import DiscordMusicPlayer from "../../providers/DiscordMusicPlayer";
import Locale from "../../services/Locale";
import DiscordMusicPlayer from '../../providers/DiscordMusicPlayer';
import Locale from '../../services/Locale';
import { makeSuccessEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse } from "../../utils/DiscordMessage";
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
import { makeSuccessEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse } from '../../utils/DiscordMessage';
import DiscordModule, { HybridInteractionMessage } from '../../utils/DiscordModule';
const EMBEDS = {
VOICECHANNEL_LEFT: (data: HybridInteractionMessage, locale: I18n) => {
@@ -32,46 +32,49 @@ const EMBEDS = {
user: data.getUser()
});
}
}
};
export default class Leave extends DiscordModule {
public id = "Discord_MusicPlayer_Leave";
public commands = ["leave", "disconnect", "dc"];
public commandInteractionName = "leave";
public id = 'Discord_MusicPlayer_Leave';
public commands = ['leave', 'disconnect', 'dc'];
public commandInteractionName = 'leave';
async GuildOnModuleCommand(args: any, message: Message) {
await this.run(new HybridInteractionMessage(message), args);
}
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
await this.run(new HybridInteractionMessage(interaction), interaction.options);
}
async run(data: HybridInteractionMessage, args: any) {
const guild = data.getGuild();
const member = data.getMember();
if(!guild || !member) return;
if (!guild || !member) return;
const locale = await Locale.getGuildLocale(guild.id);
const voiceChannel = member.voice.channel;
if (!voiceChannel)
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data, locale)] });
let instance = DiscordMusicPlayer.getGuildInstance(guild.id);
if(!instance)
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)] });
return await sendHybridInteractionMessageResponse(data, {
embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data, locale)]
});
if(instance.voiceChannel.id !== voiceChannel.id)
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data, locale)] });
let instance = DiscordMusicPlayer.getGuildInstance(guild.id);
if (!instance)
return await sendHybridInteractionMessageResponse(data, {
embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)]
});
if (instance.voiceChannel.id !== voiceChannel.id)
return await sendHybridInteractionMessageResponse(data, {
embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data, locale)]
});
DiscordMusicPlayer.destoryGuildInstance(guild.id);
await sendHybridInteractionMessageResponse(data, { embeds:[EMBEDS.VOICECHANNEL_LEFT(data, locale)] });
await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.VOICECHANNEL_LEFT(data, locale)] });
return;
}
}
}
+44 -28
View File
@@ -1,11 +1,16 @@
import { I18n } from "i18n";
import { Message, CommandInteraction } from "discord.js";
import { I18n } from 'i18n';
import { Message, CommandInteraction } from 'discord.js';
import DiscordMusicPlayer, { DiscordMusicPlayerLoopMode } from "../../providers/DiscordMusicPlayer";
import Locale from "../../services/Locale";
import DiscordMusicPlayer, { DiscordMusicPlayerLoopMode } from '../../providers/DiscordMusicPlayer';
import Locale from '../../services/Locale';
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
import { makeErrorEmbed, makeSuccessEmbed, sendHybridInteractionMessageResponse, makeInfoEmbed } from "../../utils/DiscordMessage";
import DiscordModule, { HybridInteractionMessage } from '../../utils/DiscordModule';
import {
makeErrorEmbed,
makeSuccessEmbed,
sendHybridInteractionMessageResponse,
makeInfoEmbed
} from '../../utils/DiscordMessage';
const EMBEDS = {
INVALID_LOOP_MODE: (data: HybridInteractionMessage, locale: I18n) => {
return makeErrorEmbed({
@@ -50,12 +55,11 @@ const EMBEDS = {
user: data.getUser()
});
}
}
};
export default class Loop extends DiscordModule {
public id = "Discord_MusicPlayer_Loop";
public commands = ["loop", "repeat"];
public commandInteractionName = "loop";
public id = 'Discord_MusicPlayer_Loop';
public commands = ['loop', 'repeat'];
public commandInteractionName = 'loop';
async GuildOnModuleCommand(args: any, message: Message) {
await this.run(new HybridInteractionMessage(message), args);
@@ -66,7 +70,6 @@ export default class Loop extends DiscordModule {
}
async run(data: HybridInteractionMessage, args: any) {
const guild = data.getGuild();
const user = data.getUser();
const member = data.getMember();
@@ -78,39 +81,52 @@ export default class Loop extends DiscordModule {
let query;
if (data.isMessage()) {
if (args.length !== 0)
query = args.join(' ');
}
else if (data.isApplicationCommand())
query = args.getSubcommand();
if (args.length !== 0) query = args.join(' ');
} else if (data.isApplicationCommand()) query = args.getSubcommand();
const voiceChannel = member.voice.channel;
if (!voiceChannel)
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data, locale)] });
return await sendHybridInteractionMessageResponse(data, {
embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data, locale)]
});
const instance = DiscordMusicPlayer.getGuildInstance(guild.id);
if (!instance)
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)] });
return await sendHybridInteractionMessageResponse(data, {
embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)]
});
if (instance.voiceChannel.id !== voiceChannel.id)
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data, locale)] }, true);
return await sendHybridInteractionMessageResponse(
data,
{ embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data, locale)] },
true
);
if (instance.queue.track.length === 0)
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)] });
return await sendHybridInteractionMessageResponse(data, {
embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)]
});
if (!query)
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.LOOP_STATUS(data, locale, instance.getLoopMode())] });
return await sendHybridInteractionMessageResponse(data, {
embeds: [EMBEDS.LOOP_STATUS(data, locale, instance.getLoopMode())]
});
let enumKey = Object.keys(DiscordMusicPlayerLoopMode)[Object.values(DiscordMusicPlayerLoopMode).indexOf(query.toLowerCase())];
let enumKey =
Object.keys(DiscordMusicPlayerLoopMode)[
Object.values(DiscordMusicPlayerLoopMode).indexOf(query.toLowerCase())
];
if(enumKey) {
if (enumKey) {
instance.setLoopMode(DiscordMusicPlayerLoopMode[enumKey as keyof typeof DiscordMusicPlayerLoopMode]);
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.LOOP_SET(data, locale, instance.getLoopMode())] });
return await sendHybridInteractionMessageResponse(data, {
embeds: [EMBEDS.LOOP_SET(data, locale, instance.getLoopMode())]
});
}
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.INVALID_LOOP_MODE(data, locale)] });
}
}
}
+41 -34
View File
@@ -1,17 +1,16 @@
import { Message, CommandInteraction, ActionRowBuilder, ButtonBuilder, ButtonStyle } from "discord.js";
import { I18n } from "i18n";
import { SpotifyTrack, YouTubeVideo } from "play-dl";
import { Message, CommandInteraction, ActionRowBuilder, ButtonBuilder, ButtonStyle } from 'discord.js';
import { I18n } from 'i18n';
import { SpotifyTrack, YouTubeVideo } from 'play-dl';
import DiscordProvider from "../../providers/Discord";
import DiscordMusicPlayer, { TrackUtils, ValidTracks } from "../../providers/DiscordMusicPlayer";
import Locale from "../../services/Locale";
import DiscordProvider from '../../providers/Discord';
import DiscordMusicPlayer, { TrackUtils, ValidTracks } from '../../providers/DiscordMusicPlayer';
import Locale from '../../services/Locale';
import { makeErrorEmbed, makeInfoEmbed, sendHybridInteractionMessageResponse } from "../../utils/DiscordMessage";
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
import { makeErrorEmbed, makeInfoEmbed, sendHybridInteractionMessageResponse } from '../../utils/DiscordMessage';
import DiscordModule, { HybridInteractionMessage } from '../../utils/DiscordModule';
const EMBEDS = {
NOW_PLAYING: async (data: HybridInteractionMessage, locale: I18n, track: ValidTracks) => {
const title = TrackUtils.getTitle(track);
const thumbnails = await TrackUtils.getThumbnails(track);
@@ -24,7 +23,7 @@ const EMBEDS = {
if (TrackUtils.getHighestResolutionThumbnail(thumbnails))
embed.setImage(TrackUtils.getHighestResolutionThumbnail(thumbnails).url);
return embed;
},
NO_MUSIC_PLAYING: (data: HybridInteractionMessage, locale: I18n) => {
@@ -33,14 +32,13 @@ const EMBEDS = {
user: data.getUser()
});
}
}
};
export default class NowPlaying extends DiscordModule {
public id = 'Discord_MusicPlayer_NowPlaying';
public commands = ['nowplaying', 'np'];
public commandInteractionName = 'nowplaying';
public id = "Discord_MusicPlayer_NowPlaying";
public commands = ["nowplaying", "np"];
public commandInteractionName = "nowplaying";
async GuildOnModuleCommand(args: any, message: Message) {
await this.run(new HybridInteractionMessage(message), args);
}
@@ -50,35 +48,44 @@ export default class NowPlaying extends DiscordModule {
}
async run(data: HybridInteractionMessage, args: any) {
const guild = data.getGuild();
if(!guild) return;
if (!guild) return;
const locale = await Locale.getGuildLocale(guild.id);
const instance = DiscordMusicPlayer.getGuildInstance(guild.id);
if(!instance || !instance.queue.track[0]) return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)] });
if (!instance || !instance.queue.track[0])
return await sendHybridInteractionMessageResponse(data, {
embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)]
});
const row = new ActionRowBuilder<ButtonBuilder>();
if(instance.queue.track[0] instanceof SpotifyTrack)
if (instance.queue.track[0] instanceof SpotifyTrack)
row.addComponents([
new ButtonBuilder()
.setEmoji('🟢')
.setLabel('Open in Spotify')
.setURL(encodeURI(`https://open.spotify.com/track/${instance.queue.track[0].id}`))
.setStyle(ButtonStyle.Link),
.setStyle(ButtonStyle.Link)
]);
if(instance.queue.track[0] instanceof YouTubeVideo || instance.queue.track[0] instanceof SpotifyTrack) {
const actualPlaybackURL = instance.getActualPlaybackURL();
if(instance.queue.track[0] instanceof SpotifyTrack && !actualPlaybackURL) return;
row.addComponents([
new ButtonBuilder()
.setEmoji('🔴')
.setLabel('Open in YouTube')
.setURL(instance.queue.track[0] instanceof YouTubeVideo ? encodeURI(`https://www.youtube.com/watch?v=${instance.queue.track[0].id}`) : encodeURI(instance.getActualPlaybackURL()!))
.setStyle(ButtonStyle.Link),
]);
}
return await sendHybridInteractionMessageResponse(data, { embeds: [await EMBEDS.NOW_PLAYING(data, locale, instance.queue.track[0])], components: [row] });
if (instance.queue.track[0] instanceof YouTubeVideo || instance.queue.track[0] instanceof SpotifyTrack) {
const actualPlaybackURL = instance.getActualPlaybackURL();
if (instance.queue.track[0] instanceof SpotifyTrack && !actualPlaybackURL) return;
row.addComponents([
new ButtonBuilder()
.setEmoji('🔴')
.setLabel('Open in YouTube')
.setURL(
instance.queue.track[0] instanceof YouTubeVideo
? encodeURI(`https://www.youtube.com/watch?v=${instance.queue.track[0].id}`)
: encodeURI(instance.getActualPlaybackURL()!)
)
.setStyle(ButtonStyle.Link)
]);
}
return await sendHybridInteractionMessageResponse(data, {
embeds: [await EMBEDS.NOW_PLAYING(data, locale, instance.queue.track[0])],
components: [row]
});
}
}
}
+37 -24
View File
@@ -1,12 +1,17 @@
import { Message, CommandInteraction, Interaction } from "discord.js";
import { I18n } from "i18n";
import { Message, CommandInteraction, Interaction } from 'discord.js';
import { I18n } from 'i18n';
import DiscordMusicPlayer from "../../providers/DiscordMusicPlayer";
import Locale from "../../services/Locale";
import DiscordMusicPlayer from '../../providers/DiscordMusicPlayer';
import Locale from '../../services/Locale';
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
import DiscordModule, { HybridInteractionMessage } from '../../utils/DiscordModule';
import { makeSuccessEmbed, makeInfoEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse } from "../../utils/DiscordMessage";
import {
makeSuccessEmbed,
makeInfoEmbed,
makeErrorEmbed,
sendHybridInteractionMessageResponse
} from '../../utils/DiscordMessage';
const EMBEDS = {
PAUSED: (data: HybridInteractionMessage, locale: I18n) => {
@@ -39,24 +44,22 @@ const EMBEDS = {
user: data.getUser()
});
}
}
};
export default class Pause extends DiscordModule{
public id = "Discord_MusicPlayer_Pause";
public commands = ["pause"];
public commandInteractionName = "pause";
export default class Pause extends DiscordModule {
public id = 'Discord_MusicPlayer_Pause';
public commands = ['pause'];
public commandInteractionName = 'pause';
async GuildOnModuleCommand(args: any, message: Message) {
await this.run(new HybridInteractionMessage(message), args);
}
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
await this.run(new HybridInteractionMessage(interaction), interaction.options);
}
async run(data: HybridInteractionMessage, args: any) {
const guild = data.getGuild();
const member = data.getMember();
@@ -66,23 +69,33 @@ export default class Pause extends DiscordModule{
const voiceChannel = member.voice.channel;
if (!voiceChannel)
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data, locale)] });
return await sendHybridInteractionMessageResponse(data, {
embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data, locale)]
});
const instance = DiscordMusicPlayer.getGuildInstance(guild.id);
if(!instance)
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)] });
if (!instance)
return await sendHybridInteractionMessageResponse(data, {
embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)]
});
if(instance.voiceChannel.id !== voiceChannel.id)
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data, locale)] }, true);
if (instance.voiceChannel.id !== voiceChannel.id)
return await sendHybridInteractionMessageResponse(
data,
{ embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data, locale)] },
true
);
if(instance.queue.track.length === 0)
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)] });
if (instance.queue.track.length === 0)
return await sendHybridInteractionMessageResponse(data, {
embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)]
});
if(instance.isPaused())
if (instance.isPaused())
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.ALREADY_PAUSED(data, locale)] });
instance.pausePlayer();
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.PAUSED(data, locale)] });
}
}
}
+27 -10
View File
@@ -42,7 +42,6 @@ const EMBEDS = {
});
},
ADDED_QUEUE: async (data: HybridInteractionMessage, locale: I18n, track: ValidTracks) => {
const title = TrackUtils.getTitle(track);
const thumbnails = await TrackUtils.getThumbnails(track);
@@ -354,7 +353,15 @@ export default class Play extends DiscordModule {
if (!result) return;
if (data.isMessage() && data.getMessage().embeds.length > 0 && await checkBotPermissionsInChannel({ guild, channel, permissions: [PermissionsBitField.Flags.ManageMessages]})) {
if (
data.isMessage() &&
data.getMessage().embeds.length > 0 &&
(await checkBotPermissionsInChannel({
guild,
channel,
permissions: [PermissionsBitField.Flags.ManageMessages]
}))
) {
data.getMessage().suppressEmbeds(true);
}
@@ -373,8 +380,7 @@ export default class Play extends DiscordModule {
)
.setLabel(' Add the remaining songs in the playlist')
.setStyle(ButtonStyle.Primary)
]
);
]);
return await sendHybridInteractionMessageResponse(data, {
embeds: [await EMBEDS.ADDED_QUEUE(data, locale, result)],
@@ -389,11 +395,15 @@ export default class Play extends DiscordModule {
if (linkData.type === 'playlist' || linkData.type === 'album') {
let playlist = await DiscordMusicPlayer.getSpotifySongsInPlayList(query).catch((err) => {
sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.LOOKUP_ERROR(data, locale, err)] }, true);
sendHybridInteractionMessageResponse(
data,
{ embeds: [EMBEDS.LOOKUP_ERROR(data, locale, err)] },
true
);
return null;
});
if(!playlist) return;
if (!playlist) return;
const songs = await playlist.all_tracks();
for (const song of songs) {
@@ -414,7 +424,15 @@ export default class Play extends DiscordModule {
if (!result) return;
if (data.isMessage() && data.getMessage().embeds.length > 0 && await checkBotPermissionsInChannel({ guild, channel, permissions: [PermissionsBitField.Flags.ManageMessages]})) {
if (
data.isMessage() &&
data.getMessage().embeds.length > 0 &&
(await checkBotPermissionsInChannel({
guild,
channel,
permissions: [PermissionsBitField.Flags.ManageMessages]
}))
) {
data.getMessage().suppressEmbeds(true);
}
@@ -423,7 +441,6 @@ export default class Play extends DiscordModule {
return await sendHybridInteractionMessageResponse(data, {
embeds: [await EMBEDS.ADDED_QUEUE(data, locale, result)]
});
} else {
let result = await DiscordMusicPlayer.searchYouTubeByQuery(query);
@@ -461,7 +478,7 @@ export default class Play extends DiscordModule {
)
.setLabel(' Not this? Search!')
.setStyle(ButtonStyle.Primary)
]);
]);
return await sendHybridInteractionMessageResponse(data, {
embeds: [await EMBEDS.ADDED_QUEUE(data, locale, result[0])],
+27 -33
View File
@@ -1,12 +1,12 @@
import { I18n } from "i18n";
import { Message, CommandInteraction, ActivityType, ActionRowBuilder, ButtonBuilder, ButtonStyle } from "discord.js";
import { I18n } from 'i18n';
import { Message, CommandInteraction, ActivityType, ActionRowBuilder, ButtonBuilder, ButtonStyle } from 'discord.js';
import DiscordMusicPlayer, { TrackUtils, ValidTracks } from "../../providers/DiscordMusicPlayer";
import Locale from "../../services/Locale";
import DiscordMusicPlayer, { TrackUtils, ValidTracks } from '../../providers/DiscordMusicPlayer';
import Locale from '../../services/Locale';
import { makeSuccessEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse } from "../../utils/DiscordMessage";
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
import { joinVoiceChannelProcedure } from "./Join";
import { makeSuccessEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse } from '../../utils/DiscordMessage';
import DiscordModule, { HybridInteractionMessage } from '../../utils/DiscordModule';
import { joinVoiceChannelProcedure } from './Join';
const EMBEDS = {
NOT_DETECTED: (data: HybridInteractionMessage, locale: I18n) => {
@@ -28,7 +28,6 @@ const EMBEDS = {
});
},
ADDED_QUEUE: async (data: HybridInteractionMessage, locale: I18n, track: ValidTracks) => {
const title = TrackUtils.getTitle(track);
const thumbnails = await TrackUtils.getThumbnails(track);
@@ -43,28 +42,26 @@ const EMBEDS = {
return embed;
}
}
};
export default class PlayMy extends DiscordModule {
public id = "Discord_MusicPlayer_PlayMy";
public commands = ["playmy"];
public commandInteractionName = "playmy";
public id = 'Discord_MusicPlayer_PlayMy';
public commands = ['playmy'];
public commandInteractionName = 'playmy';
async GuildOnModuleCommand(args: any, message: Message) {
await this.run(new HybridInteractionMessage(message), args);
}
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
await this.run(new HybridInteractionMessage(interaction), interaction.options);
}
async run(data: HybridInteractionMessage, args: any) {
const guild = data.getGuild();
const member = data.getMember();
if(!guild || !member) return;
if (!guild || !member) return;
const locale = await Locale.getGuildLocale(guild.id);
@@ -94,22 +91,20 @@ export default class PlayMy extends DiscordModule {
instance = DiscordMusicPlayer.getGuildInstance(guild.id);
}
if(!instance) return;
if(!member.presence) return;
if(!member.presence.activities) return;
if (!instance) return;
if (!member.presence) return;
if (!member.presence.activities) return;
let query;
let found = false;
for (const activity of member.presence.activities) {
if(activity.type === ActivityType.Listening) {
if(!activity.details) continue;
if (activity.type === ActivityType.Listening) {
if (!activity.details) continue;
found = true;
if(activity.name == "Spotify")
query = `${activity.state} - ${activity.details}`
else
query = `${activity.state} - ${activity.details}` // TODO: Find better query formula
if (activity.name == 'Spotify') query = `${activity.state} - ${activity.details}`;
else query = `${activity.state} - ${activity.details}`; // TODO: Find better query formula
const result = await DiscordMusicPlayer.searchYouTubeByQuery(query);
if (!result) continue;
instance.addTrackToQueue(result[0]);
@@ -120,10 +115,10 @@ export default class PlayMy extends DiscordModule {
// If the first result title is exact match with the query or first title contains half the space of the query, it's probably a sentence
// then we don't need to show the search results
// if(result[0].title === query || result[0].title && (Math.ceil((result[0].title.split(" ").length - 1) / 2) === Math.ceil((query.split(" ").length - 1) / 2))) return;
// The query length is too long to fit in json
if (query.length > 100 - 51) return;
row = new ActionRowBuilder<ButtonBuilder>().addComponents([
new ButtonBuilder()
.setEmoji('🔎')
@@ -138,10 +133,10 @@ export default class PlayMy extends DiscordModule {
)
.setLabel(' Not this? Search!')
.setStyle(ButtonStyle.Primary)
]);
]);
}
if(!row)
if (!row)
await sendHybridInteractionMessageResponse(data, {
embeds: [await EMBEDS.ADDED_QUEUE(data, locale, result[0])]
});
@@ -153,9 +148,8 @@ export default class PlayMy extends DiscordModule {
}
}
if(!found)
await sendHybridInteractionMessageResponse(data, { embeds:[EMBEDS.NOT_DETECTED(data, locale)] });
if (!found) await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NOT_DETECTED(data, locale)] });
return;
}
}
}
+6 -2
View File
@@ -133,10 +133,14 @@ export default class QueueCommand extends DiscordModule {
switch (query.toLowerCase()) {
case 'clear':
instance.clearQueue();
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.QUEUE_CLEARED(data, locale)] });
return await sendHybridInteractionMessageResponse(data, {
embeds: [EMBEDS.QUEUE_CLEARED(data, locale)]
});
case 'shuffle':
instance.shuffleQueue();
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.QUEUE_SHUFFLED(data, locale)] });
return await sendHybridInteractionMessageResponse(data, {
embeds: [EMBEDS.QUEUE_SHUFFLED(data, locale)]
});
}
}
}
+36 -23
View File
@@ -1,11 +1,16 @@
import { Message, CommandInteraction, Interaction } from "discord.js";
import { I18n } from "i18n";
import { Message, CommandInteraction, Interaction } from 'discord.js';
import { I18n } from 'i18n';
import DiscordMusicPlayer from "../../providers/DiscordMusicPlayer";
import DiscordMusicPlayer from '../../providers/DiscordMusicPlayer';
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
import { makeSuccessEmbed, makeInfoEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse } from "../../utils/DiscordMessage";
import Locale from "../../services/Locale";
import DiscordModule, { HybridInteractionMessage } from '../../utils/DiscordModule';
import {
makeSuccessEmbed,
makeInfoEmbed,
makeErrorEmbed,
sendHybridInteractionMessageResponse
} from '../../utils/DiscordMessage';
import Locale from '../../services/Locale';
const EMBEDS = {
RESUMED: (data: HybridInteractionMessage, locale: I18n) => {
@@ -38,24 +43,22 @@ const EMBEDS = {
user: data.getUser()
});
}
}
};
export default class Resume extends DiscordModule{
public id = "Discord_MusicPlayer_Resume";
public commands = ["resume"];
public commandInteractionName = "resume";
export default class Resume extends DiscordModule {
public id = 'Discord_MusicPlayer_Resume';
public commands = ['resume'];
public commandInteractionName = 'resume';
async GuildOnModuleCommand(args: any, message: Message) {
await this.run(new HybridInteractionMessage(message), args);
}
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
await this.run(new HybridInteractionMessage(interaction), interaction.options);
}
async run(data: HybridInteractionMessage, args: any) {
const guild = data.getGuild();
const member = data.getMember();
@@ -66,23 +69,33 @@ export default class Resume extends DiscordModule{
const voiceChannel = member.voice.channel;
if (!voiceChannel)
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data, locale)] });
return await sendHybridInteractionMessageResponse(data, {
embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data, locale)]
});
const instance = DiscordMusicPlayer.getGuildInstance(guild.id);
if(!instance)
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)] });
if (!instance)
return await sendHybridInteractionMessageResponse(data, {
embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)]
});
if(instance.voiceChannel.id !== voiceChannel.id)
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data, locale)] }, true);
if (instance.voiceChannel.id !== voiceChannel.id)
return await sendHybridInteractionMessageResponse(
data,
{ embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data, locale)] },
true
);
if(instance.queue.track.length === 0)
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)] });
if (instance.queue.track.length === 0)
return await sendHybridInteractionMessageResponse(data, {
embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)]
});
if(!instance.isPaused())
if (!instance.isPaused())
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NOT_PAUSED(data, locale)] });
instance.resumePlayer();
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.RESUMED(data, locale)] });
}
}
}
+51 -40
View File
@@ -1,13 +1,20 @@
import { Message, CommandInteraction, ActionRowBuilder, ButtonInteraction, SelectMenuBuilder, SelectMenuComponentOptionData } from "discord.js";
import { I18n } from "i18n";
import {
Message,
CommandInteraction,
ActionRowBuilder,
ButtonInteraction,
SelectMenuBuilder,
SelectMenuComponentOptionData
} from 'discord.js';
import { I18n } from 'i18n';
import { joinVoiceChannelProcedure } from "./Join";
import { joinVoiceChannelProcedure } from './Join';
import DiscordMusicPlayer, { TrackUtils, ValidTracks } from "../../providers/DiscordMusicPlayer";
import Locale from "../../services/Locale";
import DiscordMusicPlayer, { TrackUtils, ValidTracks } from '../../providers/DiscordMusicPlayer';
import Locale from '../../services/Locale';
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
import { makeErrorEmbed, sendHybridInteractionMessageResponse, makeInfoEmbed } from "../../utils/DiscordMessage";
import DiscordModule, { HybridInteractionMessage } from '../../utils/DiscordModule';
import { makeErrorEmbed, sendHybridInteractionMessageResponse, makeInfoEmbed } from '../../utils/DiscordMessage';
const EMBEDS = {
SEARCH_INFO: (data: HybridInteractionMessage, locale: I18n) => {
@@ -17,7 +24,7 @@ const EMBEDS = {
fields: [
{
name: locale.__('common.available_args'),
value: locale.__('musicplayer_search.valid_args'),
value: locale.__('musicplayer_search.valid_args')
}
],
user: data.getUser()
@@ -28,7 +35,7 @@ const EMBEDS = {
title: locale.__('musicplayer_search.title_result'),
description: `${locale.__('musicplayer_search.x_results_found', {
COUNT: result.length.toString()
})}\n\n${result.map(track => `- [${TrackUtils.getTitle(track)}](${track.url})`).join('\n')}`,
})}\n\n${result.map((track) => `- [${TrackUtils.getTitle(track)}](${track.url})`).join('\n')}`,
user: data.getUser()
});
},
@@ -44,12 +51,11 @@ const EMBEDS = {
user: data.getUser()
});
}
}
};
export default class Search extends DiscordModule {
public id = "Discord_MusicPlayer_Search";
public commands = ["search"];
public commandInteractionName = "search";
public id = 'Discord_MusicPlayer_Search';
public commands = ['search'];
public commandInteractionName = 'search';
async GuildOnModuleCommand(args: any, message: Message) {
await this.run(new HybridInteractionMessage(message), args);
@@ -70,16 +76,18 @@ export default class Search extends DiscordModule {
data.q stands for data.query
*/
if (typeof payload.m === 'undefined' ||
if (
typeof payload.m === 'undefined' ||
typeof payload.a === 'undefined' ||
payload.m !== 'MP_S' ||
payload.a !== 'search') return;
payload.a !== 'search'
)
return;
await this.run(new HybridInteractionMessage(interaction), payload.d.q);
}
async run(data: HybridInteractionMessage, args: any) {
async run(data: HybridInteractionMessage, args: any) {
const guild = data.getGuild();
const user = data.getUser();
const member = data.getMember();
@@ -95,19 +103,18 @@ export default class Search extends DiscordModule {
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SEARCH_INFO(data, locale)] });
query = args.join(' ');
}
else if (data.isApplicationCommand())
} else if (data.isApplicationCommand())
query = data.getSlashCommand().options.get('query', true).value?.toString();
else if (data.isButton())
query = args;
else if (data.isButton()) query = args;
if (!query) return;
const voiceChannel = member.voice.channel;
if (!voiceChannel)
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data, locale)] });
return await sendHybridInteractionMessageResponse(data, {
embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data, locale)]
});
if (!DiscordMusicPlayer.isGuildInstanceExists(guild.id))
await joinVoiceChannelProcedure(data, null, voiceChannel);
@@ -116,7 +123,9 @@ export default class Search extends DiscordModule {
if (!instance) return;
if (instance.voiceChannel.id !== voiceChannel.id)
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data, locale)] });
return await sendHybridInteractionMessageResponse(data, {
embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data, locale)]
});
if (!instance.isConnected()) {
await joinVoiceChannelProcedure(data, instance!, voiceChannel);
@@ -136,14 +145,16 @@ export default class Search extends DiscordModule {
data.r stands for data.requester
data.v stands for data.voiceChannel
*/
messageSelectMenu.setCustomId(JSON.stringify({
m: 'MP_SM',
a: 'play',
d: {
r: user.id,
v: voiceChannel.id
}
}))
messageSelectMenu.setCustomId(
JSON.stringify({
m: 'MP_SM',
a: 'play',
d: {
r: user.id,
v: voiceChannel.id
}
})
);
messageSelectMenu.setPlaceholder('Nothing selected');
for (let song of result) {
@@ -160,21 +171,21 @@ export default class Search extends DiscordModule {
const row = new ActionRowBuilder<SelectMenuBuilder>();
row.addComponents([messageSelectMenu]);
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SEARCH_RESULT(data, locale, result)], components: [row] });
return await sendHybridInteractionMessageResponse(data, {
embeds: [EMBEDS.SEARCH_RESULT(data, locale, result)],
components: [row]
});
}
isJsonValid(jsonString: string) {
try {
let o = JSON.parse(jsonString);
if (o && typeof o === "object") {
if (o && typeof o === 'object') {
return true;
//return o;
}
}
catch (e) { }
} catch (e) {}
return false;
}
}
}
+35 -26
View File
@@ -1,11 +1,11 @@
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
import DiscordModule, { HybridInteractionMessage } from '../../utils/DiscordModule';
import { Message, CommandInteraction } from "discord.js";
import { makeSuccessEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse } from "../../utils/DiscordMessage";
import { Message, CommandInteraction } from 'discord.js';
import { makeSuccessEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse } from '../../utils/DiscordMessage';
import DiscordMusicPlayer from "../../providers/DiscordMusicPlayer";
import { I18n } from "i18n";
import Locale from "../../services/Locale";
import DiscordMusicPlayer from '../../providers/DiscordMusicPlayer';
import { I18n } from 'i18n';
import Locale from '../../services/Locale';
const EMBEDS = {
SKIPPED: (data: HybridInteractionMessage, locale: I18n) => {
@@ -38,24 +38,22 @@ const EMBEDS = {
user: data.getUser()
});
}
}
};
export default class Skip extends DiscordModule{
public id = "Discord_MusicPlayer_Skip";
public commands = ["skip"];
public commandInteractionName = "skip";
export default class Skip extends DiscordModule {
public id = 'Discord_MusicPlayer_Skip';
public commands = ['skip'];
public commandInteractionName = 'skip';
async GuildOnModuleCommand(args: any, message: Message) {
await this.run(new HybridInteractionMessage(message), args);
}
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
await this.run(new HybridInteractionMessage(interaction), interaction.options);
}
async run(data: HybridInteractionMessage, args: any) {
const guild = data.getGuild();
const member = data.getMember();
@@ -65,24 +63,35 @@ export default class Skip extends DiscordModule{
const voiceChannel = member.voice.channel;
if (!voiceChannel)
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data, locale)] });
return await sendHybridInteractionMessageResponse(data, {
embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data, locale)]
});
const instance = DiscordMusicPlayer.getGuildInstance(guild.id);
if(!instance)
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)] });
if (!instance)
return await sendHybridInteractionMessageResponse(data, {
embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)]
});
if(instance.voiceChannel.id !== voiceChannel.id)
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data, locale)] }, true);
if (instance.voiceChannel.id !== voiceChannel.id)
return await sendHybridInteractionMessageResponse(
data,
{ embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data, locale)] },
true
);
if(instance.queue.track.length === 0)
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)] });
if (instance.queue.track.length === 0)
return await sendHybridInteractionMessageResponse(data, {
embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)]
});
instance.skipTrack();
if(instance.queue.track.length === 0)
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SKIPPED_LASTSONG(data, locale)] });
else
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SKIPPED(data, locale)] });
if (instance.queue.track.length === 0)
return await sendHybridInteractionMessageResponse(data, {
embeds: [EMBEDS.SKIPPED_LASTSONG(data, locale)]
});
else return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SKIPPED(data, locale)] });
}
}
}
+12 -20
View File
@@ -10,11 +10,7 @@ import Environment from '../providers/Environment';
import Locale from '../services/Locale';
import DiscordModule, { HybridInteractionMessage } from '../utils/DiscordModule';
import {
makeSuccessEmbed,
makeProcessingEmbed,
sendHybridInteractionMessageResponse
} from '../utils/DiscordMessage';
import { makeSuccessEmbed, makeProcessingEmbed, sendHybridInteractionMessageResponse } from '../utils/DiscordMessage';
enum MeasureType {
Ping = 'ping',
@@ -57,14 +53,14 @@ export default class Ping extends DiscordModule {
const guild = data.getGuild();
const member = data.getMember();
if(!guild || !member) return;
if (!guild || !member) return;
const locale = await Locale.getGuildLocale(guild.id);
let placeholder: HybridInteractionMessage | undefined;
let beforeEditDate = Date.now();
let _placeholder = await sendHybridInteractionMessageResponse(data, {
embeds: [EMBEDS.PINGING(data, locale)],
embeds: [EMBEDS.PINGING(data, locale)]
});
if (_placeholder) placeholder = new HybridInteractionMessage(_placeholder);
@@ -86,23 +82,17 @@ export default class Ping extends DiscordModule {
return finalString.push(stringCurrent);
}
if (
res.avg === 'unknown' ||
res.min === 'unknown' ||
res.max === 'unknown'
) {
if (res.avg === 'unknown' || res.min === 'unknown' || res.max === 'unknown') {
stringCurrent += 'Failed';
return finalString.push(stringCurrent);
}
stringCurrent += `${parseFloat(res.avg).toFixed(1)}ms (${parseFloat(
res.min
).toFixed(1)}ms - ${parseFloat(res.max).toFixed(1)}ms)`;
stringCurrent += `${parseFloat(res.avg).toFixed(1)}ms (${parseFloat(res.min).toFixed(
1
)}ms - ${parseFloat(res.max).toFixed(1)}ms)`;
finalString.push(stringCurrent);
} else if (entry.type === MeasureType.DiscordWebsocket) {
stringCurrent += `${Math.round(DiscordProvider.client.ws.ping).toFixed(
1
)}ms`;
stringCurrent += `${Math.round(DiscordProvider.client.ws.ping).toFixed(1)}ms`;
finalString.push(stringCurrent);
} else if (entry.type === MeasureType.DiscordHTTPPing) {
stringCurrent += `${Math.abs(afterEditDate - beforeEditDate).toFixed(1)}ms`;
@@ -117,9 +107,11 @@ export default class Ping extends DiscordModule {
finalString.push('');
finalString.push(
`💻 ${locale.__('ping.running_on', {HOST: os.hostname()})} ` +
`💻 ${locale.__('ping.running_on', { HOST: os.hostname() })} ` +
`${
Environment.get().NODE_ENV === 'development' ? ` / ${locale.__('ping.development_environment')}` : ''
Environment.get().NODE_ENV === 'development'
? ` / ${locale.__('ping.development_environment')}`
: ''
}`
);
+4 -6
View File
@@ -27,11 +27,9 @@ const EMBEDS = {
NO_PERMISSION: (data: HybridInteractionMessage, locale: I18n) => {
return makeErrorEmbed({
title: locale.__('common.no_permissions'),
description: locale.__(
'common.no_permissions_description', {
PERMISSIONS: 'VIEW_CHANNEL, SEND_MESSAGES, MANAGE_CHANNELS'
}
),
description: locale.__('common.no_permissions_description', {
PERMISSIONS: 'VIEW_CHANNEL, SEND_MESSAGES, MANAGE_CHANNELS'
}),
user: data.getUser()
});
},
@@ -80,7 +78,7 @@ export default class Say extends DiscordModule {
!message.member.permissions.has([
PermissionsBitField.Flags.ViewChannel,
PermissionsBitField.Flags.SendMessages,
PermissionsBitField.Flags.ManageChannels,
PermissionsBitField.Flags.ManageChannels
])
)
return await sendHybridInteractionMessageResponse(data, {
+8 -1
View File
@@ -53,7 +53,14 @@ export default async (data: HybridInteractionMessage, args: any, guild: Guild, l
if (!GuildCache) return;
const language = GuildCache.locale;
if (!(await checkMemberPermissionsInGuild({ member, data, locale, permissions: [PermissionsBitField.Flags.ManageGuild] })))
if (
!(await checkMemberPermissionsInGuild({
member,
data,
locale,
permissions: [PermissionsBitField.Flags.ManageGuild]
}))
)
return;
let newLanguage: string | null | undefined;
+16 -5
View File
@@ -19,7 +19,7 @@ import { checkMemberPermissionsInGuild } from '../../utils/DiscordPermission';
const EMBEDS = {
PREFIX_INFO: (data: HybridInteractionMessage, locale: I18n, currentPrefix: string) => {
return makeInfoEmbed({
title: locale.__('settings_prefix.info', { PREFIX: currentPrefix}),
title: locale.__('settings_prefix.info', { PREFIX: currentPrefix }),
description: locale.__('settings_prefix.info_description'),
user: data.getUser()
});
@@ -52,10 +52,17 @@ export default async (data: HybridInteractionMessage, args: any, guild: Guild, l
if (!member) return;
const GuildCache = await Cache.getCachedGuild(guild.id);
if (!GuildCache) return;
if (!GuildCache) return;
const prefix = GuildCache.prefix;
if (!(await checkMemberPermissionsInGuild({ member, data, locale, permissions: [PermissionsBitField.Flags.ManageGuild] })))
if (
!(await checkMemberPermissionsInGuild({
member,
data,
locale,
permissions: [PermissionsBitField.Flags.ManageGuild]
}))
)
return;
let newPrefix: string | null | undefined;
@@ -70,7 +77,8 @@ export default async (data: HybridInteractionMessage, args: any, guild: Guild, l
__name.shift();
_name = __name.join(' ');
newPrefix = _name;
} else if (data.isApplicationCommand()) newPrefix = data.getSlashCommand().options.get('prefix', true).value?.toString();
} else if (data.isApplicationCommand())
newPrefix = data.getSlashCommand().options.get('prefix', true).value?.toString();
if (!newPrefix)
return await sendHybridInteractionMessageResponse(data, {
@@ -82,7 +90,10 @@ export default async (data: HybridInteractionMessage, args: any, guild: Guild, l
embeds: [EMBEDS.PREFIX_TOO_LONG(data, locale)]
});
if (newPrefix.startsWith(`<@!${DiscordProvider.client.user?.id}>`) || newPrefix.startsWith(`<@${DiscordProvider.client.user?.id}>`))
if (
newPrefix.startsWith(`<@!${DiscordProvider.client.user?.id}>`) ||
newPrefix.startsWith(`<@${DiscordProvider.client.user?.id}>`)
)
return await sendHybridInteractionMessageResponse(data, {
embeds: [EMBEDS.PREFIX_IS_MENTION(data, locale)]
});
+36 -7
View File
@@ -104,29 +104,49 @@ export const setEnableServiceAnnouncement = async (
let member = data.getMember();
if (!member) return;
if (!(await checkMemberPermissionsInGuild({ member, data, locale, permissions: [PermissionsBitField.Flags.Administrator] })))
if (
!(await checkMemberPermissionsInGuild({
member,
data,
locale,
permissions: [PermissionsBitField.Flags.Administrator]
}))
)
return;
let GuildCache = await Cache.getCachedGuild(guild.id);
if(!GuildCache) return;
if (!GuildCache) return;
let newStatus: string | null | undefined;
if (data.isMessage()) {
let _name: string;
if (typeof args[1] === 'undefined')
return await sendHybridInteractionMessageResponse(data, {
embeds: [await EMBEDS.NO_SERVICE_ANNOUNCEMENT_STATUS_PROVIDED(data, locale, GuildCache.ServiceAnnouncement_Enabled)]
embeds: [
await EMBEDS.NO_SERVICE_ANNOUNCEMENT_STATUS_PROVIDED(
data,
locale,
GuildCache.ServiceAnnouncement_Enabled
)
]
});
let __name = args;
__name.shift();
_name = __name.join(' ');
newStatus = _name;
} else if (data.isApplicationCommand()) newStatus = data.getSlashCommand().options.get('status', true).value?.toString();
} else if (data.isApplicationCommand())
newStatus = data.getSlashCommand().options.get('status', true).value?.toString();
if (!newStatus)
return await sendHybridInteractionMessageResponse(data, {
embeds: [await EMBEDS.NO_SERVICE_ANNOUNCEMENT_STATUS_PROVIDED(data, locale, GuildCache.ServiceAnnouncement_Enabled)]
embeds: [
await EMBEDS.NO_SERVICE_ANNOUNCEMENT_STATUS_PROVIDED(
data,
locale,
GuildCache.ServiceAnnouncement_Enabled
)
]
});
if (!['true', 'false', 'yes', 'no', 'y', 'n', 'enable', 'disable'].includes(newStatus.toLowerCase()))
@@ -182,7 +202,14 @@ export const setServiceAnnouncementChannel = async (
let member = data.getMember();
if (!member) return;
if (!(await checkMemberPermissionsInGuild({ member, data, locale, permissions: [PermissionsBitField.Flags.Administrator] })))
if (
!(await checkMemberPermissionsInGuild({
member,
data,
locale,
permissions: [PermissionsBitField.Flags.Administrator]
}))
)
return;
let channel;
@@ -213,7 +240,9 @@ export const setServiceAnnouncementChannel = async (
});
if (
!data.getGuild()?.members.me?.permissionsIn(TargetChannel)
!data
.getGuild()
?.members.me?.permissionsIn(TargetChannel)
.has([PermissionsBitField.Flags.SendMessages, PermissionsBitField.Flags.ViewChannel])
)
return await sendHybridInteractionMessageResponse(data, {
+9 -15
View File
@@ -1,10 +1,4 @@
import {
Message,
CommandInteraction,
Guild,
PermissionsBitField,
PermissionResolvable
} from 'discord.js';
import { Message, CommandInteraction, Guild, PermissionsBitField, PermissionResolvable } from 'discord.js';
import { I18n } from 'i18n';
import DiscordProvider from '../../providers/Discord';
@@ -24,26 +18,26 @@ import * as ServiceAnnouncementModule from './ServiceAnnouncement';
export const COMMON_EMBEDS = {
MEMBER_NO_PERMISSION: (data: HybridInteractionMessage, locale: I18n, permissions: PermissionResolvable[]) => {
let allPermissions = [];
for(const value of permissions) {
for (const value of permissions) {
allPermissions.push(new PermissionsBitField(value).toArray());
}
return makeErrorEmbed({
title: locale.__('common.member_no_permissions'),
description: locale.__('common.member_no_permissions_description', { PERMISSIONS: allPermissions.join(', ')}),
description: locale.__('common.member_no_permissions_description', {
PERMISSIONS: allPermissions.join(', ')
}),
user: data.getUser()
});
},
BOT_NO_PERMISSION: (data: HybridInteractionMessage, locale: I18n, permissions: PermissionResolvable[]) => {
let allPermissions = [];
for(const value of permissions) {
for (const value of permissions) {
allPermissions.push(new PermissionsBitField(value).toArray());
}
return makeErrorEmbed({
title: locale.__('common.bot_no_permissions'),
description: locale.__('common.bot_no_permissions_description', { PERMISSIONS: allPermissions.join(', ')}),
description: locale.__('common.bot_no_permissions_description', { PERMISSIONS: allPermissions.join(', ') }),
user: data.getUser()
});
},
@@ -55,7 +49,7 @@ export const COMMON_EMBEDS = {
user: data.getUser()
});
}
}
};
const EMBEDS = {
SETTINGS_INFO: (data: HybridInteractionMessage, locale: I18n, guild: Guild) => {
@@ -68,7 +62,7 @@ const EMBEDS = {
fields: [
{
name: locale.__('common.available_args'),
value: locale.__('settings.valid_args'),
value: locale.__('settings.valid_args')
}
],
user: data.getUser()
+5 -4
View File
@@ -23,15 +23,16 @@ const EMBEDS = {
{
name: `🌐 ${locale.__('stats.users')}`,
value: `${locale.__('stats.x_servers', { COUNT: totalServers.toString() })}\n${locale.__(
'stats.x_users', { COUNT: totalUsers.toString()}
'stats.x_users',
{ COUNT: totalUsers.toString() }
)}`,
inline: true
},
{
name: `🟢 ${locale.__('stats.uptime_since')}`,
value: `${locale.__('stats.server_uptime_x', {TIME: `<t:${systemUptime.toString()}:R>`})}\n${locale.__(
'stats.process_uptime_x', { TIME: `<t:${processUptime.toString()}:R>`}
)}`,
value: `${locale.__('stats.server_uptime_x', {
TIME: `<t:${systemUptime.toString()}:R>`
})}\n${locale.__('stats.process_uptime_x', { TIME: `<t:${processUptime.toString()}:R>` })}`,
inline: true
}
],
+7 -3
View File
@@ -13,11 +13,15 @@ const EMBEDS = {
const user = data.getUser();
let message;
if (Environment.get().SUPPORT_URL)
message = locale.__('support.info', { BOT_NAME: DiscordProvider.client.user!.username, LINK: Environment.get().SUPPORT_URL});
message = locale.__('support.info', {
BOT_NAME: DiscordProvider.client.user!.username,
LINK: Environment.get().SUPPORT_URL
});
return makeInfoEmbed({
title: locale.__('support.title'),
description: message || locale.__('support.not_available', { BOT_NAME: DiscordProvider.client.user!.username}),
description:
message || locale.__('support.not_available', { BOT_NAME: DiscordProvider.client.user!.username }),
user
});
}
@@ -46,7 +50,7 @@ export default class Support extends DiscordModule {
embeds: [EMBEDS.SUPPORT_INFO(data, locale)]
});
if(Environment.get().SUPPORT_URL)
if (Environment.get().SUPPORT_URL)
await sendHybridInteractionMessageResponse(data, {
content: Environment.get().SUPPORT_URL
});
+45 -35
View File
@@ -74,22 +74,24 @@ const EMBEDS = {
if (user.presence?.activities) {
for (let activity of user.presence?.activities) {
if (activity.type === ActivityType.Custom)
embed.addFields([{
name: `${locale.__('userinfo.custom_status')}`,
value: `${
!activity.emoji
? ''
: `${
activity.emoji?.identifier.startsWith('<') &&
activity.emoji?.identifier.endsWith('>') &&
activity.emoji?.identifier.split(':').length == 2
? activity.emoji?.identifier.split(':')[0]
: activity.emoji?.name
}`
} ${activity.state === null ? '' : activity.state}
embed.addFields([
{
name: `${locale.__('userinfo.custom_status')}`,
value: `${
!activity.emoji
? ''
: `${
activity.emoji?.identifier.startsWith('<') &&
activity.emoji?.identifier.endsWith('>') &&
activity.emoji?.identifier.split(':').length == 2
? activity.emoji?.identifier.split(':')[0]
: activity.emoji?.name
}`
} ${activity.state === null ? '' : activity.state}
\u200b`,
inline: false
}]);
inline: false
}
]);
else {
let title = '';
switch (activity.type) {
@@ -111,38 +113,46 @@ const EMBEDS = {
}
const startTime = activity.timestamps?.start;
const endTime = activity.timestamps?.end;
embed.addFields([{
name: `${title}`,
value: `${activity.details === null ? '' : activity.details}
embed.addFields([
{
name: `${title}`,
value: `${activity.details === null ? '' : activity.details}
${activity.state === null ? '' : activity.state}
${
startTime
? `${locale.__('userinfo.since', {TIME: `<t:${Math.round(startTime.getTime() / 1000)}:R>` })}`
? `${locale.__('userinfo.since', {
TIME: `<t:${Math.round(startTime.getTime() / 1000)}:R>`
})}`
: ''
}${
endTime
? `\n${locale.__('userinfo.end', {TIME: `<t:${Math.round(endTime.getTime() / 1000)}:R>` })}`
: ''
}
endTime
? `\n${locale.__('userinfo.end', {
TIME: `<t:${Math.round(endTime.getTime() / 1000)}:R>`
})}`
: ''
}
\u200b`,
inline: false
}]);
inline: false
}
]);
}
}
}
embed.addFields([{
name: `📰 ${locale.__('userinfo.user_guild_info')}`,
value: `${
user.joinedAt === null
? locale.__('userinfo.join_date_unknown')
: locale.__('userinfo.join_date', {
TIME: `<t:${Math.round(user.joinedAt.getTime() / 1000).toString()}:R>`
})
}
embed.addFields([
{
name: `📰 ${locale.__('userinfo.user_guild_info')}`,
value: `${
user.joinedAt === null
? locale.__('userinfo.join_date_unknown')
: locale.__('userinfo.join_date', {
TIME: `<t:${Math.round(user.joinedAt.getTime() / 1000).toString()}:R>`
})
}
${user.isGuildOwner ? `${locale.__('userinfo.guild_owner')}` : ''}
`
}]);
}
]);
embed.setThumbnail(user.displayAvatarURL + '?size=4096');
embed.setAuthor({
+2 -14
View File
@@ -1,11 +1,4 @@
import {
Message,
ActionRowBuilder,
ButtonBuilder,
CommandInteraction,
BaseInteraction,
ButtonStyle
} from 'discord.js';
import { Message, ActionRowBuilder, ButtonBuilder, CommandInteraction, BaseInteraction, ButtonStyle } from 'discord.js';
import validator from 'validator';
import countryLookup from 'country-code-lookup';
import { countryCodeEmoji } from 'country-code-emoji';
@@ -14,11 +7,7 @@ import Prisma from '../providers/Prisma';
import osuAPI from '../providers/osuAPI';
import DiscordModule, { HybridInteractionMessage } from '../utils/DiscordModule';
import {
makeInfoEmbed,
makeErrorEmbed,
sendHybridInteractionMessageResponse
} from '../utils/DiscordMessage';
import { makeInfoEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse } from '../utils/DiscordMessage';
const EMBEDS = {
osu_INFO: (data: HybridInteractionMessage) => {
@@ -99,7 +88,6 @@ export default class osu extends DiscordModule {
const Guild = await Prisma.client.guild.findFirst({ where: { id: data.getGuild()!.id } });
if (!Guild) return;
if (!osuAPI.client)
return await sendHybridInteractionMessageResponse(data, {
embeds: [EMBEDS.NOT_INITIALIZED(data)]