mirror of
https://github.com/kirameki-cafe/Yumi.git
synced 2026-09-13 18:59:19 +00:00
Code refactor
This commit is contained in:
+12
-4
@@ -1,11 +1,16 @@
|
|||||||
import { Guild } from ".prisma/client";
|
import DiscordModule from "../utils/DiscordModule";
|
||||||
|
|
||||||
|
import { Guild } from "discord.js";
|
||||||
import Logger from "../libs/Logger";
|
import Logger from "../libs/Logger";
|
||||||
import Cache from "../providers/Cache";
|
import Cache from "../providers/Cache";
|
||||||
import DiscordProvider from "../providers/Discord";
|
import DiscordProvider from "../providers/Discord";
|
||||||
import Prisma from "../providers/Prisma";
|
import Prisma from "../providers/Prisma";
|
||||||
|
|
||||||
export default class Core {
|
export default class Core extends DiscordModule {
|
||||||
async ready() {
|
|
||||||
|
public id: string = "Discord_Core";
|
||||||
|
|
||||||
|
async Ready() {
|
||||||
|
|
||||||
let data = [];
|
let data = [];
|
||||||
for(let Guild of DiscordProvider.client.guilds.cache.map(guild => guild)) {
|
for(let Guild of DiscordProvider.client.guilds.cache.map(guild => guild)) {
|
||||||
@@ -22,14 +27,17 @@ export default class Core {
|
|||||||
Cache.updateGuildsCache();
|
Cache.updateGuildsCache();
|
||||||
}, 5 * 60 * 1000)
|
}, 5 * 60 * 1000)
|
||||||
|
|
||||||
|
setInterval(() => {
|
||||||
DiscordProvider.client.user!.setActivity("for your heart 💖", {
|
DiscordProvider.client.user!.setActivity("for your heart 💖", {
|
||||||
type: "COMPETING"
|
type: "COMPETING"
|
||||||
});
|
});
|
||||||
|
}, 5 * 60 * 1000)
|
||||||
|
|
||||||
Logger.info('Core started successfully');
|
Logger.info('Core started successfully');
|
||||||
|
|
||||||
}
|
}
|
||||||
async guildCreate(guild: Guild) {
|
|
||||||
|
async GuildCreate(guild: Guild) {
|
||||||
if(await Prisma.client.guild.findFirst({ where: {id: guild.id} })) return;
|
if(await Prisma.client.guild.findFirst({ where: {id: guild.id} })) return;
|
||||||
|
|
||||||
await Prisma.client.guild.create({
|
await Prisma.client.guild.create({
|
||||||
|
|||||||
+16
-22
@@ -1,5 +1,7 @@
|
|||||||
|
import DiscordModule, { HybridInteractionMessage } from "../utils/DiscordModule";
|
||||||
|
|
||||||
import { CommandInteraction, Interaction, Message } from "discord.js";
|
import { CommandInteraction, Interaction, Message } from "discord.js";
|
||||||
import { sendMessageOrInteractionResponse, makeInfoEmbed } from "../utils/DiscordMessage";
|
import { sendHybridInteractionMessageResponse, makeInfoEmbed } from "../utils/DiscordMessage";
|
||||||
import DiscordProvider from "../providers/Discord";
|
import DiscordProvider from "../providers/Discord";
|
||||||
import Cache from "../providers/Cache";
|
import Cache from "../providers/Cache";
|
||||||
|
|
||||||
@@ -57,32 +59,24 @@ const EMBEDS = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Help {
|
export default class Help extends DiscordModule {
|
||||||
|
|
||||||
async onCommand(command: string, args: any, message: Message) {
|
public id = "Discord_Help";
|
||||||
if(command.toLowerCase() !== 'help') return;
|
public commands = ["help"];
|
||||||
await this.process(message, args);
|
public commandInteractionName = "help";
|
||||||
|
|
||||||
|
async GuildOnModuleCommand(args: any, message: Message) {
|
||||||
|
await this.run(new HybridInteractionMessage(message), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
async interactionCreate(interaction: CommandInteraction) {
|
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||||
if(interaction.isCommand()) {
|
await this.run(new HybridInteractionMessage(interaction), interaction.options);
|
||||||
if(typeof interaction.commandName === 'undefined') return;
|
|
||||||
if((interaction.commandName).toLowerCase() !== 'help') return;
|
|
||||||
await this.process(interaction, interaction.options);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async process(data: Interaction | Message, args: any) {
|
async run(data: HybridInteractionMessage, args: any) {
|
||||||
|
const message = await sendHybridInteractionMessageResponse(data, { embeds: [await EMBEDS.INFO(data.getRaw())] });
|
||||||
const isSlashCommand = data instanceof CommandInteraction && data.isCommand();
|
|
||||||
const isMessage = data instanceof Message;
|
|
||||||
|
|
||||||
if(!isSlashCommand && !isMessage) return;
|
|
||||||
|
|
||||||
let sent = await sendMessageOrInteractionResponse(data, { embeds: [await EMBEDS.INFO(data)] });
|
|
||||||
|
|
||||||
if(isMessage)
|
|
||||||
return (sent as Message).react("♥");
|
|
||||||
|
|
||||||
|
if(message && data.isMessage())
|
||||||
|
return new HybridInteractionMessage(message).getMessage().react("♥");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
|
import DiscordModule, { HybridInteractionMessage } from "../utils/DiscordModule";
|
||||||
|
|
||||||
import { Message, Interaction, CommandInteraction } from "discord.js";
|
import { Message, Interaction, CommandInteraction } from "discord.js";
|
||||||
import { makeInfoEmbed, makeErrorEmbed, makeSuccessEmbed, makeProcessingEmbed, sendMessageOrInteractionResponse } from "../utils/DiscordMessage";
|
import { makeInfoEmbed, makeErrorEmbed, makeSuccessEmbed, makeProcessingEmbed, sendHybridInteractionMessageResponse } from "../utils/DiscordMessage";
|
||||||
import {registerAllGuildsCommands, unregisterAllGuildsCommands} from "../utils/DiscordInteraction";
|
import {registerAllGuildsCommands, unregisterAllGuildsCommands} from "../utils/DiscordInteraction";
|
||||||
import Users from "../services/Users";
|
import Users from "../services/Users";
|
||||||
|
|
||||||
@@ -46,66 +48,70 @@ const EMBEDS = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class InteractionManager {
|
export default class InteractionManager extends DiscordModule {
|
||||||
async onCommand(command: string, args: any, message: Message) {
|
|
||||||
if(command.toLowerCase() !== 'interaction') return;
|
public id = "Discord_InteractionManager";
|
||||||
await this.process(message, args);
|
public commands = ["interaction"];
|
||||||
|
public commandInteractionName = "interaction";
|
||||||
|
|
||||||
|
async GuildOnModuleCommand(args: any, message: Message) {
|
||||||
|
await this.run(new HybridInteractionMessage(message), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
async interactionCreate(interaction: CommandInteraction) {
|
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||||
if(interaction.isCommand()) {
|
await this.run(new HybridInteractionMessage(interaction), interaction.options);
|
||||||
if(typeof interaction.commandName === 'undefined') return;
|
|
||||||
if((interaction.commandName).toLowerCase() !== 'interaction') return;
|
|
||||||
await this.process(interaction, interaction.options);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async process(data: Interaction | Message, args: any) {
|
async run(data: HybridInteractionMessage, args: any) {
|
||||||
const isSlashCommand = data instanceof CommandInteraction && data.isCommand();
|
|
||||||
const isMessage = data instanceof Message;
|
|
||||||
|
|
||||||
if(!isSlashCommand && !isMessage) return;
|
const user = data.getUser();
|
||||||
|
if(!user) return;
|
||||||
|
|
||||||
if(!Users.isDeveloper(data.member?.user.id!))
|
if(!Users.isDeveloper(user.id))
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds:[EMBEDS.NOT_DEVELOPER(data)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds:[EMBEDS.NOT_DEVELOPER(data.getRaw())] });
|
||||||
|
|
||||||
const funct = {
|
const funct = {
|
||||||
reloadAll: async(data: Message | Interaction) => {
|
reloadAll: async(data: HybridInteractionMessage) => {
|
||||||
let placeholder = await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.PROCESSING(data)] });
|
|
||||||
|
let placeholder: (HybridInteractionMessage | undefined);
|
||||||
|
|
||||||
|
let _placeholder = await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.PROCESSING(data.getRaw())] });
|
||||||
|
if (_placeholder)
|
||||||
|
placeholder = new HybridInteractionMessage(_placeholder);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await unregisterAllGuildsCommands();
|
await unregisterAllGuildsCommands();
|
||||||
await registerAllGuildsCommands();
|
await registerAllGuildsCommands();
|
||||||
if(isMessage)
|
|
||||||
return (placeholder as Message).edit({ embeds: [EMBEDS.RELOADALL_SUCCESS(data)] });
|
if(data && data.isMessage() && placeholder && placeholder.isMessage())
|
||||||
else if(isSlashCommand)
|
return placeholder.getMessage().edit({ embeds: [EMBEDS.RELOADALL_SUCCESS(data.getRaw())] });
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.RELOADALL_SUCCESS(data)]}, true);
|
else if(data.isSlashCommand())
|
||||||
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.RELOADALL_SUCCESS(data.getRaw())]}, true);
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if(isMessage)
|
if(data && data.isMessage() && placeholder && placeholder.isMessage())
|
||||||
(placeholder as Message).edit({ embeds: [EMBEDS.RELOADALL_ERROR(data, err)] });
|
return placeholder.getMessage().edit({ embeds: [EMBEDS.RELOADALL_ERROR(data.getRaw(), err)] });
|
||||||
else if(isSlashCommand)
|
else if(data.isSlashCommand())
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.RELOADALL_ERROR(data, err)] }, true);
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.RELOADALL_ERROR(data.getRaw(), err)] }, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let query;
|
let query;
|
||||||
|
|
||||||
if(isMessage) {
|
if(data.isMessage()) {
|
||||||
if(data === null || !data.guildId || data.member === null || data.guild === null) return;
|
if(args.length === 0)
|
||||||
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.INTERACTION_INFO(data.getRaw())] });
|
||||||
|
|
||||||
if(args.length === 0) {
|
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.INTERACTION_INFO(data)] });
|
|
||||||
}
|
|
||||||
query = args[0].toLowerCase();
|
query = args[0].toLowerCase();
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(isSlashCommand) {
|
else if(data.isSlashCommand()) {
|
||||||
query = args.getSubcommand();
|
query = args.getSubcommand();
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(query) {
|
switch(query) {
|
||||||
case "info":
|
case "info":
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.INTERACTION_INFO(data)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.INTERACTION_INFO(data.getRaw())] });
|
||||||
case "reloadall":
|
case "reloadall":
|
||||||
return await funct.reloadAll(data);
|
return await funct.reloadAll(data);
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-18
@@ -1,5 +1,7 @@
|
|||||||
|
import DiscordModule, { HybridInteractionMessage } from "../utils/DiscordModule";
|
||||||
|
|
||||||
import { Message, CommandInteraction, Interaction } from "discord.js";
|
import { Message, CommandInteraction, Interaction } from "discord.js";
|
||||||
import { sendMessageOrInteractionResponse, makeInfoEmbed } from "../utils/DiscordMessage";
|
import { sendHybridInteractionMessageResponse, makeInfoEmbed } from "../utils/DiscordMessage";
|
||||||
import DiscordProvider from "../providers/Discord";
|
import DiscordProvider from "../providers/Discord";
|
||||||
import Users from "../services/Users"
|
import Users from "../services/Users"
|
||||||
import Environment from "../providers/Environment";
|
import Environment from "../providers/Environment";
|
||||||
@@ -18,27 +20,21 @@ const EMBEDS = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Invite {
|
export default class Invite extends DiscordModule {
|
||||||
|
|
||||||
async onCommand(command: string, args: any, message: Message) {
|
public id: string = "Discord_Invite";
|
||||||
if(command.toLowerCase() !== 'invite') return;
|
public commands = ["invite"];
|
||||||
await this.process(message, args);
|
public commandInteractionName = "invite";
|
||||||
|
|
||||||
|
async GuildOnModuleCommand(args: any, message: Message) {
|
||||||
|
await this.run(new HybridInteractionMessage(message), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
async interactionCreate(interaction: CommandInteraction) {
|
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||||
if(interaction.isCommand()) {
|
await this.run(new HybridInteractionMessage(interaction), interaction.options);
|
||||||
if(typeof interaction.commandName === 'undefined') return;
|
|
||||||
if((interaction.commandName).toLowerCase() !== 'invite') return;
|
|
||||||
await this.process(interaction, interaction.options);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async process(data: Interaction | Message, args: any) {
|
async run(data: HybridInteractionMessage, args: any) {
|
||||||
const isSlashCommand = data instanceof CommandInteraction && data.isCommand();
|
return await sendHybridInteractionMessageResponse(data, { embeds:[EMBEDS.INVITE_INFO(data.getRaw())] });
|
||||||
const isMessage = data instanceof Message;
|
|
||||||
|
|
||||||
if(!isSlashCommand && !isMessage) return;
|
|
||||||
|
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds:[EMBEDS.INVITE_INFO(data)] });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+220
-216
@@ -1,50 +1,51 @@
|
|||||||
import { GuildChannel, GuildMember, Message, Permissions, TextChannel, MessageActionRow, MessageButton, Interaction, CommandInteraction, Role, ThreadChannel } from "discord.js";
|
import DiscordModule, { HybridInteractionMessage } from "../utils/DiscordModule";
|
||||||
|
|
||||||
|
import { GuildChannel, GuildMember, Message, Permissions, TextChannel, MessageActionRow, MessageButton, Interaction, CommandInteraction, Role, ThreadChannel, ButtonInteraction } from "discord.js";
|
||||||
import App from "..";
|
import App from "..";
|
||||||
import { makeSuccessEmbed, makeInfoEmbed, makeErrorEmbed, sendMessageOrInteractionResponse } from "../utils/DiscordMessage";
|
import { makeSuccessEmbed, makeInfoEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse, sendMessage } from "../utils/DiscordMessage";
|
||||||
import Logger from "../libs/Logger";
|
|
||||||
import DiscordProvider from "../providers/Discord";
|
import DiscordProvider from "../providers/Discord";
|
||||||
import Prisma from "../providers/Prisma";
|
import Prisma from "../providers/Prisma";
|
||||||
|
|
||||||
const EMBEDS = {
|
const EMBEDS = {
|
||||||
NO_PERMISSION: (data: Message | Interaction) => {
|
NO_PERMISSION: (data: Message | Interaction) => {
|
||||||
return makeErrorEmbed ({
|
return makeErrorEmbed({
|
||||||
title: 'You need ``ADMINISTRATOR`` permission on this guild!',
|
title: 'You need ``ADMINISTRATOR`` permission on this guild!',
|
||||||
user: (data instanceof Interaction) ? data.user : data.author
|
user: (data instanceof Interaction) ? data.user : data.author
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
NO_PARAMETER: (data: Message | Interaction) => {
|
NO_PARAMETER: (data: Message | Interaction) => {
|
||||||
return makeErrorEmbed ({
|
return makeErrorEmbed({
|
||||||
title: 'Missing parameter',
|
title: 'Missing parameter',
|
||||||
description: `You must define membership screening channel and role to enable this feature`,
|
description: `You must define membership screening channel and role to enable this feature`,
|
||||||
user: (data instanceof Interaction) ? data.user : data.author
|
user: (data instanceof Interaction) ? data.user : data.author
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
NO_ROLE_MENTIONED: (data: Message | Interaction) => {
|
NO_ROLE_MENTIONED: (data: Message | Interaction) => {
|
||||||
return makeErrorEmbed ({
|
return makeErrorEmbed({
|
||||||
title: 'No role mentioned',
|
title: 'No role mentioned',
|
||||||
user: (data instanceof Interaction) ? data.user : data.author
|
user: (data instanceof Interaction) ? data.user : data.author
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
NO_ROLE_FOUND: (data: Message | Interaction) => {
|
NO_ROLE_FOUND: (data: Message | Interaction) => {
|
||||||
return makeErrorEmbed ({
|
return makeErrorEmbed({
|
||||||
title: 'Cannot find that role',
|
title: 'Cannot find that role',
|
||||||
user: (data instanceof Interaction) ? data.user : data.author
|
user: (data instanceof Interaction) ? data.user : data.author
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
NO_CHANNEL_MENTIONED: (data: Message | Interaction) => {
|
NO_CHANNEL_MENTIONED: (data: Message | Interaction) => {
|
||||||
return makeErrorEmbed ({
|
return makeErrorEmbed({
|
||||||
title: 'No channel mentioned',
|
title: 'No channel mentioned',
|
||||||
user: (data instanceof Interaction) ? data.user : data.author
|
user: (data instanceof Interaction) ? data.user : data.author
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
NO_CHANNEL_FOUND: (data: Message | Interaction) => {
|
NO_CHANNEL_FOUND: (data: Message | Interaction) => {
|
||||||
return makeErrorEmbed ({
|
return makeErrorEmbed({
|
||||||
title: 'Cannot find that channel',
|
title: 'Cannot find that channel',
|
||||||
user: (data instanceof Interaction) ? data.user : data.author
|
user: (data instanceof Interaction) ? data.user : data.author
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
MSINFO:(data: Message | Interaction) => {
|
MSINFO: (data: Message | Interaction) => {
|
||||||
return makeInfoEmbed ({
|
return makeInfoEmbed({
|
||||||
title: 'Membership Screening',
|
title: 'Membership Screening',
|
||||||
description: `Membership Screening is a feature to prevent unwanted people to join your guild, similar to whitelist feature. Moderators can approve or deny join request`,
|
description: `Membership Screening is a feature to prevent unwanted people to join your guild, similar to whitelist feature. Moderators can approve or deny join request`,
|
||||||
fields: [
|
fields: [
|
||||||
@@ -57,99 +58,105 @@ const EMBEDS = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
ALREADY_ENABLED: (data: Message | Interaction) => {
|
ALREADY_ENABLED: (data: Message | Interaction) => {
|
||||||
return makeInfoEmbed ({
|
return makeInfoEmbed({
|
||||||
title: 'Membership Screening is already enabled',
|
title: 'Membership Screening is already enabled',
|
||||||
user: (data instanceof Interaction) ? data.user : data.author
|
user: (data instanceof Interaction) ? data.user : data.author
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
MESSAGE_CREATED: (data: Message | Interaction) => {
|
||||||
|
return makeSuccessEmbed({
|
||||||
|
title: 'Membership Screening message created',
|
||||||
|
user: (data instanceof Interaction) ? data.user : data.author
|
||||||
|
});
|
||||||
|
},
|
||||||
ALREADY_DISABLED: (data: Message | Interaction) => {
|
ALREADY_DISABLED: (data: Message | Interaction) => {
|
||||||
return makeInfoEmbed ({
|
return makeInfoEmbed({
|
||||||
title: 'Membership Screening is already disabled',
|
title: 'Membership Screening is already disabled',
|
||||||
user: (data instanceof Interaction) ? data.user : data.author
|
user: (data instanceof Interaction) ? data.user : data.author
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
ENABLED: (data: Message | Interaction) => {
|
ENABLED: (data: Message | Interaction) => {
|
||||||
return makeSuccessEmbed ({
|
return makeSuccessEmbed({
|
||||||
title: 'Enabled Membership Screening',
|
title: 'Enabled Membership Screening',
|
||||||
description: `All new member join request will be sent in your defined channel`,
|
description: `All new member join request will be sent in your defined channel`,
|
||||||
user: (data instanceof Interaction) ? data.user : data.author
|
user: (data instanceof Interaction) ? data.user : data.author
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
DISABLED: (data: Message | Interaction) => {
|
DISABLED: (data: Message | Interaction) => {
|
||||||
return makeSuccessEmbed ({
|
return makeSuccessEmbed({
|
||||||
title: 'Disabled Membership Screening',
|
title: 'Disabled Membership Screening',
|
||||||
description: `No longer accepting request, all new member can join directly`,
|
description: `No longer accepting request, all new member can join directly`,
|
||||||
user: (data instanceof Interaction) ? data.user : data.author
|
user: (data instanceof Interaction) ? data.user : data.author
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
MANAGED_ROLE: (data: Message | Interaction, role: Role) => {
|
MANAGED_ROLE: (data: Message | Interaction, role: Role) => {
|
||||||
return makeErrorEmbed ({
|
return makeErrorEmbed({
|
||||||
title: 'You cannot use this role',
|
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 Interaction) ? data.user : data.author
|
user: (data instanceof Interaction) ? data.user : data.author
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
CONFIGURED_ROLE: (data: Message | Interaction, role: Role) => {
|
CONFIGURED_ROLE: (data: Message | Interaction, role: Role) => {
|
||||||
return makeSuccessEmbed ({
|
return makeSuccessEmbed({
|
||||||
title: 'Configured Membership Screening Role',
|
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 Interaction) ? data.user : data.author
|
user: (data instanceof Interaction) ? data.user : data.author
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
CONFIGURED_CHANNEL: (data: Message | Interaction, channel: GuildChannel) => {
|
CONFIGURED_CHANNEL: (data: Message | Interaction, channel: GuildChannel) => {
|
||||||
return makeSuccessEmbed ({
|
return makeSuccessEmbed({
|
||||||
title: 'Configured Membership Screening Channel',
|
title: 'Configured Membership Screening Channel',
|
||||||
description: 'Anyone with ``VIEW_CHANNEL`` permission in ' + '``' + channel.name +'``' + ' can approve or deny request',
|
description: 'Anyone with ``VIEW_CHANNEL`` permission in ' + '``' + channel.name + '``' + ' can approve or deny request',
|
||||||
user: (data instanceof Interaction) ? data.user : data.author
|
user: (data instanceof Interaction) ? data.user : data.author
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
INVALID_CHANNEL: (data: Message | Interaction, channel: GuildChannel) => {
|
INVALID_CHANNEL: (data: Message | Interaction, channel: GuildChannel) => {
|
||||||
return makeErrorEmbed ({
|
return makeErrorEmbed({
|
||||||
title: 'Invalid channel type, only TextChannel is supported',
|
title: 'Invalid channel type, only TextChannel is supported',
|
||||||
description: '``' + channel.name +'``' + ' is not a text channel',
|
description: '``' + channel.name + '``' + ' is not a text channel',
|
||||||
user: (data instanceof Interaction) ? data.user : data.author
|
user: (data instanceof Interaction) ? data.user : data.author
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
INVALID_CHANNEL_THREAD: (data: Message | Interaction, channel: GuildChannel | ThreadChannel) => {
|
INVALID_CHANNEL_THREAD: (data: Message | Interaction, channel: GuildChannel | ThreadChannel) => {
|
||||||
return makeErrorEmbed ({
|
return makeErrorEmbed({
|
||||||
title: 'Thread channel is not supported',
|
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 Interaction) ? data.user : data.author
|
user: (data instanceof Interaction) ? data.user : data.author
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
BOT_NO_PERMISSION: (data: Message | Interaction, channel: GuildChannel) => {
|
BOT_NO_PERMISSION: (data: Message | Interaction, channel: GuildChannel) => {
|
||||||
return makeErrorEmbed ({
|
return makeErrorEmbed({
|
||||||
title: `I don't have permission`,
|
title: `I don't have permission`,
|
||||||
description: 'I cannot access/send message in ' + '``' + channel.name +'``',
|
description: 'I cannot access/send message in ' + '``' + channel.name + '``',
|
||||||
user: (data instanceof Interaction) ? data.user : data.author
|
user: (data instanceof Interaction) ? data.user : data.author
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
NO_LONGER_VALID_ROLE: (data: Message | Interaction) => {
|
NO_LONGER_VALID_ROLE: (data: Message | Interaction) => {
|
||||||
return makeErrorEmbed ({
|
return makeErrorEmbed({
|
||||||
title: 'The configured role is no longer valid. Please update the role in configuration',
|
title: 'The configured role is no longer valid. Please update the role in configuration',
|
||||||
user: (data instanceof Interaction) ? data.user : data.author
|
user: (data instanceof Interaction) ? data.user : data.author
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
CANNOT_PERFORM_ASSIGN_ROLE: (data: Message | Interaction) => {
|
CANNOT_PERFORM_ASSIGN_ROLE: (data: Message | Interaction) => {
|
||||||
return makeErrorEmbed ({
|
return makeErrorEmbed({
|
||||||
title: 'Cannot grant the role to user, make sure I have permission to do that',
|
title: 'Cannot grant the role to user, make sure I have permission to do that',
|
||||||
user: (data instanceof Interaction) ? data.user : data.author
|
user: (data instanceof Interaction) ? data.user : data.author
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
CANNOT_PERFORM_ASSIGN_KICK: (data: Message | Interaction) => {
|
CANNOT_PERFORM_ASSIGN_KICK: (data: Message | Interaction) => {
|
||||||
return makeErrorEmbed ({
|
return makeErrorEmbed({
|
||||||
title: 'Cannot kick the user, make sure I have permission to do that',
|
title: 'Cannot kick the user, make sure I have permission to do that',
|
||||||
user: (data instanceof Interaction) ? data.user : data.author
|
user: (data instanceof Interaction) ? data.user : data.author
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
CANNOT_PERFORM_ASSIGN_BAN: (data: Message | Interaction) => {
|
CANNOT_PERFORM_ASSIGN_BAN: (data: Message | Interaction) => {
|
||||||
return makeErrorEmbed ({
|
return makeErrorEmbed({
|
||||||
title: 'Cannot ban the user, make sure I have permission to do that',
|
title: 'Cannot ban the user, make sure I have permission to do that',
|
||||||
user: (data instanceof Interaction) ? data.user : data.author
|
user: (data instanceof Interaction) ? data.user : data.author
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
CREATE_MESSAGE: () => {
|
CREATE_MESSAGE: () => {
|
||||||
return makeInfoEmbed ({
|
return makeInfoEmbed({
|
||||||
icon: '👋',
|
icon: '👋',
|
||||||
title: 'Welcome to this server!',
|
title: 'Welcome to this server!',
|
||||||
description: `This server have membership screening enabled, **you'll have access to the server when the moderators let you in**.\n\nAlso please make sure that you acknowledged the common rules that everyone should be doing no matter where, Discord ToS (https://discordapp.com/terms)`,
|
description: `This server have membership screening enabled, **you'll have access to the server when the moderators let you in**.\n\nAlso please make sure that you acknowledged the common rules that everyone should be doing no matter where, Discord ToS (https://discordapp.com/terms)`,
|
||||||
@@ -158,139 +165,234 @@ const EMBEDS = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class MembershipScreening {
|
export default class MembershipScreening extends DiscordModule {
|
||||||
|
|
||||||
async onCommand(command: string, args: any, message: Message) {
|
public id = "Discord_MembershipScreening";
|
||||||
|
public commands = ["membershipscreening", "ms"];
|
||||||
|
public commandInteractionName = "membershipscreening";
|
||||||
|
|
||||||
if(command.toLowerCase() !== 'membershipscreening' && command.toLowerCase() !== 'ms') return;
|
async GuildOnModuleCommand(args: any, message: Message) {
|
||||||
await this.process(message, args);
|
await this.run(new HybridInteractionMessage(message), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
async process(data: Interaction | Message, args: any) {
|
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||||
|
await this.run(new HybridInteractionMessage(interaction), interaction.options);
|
||||||
|
}
|
||||||
|
|
||||||
const isSlashCommand = data instanceof CommandInteraction && data.isCommand();
|
async GuildButtonInteractionCreate(interaction: ButtonInteraction) {
|
||||||
const isMessage = data instanceof Message;
|
|
||||||
|
|
||||||
if(!isSlashCommand && !isMessage) return;
|
const hybridData = new HybridInteractionMessage(interaction);
|
||||||
|
const guild = hybridData.getGuild();
|
||||||
|
const user = hybridData.getUser();
|
||||||
|
const channel = hybridData.getChannel();
|
||||||
|
|
||||||
if(data.guild === null || data.guildId === null) return;
|
if(!guild || !user || !channel) return;
|
||||||
|
|
||||||
const Guild = await Prisma.client.guild.findFirst({ where: { id: data.guildId }})
|
if (!this.isJsonValid(interaction.customId)) return;
|
||||||
|
const payload = JSON.parse(interaction.customId);
|
||||||
|
|
||||||
// TODO: Handle if guild is not found
|
if (typeof payload.m === 'undefined' ||
|
||||||
if(!Guild) throw new Error('Guild not found');
|
typeof payload.a === 'undefined' ||
|
||||||
|
payload.m !== 'MembershipScreening') return;
|
||||||
|
|
||||||
|
const message = await channel.messages.fetch(interaction.message.id);
|
||||||
|
if (!message) return;
|
||||||
|
|
||||||
|
const embed = message.embeds;
|
||||||
|
if (!embed || embed.length === 0) return;
|
||||||
|
|
||||||
|
const PrismaGuild = await Prisma.client.guild.findFirst({ where: { id: guild.id } });
|
||||||
|
if (!PrismaGuild) return;
|
||||||
|
|
||||||
|
if (!PrismaGuild.MembershipScreening_Enabled ||
|
||||||
|
PrismaGuild.MembershipScreening_ApprovalChannel === null ||
|
||||||
|
PrismaGuild.MembershipScreening_GivenRole === null) return;
|
||||||
|
|
||||||
|
embed[0].footer = {
|
||||||
|
text: `${interaction.user.username} | v${App.version}`,
|
||||||
|
iconURL: interaction.user.avatarURL() || ''
|
||||||
|
}
|
||||||
|
|
||||||
|
if (['approve', 'deny', 'ban'].includes(payload.a)) {
|
||||||
|
|
||||||
|
if (!payload.d.requester) return;
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
if (!role)
|
||||||
|
return await interaction.reply({ ephemeral: true, embeds: [EMBEDS.NO_LONGER_VALID_ROLE(interaction)] });
|
||||||
|
|
||||||
|
if (!requesterMember) {
|
||||||
|
embed[0].addField("❌ Invalid", `Unable to find the user. User left already?`);
|
||||||
|
return await message.edit({ components: [], embeds: embed });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (requesterMember.roles.cache.has(PrismaGuild.MembershipScreening_GivenRole)) {
|
||||||
|
embed[0].addField("✅ Approved", `By: Unknown (User already obtained the role by other means)`);
|
||||||
|
return await message.edit({ components: [], embeds: embed });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (payload.a === 'approve') {
|
||||||
|
try {
|
||||||
|
await requesterMember.roles.add(role);
|
||||||
|
embed[0].addField("✅ Approved", `By: ${interaction.user.username}#${interaction.user.discriminator} (${interaction.user.id})`);
|
||||||
|
await message.edit({ components: [], embeds: embed });
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
return interaction.reply({ ephemeral: true, embeds: [EMBEDS.CANNOT_PERFORM_ASSIGN_ROLE(message)] });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (payload.a === 'deny') {
|
||||||
|
try {
|
||||||
|
await requesterMember.kick();
|
||||||
|
embed[0].addField("❌ Denied", `By: ${interaction.user.username}#${interaction.user.discriminator} (${interaction.user.id})`);
|
||||||
|
await message.edit({ components: [], embeds: embed });
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
return interaction.reply({ ephemeral: true, embeds: [EMBEDS.CANNOT_PERFORM_ASSIGN_KICK(message)] });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (payload.a === 'ban') {
|
||||||
|
try {
|
||||||
|
await requesterMember.ban({
|
||||||
|
reason: `Membership Screening, action issued by ${interaction.user.username}#${interaction.user.discriminator} (${interaction.user.id})`
|
||||||
|
});
|
||||||
|
embed[0].addField("🔪 Banned", `By: ${interaction.user.username}#${interaction.user.discriminator} (${interaction.user.id})`);
|
||||||
|
await message.edit({ components: [], embeds: embed });
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
return interaction.reply({ ephemeral: true, embeds: [EMBEDS.CANNOT_PERFORM_ASSIGN_BAN(message)] });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async run(data: HybridInteractionMessage, args: any) {
|
||||||
|
|
||||||
|
const guild = data.getGuild();
|
||||||
|
const user = data.getUser();
|
||||||
|
const member = data.getMember();
|
||||||
|
const channel = data.getChannel();
|
||||||
|
|
||||||
|
if (!guild || !user || !member || !channel) return;
|
||||||
|
|
||||||
|
const PrismaGuild = await Prisma.client.guild.findFirst({ where: { id: guild.id } })
|
||||||
|
if (!PrismaGuild) return;
|
||||||
|
|
||||||
|
|
||||||
const funct = {
|
const funct = {
|
||||||
enable: async(data: Message | Interaction)=> {
|
enable: async (data: HybridInteractionMessage) => {
|
||||||
if(!Guild.MembershipScreening_Enabled) {
|
if (!PrismaGuild.MembershipScreening_Enabled) {
|
||||||
|
|
||||||
if(Guild.MembershipScreening_GivenRole === null || Guild.MembershipScreening_ApprovalChannel == null)
|
if (PrismaGuild.MembershipScreening_GivenRole === null || PrismaGuild.MembershipScreening_ApprovalChannel == null)
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.NO_PARAMETER(data)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_PARAMETER(data.getRaw())] });
|
||||||
|
|
||||||
await Prisma.client.guild.update({ where: { id: data.guildId! }, data: { MembershipScreening_Enabled: true }});
|
await Prisma.client.guild.update({ where: { id: guild.id }, data: { MembershipScreening_Enabled: true } });
|
||||||
|
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.ENABLED(data)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.ENABLED(data.getRaw())] });
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.ALREADY_ENABLED(data)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.ALREADY_ENABLED(data.getRaw())] });
|
||||||
},
|
},
|
||||||
disable: async(data: Message | Interaction) => {
|
disable: async (data: HybridInteractionMessage) => {
|
||||||
if(Guild.MembershipScreening_Enabled) {
|
if (PrismaGuild.MembershipScreening_Enabled) {
|
||||||
await Prisma.client.guild.update({
|
await Prisma.client.guild.update({
|
||||||
where: {id: data.guildId! },
|
where: { id: guild.id },
|
||||||
data: {MembershipScreening_Enabled: false}
|
data: { MembershipScreening_Enabled: false }
|
||||||
});
|
});
|
||||||
|
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.DISABLED(data)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.DISABLED(data.getRaw())] });
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.ALREADY_DISABLED(data)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.ALREADY_DISABLED(data.getRaw())] });
|
||||||
},
|
},
|
||||||
setRole: async(data: Message | Interaction) => {
|
setRole: async (data: HybridInteractionMessage) => {
|
||||||
|
|
||||||
let role: Role | undefined;
|
let role: Role | undefined;
|
||||||
|
|
||||||
if(data instanceof Message) {
|
if (data.isMessage()) {
|
||||||
let _name: string;
|
let _name: string;
|
||||||
if(typeof args[1] === 'undefined')
|
if (typeof args[1] === 'undefined')
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.NO_ROLE_MENTIONED(data)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_ROLE_MENTIONED(data.getRaw())] });
|
||||||
|
|
||||||
let __name = args;
|
let __name = args;
|
||||||
__name.shift();
|
__name.shift();
|
||||||
_name = __name.join(" ");
|
_name = __name.join(" ");
|
||||||
role = data.mentions.roles.first() || data.guild!.roles.cache.find(role => role.name === _name);
|
|
||||||
|
role = data.getMessage().mentions.roles.first() || guild.roles.cache.find(role => role.name === _name);
|
||||||
}
|
}
|
||||||
else if(data instanceof CommandInteraction)
|
else if (data.isSlashCommand())
|
||||||
role = data.guild!.roles.cache.find(role => role.id === data.options.getRole('role')?.id);
|
role = guild.roles.cache.find(role => role.id === data.getSlashCommand().options.getRole('role')?.id);
|
||||||
|
|
||||||
|
if (!role)
|
||||||
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_ROLE_FOUND(data.getRaw())] });
|
||||||
|
|
||||||
if(typeof role === 'undefined' || !role)
|
if (role.managed)
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.NO_ROLE_FOUND(data)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.MANAGED_ROLE(data.getRaw(), role)] });
|
||||||
|
|
||||||
await Prisma.client.guild.update({ where: {id: data.guildId! }, data: {MembershipScreening_GivenRole: role.id}});
|
await Prisma.client.guild.update({ where: { id: guild.id }, data: { MembershipScreening_GivenRole: role.id } });
|
||||||
|
|
||||||
if(role.managed)
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.CONFIGURED_ROLE(data.getRaw(), role)] });
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.MANAGED_ROLE(data, role)] });
|
|
||||||
|
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.CONFIGURED_ROLE(data, role)] });
|
|
||||||
},
|
},
|
||||||
setChannel: async(data: Message | CommandInteraction) => {
|
setChannel: async (data: HybridInteractionMessage) => {
|
||||||
|
|
||||||
let channel;
|
let mentionChannel;
|
||||||
if(data instanceof Message) {
|
if (data.isMessage()) {
|
||||||
if(typeof args[1] === 'undefined')
|
if (!args[1])
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.NO_CHANNEL_MENTIONED(data)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_CHANNEL_MENTIONED(data.getRaw())] });
|
||||||
channel = data.mentions.channels.first();
|
mentionChannel = data.getMessage().mentions.channels.first();
|
||||||
}
|
}
|
||||||
else if(data instanceof CommandInteraction)
|
else if (data.isSlashCommand())
|
||||||
channel = data.options.getChannel('channel');
|
mentionChannel = data.getSlashCommand().options.getChannel('channel');
|
||||||
|
|
||||||
if(!channel)
|
if (!mentionChannel)
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.NO_CHANNEL_FOUND(data)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_CHANNEL_FOUND(data.getRaw())] });
|
||||||
|
|
||||||
let TargetChannel = data.guild!.channels.cache.get(channel.id);
|
let TargetChannel = guild.channels.cache.get(mentionChannel.id);
|
||||||
if(typeof TargetChannel === 'undefined') return;
|
if (!TargetChannel) return;
|
||||||
|
|
||||||
if(TargetChannel instanceof ThreadChannel || TargetChannel.isThread())
|
if (TargetChannel instanceof ThreadChannel || TargetChannel.isThread())
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.INVALID_CHANNEL_THREAD(data, TargetChannel)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.INVALID_CHANNEL_THREAD(data.getRaw(), TargetChannel)] });
|
||||||
|
|
||||||
if(!TargetChannel.isText())
|
if (!TargetChannel.isText())
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.INVALID_CHANNEL(data, TargetChannel)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.INVALID_CHANNEL(data.getRaw(), TargetChannel)] });
|
||||||
|
|
||||||
if(!(data!.guild!.me?.permissionsIn(TargetChannel).has([Permissions.FLAGS.SEND_MESSAGES, Permissions.FLAGS.VIEW_CHANNEL])))
|
if (!(guild.me!.permissionsIn(TargetChannel).has([Permissions.FLAGS.SEND_MESSAGES, Permissions.FLAGS.VIEW_CHANNEL])))
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.BOT_NO_PERMISSION(data, TargetChannel)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.BOT_NO_PERMISSION(data.getRaw(), TargetChannel)] });
|
||||||
|
|
||||||
await Prisma.client.guild.update({ where: {id: data.guildId! }, data: { MembershipScreening_ApprovalChannel: channel.id }});
|
await Prisma.client.guild.update({ where: { id: guild.id }, data: { MembershipScreening_ApprovalChannel: mentionChannel.id } });
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.CONFIGURED_CHANNEL(data, TargetChannel)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.CONFIGURED_CHANNEL(data.getRaw(), TargetChannel)] });
|
||||||
},
|
},
|
||||||
createMessage: async(data: Message | CommandInteraction) => {
|
createMessage: async (data: HybridInteractionMessage) => {
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.CREATE_MESSAGE()] });
|
if(data.isMessage())
|
||||||
|
return await sendMessage(channel, undefined, { embeds: [EMBEDS.CREATE_MESSAGE()] });
|
||||||
|
else if(data.isSlashCommand()) {
|
||||||
|
await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.MESSAGE_CREATED(data.getRaw())] });
|
||||||
|
return await sendMessage(channel, undefined, { embeds: [EMBEDS.CREATE_MESSAGE()] });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let query;
|
let query;
|
||||||
|
|
||||||
if(isMessage) {
|
if (!member.permissions.has([Permissions.FLAGS.ADMINISTRATOR]))
|
||||||
if(data === null || !data.guildId || data.member === null || data.guild === null) return;
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_PERMISSION(data.getRaw())] });
|
||||||
if (!data.member.permissions.has([Permissions.FLAGS.ADMINISTRATOR]))
|
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.NO_PERMISSION(data)] });
|
if (data.isMessage()) {
|
||||||
|
if (args.length === 0)
|
||||||
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.MSINFO(data.getRaw())] });
|
||||||
|
|
||||||
if(args.length === 0) {
|
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.MSINFO(data)] });
|
|
||||||
}
|
|
||||||
query = args[0].toLowerCase();
|
query = args[0].toLowerCase();
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(isSlashCommand) {
|
else if (data.isSlashCommand())
|
||||||
if(!data.guild.members.cache.get(data.user.id)?.permissions.has([Permissions.FLAGS.ADMINISTRATOR]))
|
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.NO_PERMISSION(data)] });
|
|
||||||
|
|
||||||
query = args.getSubcommand();
|
query = args.getSubcommand();
|
||||||
}
|
|
||||||
|
|
||||||
switch(query) {
|
switch (query) {
|
||||||
case "enable":
|
case "enable":
|
||||||
case "on":
|
case "on":
|
||||||
return await funct.enable(data);
|
return await funct.enable(data);
|
||||||
@@ -300,121 +402,23 @@ export default class MembershipScreening {
|
|||||||
case "setrole":
|
case "setrole":
|
||||||
return await funct.setRole(data);
|
return await funct.setRole(data);
|
||||||
case "setchannel":
|
case "setchannel":
|
||||||
return await funct.setChannel(data as CommandInteraction);
|
return await funct.setChannel(data);
|
||||||
case "createmessage":
|
case "createmessage":
|
||||||
return await funct.createMessage(data as CommandInteraction);
|
return await funct.createMessage(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async interactionCreate(interaction: Interaction) {
|
async GuildMemberAdd(member: GuildMember) {
|
||||||
|
|
||||||
if (interaction.isButton()) {
|
if (member.user.bot) return;
|
||||||
|
|
||||||
if(!interaction.guild || !interaction.guildId) return;
|
|
||||||
if(!(interaction.channel instanceof TextChannel)) return;
|
|
||||||
if(!this.tryParseJSONObject(interaction.customId)) return;
|
|
||||||
|
|
||||||
Logger.log('debug', `${interaction.user.username}#${interaction.user.discriminator} (UserID: ${interaction.user.id}) (InteractionID: ${interaction.id}) executed button interaction ${interaction.customId}`);
|
|
||||||
|
|
||||||
let payload = JSON.parse(interaction.customId);
|
|
||||||
|
|
||||||
if( typeof payload.m === 'undefined' ||
|
|
||||||
typeof payload.a === 'undefined' ||
|
|
||||||
payload.m !== 'MembershipScreening') return;
|
|
||||||
|
|
||||||
const message = await interaction.channel.messages.fetch(interaction.message.id);
|
|
||||||
if(typeof message === 'undefined') return;
|
|
||||||
|
|
||||||
const embed = message.embeds;
|
|
||||||
if(typeof embed === 'undefined' || embed.length === 0) return;
|
|
||||||
|
|
||||||
const Guild = await Prisma.client.guild.findFirst({ where: { id: interaction.guildId } });
|
|
||||||
if(!Guild) throw new Error('TODO: Handle if guild is not found');
|
|
||||||
|
|
||||||
if(!Guild.MembershipScreening_Enabled ||
|
|
||||||
Guild.MembershipScreening_ApprovalChannel === null ||
|
|
||||||
Guild.MembershipScreening_GivenRole === null) return;
|
|
||||||
|
|
||||||
embed[0].footer = {
|
|
||||||
text: `${interaction.user.username} | v${App.version}`,
|
|
||||||
iconURL: interaction.user.avatarURL() || ''
|
|
||||||
}
|
|
||||||
|
|
||||||
if(['approve', 'deny', 'ban'].includes(payload.a)) {
|
|
||||||
|
|
||||||
if(!payload.d.requester) return;
|
|
||||||
let role = (await interaction.guild.roles.fetch()).find(role => role.id === Guild.MembershipScreening_GivenRole);
|
|
||||||
let member = (await interaction.guild.members.fetch()).find(member => member.id === payload.d.requester);
|
|
||||||
|
|
||||||
if(!role)
|
|
||||||
return await interaction.reply({ ephemeral: true, embeds: [EMBEDS.NO_LONGER_VALID_ROLE(interaction)]});
|
|
||||||
|
|
||||||
if(!member) {
|
|
||||||
embed[0].addField("❌ Invalid", `Unable to find the user. User left already?`);
|
|
||||||
return await message.edit({ components: [], embeds: embed });
|
|
||||||
}
|
|
||||||
|
|
||||||
if(member.roles.cache.has(Guild.MembershipScreening_GivenRole)) {
|
|
||||||
embed[0].addField("✅ Approved", `By: Unknown (User already obtained the role by other means)`);
|
|
||||||
return await message.edit({ components: [], embeds: embed });
|
|
||||||
}
|
|
||||||
|
|
||||||
if(payload.a === 'approve') {
|
|
||||||
try {
|
|
||||||
await member.roles.add(role);
|
|
||||||
embed[0].addField("✅ Approved", `By: ${interaction.user.username}#${interaction.user.discriminator} (${interaction.user.id})`);
|
|
||||||
await message.edit({ components: [], embeds: embed });
|
|
||||||
}
|
|
||||||
catch(err) {
|
|
||||||
return interaction.reply({ ephemeral: true, embeds: [EMBEDS.CANNOT_PERFORM_ASSIGN_ROLE(message)]});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if(payload.a === 'deny') {
|
|
||||||
try {
|
|
||||||
await member.kick();
|
|
||||||
embed[0].addField("❌ Denied", `By: ${interaction.user.username}#${interaction.user.discriminator} (${interaction.user.id})`);
|
|
||||||
await message.edit({ components: [], embeds: embed });
|
|
||||||
}
|
|
||||||
catch(err) {
|
|
||||||
return interaction.reply({ ephemeral: true, embeds: [EMBEDS.CANNOT_PERFORM_ASSIGN_KICK(message)]});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if(payload.a === 'ban') {
|
|
||||||
try {
|
|
||||||
await member.ban({
|
|
||||||
reason: `Membership Screening, action issued by ${interaction.user.username}#${interaction.user.discriminator} (${interaction.user.id})`
|
|
||||||
});
|
|
||||||
embed[0].addField("🔪 Banned", `By: ${interaction.user.username}#${interaction.user.discriminator} (${interaction.user.id})`);
|
|
||||||
await message.edit({ components: [], embeds: embed });
|
|
||||||
}
|
|
||||||
catch(err) {
|
|
||||||
return interaction.reply({ ephemeral: true, embeds: [EMBEDS.CANNOT_PERFORM_ASSIGN_BAN(message)]});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if(interaction.isCommand()) {
|
|
||||||
if(typeof interaction.commandName === 'undefined') return;
|
|
||||||
if((interaction.commandName).toLowerCase() !== 'membershipscreening') return;
|
|
||||||
await this.process(interaction, interaction.options);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async guildMemberAdd(member: GuildMember) {
|
|
||||||
|
|
||||||
if(member.user.bot) return;
|
|
||||||
|
|
||||||
const Guild = await Prisma.client.guild.findFirst({ where: { id: member.guild.id } });
|
const Guild = await Prisma.client.guild.findFirst({ where: { id: member.guild.id } });
|
||||||
if(!Guild) return;
|
if (!Guild) return;
|
||||||
|
|
||||||
if(!Guild.MembershipScreening_Enabled) return;
|
if (!Guild.MembershipScreening_Enabled) return;
|
||||||
if(Guild.MembershipScreening_ApprovalChannel === null) return;
|
if (Guild.MembershipScreening_ApprovalChannel === null) return;
|
||||||
if(Guild.MembershipScreening_GivenRole === null) return;
|
if (Guild.MembershipScreening_GivenRole === null) return;
|
||||||
|
|
||||||
let channel = undefined;
|
let channel = undefined;
|
||||||
try {
|
try {
|
||||||
@@ -423,9 +427,9 @@ export default class MembershipScreening {
|
|||||||
// TODO: Handle channel not found error
|
// TODO: Handle channel not found error
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(!channel) return;
|
if (!channel) return;
|
||||||
|
|
||||||
const embed = makeInfoEmbed ({
|
const embed = makeInfoEmbed({
|
||||||
title: 'New member joined!',
|
title: 'New member joined!',
|
||||||
description: `${member.user.username}#${member.user.discriminator} (${member.user.id})`,
|
description: `${member.user.username}#${member.user.discriminator} (${member.user.id})`,
|
||||||
fields: [
|
fields: [
|
||||||
@@ -482,7 +486,7 @@ export default class MembershipScreening {
|
|||||||
await channel.send({ content: '\u200b', embeds: [embed], components: [row] });
|
await channel.send({ content: '\u200b', embeds: [embed], components: [row] });
|
||||||
}
|
}
|
||||||
|
|
||||||
tryParseJSONObject(jsonString: string) {
|
private 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") {
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
|
||||||
|
|
||||||
import { Message, CommandInteraction, Interaction, VoiceChannel, Permissions, GuildMember, DMChannel, StageChannel, MessageActionRow, MessageButton, TextChannel } from "discord.js";
|
import { Message, CommandInteraction, Interaction, VoiceChannel, Permissions, GuildMember, DMChannel, StageChannel, MessageActionRow, MessageButton, TextChannel } from "discord.js";
|
||||||
import { makeSuccessEmbed, makeErrorEmbed, sendMessage, sendMessageOrInteractionResponse, makeInfoEmbed } from "../../utils/DiscordMessage";
|
import { makeSuccessEmbed, makeErrorEmbed, sendMessage, sendMessageOrInteractionResponse, sendHybridInteractionMessageResponse, makeInfoEmbed } from "../../utils/DiscordMessage";
|
||||||
import DiscordProvider from "../../providers/Discord";
|
import DiscordProvider from "../../providers/Discord";
|
||||||
import DiscordMusicPlayer, { PlayerPlayingEvent, PlayerErrorEvent, VoiceDisconnectedEvent, ValidTracks, DiscordMusicPlayerInstance } from "../../providers/DiscordMusicPlayer";
|
import DiscordMusicPlayer, { PlayerPlayingEvent, PlayerErrorEvent, VoiceDisconnectedEvent, ValidTracks, DiscordMusicPlayerInstance } from "../../providers/DiscordMusicPlayer";
|
||||||
|
|
||||||
@@ -177,68 +179,33 @@ export async function joinVoiceChannelProcedure (data: Interaction | Message, in
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Join {
|
export default class Join extends DiscordModule {
|
||||||
|
|
||||||
|
public id = "Discord_MusicPlayer_Join";
|
||||||
|
public commands = ["join"];
|
||||||
|
public commandInteractionName = "join";
|
||||||
|
|
||||||
async onCommand(command: string, args: any, message: Message) {
|
async GuildOnModuleCommand(args: any, message: Message) {
|
||||||
if (command.toLowerCase() !== 'join') return;
|
await this.run(new HybridInteractionMessage(message), args);
|
||||||
await this.process(message, args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async interactionCreate(interaction: CommandInteraction) {
|
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||||
if (interaction.isCommand()) {
|
await this.run(new HybridInteractionMessage(interaction), interaction.options);
|
||||||
if (typeof interaction.commandName === 'undefined') return;
|
|
||||||
if ((interaction.commandName).toLowerCase() !== 'join') return;
|
|
||||||
await this.process(interaction, interaction.options);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async process(data: Interaction | Message, args: any) {
|
async run(data: HybridInteractionMessage, args: any) {
|
||||||
const isSlashCommand = data instanceof CommandInteraction && data.isCommand();
|
|
||||||
const isMessage = data instanceof Message;
|
|
||||||
|
|
||||||
if (!isSlashCommand && !isMessage) return;
|
const guild = data.getGuild();
|
||||||
|
const member = data.getMember();
|
||||||
|
|
||||||
if (!data.member) return;
|
if(!guild || !member) return;
|
||||||
|
|
||||||
this.joinCommands(data, args);
|
const voiceChannel = member.voice.channel;
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public async joinCommands(data: Interaction | Message, args: any) {
|
|
||||||
|
|
||||||
const isSlashCommand = data instanceof CommandInteraction && data.isCommand();
|
|
||||||
const isMessage = data instanceof Message;
|
|
||||||
if (!isSlashCommand && !isMessage) return;
|
|
||||||
|
|
||||||
if (!data.member) return;
|
|
||||||
if (!data.channel) return;
|
|
||||||
if (!data.guildId) return;
|
|
||||||
|
|
||||||
if (data.channel instanceof DMChannel) return;
|
|
||||||
if (!(data.channel instanceof TextChannel)) return;
|
|
||||||
|
|
||||||
const channel: any = isMessage ? data.member.voice.channel : DiscordProvider.client.guilds.cache.get((data as Interaction).guildId!)!.members.cache.get((data as Interaction).user.id)?.voice.channel;
|
|
||||||
if (!channel) return;
|
|
||||||
|
|
||||||
if (!data.member.voice.channel)
|
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data)] });
|
|
||||||
|
|
||||||
let voiceChannel = data.member.voice.channel;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//if(!DiscordMusicPlayer.isGuildInstanceExists(data.guildId)) {
|
|
||||||
// DiscordMusicPlayer.createGuildInstance(data.guildId, voiceChannel);
|
|
||||||
//}
|
|
||||||
|
|
||||||
let instance = DiscordMusicPlayer.getGuildInstance(data.guildId);
|
|
||||||
|
|
||||||
await joinVoiceChannelProcedure(data, instance!, voiceChannel);
|
|
||||||
|
|
||||||
//if(!instance.isConnected())
|
|
||||||
// instance.joinVoiceChannel(voiceChannel, data.channel ? data.channel : undefined);
|
|
||||||
|
|
||||||
|
if (!voiceChannel)
|
||||||
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data.getRaw())] });
|
||||||
|
|
||||||
|
const instance = DiscordMusicPlayer.getGuildInstance(guild.id);
|
||||||
|
await joinVoiceChannelProcedure(data.getRaw(), instance, voiceChannel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
|
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
|
||||||
|
|
||||||
import { Message, CommandInteraction, Interaction } from "discord.js";
|
import { Message, CommandInteraction, Interaction } from "discord.js";
|
||||||
import { makeSuccessEmbed, makeErrorEmbed, sendMessageOrInteractionResponse } from "../../utils/DiscordMessage";
|
import { makeSuccessEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse } from "../../utils/DiscordMessage";
|
||||||
import DiscordProvider from "../../providers/Discord";
|
import DiscordProvider from "../../providers/Discord";
|
||||||
import DiscordMusicPlayer from "../../providers/DiscordMusicPlayer";
|
import DiscordMusicPlayer from "../../providers/DiscordMusicPlayer";
|
||||||
|
|
||||||
@@ -31,47 +33,41 @@ const EMBEDS = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Leave {
|
export default class Leave extends DiscordModule {
|
||||||
|
|
||||||
async onCommand(command: string, args: any, message: Message) {
|
public id = "Discord_MusicPlayer_Leave";
|
||||||
if(command.toLowerCase() !== 'leave') return;
|
public commands = ["leave", "disconnect", "dc"];
|
||||||
await this.process(message, args);
|
public commandInteractionName = "leave";
|
||||||
|
|
||||||
|
async GuildOnModuleCommand(args: any, message: Message) {
|
||||||
|
await this.run(new HybridInteractionMessage(message), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
async interactionCreate(interaction: CommandInteraction) {
|
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||||
if(interaction.isCommand()) {
|
await this.run(new HybridInteractionMessage(interaction), interaction.options);
|
||||||
if(typeof interaction.commandName === 'undefined') return;
|
|
||||||
if((interaction.commandName).toLowerCase() !== 'leave') return;
|
|
||||||
await this.process(interaction, interaction.options);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async process(data: Interaction | Message, args: any) {
|
async run(data: HybridInteractionMessage, args: any) {
|
||||||
const isSlashCommand = data instanceof CommandInteraction && data.isCommand();
|
|
||||||
const isMessage = data instanceof Message;
|
|
||||||
|
|
||||||
if(!isSlashCommand && !isMessage) return;
|
const guild = data.getGuild();
|
||||||
|
const member = data.getMember();
|
||||||
|
|
||||||
if(!data.member) return;
|
if(!guild || !member) return;
|
||||||
if(!data.guildId) return;
|
|
||||||
|
|
||||||
const channel: any = isMessage ? data.member.voice.channel : DiscordProvider.client.guilds.cache.get((data as Interaction).guildId!)!.members.cache.get((data as Interaction).user.id)?.voice.channel;
|
const voiceChannel = member.voice.channel;
|
||||||
if (!data.member.voice.channel)
|
if (!voiceChannel)
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data.getRaw())] });
|
||||||
|
|
||||||
if(!channel) return;
|
let instance = DiscordMusicPlayer.getGuildInstance(guild.id);
|
||||||
|
|
||||||
|
|
||||||
let instance = DiscordMusicPlayer.getGuildInstance(data.guildId);
|
|
||||||
if(!instance)
|
if(!instance)
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data.getRaw())] });
|
||||||
|
|
||||||
if(instance.voiceChannel.id !== data.member.voice.channel.id)
|
if(instance.voiceChannel.id !== voiceChannel.id)
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data.getRaw())] });
|
||||||
|
|
||||||
|
|
||||||
DiscordMusicPlayer.destoryGuildInstance(data.guild?.id!);
|
DiscordMusicPlayer.destoryGuildInstance(guild.id);
|
||||||
await sendMessageOrInteractionResponse(data, { embeds:[EMBEDS.VOICECHANNEL_LEFT(data)] });
|
await sendHybridInteractionMessageResponse(data, { embeds:[EMBEDS.VOICECHANNEL_LEFT(data.getRaw())] });
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
|
||||||
|
|
||||||
import { Message, CommandInteraction, Interaction, MessageActionRow, TextChannel, MessageButton } from "discord.js";
|
import { Message, CommandInteraction, Interaction, MessageActionRow, TextChannel, MessageButton } from "discord.js";
|
||||||
import { makeErrorEmbed, sendMessageOrInteractionResponse, makeInfoEmbed } from "../../utils/DiscordMessage";
|
import { makeErrorEmbed, makeInfoEmbed, sendHybridInteractionMessageResponse } from "../../utils/DiscordMessage";
|
||||||
import DiscordProvider from "../../providers/Discord";
|
import DiscordProvider from "../../providers/Discord";
|
||||||
import DiscordMusicPlayer, { ValidTracks } from "../../providers/DiscordMusicPlayer";
|
import DiscordMusicPlayer, { ValidTracks } from "../../providers/DiscordMusicPlayer";
|
||||||
|
|
||||||
@@ -23,36 +25,27 @@ const EMBEDS = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class NowPlaying {
|
export default class NowPlaying extends DiscordModule {
|
||||||
|
|
||||||
async onCommand(command: string, args: any, message: Message) {
|
public id = "Discord_MusicPlayer_NowPlaying";
|
||||||
if(command.toLowerCase() !== 'nowplaying' && command.toLowerCase() !== 'np') return;
|
public commands = ["nowplaying", "np"];
|
||||||
await this.process(message, args);
|
public commandInteractionName = "nowplaying";
|
||||||
|
|
||||||
|
async GuildOnModuleCommand(args: any, message: Message) {
|
||||||
|
await this.run(new HybridInteractionMessage(message), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
async interactionCreate(interaction: CommandInteraction) {
|
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||||
if(interaction.isCommand()) {
|
await this.run(new HybridInteractionMessage(interaction), interaction.options);
|
||||||
if(typeof interaction.commandName === 'undefined') return;
|
|
||||||
if((interaction.commandName).toLowerCase() !== 'nowplaying') return;
|
|
||||||
await this.process(interaction, interaction.options);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async process(data: Interaction | Message, args: any) {
|
async run(data: HybridInteractionMessage, args: any) {
|
||||||
const isSlashCommand = data instanceof CommandInteraction && data.isCommand();
|
|
||||||
const isMessage = data instanceof Message;
|
|
||||||
|
|
||||||
if(!isSlashCommand && !isMessage) return;
|
const guild = data.getGuild();
|
||||||
|
if(!guild) return;
|
||||||
|
|
||||||
if(!data.member) return;
|
const instance = DiscordMusicPlayer.getGuildInstance(guild.id);
|
||||||
if(!data.guildId) return;
|
if(!instance || !instance.queue.track[0]) return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data.getRaw())] });
|
||||||
if(!(data.channel instanceof TextChannel)) return;
|
|
||||||
|
|
||||||
//const channel: any = isMessage ? data.member.voice.channel : DiscordProvider.client.guilds.cache.get((data as Interaction).guildId!)!.members.cache.get((data as Interaction).user.id)?.voice.channel;
|
|
||||||
//if(!channel) return;
|
|
||||||
|
|
||||||
const instance = DiscordMusicPlayer.getGuildInstance(data.guildId);
|
|
||||||
if(!instance || !instance.queue.track[0]) return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data)] });
|
|
||||||
|
|
||||||
const row = new MessageActionRow()
|
const row = new MessageActionRow()
|
||||||
.addComponents(
|
.addComponents(
|
||||||
@@ -63,6 +56,6 @@ export default class NowPlaying {
|
|||||||
.setStyle('LINK'),
|
.setStyle('LINK'),
|
||||||
)
|
)
|
||||||
|
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.NOW_PLAYING(data, instance.queue.track[0])], components: [row] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NOW_PLAYING(data.getRaw(), instance.queue.track[0])], components: [row] });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+120
-128
@@ -1,5 +1,7 @@
|
|||||||
import { Message, CommandInteraction, Interaction, VoiceChannel, MessageActionRow, MessageButton, TextChannel } from "discord.js";
|
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
|
||||||
import { makeErrorEmbed, makeSuccessEmbed, sendMessageOrInteractionResponse, makeInfoEmbed } from "../../utils/DiscordMessage";
|
|
||||||
|
import { Message, CommandInteraction, Interaction, VoiceChannel, MessageActionRow, MessageButton, SelectMenuInteraction, ButtonInteraction } from "discord.js";
|
||||||
|
import { makeErrorEmbed, makeSuccessEmbed, sendHybridInteractionMessageResponse, makeInfoEmbed } from "../../utils/DiscordMessage";
|
||||||
import DiscordProvider from "../../providers/Discord";
|
import DiscordProvider from "../../providers/Discord";
|
||||||
import DiscordMusicPlayer, { ValidTracks } from "../../providers/DiscordMusicPlayer";
|
import DiscordMusicPlayer, { ValidTracks } from "../../providers/DiscordMusicPlayer";
|
||||||
import { joinVoiceChannelProcedure } from "./Join";
|
import { joinVoiceChannelProcedure } from "./Join";
|
||||||
@@ -60,83 +62,30 @@ const EMBEDS = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
export default class Play extends DiscordModule {
|
||||||
|
|
||||||
|
public id = "Discord_MusicPlayer_Play";
|
||||||
|
public commands = ["play", "p"];
|
||||||
|
public commandInteractionName = "play";
|
||||||
|
|
||||||
export default class Play {
|
async GuildOnModuleCommand(args: any, message: Message) {
|
||||||
|
await this.run(new HybridInteractionMessage(message), args);
|
||||||
async onCommand(command: string, args: any, message: Message) {
|
|
||||||
if (command.toLowerCase() !== 'play' && command.toLowerCase() !== 'p') return;
|
|
||||||
await this.process(message, args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async interactionCreate(interaction: Interaction) {
|
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||||
if (interaction.isCommand()) {
|
await this.run(new HybridInteractionMessage(interaction), interaction.options);
|
||||||
if (typeof interaction.commandName === 'undefined') return;
|
|
||||||
if ((interaction.commandName).toLowerCase() !== 'play') return;
|
|
||||||
await this.process(interaction, interaction.options);
|
|
||||||
}
|
}
|
||||||
else if (interaction.isSelectMenu()) {
|
|
||||||
if (!interaction.guild || !interaction.guildId) return;
|
async GuildButtonInteractionCreate(interaction: ButtonInteraction) {
|
||||||
if (!this.tryParseJSONObject(interaction.customId)) return;
|
const hybridData = new HybridInteractionMessage(interaction);
|
||||||
|
const guild = hybridData.getGuild();
|
||||||
|
const member = hybridData.getMember();
|
||||||
|
const user = hybridData.getUser();
|
||||||
|
|
||||||
|
if (!guild || !member || !user) return;
|
||||||
|
if (!this.isJSONValid(interaction.customId)) return;
|
||||||
|
|
||||||
let payload = JSON.parse(interaction.customId);
|
let payload = JSON.parse(interaction.customId);
|
||||||
if (!interaction.member?.user?.id) return;
|
|
||||||
|
|
||||||
if (typeof payload.m === 'undefined' || typeof payload.a === 'undefined') return;
|
|
||||||
|
|
||||||
/*
|
|
||||||
Discord have 100 char custom id char limit
|
|
||||||
So we need to shorten our json.
|
|
||||||
MP_SM stands for MusicPlayer_SearchMenu
|
|
||||||
data.r stands for data.requester
|
|
||||||
data.v stands for data.voiceChannel
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (payload.m === 'MP_SM' && payload.a === 'play') {
|
|
||||||
|
|
||||||
await interaction.deferReply();
|
|
||||||
|
|
||||||
let voiceChannel = DiscordProvider.client.guilds.cache.get(interaction.guildId)?.channels.cache.get(payload.d.v);
|
|
||||||
let member = DiscordProvider.client.guilds.cache.get(interaction.guildId)?.members.cache.get(interaction.member?.user?.id);
|
|
||||||
|
|
||||||
if (!member) return;
|
|
||||||
if (!voiceChannel || !(voiceChannel instanceof VoiceChannel)) return;
|
|
||||||
|
|
||||||
|
|
||||||
if (!member.voice.channel)
|
|
||||||
return await sendMessageOrInteractionResponse(interaction, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(interaction)] }, true);
|
|
||||||
|
|
||||||
if (!DiscordMusicPlayer.isGuildInstanceExists(interaction.guildId)) {
|
|
||||||
await joinVoiceChannelProcedure(interaction, null, voiceChannel);
|
|
||||||
}
|
|
||||||
|
|
||||||
let instance = DiscordMusicPlayer.getGuildInstance(interaction.guildId);
|
|
||||||
|
|
||||||
if (instance!.voiceChannel.id !== member.voice.channel.id)
|
|
||||||
return await sendMessageOrInteractionResponse(interaction, { embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(interaction)] }, true);
|
|
||||||
|
|
||||||
if (!instance!.isConnected()) {
|
|
||||||
await joinVoiceChannelProcedure(interaction, instance!, voiceChannel);
|
|
||||||
instance = DiscordMusicPlayer.getGuildInstance(interaction.guildId);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!instance) return;
|
|
||||||
|
|
||||||
let result = await DiscordMusicPlayer.searchYouTubeByYouTubeLink(DiscordMusicPlayer.parseYouTubeLink(interaction.values[0]));
|
|
||||||
if (!result) return;
|
|
||||||
|
|
||||||
instance.addTrackToQueue(result);
|
|
||||||
//interaction.editReply({ embeds: [EMBEDS.ADDED_QUEUE(interaction, result)] });
|
|
||||||
return await sendMessageOrInteractionResponse(interaction, { embeds: [EMBEDS.ADDED_QUEUE(interaction, result)] }, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (interaction.isButton()) {
|
|
||||||
|
|
||||||
if (!interaction.guild || !interaction.guildId) return;
|
|
||||||
if (!this.tryParseJSONObject(interaction.customId)) return;
|
|
||||||
|
|
||||||
let payload = JSON.parse(interaction.customId);
|
|
||||||
if (!interaction.member?.user?.id) return;
|
|
||||||
|
|
||||||
if (typeof payload.m === 'undefined' || typeof payload.a === 'undefined') return;
|
if (typeof payload.m === 'undefined' || typeof payload.a === 'undefined') return;
|
||||||
|
|
||||||
@@ -153,7 +102,7 @@ export default class Play {
|
|||||||
if (typeof payload.d === 'undefined') return;
|
if (typeof payload.d === 'undefined') return;
|
||||||
|
|
||||||
let data = payload.d.split('$');
|
let data = payload.d.split('$');
|
||||||
if(data.length !== 3) return;
|
if (data.length !== 3) return;
|
||||||
|
|
||||||
payload.d = {
|
payload.d = {
|
||||||
c: data[0],
|
c: data[0],
|
||||||
@@ -163,28 +112,26 @@ export default class Play {
|
|||||||
|
|
||||||
await interaction.deferReply();
|
await interaction.deferReply();
|
||||||
|
|
||||||
let voiceChannel = DiscordProvider.client.guilds.cache.get(interaction.guildId)?.channels.cache.get(payload.d.c);
|
let voiceChannel = DiscordProvider.client.guilds.cache.get(guild.id)?.channels.cache.get(payload.d.c);
|
||||||
let member = DiscordProvider.client.guilds.cache.get(interaction.guildId)?.members.cache.get(interaction.member?.user?.id);
|
//let member = DiscordProvider.client.guilds.cache.get(guild.id)?.members.cache.get(interaction.member?.user?.id);
|
||||||
|
|
||||||
if (!member) return;
|
|
||||||
if (!voiceChannel || !(voiceChannel instanceof VoiceChannel)) return;
|
if (!voiceChannel || !(voiceChannel instanceof VoiceChannel)) return;
|
||||||
|
|
||||||
|
|
||||||
if (!member.voice.channel)
|
if (!member.voice.channel)
|
||||||
return await sendMessageOrInteractionResponse(interaction, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(interaction)] }, true);
|
return await sendHybridInteractionMessageResponse(hybridData, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(hybridData.getRaw())] }, true);
|
||||||
|
|
||||||
if (!DiscordMusicPlayer.isGuildInstanceExists(interaction.guildId)) {
|
if (!DiscordMusicPlayer.isGuildInstanceExists(guild.id))
|
||||||
await joinVoiceChannelProcedure(interaction, null, voiceChannel);
|
await joinVoiceChannelProcedure(interaction, null, voiceChannel);
|
||||||
}
|
|
||||||
|
|
||||||
let instance = DiscordMusicPlayer.getGuildInstance(interaction.guildId);
|
let instance = DiscordMusicPlayer.getGuildInstance(guild.id);
|
||||||
|
|
||||||
if (instance!.voiceChannel.id !== member.voice.channel.id)
|
if (instance!.voiceChannel.id !== member.voice.channel.id)
|
||||||
return await sendMessageOrInteractionResponse(interaction, { embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(interaction)] }, true);
|
return await sendHybridInteractionMessageResponse(hybridData, { embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(hybridData.getRaw())] }, true);
|
||||||
|
|
||||||
if (!instance!.isConnected()) {
|
if (!instance!.isConnected()) {
|
||||||
await joinVoiceChannelProcedure(interaction, instance!, voiceChannel);
|
await joinVoiceChannelProcedure(interaction, instance!, voiceChannel);
|
||||||
instance = DiscordMusicPlayer.getGuildInstance(interaction.guildId);
|
instance = DiscordMusicPlayer.getGuildInstance(guild.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!instance) return;
|
if (!instance) return;
|
||||||
@@ -194,61 +141,111 @@ export default class Play {
|
|||||||
return payload.d.v !== song.id;
|
return payload.d.v !== song.id;
|
||||||
});
|
});
|
||||||
|
|
||||||
for(let song of songs) {
|
for (let song of songs) {
|
||||||
instance.addTrackToQueue(song);
|
instance.addTrackToQueue(song);
|
||||||
}
|
}
|
||||||
|
|
||||||
await (interaction.message as Message).edit({ components: [] });
|
if(hybridData.getSelectMenu().message instanceof Message)
|
||||||
return await sendMessageOrInteractionResponse(interaction, { embeds: [EMBEDS.ADDED_SONGS_QUEUE(interaction, songs)] }, true);
|
await (hybridData.getSelectMenu().message as Message).edit({ components: [] });
|
||||||
}
|
|
||||||
|
return await sendHybridInteractionMessageResponse(hybridData, { embeds: [EMBEDS.ADDED_SONGS_QUEUE(hybridData.getRaw(), songs)] }, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async process(data: Interaction | Message, args: any) {
|
async GuildSelectMenuInteractionCreate(interaction: SelectMenuInteraction) {
|
||||||
const isSlashCommand = data instanceof CommandInteraction && data.isCommand();
|
|
||||||
const isMessage = data instanceof Message;
|
|
||||||
|
|
||||||
if (!isSlashCommand && !isMessage) return;
|
const hybridData = new HybridInteractionMessage(interaction);
|
||||||
|
const guild = hybridData.getGuild();
|
||||||
|
const member = hybridData.getMember();
|
||||||
|
const user = hybridData.getUser();
|
||||||
|
|
||||||
if (!data.member) return;
|
if (!guild || !member || !user) return;
|
||||||
if (!data.guild) return;
|
if (!this.isJSONValid(interaction.customId)) return;
|
||||||
if (!data.guildId) return;
|
|
||||||
|
let payload = JSON.parse(interaction.customId);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Discord have 100 char custom id char limit
|
||||||
|
So we need to shorten our json.
|
||||||
|
MP_SM stands for MusicPlayer_SearchMenu
|
||||||
|
data.r stands for data.requester
|
||||||
|
data.v stands for data.voiceChannel
|
||||||
|
*/
|
||||||
|
if (typeof payload.m === 'undefined' || typeof payload.a === 'undefined') return;
|
||||||
|
|
||||||
|
if (payload.m === 'MP_SM' && payload.a === 'play') {
|
||||||
|
|
||||||
|
await interaction.deferReply();
|
||||||
|
|
||||||
|
const voiceChannel = DiscordProvider.client.guilds.cache.get(guild.id)?.channels.cache.get(payload.d.v);
|
||||||
|
//let member = DiscordProvider.client.guilds.cache.get(guild.id)?.members.cache.get(user.id);
|
||||||
|
|
||||||
|
if (!voiceChannel || !(voiceChannel instanceof VoiceChannel)) return;
|
||||||
|
|
||||||
|
if (!member.voice.channel)
|
||||||
|
return await sendHybridInteractionMessageResponse(hybridData, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(interaction)] }, true);
|
||||||
|
|
||||||
|
if (!DiscordMusicPlayer.isGuildInstanceExists(guild.id))
|
||||||
|
await joinVoiceChannelProcedure(interaction, null, voiceChannel);
|
||||||
|
|
||||||
|
|
||||||
|
let instance = DiscordMusicPlayer.getGuildInstance(guild.id);
|
||||||
|
|
||||||
|
if (instance!.voiceChannel.id !== member.voice.channel.id)
|
||||||
|
return await sendHybridInteractionMessageResponse(hybridData, { embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(interaction)] }, true);
|
||||||
|
|
||||||
|
if (!instance!.isConnected()) {
|
||||||
|
await joinVoiceChannelProcedure(interaction, instance!, voiceChannel);
|
||||||
|
instance = DiscordMusicPlayer.getGuildInstance(guild.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!instance) return;
|
||||||
|
|
||||||
|
let result = await DiscordMusicPlayer.searchYouTubeByYouTubeLink(DiscordMusicPlayer.parseYouTubeLink(interaction.values[0]));
|
||||||
|
if (!result) return;
|
||||||
|
|
||||||
|
instance.addTrackToQueue(result);
|
||||||
|
return await sendHybridInteractionMessageResponse(hybridData, { embeds: [EMBEDS.ADDED_QUEUE(interaction, result)] }, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
async run(data: HybridInteractionMessage, args: any) {
|
||||||
|
|
||||||
let query;
|
let query;
|
||||||
|
const guild = data.getGuild();
|
||||||
|
const channel = data.getChannel();
|
||||||
|
const member = data.getMember();
|
||||||
|
|
||||||
if (isMessage) {
|
if (data.isMessage()) {
|
||||||
if (data === null || !data.guildId || data.member === null || data.guild === null) return;
|
if (args.length === 0)
|
||||||
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.PLAY_INFO(data.getRaw())] });
|
||||||
|
|
||||||
if (args.length === 0) {
|
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.PLAY_INFO(data)] });
|
|
||||||
}
|
|
||||||
query = args.join(' ');
|
query = args.join(' ');
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (isSlashCommand) {
|
else if (data.isSlashCommand()) {
|
||||||
query = args.getSubcommand();
|
query = args.getSubcommand();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!query) return;
|
if (!query || !guild || !channel || !member) return;
|
||||||
if (!(data.channel instanceof TextChannel)) return;
|
|
||||||
|
|
||||||
if (!data.member.voice.channel)
|
if (!member.voice.channel)
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data.getRaw())] });
|
||||||
|
|
||||||
let voiceChannel = data.member.voice.channel;
|
const voiceChannel = member.voice.channel;
|
||||||
|
|
||||||
if (!DiscordMusicPlayer.isGuildInstanceExists(data.guildId)) {
|
if (!DiscordMusicPlayer.isGuildInstanceExists(guild.id)) {
|
||||||
await joinVoiceChannelProcedure(data, null, voiceChannel);
|
await joinVoiceChannelProcedure(data.getRaw(), null, voiceChannel);
|
||||||
}
|
}
|
||||||
|
|
||||||
let instance = DiscordMusicPlayer.getGuildInstance(data.guildId);
|
let instance = DiscordMusicPlayer.getGuildInstance(guild.id);
|
||||||
|
|
||||||
if (instance!.voiceChannel.id !== data.member.voice.channel.id)
|
if (instance!.voiceChannel.id !== member.voice.channel.id)
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data)] }, true);
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data.getRaw())] }, true);
|
||||||
|
|
||||||
if (!instance!.isConnected()) {
|
if (!instance!.isConnected()) {
|
||||||
await joinVoiceChannelProcedure(data, instance!, voiceChannel);
|
await joinVoiceChannelProcedure(data.getRaw(), instance!, voiceChannel);
|
||||||
instance = DiscordMusicPlayer.getGuildInstance(data.guildId);
|
instance = DiscordMusicPlayer.getGuildInstance(guild.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!instance) return;
|
if (!instance) return;
|
||||||
@@ -256,22 +253,22 @@ export default class Play {
|
|||||||
if (DiscordMusicPlayer.isYouTubeLink(query)) {
|
if (DiscordMusicPlayer.isYouTubeLink(query)) {
|
||||||
let linkData = DiscordMusicPlayer.parseYouTubeLink(query);
|
let linkData = DiscordMusicPlayer.parseYouTubeLink(query);
|
||||||
|
|
||||||
if(linkData.videoId === "" && linkData.list) {
|
if (linkData.videoId === "" && linkData.list) {
|
||||||
let playlist = await DiscordMusicPlayer.getYouTubeSongsInPlayList(query);
|
let playlist = await DiscordMusicPlayer.getYouTubeSongsInPlayList(query);
|
||||||
const songs = await playlist.all_videos();
|
const songs = await playlist.all_videos();
|
||||||
|
|
||||||
for(let song of songs) {
|
for (let song of songs) {
|
||||||
instance.addTrackToQueue(song);
|
instance.addTrackToQueue(song);
|
||||||
}
|
}
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.ADDED_SONGS_QUEUE(data, songs)] }, true);
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.ADDED_SONGS_QUEUE(data.getRaw(), songs)] }, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = await DiscordMusicPlayer.searchYouTubeByYouTubeLink(linkData);
|
let result = await DiscordMusicPlayer.searchYouTubeByYouTubeLink(linkData);
|
||||||
|
|
||||||
if (!result) return;
|
if (!result) return;
|
||||||
|
|
||||||
if (isMessage && (data as Message).embeds.length > 0) {
|
if (data.isMessage() && data.getMessage().embeds.length > 0) {
|
||||||
(data as Message).suppressEmbeds(true);
|
data.getMessage().suppressEmbeds(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
instance.addTrackToQueue(result);
|
instance.addTrackToQueue(result);
|
||||||
@@ -290,10 +287,10 @@ export default class Play {
|
|||||||
.setStyle('PRIMARY')
|
.setStyle('PRIMARY')
|
||||||
)
|
)
|
||||||
|
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.ADDED_QUEUE(data, result)], components: [row] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.ADDED_QUEUE(data.getRaw(), result)], components: [row] });
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.ADDED_QUEUE(data, result)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.ADDED_QUEUE(data.getRaw(), result)] });
|
||||||
} else {
|
} else {
|
||||||
let result = await DiscordMusicPlayer.searchYouTubeByQuery(query);
|
let result = await DiscordMusicPlayer.searchYouTubeByQuery(query);
|
||||||
|
|
||||||
@@ -325,27 +322,22 @@ export default class Play {
|
|||||||
.setStyle('PRIMARY')
|
.setStyle('PRIMARY')
|
||||||
)
|
)
|
||||||
|
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.ADDED_QUEUE(data, result[0])], components: [row] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.ADDED_QUEUE(data.getRaw(), result[0])], components: [row] });
|
||||||
}
|
}
|
||||||
|
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.ADDED_QUEUE(data, result[0])] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.ADDED_QUEUE(data.getRaw(), result[0])] });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
isJSONValid(jsonString: string) {
|
||||||
}
|
|
||||||
|
|
||||||
tryParseJSONObject(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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e) { }
|
catch (e) { }
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
|
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
|
||||||
|
|
||||||
import { Message, CommandInteraction, Interaction, TextChannel } from "discord.js";
|
import { Message, CommandInteraction, Interaction, TextChannel } from "discord.js";
|
||||||
import { makeErrorEmbed, sendMessageOrInteractionResponse, makeInfoEmbed } from "../../utils/DiscordMessage";
|
import { makeErrorEmbed, sendHybridInteractionMessageResponse, makeInfoEmbed } from "../../utils/DiscordMessage";
|
||||||
|
|
||||||
import DiscordMusicPlayer, { Queue } from "../../providers/DiscordMusicPlayer";
|
import DiscordMusicPlayer, { Queue } from "../../providers/DiscordMusicPlayer";
|
||||||
|
|
||||||
@@ -46,38 +48,30 @@ const EMBEDS = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class QueueCommand {
|
export default class QueueCommand extends DiscordModule {
|
||||||
|
|
||||||
async onCommand(command: string, args: any, message: Message) {
|
public id = "Discord_MusicPlayer_Queue";
|
||||||
if(command.toLowerCase() !== 'queue') return;
|
public commands = ["queue", "q"];
|
||||||
await this.process(message, args);
|
public commandInteractionName = "queue";
|
||||||
|
|
||||||
|
async GuildOnModuleCommand(args: any, message: Message) {
|
||||||
|
await this.run(new HybridInteractionMessage(message), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
async interactionCreate(interaction: CommandInteraction) {
|
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||||
if(interaction.isCommand()) {
|
await this.run(new HybridInteractionMessage(interaction), interaction.options);
|
||||||
if(typeof interaction.commandName === 'undefined') return;
|
|
||||||
if((interaction.commandName).toLowerCase() !== 'queue') return;
|
|
||||||
await this.process(interaction, interaction.options);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async process(data: Interaction | Message, args: any) {
|
async run(data: HybridInteractionMessage, args: any) {
|
||||||
const isSlashCommand = data instanceof CommandInteraction && data.isCommand();
|
|
||||||
const isMessage = data instanceof Message;
|
|
||||||
|
|
||||||
if(!isSlashCommand && !isMessage) return;
|
const guild = data.getGuild();
|
||||||
|
|
||||||
if(!data.member) return;
|
if(!guild) return;
|
||||||
if(!data.guildId) return;
|
|
||||||
if(!(data.channel instanceof TextChannel)) return;
|
|
||||||
|
|
||||||
//const channel: any = isMessage ? data.member.voice.channel : DiscordProvider.client.guilds.cache.get((data as Interaction).guildId!)!.members.cache.get((data as Interaction).user.id)?.voice.channel;
|
const instance = DiscordMusicPlayer.getGuildInstance(guild.id);
|
||||||
//if(!channel) return;
|
if(!instance) return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data.getRaw())] });
|
||||||
|
|
||||||
const instance = DiscordMusicPlayer.getGuildInstance(data.guildId);
|
await sendHybridInteractionMessageResponse(data, { embeds:[EMBEDS.QUEUE(data.getRaw(), instance.queue)] });
|
||||||
if(!instance) return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data)] });
|
|
||||||
|
|
||||||
await sendMessageOrInteractionResponse(data, { embeds:[EMBEDS.QUEUE(data, instance.queue)] });
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
import { Message, CommandInteraction, Interaction, MessageActionRow, TextChannel, MessageSelectMenu, MessageSelectOptionData } from "discord.js";
|
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
|
||||||
import { makeErrorEmbed, makeSuccessEmbed, sendMessageOrInteractionResponse, makeInfoEmbed } from "../../utils/DiscordMessage";
|
|
||||||
|
import { Message, CommandInteraction, Interaction, MessageActionRow, ButtonInteraction, MessageSelectMenu, MessageSelectOptionData } from "discord.js";
|
||||||
|
import { makeErrorEmbed, makeSuccessEmbed, sendHybridInteractionMessageResponse, makeInfoEmbed } from "../../utils/DiscordMessage";
|
||||||
import DiscordMusicPlayer, { ValidTracks } from "../../providers/DiscordMusicPlayer";
|
import DiscordMusicPlayer, { ValidTracks } from "../../providers/DiscordMusicPlayer";
|
||||||
import { joinVoiceChannelProcedure } from "./Join";
|
import { joinVoiceChannelProcedure } from "./Join";
|
||||||
|
|
||||||
const EMBEDS = {
|
const EMBEDS = {
|
||||||
SEARCH_INFO: (data: Message | Interaction) => {
|
SEARCH_INFO: (data: Message | Interaction) => {
|
||||||
return makeInfoEmbed ({
|
return makeInfoEmbed({
|
||||||
title: 'Search',
|
title: 'Search',
|
||||||
description: `Search for a song`,
|
description: `Search for a song`,
|
||||||
fields: [
|
fields: [
|
||||||
@@ -52,27 +54,23 @@ const EMBEDS = {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
export default class Search extends DiscordModule {
|
||||||
|
|
||||||
|
public id = "Discord_MusicPlayer_Search";
|
||||||
|
public commands = ["search"];
|
||||||
|
public commandInteractionName = "search";
|
||||||
|
|
||||||
export default class Search {
|
async GuildOnModuleCommand(args: any, message: Message) {
|
||||||
|
await this.run(new HybridInteractionMessage(message), args);
|
||||||
async onCommand(command: string, args: any, message: Message) {
|
|
||||||
if (command.toLowerCase() !== 'search') return;
|
|
||||||
await this.process(message, args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async interactionCreate(interaction: Interaction) {
|
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||||
if (interaction.isCommand()) {
|
await this.run(new HybridInteractionMessage(interaction), interaction.options);
|
||||||
if (typeof interaction.commandName === 'undefined') return;
|
|
||||||
if ((interaction.commandName).toLowerCase() !== 'search') return;
|
|
||||||
await this.process(interaction, interaction.options);
|
|
||||||
}
|
}
|
||||||
else if (interaction.isButton()) {
|
|
||||||
if(!interaction.guild || !interaction.guildId) return;
|
|
||||||
if (!this.tryParseJSONObject(interaction.customId)) return;
|
|
||||||
|
|
||||||
let payload = JSON.parse(interaction.customId);
|
async GuildButtonInteractionCreate(interaction: ButtonInteraction) {
|
||||||
if(!interaction.member?.user?.id) return;
|
if (!this.isJsonValid(interaction.customId)) return;
|
||||||
|
const payload = JSON.parse(interaction.customId);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Discord have 100 char custom id char limit
|
Discord have 100 char custom id char limit
|
||||||
@@ -86,71 +84,55 @@ export default class Search {
|
|||||||
payload.m !== 'MP_S' ||
|
payload.m !== 'MP_S' ||
|
||||||
payload.a !== 'search') return;
|
payload.a !== 'search') return;
|
||||||
|
|
||||||
await this.process(interaction, payload.d.q);
|
await this.run(new HybridInteractionMessage(interaction), payload.d.q);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async process(data: Interaction | Message, args: any) {
|
async run(data: HybridInteractionMessage, args: any) {
|
||||||
const isSlashCommand = data instanceof CommandInteraction && data.isCommand();
|
|
||||||
const isButton = data instanceof Interaction && data.isButton();
|
|
||||||
const isMessage = data instanceof Message;
|
|
||||||
|
|
||||||
if (!isSlashCommand && !isMessage && !isButton) return;
|
const guild = data.getGuild();
|
||||||
|
const user = data.getUser();
|
||||||
|
const member = data.getMember();
|
||||||
|
const channel = data.getChannel();
|
||||||
|
|
||||||
if (!data.member) return;
|
if (!guild || !user || !member || !channel) return;
|
||||||
if (!data.guild) return;
|
|
||||||
if (!data.guildId) return;
|
|
||||||
|
|
||||||
let query;
|
let query;
|
||||||
|
|
||||||
if (isMessage) {
|
if (data.isMessage()) {
|
||||||
if (data === null || !data.guildId || data.member === null || data.guild === null) return;
|
if (args.length === 0)
|
||||||
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SEARCH_INFO(data.getRaw())] });
|
||||||
|
|
||||||
if (args.length === 0) {
|
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.SEARCH_INFO(data)] });
|
|
||||||
}
|
|
||||||
query = args.join(' ');
|
query = args.join(' ');
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (isSlashCommand) {
|
else if (data.isSlashCommand())
|
||||||
query = args.getSubcommand();
|
query = args.getSubcommand();
|
||||||
}
|
else if (data.isButton())
|
||||||
else if (isButton) {
|
|
||||||
query = args;
|
query = args;
|
||||||
}
|
|
||||||
|
|
||||||
if (!query) return;
|
if (!query) return;
|
||||||
if (!(data.channel instanceof TextChannel)) return;
|
|
||||||
|
|
||||||
let guildMember = data.member;
|
const voiceChannel = member.voice.channel;
|
||||||
|
|
||||||
if(isButton)
|
if (!voiceChannel)
|
||||||
guildMember = data.guild.members.cache.get(data.user.id)!
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data.getRaw())] });
|
||||||
|
|
||||||
if (!guildMember.voice.channel)
|
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data)] });
|
|
||||||
|
|
||||||
let voiceChannel = guildMember.voice.channel;
|
if (!DiscordMusicPlayer.isGuildInstanceExists(guild.id))
|
||||||
|
await joinVoiceChannelProcedure(data.getRaw(), null, voiceChannel);
|
||||||
if (!DiscordMusicPlayer.isGuildInstanceExists(data.guildId)) {
|
|
||||||
await joinVoiceChannelProcedure(data, null, voiceChannel);
|
|
||||||
}
|
|
||||||
|
|
||||||
let instance = DiscordMusicPlayer.getGuildInstance(data.guildId);
|
|
||||||
|
|
||||||
if (instance!.voiceChannel.id !== voiceChannel.id)
|
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data)] });
|
|
||||||
|
|
||||||
if (!instance!.isConnected()) {
|
|
||||||
await joinVoiceChannelProcedure(data, instance!, voiceChannel);
|
|
||||||
instance = DiscordMusicPlayer.getGuildInstance(data.guildId);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
let instance = DiscordMusicPlayer.getGuildInstance(guild.id);
|
||||||
if (!instance) return;
|
if (!instance) return;
|
||||||
|
|
||||||
let result = await DiscordMusicPlayer.searchYouTubeByQuery(query);
|
if (instance.voiceChannel.id !== voiceChannel.id)
|
||||||
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data.getRaw())] });
|
||||||
|
|
||||||
if (!result) return;
|
if (!instance.isConnected()) {
|
||||||
|
await joinVoiceChannelProcedure(data.getRaw(), instance!, voiceChannel);
|
||||||
|
instance = DiscordMusicPlayer.getGuildInstance(guild.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
let result = await DiscordMusicPlayer.searchYouTubeByQuery(query);
|
||||||
|
if (!result) return; // TODO: Handle when search returned nothing
|
||||||
|
|
||||||
const menuOptions: MessageSelectOptionData[] = [];
|
const menuOptions: MessageSelectOptionData[] = [];
|
||||||
|
|
||||||
@@ -166,14 +148,14 @@ export default class Search {
|
|||||||
m: 'MP_SM',
|
m: 'MP_SM',
|
||||||
a: 'play',
|
a: 'play',
|
||||||
d: {
|
d: {
|
||||||
r: guildMember.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) {
|
||||||
if(!song.title) continue;
|
if (!song.title) continue;
|
||||||
menuOptions.push({
|
menuOptions.push({
|
||||||
label: song.title,
|
label: song.title,
|
||||||
description: `${song.durationInSec} sec | ${song.views} views`,
|
description: `${song.durationInSec} sec | ${song.views} views`,
|
||||||
@@ -186,13 +168,11 @@ export default class Search {
|
|||||||
const row = new MessageActionRow();
|
const row = new MessageActionRow();
|
||||||
row.addComponents(messageSelectMenu);
|
row.addComponents(messageSelectMenu);
|
||||||
|
|
||||||
await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.SEARCH_RESULT(data, result)], components: [row] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SEARCH_RESULT(data.getRaw(), result)], components: [row] });
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
tryParseJSONObject(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") {
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
|
||||||
|
|
||||||
import { Message, CommandInteraction, Interaction } from "discord.js";
|
import { Message, CommandInteraction, Interaction } from "discord.js";
|
||||||
import { makeSuccessEmbed, makeErrorEmbed, sendMessageOrInteractionResponse } from "../../utils/DiscordMessage";
|
import { makeSuccessEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse } from "../../utils/DiscordMessage";
|
||||||
import DiscordProvider from "../../providers/Discord";
|
import DiscordProvider from "../../providers/Discord";
|
||||||
import DiscordMusicPlayer from "../../providers/DiscordMusicPlayer";
|
import DiscordMusicPlayer from "../../providers/DiscordMusicPlayer";
|
||||||
|
|
||||||
@@ -36,55 +38,48 @@ const EMBEDS = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Skip {
|
export default class Skip extends DiscordModule{
|
||||||
|
|
||||||
async onCommand(command: string, args: any, message: Message) {
|
public id = "Discord_MusicPlayer_Skip";
|
||||||
if (command.toLowerCase() !== 'skip') return;
|
public commands = ["skip"];
|
||||||
await this.process(message, args);
|
public commandInteractionName = "skip";
|
||||||
|
|
||||||
|
async GuildOnModuleCommand(args: any, message: Message) {
|
||||||
|
await this.run(new HybridInteractionMessage(message), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
async interactionCreate(interaction: CommandInteraction) {
|
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||||
if (interaction.isCommand()) {
|
await this.run(new HybridInteractionMessage(interaction), interaction.options);
|
||||||
if (typeof interaction.commandName === 'undefined') return;
|
|
||||||
if ((interaction.commandName).toLowerCase() !== 'skip') return;
|
|
||||||
await this.process(interaction, interaction.options);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async process(data: Interaction | Message, args: any) {
|
async run(data: HybridInteractionMessage, args: any) {
|
||||||
const isSlashCommand = data instanceof CommandInteraction && data.isCommand();
|
|
||||||
const isMessage = data instanceof Message;
|
|
||||||
|
|
||||||
if (!isSlashCommand && !isMessage) return;
|
const guild = data.getGuild();
|
||||||
|
const member = data.getMember();
|
||||||
|
|
||||||
if (!data.member) return;
|
if (!guild || !member) return;
|
||||||
if (!data.guildId) return;
|
|
||||||
|
|
||||||
const channel: any = isMessage ? data.member.voice.channel : DiscordProvider.client.guilds.cache.get((data as Interaction).guildId!)!.members.cache.get((data as Interaction).user.id)?.voice.channel;
|
const voiceChannel = member.voice.channel;
|
||||||
|
|
||||||
if (!data.member.voice.channel)
|
if (!voiceChannel)
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data.getRaw())] });
|
||||||
|
|
||||||
if (!channel) return;
|
const instance = DiscordMusicPlayer.getGuildInstance(guild.id);
|
||||||
|
|
||||||
let voiceChannel = data.member.voice.channel;
|
if(!instance)
|
||||||
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data.getRaw())] });
|
||||||
|
|
||||||
if(!DiscordMusicPlayer.isGuildInstanceExists(data.guildId))
|
if(instance.voiceChannel.id !== voiceChannel.id)
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data.getRaw())] }, true);
|
||||||
|
|
||||||
const instance = DiscordMusicPlayer.getGuildInstance(data.guildId);
|
if(instance.queue.track.length === 0)
|
||||||
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data.getRaw())] });
|
||||||
|
|
||||||
if(instance!.voiceChannel.id !== data.member.voice.channel.id)
|
instance.skipTrack();
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data)] }, true);
|
|
||||||
|
|
||||||
if(instance?.queue.track.length === 0)
|
if(instance.queue.track.length === 0)
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SKIPPED_LASTSONG(data.getRaw())] });
|
||||||
|
|
||||||
instance!.skipTrack();
|
|
||||||
|
|
||||||
if(instance?.queue.track.length === 0)
|
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.SKIPPED_LASTSONG(data)] });
|
|
||||||
else
|
else
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.SKIPPED(data)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SKIPPED(data.getRaw())] });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+39
-36
@@ -1,5 +1,8 @@
|
|||||||
|
import DiscordModule, { HybridInteractionMessage } from "../utils/DiscordModule";
|
||||||
|
|
||||||
import { CommandInteraction, Message, Interaction } from "discord.js";
|
import { CommandInteraction, Message, Interaction } from "discord.js";
|
||||||
import { makeSuccessEmbed, makeProcessingEmbed, sendMessageOrInteractionResponse } from "../utils/DiscordMessage";
|
import { makeSuccessEmbed, makeProcessingEmbed, sendHybridInteractionMessageResponse } from "../utils/DiscordMessage";
|
||||||
|
|
||||||
import DiscordProvider from "../providers/Discord";
|
import DiscordProvider from "../providers/Discord";
|
||||||
import NodePing from "ping";
|
import NodePing from "ping";
|
||||||
import { Promise } from "bluebird";
|
import { Promise } from "bluebird";
|
||||||
@@ -13,7 +16,6 @@ enum MeasureType {
|
|||||||
DiscordWebsocket = "discordwebsocket"
|
DiscordWebsocket = "discordwebsocket"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const EMBEDS = {
|
const EMBEDS = {
|
||||||
PING_INFO: (data: Message | Interaction, description: string) => {
|
PING_INFO: (data: Message | Interaction, description: string) => {
|
||||||
return makeSuccessEmbed({
|
return makeSuccessEmbed({
|
||||||
@@ -22,44 +24,43 @@ const EMBEDS = {
|
|||||||
description: description,
|
description: description,
|
||||||
user: (data instanceof Interaction) ? data.user : data.author
|
user: (data instanceof Interaction) ? data.user : data.author
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
PINGING: (data: HybridInteractionMessage) => {
|
||||||
|
return makeProcessingEmbed({
|
||||||
|
icon: data.isMessage() ? undefined : '⌛',
|
||||||
|
title: `Measuring network performance`,
|
||||||
|
user: (data.isInteraction()) ? data.getInteraction().user : data.getMessage().author
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Ping {
|
export default class Ping extends DiscordModule {
|
||||||
|
|
||||||
async onCommand(command: string, args: any, message: Message) {
|
public id = "Discord_Ping";
|
||||||
if (command.toLowerCase() !== 'ping') return;
|
public commands = ["ping"];
|
||||||
await this.process(message, args);
|
public commandInteractionName = "ping";
|
||||||
|
|
||||||
|
async GuildOnModuleCommand(args: any, message: Message) {
|
||||||
|
await this.run(new HybridInteractionMessage(message), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
async interactionCreate(interaction: CommandInteraction) {
|
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||||
if (interaction.isCommand()) {
|
await this.run(new HybridInteractionMessage(interaction), interaction.options);
|
||||||
if (typeof interaction.commandName === 'undefined') return;
|
|
||||||
if ((interaction.commandName).toLowerCase() !== 'ping') return;
|
|
||||||
await this.process(interaction, interaction.options);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async process(data: Interaction | Message, args: any) {
|
async run(data: HybridInteractionMessage, args: any) {
|
||||||
const isSlashCommand = data instanceof CommandInteraction && data.isCommand();
|
let placeholder: (HybridInteractionMessage | undefined);
|
||||||
const isMessage = data instanceof Message;
|
|
||||||
|
|
||||||
if (!isSlashCommand && !isMessage) return;
|
|
||||||
|
|
||||||
let placeholder;
|
|
||||||
|
|
||||||
const loadingEmbed = makeProcessingEmbed({
|
|
||||||
icon: isMessage ? undefined : '⌛',
|
|
||||||
title: `Measuring network performance`,
|
|
||||||
user: (data instanceof Interaction) ? data.user : data.author
|
|
||||||
});
|
|
||||||
|
|
||||||
let beforeEditDate = Date.now();
|
let beforeEditDate = Date.now();
|
||||||
placeholder = await sendMessageOrInteractionResponse(data, { embeds: [loadingEmbed] });
|
|
||||||
|
let _placeholder = await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.PINGING(data)] });
|
||||||
|
if (_placeholder)
|
||||||
|
placeholder = new HybridInteractionMessage(_placeholder);
|
||||||
|
|
||||||
let afterEditDate = Date.now();
|
let afterEditDate = Date.now();
|
||||||
|
|
||||||
|
|
||||||
let desString = [];
|
let finalString = [];
|
||||||
|
|
||||||
await Promise.map(Configuration.getConfig("Ping"), (entry: any) => {
|
await Promise.map(Configuration.getConfig("Ping"), (entry: any) => {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
@@ -70,33 +71,35 @@ export default class Ping {
|
|||||||
|
|
||||||
if (!res.alive) {
|
if (!res.alive) {
|
||||||
stringCurrent += "Failed";
|
stringCurrent += "Failed";
|
||||||
return desString.push(stringCurrent);
|
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";
|
stringCurrent += "Failed";
|
||||||
return desString.push(stringCurrent);
|
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)`;
|
||||||
desString.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(1)}ms`;
|
stringCurrent += `${Math.round(DiscordProvider.client.ws.ping).toFixed(1)}ms`;
|
||||||
desString.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`;
|
||||||
desString.push(stringCurrent);
|
finalString.push(stringCurrent);
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
}, { concurrency: 5 });
|
}, { concurrency: 5 });
|
||||||
|
|
||||||
desString.push("");
|
finalString.push("");
|
||||||
desString.push("💻 Running on " + `${os.hostname()}${Environment.get().NODE_ENV === "development" ? ' / Development Environment' : ''}`);
|
finalString.push("💻 Running on " + `${os.hostname()}${Environment.get().NODE_ENV === "development" ? ' / Development Environment' : ''}`);
|
||||||
|
|
||||||
if (isSlashCommand) return await data.editReply({ embeds: [EMBEDS.PING_INFO(data, desString.join('\n'))] });
|
if (data.isSlashCommand())
|
||||||
else if (typeof placeholder !== "undefined" && isMessage && placeholder instanceof Message) return await placeholder.edit({ embeds: [EMBEDS.PING_INFO(data, desString.join('\n'))] });
|
return await data.getMessageComponentInteraction().editReply({ embeds: [EMBEDS.PING_INFO(data.getRaw(), finalString.join('\n'))] });
|
||||||
|
else if (data && data.isMessage() && placeholder && placeholder.isMessage())
|
||||||
|
return await placeholder.getMessage().edit({ embeds: [EMBEDS.PING_INFO(data.getRaw(), finalString.join('\n'))] });
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+36
-35
@@ -1,5 +1,7 @@
|
|||||||
|
import DiscordModule, { HybridInteractionMessage } from "../utils/DiscordModule";
|
||||||
|
|
||||||
import { Message, Permissions, Interaction, CommandInteraction } from "discord.js";
|
import { Message, Permissions, Interaction, CommandInteraction } from "discord.js";
|
||||||
import { makeSuccessEmbed, sendMessageOrInteractionResponse, makeErrorEmbed, makeInfoEmbed } from "../utils/DiscordMessage";
|
import { makeSuccessEmbed, sendHybridInteractionMessageResponse, makeErrorEmbed, makeInfoEmbed } from "../utils/DiscordMessage";
|
||||||
|
|
||||||
const EMBEDS = {
|
const EMBEDS = {
|
||||||
SAY_INFO: (data: Message | Interaction) => {
|
SAY_INFO: (data: Message | Interaction) => {
|
||||||
@@ -29,56 +31,55 @@ const EMBEDS = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Say {
|
export default class Say extends DiscordModule {
|
||||||
|
|
||||||
async onCommand(command: string, args: any, message: Message) {
|
public id = "Discord_Say";
|
||||||
if(command.toLowerCase() !== 'say') return;
|
public commands = ["say"];
|
||||||
await this.process(message, args);
|
public commandInteractionName = "say";
|
||||||
|
|
||||||
|
async GuildOnModuleCommand(args: any, message: Message) {
|
||||||
|
await this.run(new HybridInteractionMessage(message), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
async interactionCreate(interaction: CommandInteraction) {
|
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||||
if(interaction.isCommand()) {
|
await this.run(new HybridInteractionMessage(interaction), interaction.options);
|
||||||
if(typeof interaction.commandName === 'undefined') return;
|
|
||||||
if((interaction.commandName).toLowerCase() !== 'say') return;
|
|
||||||
await this.process(interaction, interaction.options);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async process(data: Interaction | Message, args: any) {
|
async run(data: HybridInteractionMessage, args: any) {
|
||||||
const isSlashCommand = data instanceof CommandInteraction && data.isCommand();
|
|
||||||
const isMessage = data instanceof Message;
|
|
||||||
|
|
||||||
if(!isSlashCommand && !isMessage) return;
|
|
||||||
|
|
||||||
let query;
|
let query;
|
||||||
|
|
||||||
if(isMessage) {
|
if(data.isMessage()) {
|
||||||
if(data === null || !data.guildId || data.member === null || data.guild === null) return;
|
const message = data.getMessage();
|
||||||
if (!data.member.permissions.has([Permissions.FLAGS.VIEW_CHANNEL, Permissions.FLAGS.SEND_MESSAGES, Permissions.FLAGS.MANAGE_CHANNELS]))
|
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.NO_PERMISSION(data)] });
|
if(!message.member) return;
|
||||||
|
|
||||||
|
if (!message.member.permissions.has([Permissions.FLAGS.VIEW_CHANNEL, Permissions.FLAGS.SEND_MESSAGES, Permissions.FLAGS.MANAGE_CHANNELS]))
|
||||||
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_PERMISSION(data.getRaw())] });
|
||||||
|
|
||||||
|
if(args.length === 0)
|
||||||
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SAY_INFO(data.getRaw())] });
|
||||||
|
|
||||||
if(args.length === 0) {
|
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.SAY_INFO(data)] });
|
|
||||||
}
|
|
||||||
query = args.join(" ");
|
query = args.join(" ");
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(isSlashCommand) {
|
else if(data.isSlashCommand()) {
|
||||||
if(!data.guild!.members.cache.get(data.user.id)?.permissions.has([Permissions.FLAGS.ADMINISTRATOR]))
|
const interaction = data.getSlashCommand();
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.NO_PERMISSION(data)] });
|
if(!data.getGuild()!.members.cache.get(interaction.user.id)?.permissions.has([Permissions.FLAGS.ADMINISTRATOR]))
|
||||||
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_PERMISSION(data.getRaw())] });
|
||||||
|
|
||||||
query = data.options.getString('message');
|
query = interaction.options.getString('message');
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isSlashCommand) {
|
if(data.isSlashCommand() && data.getChannel()) {
|
||||||
await data.channel!.send({ content: query });
|
await data.getChannel()!.send({ content: query });
|
||||||
await data.reply({ ephemeral: true, embeds: [EMBEDS.SUCCESSFULLY_SAID(data)] });
|
await data.getMessageComponentInteraction().reply({ ephemeral: true, embeds: [EMBEDS.SUCCESSFULLY_SAID(data.getRaw())] });
|
||||||
}
|
}
|
||||||
else {
|
else if(data.isMessage()) {
|
||||||
if(data.deletable)
|
const message = data.getMessage();
|
||||||
await data.delete();
|
if(message.deletable)
|
||||||
|
await message.delete();
|
||||||
|
|
||||||
await data.channel.send({ content: query });
|
await data.getChannel()!.send({ content: query });
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+97
-108
@@ -1,5 +1,7 @@
|
|||||||
|
import DiscordModule, { HybridInteractionMessage } from "../utils/DiscordModule";
|
||||||
|
|
||||||
import { Message, Interaction, CommandInteraction, Permissions, ThreadChannel, GuildChannel } from "discord.js";
|
import { Message, Interaction, CommandInteraction, Permissions, ThreadChannel, GuildChannel } from "discord.js";
|
||||||
import { makeInfoEmbed, makeErrorEmbed, makeSuccessEmbed, makeProcessingEmbed, sendMessageOrInteractionResponse } from "../utils/DiscordMessage";
|
import { makeInfoEmbed, makeErrorEmbed, makeSuccessEmbed, makeProcessingEmbed, sendHybridInteractionMessageResponse } from "../utils/DiscordMessage";
|
||||||
import DiscordProvider from "../providers/Discord";
|
import DiscordProvider from "../providers/Discord";
|
||||||
import Prisma from "../providers/Prisma";
|
import Prisma from "../providers/Prisma";
|
||||||
import Cache from "../providers/Cache";
|
import Cache from "../providers/Cache";
|
||||||
@@ -18,11 +20,11 @@ const EMBEDS = {
|
|||||||
user: (data instanceof Interaction) ? data.user : data.author
|
user: (data instanceof Interaction) ? data.user : data.author
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
PROCESSING: (data: Message | Interaction) => {
|
PROCESSING: (data: HybridInteractionMessage) => {
|
||||||
return makeProcessingEmbed({
|
return makeProcessingEmbed({
|
||||||
icon: (data instanceof Message) ? undefined : '⌛',
|
icon: (data.isMessage()) ? undefined : '⌛',
|
||||||
title: `Performing actions`,
|
title: `Performing actions`,
|
||||||
user: (data instanceof Interaction) ? data.user : data.author
|
user: data.getUser()
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
NO_PERMISSION: (data: Message | Interaction) => {
|
NO_PERMISSION: (data: Message | Interaction) => {
|
||||||
@@ -44,7 +46,7 @@ const EMBEDS = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
NO_SERVICE_ANNOUNCEMENT_STATUS_PROVIDED: async (data: Message | Interaction) => {
|
NO_SERVICE_ANNOUNCEMENT_STATUS_PROVIDED: async (data: Message | Interaction) => {
|
||||||
let GuildCache = await Cache.getGuild(data.guildId!);
|
let GuildCache = await Cache.getGuild(data.guild!.id);
|
||||||
|
|
||||||
// TODO: Better error handling
|
// TODO: Better error handling
|
||||||
if(typeof GuildCache === 'undefined')
|
if(typeof GuildCache === 'undefined')
|
||||||
@@ -137,196 +139,183 @@ const EMBEDS = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Settings {
|
export default class Settings extends DiscordModule {
|
||||||
async onCommand(command: string, args: any, message: Message) {
|
|
||||||
if(command.toLowerCase() !== 'settings') return;
|
public id = "Discord_Settings";
|
||||||
await this.process(message, args);
|
public commands = ["settings"];
|
||||||
|
public commandInteractionName = "settings";
|
||||||
|
|
||||||
|
async GuildOnModuleCommand(args: any, message: Message) {
|
||||||
|
await this.run(new HybridInteractionMessage(message), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
async interactionCreate(interaction: CommandInteraction) {
|
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||||
if(interaction.isCommand()) {
|
await this.run(new HybridInteractionMessage(interaction), interaction.options);
|
||||||
if(typeof interaction.commandName === 'undefined') return;
|
|
||||||
if((interaction.commandName).toLowerCase() !== 'settings') return;
|
|
||||||
await this.process(interaction, interaction.options);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async process(data: Interaction | Message, args: any) {
|
async run(data: HybridInteractionMessage, args: any) {
|
||||||
|
|
||||||
const isSlashCommand = data instanceof CommandInteraction && data.isCommand();
|
const Guild = await Prisma.client.guild.findFirst({ where: { id: data.getGuild()!.id }})
|
||||||
const isMessage = data instanceof Message;
|
if(!Guild) return;
|
||||||
|
|
||||||
if(!isSlashCommand && !isMessage) return;
|
|
||||||
|
|
||||||
if(data.guild === null || data.guildId === null) return;
|
|
||||||
|
|
||||||
const Guild = await Prisma.client.guild.findFirst({ where: { id: data.guildId }})
|
|
||||||
if(!Guild) throw new Error('TODO: Handle if guild is not found');
|
|
||||||
|
|
||||||
const funct = {
|
const funct = {
|
||||||
setPrefix: async(data: Message | Interaction) => {
|
setPrefix: async(data: HybridInteractionMessage) => {
|
||||||
|
|
||||||
if(data === null || !data.guildId || data.member === null || data.guild === null) return;
|
let member = data.getMember();
|
||||||
|
if(!member) return;
|
||||||
|
|
||||||
if(data instanceof Message) {
|
if (!member.permissions.has([Permissions.FLAGS.ADMINISTRATOR]))
|
||||||
if (!data.member.permissions.has([Permissions.FLAGS.ADMINISTRATOR]))
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_PERMISSION(data.getRaw())] });
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.NO_PERMISSION(data)] });
|
|
||||||
}
|
|
||||||
else if(isSlashCommand) {
|
|
||||||
if(!data.guild.members.cache.get(data.user.id)?.permissions.has([Permissions.FLAGS.ADMINISTRATOR]))
|
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.NO_PERMISSION(data)] });
|
|
||||||
}
|
|
||||||
|
|
||||||
|
let newPrefix: string | null | undefined;
|
||||||
let newPrefix: string | undefined;
|
if(data.isMessage()) {
|
||||||
if(data instanceof Message) {
|
|
||||||
let _name: string;
|
let _name: string;
|
||||||
if(typeof args[1] === 'undefined')
|
if(typeof args[1] === 'undefined')
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.NO_PREFIX_PROVIDED(data)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_PREFIX_PROVIDED(data.getRaw())] });
|
||||||
|
|
||||||
let __name = args;
|
let __name = args;
|
||||||
__name.shift();
|
__name.shift();
|
||||||
_name = __name.join(" ");
|
_name = __name.join(" ");
|
||||||
newPrefix = _name;
|
newPrefix = _name;
|
||||||
}
|
}
|
||||||
else if(data instanceof CommandInteraction)
|
else if(data.isSlashCommand())
|
||||||
newPrefix = data.options.getString('prefix')!;
|
newPrefix = data.getSlashCommand().options.getString('prefix');
|
||||||
|
|
||||||
if(!newPrefix)
|
if(!newPrefix)
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.NO_PREFIX_PROVIDED(data)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_PREFIX_PROVIDED(data.getRaw())] });
|
||||||
|
|
||||||
if(newPrefix.length > 200)
|
if(newPrefix.length > 200)
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.PREFIX_TOO_LONG(data)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.PREFIX_TOO_LONG(data.getRaw())] });
|
||||||
|
|
||||||
if(newPrefix.startsWith(`<@!${DiscordProvider.client.user?.id}>`))
|
if(newPrefix.startsWith(`<@!${DiscordProvider.client.user?.id}>`))
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.PREFIX_IS_MENTION(data)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.PREFIX_IS_MENTION(data.getRaw())] });
|
||||||
|
|
||||||
let placeholder = await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.PROCESSING(data)] });
|
let placeholder: (HybridInteractionMessage | undefined);
|
||||||
|
|
||||||
await Prisma.client.guild.update({ where: { id: data.guildId! }, data: { prefix: newPrefix }});
|
let _placeholder = await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.PROCESSING(data)] });
|
||||||
Cache.updateGuildCache(data.guildId!);
|
if (_placeholder)
|
||||||
|
placeholder = new HybridInteractionMessage(_placeholder);
|
||||||
|
|
||||||
if(isMessage)
|
await Prisma.client.guild.update({ where: { id: data.getGuild()!.id }, data: { prefix: newPrefix }});
|
||||||
return await (placeholder as Message).edit({ embeds: [EMBEDS.PREFIX_UPDATED(data, newPrefix)] });
|
Cache.updateGuildCache(data.getGuild()!.id);
|
||||||
else if(isSlashCommand)
|
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.PREFIX_UPDATED(data, newPrefix)]}, true);
|
if(data && data.isMessage() && placeholder && placeholder.isMessage())
|
||||||
|
return placeholder.getMessage().edit({ embeds: [EMBEDS.PREFIX_UPDATED(data.getRaw(), newPrefix)] });
|
||||||
|
else if(data.isSlashCommand())
|
||||||
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.PREFIX_UPDATED(data.getRaw(), newPrefix)]}, true);
|
||||||
},
|
},
|
||||||
setEnableServiceAnnouncement: async(data: Message | Interaction) => {
|
setEnableServiceAnnouncement: async(data: HybridInteractionMessage) => {
|
||||||
|
|
||||||
if(data === null || !data.guildId || data.member === null || data.guild === null) return;
|
let member = data.getMember();
|
||||||
|
if(!member) return;
|
||||||
|
|
||||||
if(data instanceof Message) {
|
if (!member.permissions.has([Permissions.FLAGS.ADMINISTRATOR]))
|
||||||
if (!data.member.permissions.has([Permissions.FLAGS.ADMINISTRATOR]))
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_PERMISSION(data.getRaw())] });
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.NO_PERMISSION(data)] });
|
|
||||||
}
|
|
||||||
else if(isSlashCommand) {
|
|
||||||
if(!data.guild.members.cache.get(data.user.id)?.permissions.has([Permissions.FLAGS.ADMINISTRATOR]))
|
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.NO_PERMISSION(data)] });
|
|
||||||
}
|
|
||||||
|
|
||||||
|
let newStatus: string | null | undefined;
|
||||||
let newStatus: string | undefined;
|
if(data.isMessage()) {
|
||||||
if(data instanceof Message) {
|
|
||||||
let _name: string;
|
let _name: string;
|
||||||
if(typeof args[1] === 'undefined') {
|
if(typeof args[1] === 'undefined')
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [await EMBEDS.NO_SERVICE_ANNOUNCEMENT_STATUS_PROVIDED(data)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [await EMBEDS.NO_SERVICE_ANNOUNCEMENT_STATUS_PROVIDED(data.getRaw())] });
|
||||||
}
|
|
||||||
|
|
||||||
let __name = args;
|
let __name = args;
|
||||||
__name.shift();
|
__name.shift();
|
||||||
_name = __name.join(" ");
|
_name = __name.join(" ");
|
||||||
newStatus = _name;
|
newStatus = _name;
|
||||||
}
|
}
|
||||||
else if(data instanceof CommandInteraction)
|
else if(data.isSlashCommand())
|
||||||
newStatus = data.options.getString('status')!;
|
newStatus = data.getSlashCommand().options.getString('status')!;
|
||||||
|
|
||||||
if(!newStatus)
|
if(!newStatus)
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [await EMBEDS.NO_SERVICE_ANNOUNCEMENT_STATUS_PROVIDED(data)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [await EMBEDS.NO_SERVICE_ANNOUNCEMENT_STATUS_PROVIDED(data.getRaw())] });
|
||||||
|
|
||||||
if(!["true", "false", "yes", "no", "y", "n", "enable", "disable"].includes(newStatus.toLowerCase()))
|
if(!["true", "false", "yes", "no", "y", "n", "enable", "disable"].includes(newStatus.toLowerCase()))
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_INVALID_STATUS(data)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_INVALID_STATUS(data.getRaw())] });
|
||||||
|
|
||||||
await Cache.updateGuildCache(data.guildId!);
|
await Cache.updateGuildCache(data.getGuild()!.id);
|
||||||
let GuildCache = await Cache.getGuild(data.guildId!);
|
let GuildCache = await Cache.getGuild(data.getGuild()!.id);
|
||||||
|
|
||||||
const newStatusBool = ["true", "yes", "y", "enable"].includes(newStatus.toLowerCase()) ? true : false;
|
const newStatusBool = ["true", "yes", "y", "enable"].includes(newStatus.toLowerCase()) ? true : false;
|
||||||
|
|
||||||
if(GuildCache?.ServiceAnnouncement_Enabled === newStatusBool)
|
if(GuildCache?.ServiceAnnouncement_Enabled === newStatusBool)
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_STATUS_ALREADY_SET(data, newStatusBool)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_STATUS_ALREADY_SET(data.getRaw(), newStatusBool)] });
|
||||||
|
|
||||||
if(GuildCache?.ServiceAnnouncement_Channel === null)
|
if(GuildCache?.ServiceAnnouncement_Channel === null)
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_NO_PARAMETER(data)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_NO_PARAMETER(data.getRaw())] });
|
||||||
|
|
||||||
let placeholder = await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.PROCESSING(data)] });
|
let placeholder = await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.PROCESSING(data)] });
|
||||||
|
|
||||||
await Prisma.client.guild.update(
|
await Prisma.client.guild.update(
|
||||||
{ where: { id: data.guildId! },
|
{ where: { id: data.getGuild()!.id },
|
||||||
data: {
|
data: {
|
||||||
ServiceAnnouncement_Enabled: newStatusBool
|
ServiceAnnouncement_Enabled: newStatusBool
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Cache.updateGuildCache(data.guildId!);
|
Cache.updateGuildCache(data.getGuild()!.id);
|
||||||
|
|
||||||
if(isMessage)
|
if(data.isMessage())
|
||||||
return await (placeholder as Message).edit({ embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_STATUS_UPDATED(data, newStatusBool)]});
|
return await (placeholder as Message).edit({ embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_STATUS_UPDATED(data.getRaw(), newStatusBool)]});
|
||||||
else if(isSlashCommand)
|
else if(data.isSlashCommand())
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_STATUS_UPDATED(data, newStatusBool)]}, true);
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_STATUS_UPDATED(data.getRaw(), newStatusBool)]}, true);
|
||||||
},
|
},
|
||||||
setServiceAnnouncementChannel: async(data: Message | CommandInteraction) => {
|
setServiceAnnouncementChannel: async(data: HybridInteractionMessage) => {
|
||||||
|
|
||||||
|
let member = data.getMember();
|
||||||
|
if(!member) return;
|
||||||
|
|
||||||
|
if (!member.permissions.has([Permissions.FLAGS.ADMINISTRATOR]))
|
||||||
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_PERMISSION(data.getRaw())] });
|
||||||
|
|
||||||
let channel;
|
let channel;
|
||||||
if(data instanceof Message) {
|
if(data.isMessage()) {
|
||||||
if(typeof args[1] === 'undefined')
|
if(typeof args[1] === 'undefined')
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.NO_CHANNEL_MENTIONED(data)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_CHANNEL_MENTIONED(data.getRaw())] });
|
||||||
channel = data.mentions.channels.first();
|
channel = data.getMessage().mentions.channels.first();
|
||||||
}
|
}
|
||||||
else if(data instanceof CommandInteraction)
|
else if(data.isSlashCommand())
|
||||||
channel = data.options.getChannel('channel');
|
channel = data.getSlashCommand().options.getChannel('channel');
|
||||||
|
|
||||||
if(!channel)
|
if(!channel)
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.NO_CHANNEL_FOUND(data)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_CHANNEL_FOUND(data.getRaw())] });
|
||||||
|
|
||||||
let TargetChannel = data.guild!.channels.cache.get(channel.id);
|
let TargetChannel = data.getGuild()!.channels.cache.get(channel.id);
|
||||||
if(typeof TargetChannel === 'undefined') return;
|
if(typeof TargetChannel === 'undefined') return;
|
||||||
|
|
||||||
if(TargetChannel instanceof ThreadChannel || TargetChannel.isThread())
|
if(TargetChannel instanceof ThreadChannel || TargetChannel.isThread())
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.INVALID_CHANNEL_THREAD(data, TargetChannel)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.INVALID_CHANNEL_THREAD(data.getRaw(), TargetChannel)] });
|
||||||
|
|
||||||
if(!TargetChannel.isText())
|
if(!TargetChannel.isText())
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.INVALID_CHANNEL(data, TargetChannel)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.INVALID_CHANNEL(data.getRaw(), TargetChannel)] });
|
||||||
|
|
||||||
if(!(data!.guild!.me?.permissionsIn(TargetChannel).has([Permissions.FLAGS.SEND_MESSAGES, Permissions.FLAGS.VIEW_CHANNEL])))
|
if(!(data.getGuild()!.me?.permissionsIn(TargetChannel).has([Permissions.FLAGS.SEND_MESSAGES, Permissions.FLAGS.VIEW_CHANNEL])))
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.BOT_NO_PERMISSION(data, TargetChannel)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.BOT_NO_PERMISSION(data.getRaw(), TargetChannel)] });
|
||||||
|
|
||||||
let placeholder = await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.PROCESSING(data)] });
|
let placeholder = await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.PROCESSING(data)] });
|
||||||
|
|
||||||
await Prisma.client.guild.update({ where: {id: data.guildId! }, data: { ServiceAnnouncement_Channel: channel.id }});
|
await Prisma.client.guild.update({ where: {id: data.getGuild()!.id }, data: { ServiceAnnouncement_Channel: channel.id }});
|
||||||
|
|
||||||
if(isMessage)
|
if(data.isMessage())
|
||||||
return await (placeholder as Message).edit({ embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_CONFIGURED_CHANNEL(data, TargetChannel)]});
|
return await (placeholder as Message).edit({ embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_CONFIGURED_CHANNEL(data.getRaw(), TargetChannel)]});
|
||||||
else if(isSlashCommand)
|
else if(data.isSlashCommand())
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_CONFIGURED_CHANNEL(data, TargetChannel)]}, true);
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_CONFIGURED_CHANNEL(data.getRaw(), TargetChannel)]}, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let query;
|
let query;
|
||||||
|
|
||||||
if(isMessage) {
|
if(data.isMessage()) {
|
||||||
if(data === null || !data.guildId || data.member === null || data.guild === null) return;
|
if(args.length === 0)
|
||||||
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SETTINGS_INFO(data.getRaw())] });
|
||||||
|
|
||||||
if(args.length === 0) {
|
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.SETTINGS_INFO(data)] });
|
|
||||||
}
|
|
||||||
query = args[0].toLowerCase();
|
query = args[0].toLowerCase();
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(isSlashCommand) {
|
else if(data.isSlashCommand()) {
|
||||||
query = args.getSubcommand();
|
query = args.getSubcommand();
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(query) {
|
switch(query) {
|
||||||
case "info":
|
case "info":
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.SETTINGS_INFO(data)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SETTINGS_INFO(data.getRaw())] });
|
||||||
case "setprefix":
|
case "setprefix":
|
||||||
return await funct.setPrefix(data);
|
return await funct.setPrefix(data);
|
||||||
case "setenableserviceannouncement":
|
case "setenableserviceannouncement":
|
||||||
|
|||||||
+14
-18
@@ -1,5 +1,7 @@
|
|||||||
|
import DiscordModule, { HybridInteractionMessage } from "../utils/DiscordModule";
|
||||||
|
|
||||||
import { Message, CommandInteraction, Interaction } from "discord.js";
|
import { Message, CommandInteraction, Interaction } from "discord.js";
|
||||||
import { sendMessageOrInteractionResponse, makeInfoEmbed } from "../utils/DiscordMessage";
|
import { sendHybridInteractionMessageResponse, makeInfoEmbed } from "../utils/DiscordMessage";
|
||||||
import DiscordProvider from "../providers/Discord";
|
import DiscordProvider from "../providers/Discord";
|
||||||
import os from "os-utils";
|
import os from "os-utils";
|
||||||
|
|
||||||
@@ -28,27 +30,21 @@ const EMBEDS = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Stats {
|
export default class Stats extends DiscordModule {
|
||||||
|
|
||||||
async onCommand(command: string, args: any, message: Message) {
|
public id = "Discord_Stats";
|
||||||
if(command.toLowerCase() !== 'stats') return;
|
public commands = ["stats"];
|
||||||
await this.process(message, args);
|
public commandInteractionName = "stats";
|
||||||
|
|
||||||
|
async GuildOnModuleCommand(args: any, message: Message) {
|
||||||
|
await this.run(new HybridInteractionMessage(message), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
async interactionCreate(interaction: CommandInteraction) {
|
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||||
if(interaction.isCommand()) {
|
await this.run(new HybridInteractionMessage(interaction), interaction.options);
|
||||||
if(typeof interaction.commandName === 'undefined') return;
|
|
||||||
if((interaction.commandName).toLowerCase() !== 'stats') return;
|
|
||||||
await this.process(interaction, interaction.options);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async process(data: Interaction | Message, args: any) {
|
async run(data: HybridInteractionMessage, args: any) {
|
||||||
const isSlashCommand = data instanceof CommandInteraction && data.isCommand();
|
return await sendHybridInteractionMessageResponse(data, { embeds:[EMBEDS.STATS_INFO(data.getRaw())] });
|
||||||
const isMessage = data instanceof Message;
|
|
||||||
|
|
||||||
if(!isSlashCommand && !isMessage) return;
|
|
||||||
|
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds:[EMBEDS.STATS_INFO(data)] });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+34
-42
@@ -1,5 +1,7 @@
|
|||||||
|
import DiscordModule, { HybridInteractionMessage } from "../utils/DiscordModule";
|
||||||
|
|
||||||
import { Message, Interaction, CommandInteraction } from "discord.js";
|
import { Message, Interaction, CommandInteraction } from "discord.js";
|
||||||
import { sendMessageOrInteractionResponse, makeErrorEmbed, makeInfoEmbed } from "../utils/DiscordMessage";
|
import { sendHybridInteractionMessageResponse, makeErrorEmbed, makeInfoEmbed } from "../utils/DiscordMessage";
|
||||||
import { getColorFromURL } from "color-thief-node";
|
import { getColorFromURL } from "color-thief-node";
|
||||||
|
|
||||||
const EMBEDS = {
|
const EMBEDS = {
|
||||||
@@ -24,58 +26,45 @@ const EMBEDS = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class UserInfo {
|
export default class UserInfo extends DiscordModule {
|
||||||
|
|
||||||
async onCommand(command: string, args: any, message: Message) {
|
public id = "Discord_UserInfo";
|
||||||
if(command.toLowerCase() !== 'userinfo') return;
|
public commands = ["userinfo"];
|
||||||
await this.process(message, args);
|
public commandInteractionName = "userinfo";
|
||||||
|
|
||||||
|
async GuildOnModuleCommand(args: any, message: Message) {
|
||||||
|
await this.run(new HybridInteractionMessage(message), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
async interactionCreate(interaction: CommandInteraction) {
|
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||||
if(interaction.isCommand()) {
|
await this.run(new HybridInteractionMessage(interaction), interaction.options);
|
||||||
if(typeof interaction.commandName === 'undefined') return;
|
|
||||||
if((interaction.commandName).toLowerCase() !== 'userinfo') return;
|
|
||||||
await this.process(interaction, interaction.options);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async process(data: Interaction | Message, args: any) {
|
async run(data: HybridInteractionMessage, args: any) {
|
||||||
const isSlashCommand = data instanceof CommandInteraction && data.isCommand();
|
|
||||||
const isMessage = data instanceof Message;
|
|
||||||
|
|
||||||
if(!isSlashCommand && !isMessage) return;
|
|
||||||
|
|
||||||
let query;
|
let query;
|
||||||
|
|
||||||
if(isMessage) {
|
if(data.isMessage()) {
|
||||||
if(data === null || !data.guildId || data.member === null || data.guild === null) return;
|
if(args.length === 0)
|
||||||
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SAY_INFO(data.getRaw())] });
|
||||||
|
|
||||||
if(args.length === 0) {
|
if(typeof data.getMessage().mentions.users.first() !== 'undefined')
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.SAY_INFO(data)] });
|
query = data.getMessage().mentions.users.first()?.id;
|
||||||
}
|
else
|
||||||
|
|
||||||
if(typeof data.mentions.users.first() !== 'undefined') {
|
|
||||||
query = data.mentions.users.first()?.id;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
query = args[0];
|
query = args[0];
|
||||||
}
|
}
|
||||||
|
else if(data.isSlashCommand())
|
||||||
|
query = data.getSlashCommand().options.getUser('user')?.id;
|
||||||
|
|
||||||
}
|
// Find the user want to look up
|
||||||
else if(isSlashCommand) {
|
let TargetMember = (await data.getGuild()!.members.fetch()).get(query);
|
||||||
query = data.options.getUser('user')?.id;
|
if(!TargetMember) return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_FOUND(data.getRaw())] });
|
||||||
}
|
|
||||||
|
|
||||||
let TargetMember = (await data.guild!.members.fetch()).get(query);
|
|
||||||
if(typeof TargetMember === 'undefined') return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.USER_NOT_FOUND(data)] });
|
|
||||||
|
|
||||||
if(isSlashCommand) {
|
if(data.isSlashCommand())
|
||||||
await data.deferReply();
|
await data.getMessageComponentInteraction().deferReply();
|
||||||
}
|
|
||||||
else if(isMessage) {
|
let readableStatus: string;
|
||||||
}
|
|
||||||
|
|
||||||
let readableStatus: string = "Unknown";
|
|
||||||
switch(TargetMember.presence?.status) {
|
switch(TargetMember.presence?.status) {
|
||||||
case "online":
|
case "online":
|
||||||
readableStatus = "🟢 Online";
|
readableStatus = "🟢 Online";
|
||||||
@@ -89,6 +78,9 @@ export default class UserInfo {
|
|||||||
case "offline":
|
case "offline":
|
||||||
readableStatus = "⚫ Offline";
|
readableStatus = "⚫ Offline";
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
readableStatus = "❓ Unknown";
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const embed = makeInfoEmbed ({
|
const embed = makeInfoEmbed ({
|
||||||
@@ -100,7 +92,7 @@ export default class UserInfo {
|
|||||||
value: `\u200b`
|
value: `\u200b`
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
user: (data instanceof Interaction) ? data.user : data.author
|
user: data.getUser()
|
||||||
});
|
});
|
||||||
|
|
||||||
if(TargetMember.presence?.activities)
|
if(TargetMember.presence?.activities)
|
||||||
@@ -137,7 +129,7 @@ export default class UserInfo {
|
|||||||
|
|
||||||
embed.addField(`📰 Information on this guild`, `${
|
embed.addField(`📰 Information on this guild`, `${
|
||||||
(TargetMember.joinedAt === null) ? 'Cannot determine joined date' : `Joined <t:${Math.round(TargetMember.joinedAt.getTime() / 1000)}:R>`}
|
(TargetMember.joinedAt === null) ? 'Cannot determine joined date' : `Joined <t:${Math.round(TargetMember.joinedAt.getTime() / 1000)}:R>`}
|
||||||
${(TargetMember.id === data.guild!.ownerId) ? 'Owner of this guild 👑' : ''}
|
${(TargetMember.id === data.getGuild()!.ownerId) ? 'Owner of this guild 👑' : ''}
|
||||||
`);
|
`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -150,7 +142,7 @@ export default class UserInfo {
|
|||||||
embed.setThumbnail(TargetMember.user.displayAvatarURL());
|
embed.setThumbnail(TargetMember.user.displayAvatarURL());
|
||||||
embed.setAuthor(`${TargetMember.displayName}`, TargetMember.user.displayAvatarURL());
|
embed.setAuthor(`${TargetMember.displayName}`, TargetMember.user.displayAvatarURL());
|
||||||
|
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [embed] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [embed] });
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
|
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
|
||||||
|
|
||||||
import { Message, Interaction, CommandInteraction } from "discord.js";
|
import { Message, Interaction, CommandInteraction } from "discord.js";
|
||||||
import { makeInfoEmbed, makeErrorEmbed, sendMessageOrInteractionResponse } from "../../utils/DiscordMessage";
|
import { 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";
|
||||||
|
|
||||||
@@ -26,35 +28,33 @@ const EMBEDS = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class FakeError {
|
export default class FakeError extends DiscordModule {
|
||||||
|
|
||||||
async onCommand(command: string, args: any, message: Message) {
|
public id = "Discord_Developer_FakeError";
|
||||||
if (command.toLowerCase() !== 'fakeerror') return;
|
public commands = ["fakeerror"];
|
||||||
await this.process(message, args);
|
public commandInteractionName = "fakeerror";
|
||||||
|
|
||||||
|
async GuildOnModuleCommand(args: any, message: Message) {
|
||||||
|
await this.run(new HybridInteractionMessage(message), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
async interactionCreate(interaction: CommandInteraction) {
|
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||||
if (interaction.isCommand()) {
|
await this.run(new HybridInteractionMessage(interaction), interaction.options);
|
||||||
if (typeof interaction.commandName === 'undefined') return;
|
|
||||||
if ((interaction.commandName).toLowerCase() !== 'fakeerror') return;
|
|
||||||
await this.process(interaction, interaction.options);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async process(data: Interaction | Message, args: any) {
|
async run(data: HybridInteractionMessage, args: any) {
|
||||||
const isSlashCommand = data instanceof CommandInteraction && data.isCommand();
|
|
||||||
const isMessage = data instanceof Message;
|
|
||||||
|
|
||||||
if (!isSlashCommand && !isMessage) return;
|
const guild = data.getGuild();
|
||||||
|
const user = data.getUser();
|
||||||
|
|
||||||
if (!Users.isDeveloper(data.member?.user.id!))
|
if(!guild || !user) return;
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.NOT_DEVELOPER(data)] });
|
|
||||||
|
|
||||||
if(!data.guildId) return;
|
if (!Users.isDeveloper(user.id!))
|
||||||
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NOT_DEVELOPER(data.getRaw())] });
|
||||||
|
|
||||||
const funct = {
|
const funct = {
|
||||||
crashMusicPlayer: async (data: Message | Interaction) => {
|
crashMusicPlayer: async (data: HybridInteractionMessage) => {
|
||||||
const instance = DiscordMusicPlayer.getGuildInstance(data.guildId!);
|
const instance = DiscordMusicPlayer.getGuildInstance(guild.id);
|
||||||
if(!instance) return;
|
if(!instance) return;
|
||||||
|
|
||||||
instance._fake_error_on_player();
|
instance._fake_error_on_player();
|
||||||
@@ -63,22 +63,19 @@ export default class FakeError {
|
|||||||
|
|
||||||
let query;
|
let query;
|
||||||
|
|
||||||
if (isMessage) {
|
if (data.isMessage()) {
|
||||||
if (data === null || !data.guildId || data.member === null || data.guild === null) return;
|
if (args.length === 0)
|
||||||
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.FAKEERROR_INFO(data.getRaw())] });
|
||||||
|
|
||||||
if (args.length === 0) {
|
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.FAKEERROR_INFO(data)] });
|
|
||||||
}
|
|
||||||
query = args[0].toLowerCase();
|
query = args[0].toLowerCase();
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (isSlashCommand) {
|
else if (data.isSlashCommand()) {
|
||||||
query = args.getSubcommand();
|
query = args.getSubcommand();
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (query) {
|
switch (query) {
|
||||||
case "info":
|
case "info":
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.FAKEERROR_INFO(data)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.FAKEERROR_INFO(data.getRaw())] });
|
||||||
case "crashmusicplayer":
|
case "crashmusicplayer":
|
||||||
return await funct.crashMusicPlayer(data);
|
return await funct.crashMusicPlayer(data);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
|
||||||
|
|
||||||
import { Message, MessageEmbed, Interaction, CommandInteraction, TextChannel } from "discord.js";
|
import { Message, MessageEmbed, Interaction, CommandInteraction, TextChannel } from "discord.js";
|
||||||
import { makeInfoEmbed, makeErrorEmbed, makeSuccessEmbed, makeProcessingEmbed, makeWarningEmbed, sendMessageOrInteractionResponse, sendMessage } from "../../utils/DiscordMessage";
|
import { makeInfoEmbed, makeErrorEmbed, makeSuccessEmbed, makeProcessingEmbed, makeWarningEmbed, sendHybridInteractionMessageResponse, sendMessage } from "../../utils/DiscordMessage";
|
||||||
import DiscordProvider from "../../providers/Discord";
|
import DiscordProvider from "../../providers/Discord";
|
||||||
import Prisma from "../../providers/Prisma";
|
import Prisma from "../../providers/Prisma";
|
||||||
import Users from "../../services/Users";
|
import Users from "../../services/Users";
|
||||||
@@ -31,7 +33,7 @@ const EMBEDS = {
|
|||||||
user: (data instanceof Interaction) ? data.user : data.author
|
user: (data instanceof Interaction) ? data.user : data.author
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
MAKE_PAYLOAD: (data: Message | Interaction, payload: any) => {
|
MAKE_PAYLOAD: (payload: any) => {
|
||||||
const user = DiscordProvider.client.user;
|
const user = DiscordProvider.client.user;
|
||||||
payload.footer = {
|
payload.footer = {
|
||||||
text: `${user?.username}`,
|
text: `${user?.username}`,
|
||||||
@@ -123,10 +125,13 @@ let Announcements = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
export default class InteractionManager {
|
export default class ServiceAnnouncement extends DiscordModule {
|
||||||
|
|
||||||
async init() {
|
public id = "Discord_Developer_ServiceAnnouncement";
|
||||||
|
public commands = ["serviceannouncement"];
|
||||||
|
public commandInteractionName = "serviceannouncement";
|
||||||
|
|
||||||
|
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(path.join(process.cwd(), 'configs/ServiceAnnouncement.json'));
|
const rawData = fs.readFileSync(path.join(process.cwd(), 'configs/ServiceAnnouncement.json'));
|
||||||
@@ -138,30 +143,24 @@ export default class InteractionManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async onCommand(command: string, args: any, message: Message) {
|
async GuildOnModuleCommand(args: any, message: Message) {
|
||||||
if (command.toLowerCase() !== 'serviceannouncement') return;
|
await this.run(new HybridInteractionMessage(message), args);
|
||||||
await this.process(message, args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async interactionCreate(interaction: CommandInteraction) {
|
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||||
if (interaction.isCommand()) {
|
await this.run(new HybridInteractionMessage(interaction), interaction.options);
|
||||||
if (typeof interaction.commandName === 'undefined') return;
|
|
||||||
if ((interaction.commandName).toLowerCase() !== 'serviceannouncement') return;
|
|
||||||
await this.process(interaction, interaction.options);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async process(data: Interaction | Message, args: any) {
|
async run(data: HybridInteractionMessage, args: any) {
|
||||||
const isSlashCommand = data instanceof CommandInteraction && data.isCommand();
|
|
||||||
const isMessage = data instanceof Message;
|
|
||||||
|
|
||||||
if (!isSlashCommand && !isMessage) return;
|
if (!Users.isDeveloper(data.getUser()!.id))
|
||||||
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NOT_DEVELOPER(data.getRaw())] });
|
||||||
|
|
||||||
if (!Users.isDeveloper(data.member?.user.id!))
|
const channel = data.getChannel();
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.NOT_DEVELOPER(data)] });
|
if(!channel) return;
|
||||||
|
|
||||||
const funct = {
|
const funct = {
|
||||||
reload: async (data: Message | Interaction) => {
|
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 {
|
||||||
@@ -170,27 +169,27 @@ export default class InteractionManager {
|
|||||||
Announcements = jsonData;
|
Announcements = jsonData;
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
Logger.error("Unable to load custom ServiceAnnouncement config: " + err);
|
Logger.error("Unable to load custom ServiceAnnouncement config: " + err);
|
||||||
return await sendMessage(data.channel!, undefined, { embeds: [EMBEDS.RELOAD_ERROR(data, err)] });
|
return await sendMessage(channel, undefined, { embeds: [EMBEDS.RELOAD_ERROR(data.getRaw(), err)] });
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fs.writeFileSync(path.join(process.cwd(), 'configs/ServiceAnnouncement.json'), JSON.stringify(Announcements, null, 4), 'utf8');
|
fs.writeFileSync(path.join(process.cwd(), 'configs/ServiceAnnouncement.json'), JSON.stringify(Announcements, null, 4), 'utf8');
|
||||||
}
|
}
|
||||||
|
|
||||||
return await sendMessage(data.channel!, undefined, { embeds: [EMBEDS.RELOADED(data)] });
|
return await sendMessage(channel, undefined, { embeds: [EMBEDS.RELOADED(data.getRaw())] });
|
||||||
},
|
},
|
||||||
previewNews: async (data: Message | Interaction) => {
|
previewNews: async (data: HybridInteractionMessage) => {
|
||||||
return await sendMessage(data.channel!, undefined, { embeds: [EMBEDS.MAKE_PAYLOAD(data, Announcements.News)] });
|
return await sendMessage(channel, undefined, { embeds: [EMBEDS.MAKE_PAYLOAD(Announcements.News)] });
|
||||||
},
|
},
|
||||||
previewMaintenance: async (data: Message | Interaction) => {
|
previewMaintenance: async (data: HybridInteractionMessage) => {
|
||||||
return await sendMessage(data.channel!, undefined, { embeds: [EMBEDS.MAKE_PAYLOAD(data, Announcements.Maintenance)] });
|
return await sendMessage(channel, undefined, { embeds: [EMBEDS.MAKE_PAYLOAD(Announcements.Maintenance)] });
|
||||||
},
|
},
|
||||||
previewMessage: async (data: Message | Interaction) => {
|
previewMessage: async (data: HybridInteractionMessage) => {
|
||||||
return await sendMessage(data.channel!, undefined, { embeds: [EMBEDS.MAKE_PAYLOAD(data, Announcements.Message)] });
|
return await sendMessage(channel, undefined, { embeds: [EMBEDS.MAKE_PAYLOAD(Announcements.Message)] });
|
||||||
},
|
},
|
||||||
previewAlert: async (data: Message | Interaction) => {
|
previewAlert: async (data: HybridInteractionMessage) => {
|
||||||
return await sendMessage(data.channel!, undefined, { embeds: [EMBEDS.MAKE_PAYLOAD(data, Announcements.Alert)] });
|
return await sendMessage(channel, undefined, { embeds: [EMBEDS.MAKE_PAYLOAD(Announcements.Alert)] });
|
||||||
},
|
},
|
||||||
publishServiceAnnouncement: async (data: Message | Interaction, embed: any) => {
|
publishServiceAnnouncement: async (data: HybridInteractionMessage, embed: any) => {
|
||||||
const Guilds = await Prisma.client.guild.findMany({});
|
const Guilds = await Prisma.client.guild.findMany({});
|
||||||
const toSend = new Map();
|
const toSend = new Map();
|
||||||
|
|
||||||
@@ -204,7 +203,6 @@ export default class InteractionManager {
|
|||||||
try {
|
try {
|
||||||
channel = await DiscordProvider.client.channels.fetch(Guild.ServiceAnnouncement_Channel) as TextChannel;
|
channel = await DiscordProvider.client.channels.fetch(Guild.ServiceAnnouncement_Channel) as TextChannel;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// TODO: Handle channel not found error
|
|
||||||
withError = true;
|
withError = true;
|
||||||
const guildObject = DiscordProvider.client.guilds.cache.get(Guild.id);
|
const guildObject = DiscordProvider.client.guilds.cache.get(Guild.id);
|
||||||
Logger.warn(`Unable to find channel for Service Announcement to ${guildObject?.name} (${Guild.id}) (Channel ID: ${Guild.ServiceAnnouncement_Channel})`);
|
Logger.warn(`Unable to find channel for Service Announcement to ${guildObject?.name} (${Guild.id}) (Channel ID: ${Guild.ServiceAnnouncement_Channel})`);
|
||||||
@@ -215,7 +213,11 @@ export default class InteractionManager {
|
|||||||
toSend.set(Guild, channel);
|
toSend.set(Guild, channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
let placeholder = await sendMessage(data.channel!, undefined, { embeds: [EMBEDS.SENDING_SERVICE_ANNOUNCEMENT(data)] });
|
let placeholder: (HybridInteractionMessage | undefined);
|
||||||
|
|
||||||
|
let _placeholder = await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SENDING_SERVICE_ANNOUNCEMENT(data.getRaw())] }, true);
|
||||||
|
if (_placeholder)
|
||||||
|
placeholder = new HybridInteractionMessage(_placeholder);
|
||||||
|
|
||||||
await Promise.map(toSend, element => {
|
await Promise.map(toSend, element => {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
@@ -226,7 +228,7 @@ export default class InteractionManager {
|
|||||||
if (!guildObject)
|
if (!guildObject)
|
||||||
throw new Error('Guild not found');
|
throw new Error('Guild not found');
|
||||||
Logger.info(`Sending Service Announcement to ${guildObject?.name} (${guildObject.id}) #${Channel.name} (${Channel.id})`);
|
Logger.info(`Sending Service Announcement to ${guildObject?.name} (${guildObject.id}) #${Channel.name} (${Channel.id})`);
|
||||||
await sendMessage(Channel, undefined, { embeds: [EMBEDS.MAKE_PAYLOAD(data, embed)] })
|
await sendMessage(Channel, undefined, { embeds: [EMBEDS.MAKE_PAYLOAD(embed)] })
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
withError = true;
|
withError = true;
|
||||||
const guildObject = DiscordProvider.client.guilds.cache.get(Guild.id);
|
const guildObject = DiscordProvider.client.guilds.cache.get(Guild.id);
|
||||||
@@ -242,38 +244,34 @@ export default class InteractionManager {
|
|||||||
}, { concurrency: 2 });
|
}, { concurrency: 2 });
|
||||||
|
|
||||||
if (withError) {
|
if (withError) {
|
||||||
if (isMessage)
|
if(data && data.isMessage() && placeholder && placeholder.isMessage())
|
||||||
(placeholder as Message).edit({ embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_SENT_WITH_ERRORS(data)] });
|
return placeholder.getMessage().edit({ embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_SENT_WITH_ERRORS(data.getRaw())] });
|
||||||
else if (isSlashCommand)
|
else if(data.isSlashCommand())
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_SENT_WITH_ERRORS(data)] }, true);
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_SENT_WITH_ERRORS(data.getRaw())] }, true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (isMessage)
|
if(data && data.isMessage() && placeholder && placeholder.isMessage())
|
||||||
(placeholder as Message).edit({ embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_SENT(data)] });
|
return placeholder.getMessage().edit({ embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_SENT(data.getRaw())] });
|
||||||
else if (isSlashCommand)
|
else if(data.isSlashCommand())
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_SENT(data)] }, true);
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_SENT(data.getRaw())] }, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let query;
|
let query;
|
||||||
|
|
||||||
if (isMessage) {
|
if (data.isMessage()) {
|
||||||
if (data === null || !data.guildId || data.member === null || data.guild === null) return;
|
if (args.length === 0)
|
||||||
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.ANNOUNCEMENT_INFO(data.getRaw())] });
|
||||||
if (args.length === 0) {
|
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.ANNOUNCEMENT_INFO(data)] });
|
|
||||||
}
|
|
||||||
query = args[0].toLowerCase();
|
query = args[0].toLowerCase();
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (isSlashCommand) {
|
else if (data.isSlashCommand()) {
|
||||||
query = args.getSubcommand();
|
query = args.getSubcommand();
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (query) {
|
switch (query) {
|
||||||
case "info":
|
case "info":
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.ANNOUNCEMENT_INFO(data)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.ANNOUNCEMENT_INFO(data.getRaw())] });
|
||||||
case "reload":
|
case "reload":
|
||||||
return await funct.reload(data);
|
return await funct.reload(data);
|
||||||
case "previewnews":
|
case "previewnews":
|
||||||
@@ -293,6 +291,5 @@ export default class InteractionManager {
|
|||||||
case "sendalert":
|
case "sendalert":
|
||||||
return await funct.publishServiceAnnouncement(data, Announcements.Alert);
|
return await funct.publishServiceAnnouncement(data, Announcements.Alert);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+42
-48
@@ -1,5 +1,7 @@
|
|||||||
|
import DiscordModule, { HybridInteractionMessage } from "../utils/DiscordModule";
|
||||||
|
|
||||||
import { Message, MessageActionRow, MessageButton, Interaction, CommandInteraction } from "discord.js";
|
import { Message, MessageActionRow, MessageButton, Interaction, CommandInteraction } from "discord.js";
|
||||||
import { makeInfoEmbed, makeErrorEmbed, sendMessageOrInteractionResponse } from "../utils/DiscordMessage";
|
import { makeInfoEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse } from "../utils/DiscordMessage";
|
||||||
import Prisma from "../providers/Prisma";
|
import Prisma from "../providers/Prisma";
|
||||||
import osuAPI from "../providers/osuAPI";
|
import osuAPI from "../providers/osuAPI";
|
||||||
import { countryCodeEmoji } from "country-code-emoji";
|
import { countryCodeEmoji } from "country-code-emoji";
|
||||||
@@ -62,59 +64,49 @@ const EMBEDS = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class osu {
|
export default class osu extends DiscordModule {
|
||||||
|
|
||||||
async onCommand(command: string, args: any, message: Message) {
|
public id = "Discord_osu";
|
||||||
|
public commands = ["osu"];
|
||||||
|
public commandInteractionName = "osu";
|
||||||
|
|
||||||
if(command.toLowerCase() !== 'osu') return;
|
async GuildOnModuleCommand(args: any, message: Message) {
|
||||||
await this.process(message, args);
|
await this.run(new HybridInteractionMessage(message), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
async interactionCreate(interaction: CommandInteraction) {
|
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||||
if(interaction.isCommand()) {
|
await this.run(new HybridInteractionMessage(interaction), interaction.options);
|
||||||
if(typeof interaction.commandName === 'undefined') return;
|
|
||||||
if((interaction.commandName).toLowerCase() !== 'osu') return;
|
|
||||||
await this.process(interaction, interaction.options);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async process(data: Interaction | Message, args: any) {
|
async run(data: HybridInteractionMessage, args: any) {
|
||||||
|
|
||||||
const isSlashCommand = data instanceof CommandInteraction && data.isCommand();
|
|
||||||
const isMessage = data instanceof Message;
|
|
||||||
|
|
||||||
if(!isSlashCommand && !isMessage) return;
|
|
||||||
|
|
||||||
if(data.guild === null || data.guildId === null) return;
|
|
||||||
|
|
||||||
const Guild = await Prisma.client.guild.findFirst({ where: { id: data.guildId }})
|
|
||||||
if(!Guild) throw new Error('TODO: Handle if guild is not found');
|
|
||||||
|
|
||||||
|
const Guild = await Prisma.client.guild.findFirst({ where: { id: data.getGuild()!.id }})
|
||||||
|
if(!Guild) return;
|
||||||
|
|
||||||
const funct = {
|
const funct = {
|
||||||
user: async(data: Message | CommandInteraction) => {
|
user: async(data: HybridInteractionMessage) => {
|
||||||
|
|
||||||
let user;
|
let user;
|
||||||
if(data instanceof Message) {
|
if(data.isMessage()) {
|
||||||
if(typeof args[1] === 'undefined')
|
if(typeof args[1] === 'undefined')
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.NO_USER_MENTIONED(data)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_USER_MENTIONED(data.getRaw())] });
|
||||||
const [removed, ...newArgs] = args;
|
const [removed, ...newArgs] = args;
|
||||||
user = newArgs.join(" ");
|
user = newArgs.join(" ");
|
||||||
}
|
}
|
||||||
else if(data instanceof CommandInteraction)
|
else if(data.isSlashCommand())
|
||||||
user = data.options.getString('user');
|
user = data.getSlashCommand().options.getString('user');
|
||||||
|
|
||||||
|
|
||||||
if(!validator.isNumeric(user) && !this.validate_osu_username(user))
|
if(!validator.isNumeric(user) && !this.validate_osu_username(user))
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.INVALID_USER_MENTIONED(data)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.INVALID_USER_MENTIONED(data.getRaw())] });
|
||||||
|
|
||||||
let result = await osuAPI.client.getUser({ u: user });
|
let result = await osuAPI.client.getUser({ u: user });
|
||||||
|
|
||||||
if(result instanceof Array && result.length === 0)
|
if(result instanceof Array && result.length === 0)
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.NO_USER_FOUND(data)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_USER_FOUND(data.getRaw())] });
|
||||||
|
|
||||||
if(isSlashCommand) {
|
if(data.isSlashCommand()) {
|
||||||
await (data as CommandInteraction).deferReply();
|
await data.getSlashCommand().deferReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
const level = {
|
const level = {
|
||||||
@@ -202,7 +194,7 @@ export default class osu {
|
|||||||
value: `*How about we explore the area ahead of us later?*`
|
value: `*How about we explore the area ahead of us later?*`
|
||||||
}*/
|
}*/
|
||||||
],
|
],
|
||||||
user: (data instanceof Interaction) ? data.user : data.author
|
user: data.getUser()
|
||||||
});
|
});
|
||||||
|
|
||||||
embed.setAuthor(`${result.name}'s osu profile`, 'https://upload.wikimedia.org/wikipedia/commons/4/44/Osu%21Logo_%282019%29.png', `https://osu.ppy.sh/users/${result.id}`);
|
embed.setAuthor(`${result.name}'s osu profile`, 'https://upload.wikimedia.org/wikipedia/commons/4/44/Osu%21Logo_%282019%29.png', `https://osu.ppy.sh/users/${result.id}`);
|
||||||
@@ -218,32 +210,31 @@ export default class osu {
|
|||||||
.setStyle('LINK'),
|
.setStyle('LINK'),
|
||||||
)
|
)
|
||||||
|
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [embed], components: [row] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [embed], components: [row] });
|
||||||
},
|
},
|
||||||
beatmap: async(data: Message | CommandInteraction) => {
|
beatmap: async(data: HybridInteractionMessage) => {
|
||||||
|
|
||||||
let beatmap;
|
let beatmap;
|
||||||
if(data instanceof Message) {
|
if(data.isMessage()) {
|
||||||
if(typeof args[1] === 'undefined')
|
if(typeof args[1] === 'undefined')
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.NO_BEATMAP_MENTIONED(data)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_BEATMAP_MENTIONED(data.getRaw())] });
|
||||||
const [removed, ...newArgs] = args;
|
const [removed, ...newArgs] = args;
|
||||||
beatmap = newArgs.join(" ");
|
beatmap = newArgs.join(" ");
|
||||||
}
|
}
|
||||||
else if(data instanceof CommandInteraction)
|
else if(data.isSlashCommand())
|
||||||
beatmap = data.options.getString('beatmap');
|
beatmap = data.getSlashCommand().options.getString('beatmap');
|
||||||
|
|
||||||
|
|
||||||
if(!validator.isNumeric(beatmap))
|
if(!validator.isNumeric(beatmap))
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.INVALID_BEATMAP_ID_MENTIONED(data)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.INVALID_BEATMAP_ID_MENTIONED(data.getRaw())] });
|
||||||
|
|
||||||
let result = await osuAPI.client.getBeatmaps({ b: beatmap });
|
let result = await osuAPI.client.getBeatmaps({ b: beatmap });
|
||||||
|
|
||||||
if(result instanceof Array && result.length === 0)
|
if(result instanceof Array && result.length === 0)
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.NO_BEATMAP_FOUND(data)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_BEATMAP_FOUND(data.getRaw())] });
|
||||||
|
|
||||||
if(isSlashCommand) {
|
if(data.isSlashCommand())
|
||||||
await (data as CommandInteraction).deferReply();
|
await data.getSlashCommand().deferReply();
|
||||||
}
|
|
||||||
|
|
||||||
const bm_result = result[0];
|
const bm_result = result[0];
|
||||||
|
|
||||||
@@ -359,7 +350,7 @@ export default class osu {
|
|||||||
value: `\`\`${bm_result.tags.join(" ")}\`\``,
|
value: `\`\`${bm_result.tags.join(" ")}\`\``,
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
user: (data instanceof Interaction) ? data.user : data.author
|
user: data.getUser()
|
||||||
});
|
});
|
||||||
|
|
||||||
embed2.setAuthor(`osu! beatmap`, 'https://upload.wikimedia.org/wikipedia/commons/4/44/Osu%21Logo_%282019%29.png', `https://osu.ppy.sh/beatmapsets/${bm_result.beatmapSetId}${url_mode}/${bm_result.id}`);
|
embed2.setAuthor(`osu! beatmap`, 'https://upload.wikimedia.org/wikipedia/commons/4/44/Osu%21Logo_%282019%29.png', `https://osu.ppy.sh/beatmapsets/${bm_result.beatmapSetId}${url_mode}/${bm_result.id}`);
|
||||||
@@ -389,19 +380,19 @@ export default class osu {
|
|||||||
.setStyle('LINK'),
|
.setStyle('LINK'),
|
||||||
)
|
)
|
||||||
|
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [embed2], components: [row] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [embed2], components: [row] });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let query;
|
let query;
|
||||||
|
|
||||||
if(isMessage) {
|
if(data.isMessage()) {
|
||||||
if(args.length === 0) {
|
if(args.length === 0) {
|
||||||
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.osu_INFO(data)] });
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.osu_INFO(data.getRaw())] });
|
||||||
}
|
}
|
||||||
query = args[0].toLowerCase();
|
query = args[0].toLowerCase();
|
||||||
}
|
}
|
||||||
else if(isSlashCommand) {
|
else if(data.isSlashCommand()) {
|
||||||
query = args.getSubcommand();
|
query = args.getSubcommand();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -415,6 +406,7 @@ export default class osu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private numberWithCommas(x: Number) {
|
private numberWithCommas(x: Number) {
|
||||||
try {
|
try {
|
||||||
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
||||||
@@ -422,6 +414,7 @@ export default class osu {
|
|||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Criteria from https://github.com/ppy/osu-web/blob/9de00a0b874c56893d98261d558d78d76259d81b/app/Libraries/UsernameValidation.php
|
// Criteria from https://github.com/ppy/osu-web/blob/9de00a0b874c56893d98261d558d78d76259d81b/app/Libraries/UsernameValidation.php
|
||||||
private validate_osu_username(username: string) {
|
private validate_osu_username(username: string) {
|
||||||
|
|
||||||
@@ -442,4 +435,5 @@ export default class osu {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+84
-65
@@ -1,4 +1,5 @@
|
|||||||
import {Client, Guild, GuildMember, Intents, Interaction, Message, TextChannel} from "discord.js";
|
import { Guild, Client, GuildMember, Intents, Interaction, Message, TextChannel} from "discord.js";
|
||||||
|
import { Guild as GuildPrisma } from ".prisma/client";
|
||||||
|
|
||||||
import Logger from "../libs/Logger";
|
import Logger from "../libs/Logger";
|
||||||
import Environment from "./Environment";
|
import Environment from "./Environment";
|
||||||
@@ -21,117 +22,136 @@ import Discord_MusicPlayer_Join from "../discord/MusicPlayer/Join";
|
|||||||
import Discord_MusicPlayer_Leave from "../discord/MusicPlayer/Leave";
|
import Discord_MusicPlayer_Leave from "../discord/MusicPlayer/Leave";
|
||||||
import Discord_MusicPlayer_Queue from "../discord/MusicPlayer/Queue";
|
import Discord_MusicPlayer_Queue from "../discord/MusicPlayer/Queue";
|
||||||
import Discord_MusicPlayer_Search from "../discord/MusicPlayer/Search";
|
import Discord_MusicPlayer_Search from "../discord/MusicPlayer/Search";
|
||||||
import Discord_MusicPlayer_Search_NowPlaying from "../discord/MusicPlayer/NowPlaying";
|
import Discord_MusicPlayer_NowPlaying from "../discord/MusicPlayer/NowPlaying";
|
||||||
|
|
||||||
import Discord_Developer_ServiceAnnouncement from "../discord/developer/ServiceAnnouncement";
|
import Discord_Developer_ServiceAnnouncement from "../discord/developer/ServiceAnnouncement";
|
||||||
import Discord_Developer_FakeError from "../discord/developer/FakeError";
|
import Discord_Developer_FakeError from "../discord/developer/FakeError";
|
||||||
|
|
||||||
import Cache from "./Cache";
|
import Cache from "./Cache";
|
||||||
|
import DiscordModule from "../utils/DiscordModule";
|
||||||
|
import { Map } from "typescript";
|
||||||
|
|
||||||
class Discord {
|
class Discord {
|
||||||
|
|
||||||
public client: Client;
|
public client: Client;
|
||||||
private loaded_module: any;
|
private loaded_module = new Map<string, DiscordModule>();
|
||||||
|
|
||||||
constructor () {
|
constructor () {
|
||||||
this.client = new Client({
|
this.client = new Client({
|
||||||
//partials: ['MESSAGE', 'CHANNEL', 'REACTION'],
|
//partials: ['MESSAGE', 'CHANNEL', 'REACTION'],
|
||||||
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MEMBERS, Intents.FLAGS.GUILD_PRESENCES, Intents.FLAGS.GUILD_VOICE_STATES]
|
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MEMBERS, Intents.FLAGS.GUILD_PRESENCES, Intents.FLAGS.GUILD_VOICE_STATES]
|
||||||
});
|
});
|
||||||
this.loaded_module = {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public init(): void {
|
public init(): void {
|
||||||
|
|
||||||
Logger.info('Logging in to discord');
|
Logger.info('Logging in to discord');
|
||||||
this.client.login(Environment.get().DISCORD_TOKEN);
|
this.client.login(Environment.get().DISCORD_TOKEN);
|
||||||
|
|
||||||
|
const modules: DiscordModule[] = [
|
||||||
|
new Discord_Core(),
|
||||||
|
new Discord_Help(),
|
||||||
|
new Discord_Invite(),
|
||||||
|
new Discord_Ping(),
|
||||||
|
new Discord_Stats(),
|
||||||
|
new Discord_UserInfo(),
|
||||||
|
new Discord_Say(),
|
||||||
|
new Discord_InteractionManager(),
|
||||||
|
new Discord_osu(),
|
||||||
|
new Discord_Settings(),
|
||||||
|
|
||||||
// TODO: Improve this
|
new Discord_MusicPlayer_Play(),
|
||||||
this.loaded_module["Core"] = new Discord_Core();
|
new Discord_MusicPlayer_NowPlaying(),
|
||||||
this.loaded_module["Discord_Settings"] = new Discord_Settings();
|
new Discord_MusicPlayer_Skip(),
|
||||||
this.loaded_module["Discord_Ping"] = new Discord_Ping();
|
new Discord_MusicPlayer_Join(),
|
||||||
this.loaded_module["Discord_Help"] = new Discord_Help();
|
new Discord_MusicPlayer_Leave(),
|
||||||
this.loaded_module["Discord_Invite"] = new Discord_Invite();
|
new Discord_MusicPlayer_Queue(),
|
||||||
this.loaded_module["Discord_InteractionManager"] = new Discord_InteractionManager();
|
new Discord_MusicPlayer_Search(),
|
||||||
this.loaded_module["Discord_Say"] = new Discord_Say();
|
|
||||||
this.loaded_module["Discord_osu"] = new Discord_osu();
|
|
||||||
this.loaded_module["Discord_UserInfo"] = new Discord_UserInfo();
|
|
||||||
this.loaded_module["Discord_Stats"] = new Discord_Stats();
|
|
||||||
|
|
||||||
this.loaded_module["Discord_MusicPlayer_Play"] = new Discord_MusicPlayer_Play();
|
new Discord_MembershipScreening(),
|
||||||
this.loaded_module["Discord_MusicPlayer_Skip"] = new Discord_MusicPlayer_Skip();
|
|
||||||
this.loaded_module["Discord_MusicPlayer_Join"] = new Discord_MusicPlayer_Join();
|
|
||||||
this.loaded_module["Discord_MusicPlayer_Leave"] = new Discord_MusicPlayer_Leave();
|
|
||||||
this.loaded_module["Discord_MusicPlayer_Queue"] = new Discord_MusicPlayer_Queue();
|
|
||||||
this.loaded_module["Discord_MusicPlayer_Search"] = new Discord_MusicPlayer_Search();
|
|
||||||
this.loaded_module["Discord_MusicPlayer_Search_NowPlaying"] = new Discord_MusicPlayer_Search_NowPlaying();
|
|
||||||
|
|
||||||
this.loaded_module["MembershipScreening"] = new Discord_MembershipScreening();
|
new Discord_Developer_ServiceAnnouncement(),
|
||||||
|
new Discord_Developer_FakeError()
|
||||||
|
];
|
||||||
|
|
||||||
this.loaded_module["Discord_Developer_ServiceAnnouncement"] = new Discord_Developer_ServiceAnnouncement();
|
for(const _module of modules) {
|
||||||
this.loaded_module["Discord_Developer_FakeError"] = new Discord_Developer_FakeError();
|
if(_module.id) {
|
||||||
|
if(this.loaded_module.has(_module.id))
|
||||||
|
Logger.error(`Module ${_module.constructor.name} is trying to assign a conflicting module id ${_module.id}. ${this.loaded_module.get(_module.id)!.constructor.name} is already assigned to this id.`);
|
||||||
|
else
|
||||||
|
this.loaded_module.set(_module.id, _module);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Logger.error(`Invalid module ${_module.constructor.name}. The module does not have an id.`);
|
||||||
|
}
|
||||||
|
|
||||||
for(const module in this.loaded_module) {
|
Logger.info(`Loaded ${this.loaded_module.size} Discord Modules`);
|
||||||
let thisModule = this.loaded_module[module];
|
|
||||||
|
|
||||||
if (typeof thisModule.init === "function")
|
for(const module of this.loaded_module) {
|
||||||
thisModule.init();
|
let thisModule: DiscordModule = module[1];
|
||||||
|
thisModule.Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
// On bot logged in
|
// On bot logged in
|
||||||
this.client.on("ready", () => {
|
this.client.on("ready", () => {
|
||||||
for(const module in this.loaded_module) {
|
for(const module of this.loaded_module) {
|
||||||
let thisModule = this.loaded_module[module];
|
let thisModule: DiscordModule = module[1];
|
||||||
|
thisModule.Ready();
|
||||||
if (typeof thisModule.ready === "function")
|
|
||||||
thisModule.ready();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Member join guild event to modules
|
// Member join guild event to modules
|
||||||
this.client.on("guildMemberAdd", (member: GuildMember) => {
|
this.client.on("guildMemberAdd", (member: GuildMember) => {
|
||||||
for(const module in this.loaded_module) {
|
for(const module of this.loaded_module) {
|
||||||
let thisModule = this.loaded_module[module];
|
let thisModule: DiscordModule = module[1];
|
||||||
|
thisModule.GuildMemberAdd(member);
|
||||||
if (typeof thisModule.guildMemberAdd === "function")
|
|
||||||
thisModule.guildMemberAdd(member);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Interaction create event to modules
|
// Interaction create event to modules
|
||||||
this.client.on("interactionCreate", (interaction: Interaction) => {
|
this.client.on("interactionCreate", (interaction: Interaction) => {
|
||||||
for(const module in this.loaded_module) {
|
for(const module of this.loaded_module) {
|
||||||
let thisModule = this.loaded_module[module];
|
let thisModule: DiscordModule = module[1];
|
||||||
|
|
||||||
if (typeof thisModule.interactionCreate === "function")
|
if(interaction.guild) {
|
||||||
thisModule.interactionCreate(interaction);
|
thisModule.GuildInteractionCreate(interaction);
|
||||||
|
|
||||||
|
if(interaction.isCommand() && interaction.commandName && thisModule.commandInteractionName) {
|
||||||
|
thisModule.GuildCommandInteractionCreate(interaction);
|
||||||
|
if(interaction.commandName.toLowerCase() === thisModule.commandInteractionName)
|
||||||
|
thisModule.GuildModuleCommandInteractionCreate(interaction);
|
||||||
|
}
|
||||||
|
else if(interaction.isButton()) {
|
||||||
|
thisModule.GuildButtonInteractionCreate(interaction);
|
||||||
|
}
|
||||||
|
else if(interaction.isSelectMenu()) {
|
||||||
|
thisModule.GuildSelectMenuInteractionCreate(interaction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//thisModule.InteractionCreate(interaction);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Message create event to modules
|
// Message create event to modules
|
||||||
this.client.on("messageCreate", (message: Message) => {
|
this.client.on("messageCreate", (message: Message) => {
|
||||||
for(const module in this.loaded_module) {
|
for(const module of this.loaded_module) {
|
||||||
let thisModule = this.loaded_module[module];
|
let thisModule: DiscordModule = module[1];
|
||||||
|
thisModule.GuildMessageCreate(message);
|
||||||
if (typeof thisModule.messageCreate === "function")
|
|
||||||
thisModule.messageCreate(message);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Joined guild event to modules
|
// Joined guild event to modules
|
||||||
this.client.on("guildCreate", (guild : Guild) => {
|
this.client.on("guildCreate", (guild: Guild) => {
|
||||||
for(const module in this.loaded_module) {
|
for(const module of this.loaded_module) {
|
||||||
let thisModule = this.loaded_module[module];
|
let thisModule: DiscordModule = module[1];
|
||||||
|
thisModule.GuildCreate(guild);
|
||||||
if (typeof thisModule.guildCreate === "function")
|
|
||||||
thisModule.guildCreate(guild);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Handling commands
|
// Handling guild commands
|
||||||
this.client.on("messageCreate", async (message: Message) => {
|
this.client.on("messageCreate", async (message: Message) => {
|
||||||
|
|
||||||
// TODO: Handle DMs commands soon
|
|
||||||
if(!(message.channel instanceof TextChannel)) return;
|
if(!(message.channel instanceof TextChannel)) 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;
|
||||||
@@ -196,11 +216,12 @@ class Discord {
|
|||||||
if(args.length === 0)
|
if(args.length === 0)
|
||||||
args = [];
|
args = [];
|
||||||
|
|
||||||
for(const module in this.loaded_module) {
|
for(const module of this.loaded_module) {
|
||||||
let thisModule = this.loaded_module[module];
|
let thisModule: DiscordModule = module[1];
|
||||||
|
thisModule.GuildOnCommand(command, args, message);
|
||||||
|
|
||||||
if (typeof thisModule.onCommand === "function")
|
if(thisModule.commands && thisModule.commands.includes(command))
|
||||||
thisModule.onCommand(command, args, message);
|
thisModule.GuildOnModuleCommand(args, message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -227,11 +248,9 @@ class Discord {
|
|||||||
if(args.length === 0)
|
if(args.length === 0)
|
||||||
args = [];
|
args = [];
|
||||||
|
|
||||||
for(const module in this.loaded_module) {
|
for(const module of this.loaded_module) {
|
||||||
let thisModule = this.loaded_module[module];
|
let thisModule = module[1];
|
||||||
|
thisModule.GuildOnCommand(command, args, message);
|
||||||
if (typeof thisModule.onCommand === "function")
|
|
||||||
thisModule.onCommand(command, args, message);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { MessageEmbed, User, MessagePayload, MessageOptions, GuildTextBasedChannel, TextChannel, DMChannel, PartialDMChannel, BaseGuildTextChannel, Message, ColorResolvable, Interaction, InteractionReplyOptions } from "discord.js";
|
import { MessageEmbed, User, MessagePayload, MessageOptions, GuildTextBasedChannel, TextChannel, DMChannel, PartialDMChannel, BaseGuildTextChannel, Message, ColorResolvable, Interaction, InteractionReplyOptions } from "discord.js";
|
||||||
import App from "..";
|
import App from "..";
|
||||||
import Logger from "../libs/Logger";
|
import Logger from "../libs/Logger";
|
||||||
|
import { HybridInteractionMessage } from "./DiscordModule";
|
||||||
|
|
||||||
const emotes = {
|
const emotes = {
|
||||||
"yumiloading": "<a:yumiloading:887350424938627173>"
|
"yumiloading": "<a:yumiloading:887350424938627173>"
|
||||||
@@ -136,6 +137,50 @@ export async function sendMessageOrInteractionResponse(data: Message | Interacti
|
|||||||
else if(isMessage) return await sendReply(data, payload);
|
else if(isMessage) return await sendReply(data, payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function sendHybridInteractionMessageResponse(data: HybridInteractionMessage, payload: MessageOptions | InteractionReplyOptions, replace = false): (Promise<Message | Interaction | undefined>) {
|
||||||
|
|
||||||
|
if(data.isSlashCommand() || data.isButton() || data.isSelectMenu()) {
|
||||||
|
|
||||||
|
const messageComponent = data.getMessageComponentInteraction();
|
||||||
|
|
||||||
|
if(!messageComponent.replied) {
|
||||||
|
let message;
|
||||||
|
try {
|
||||||
|
if(!messageComponent.deferred) {
|
||||||
|
await messageComponent.reply(payload);
|
||||||
|
return messageComponent;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
await messageComponent.editReply(payload);
|
||||||
|
return messageComponent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(errorDM) {
|
||||||
|
Logger.error(`Cannot find available destinations to send the message CID: ${messageComponent.channel!.id} UID: ${messageComponent.user.id} DM_ERR: ${errorDM}`);
|
||||||
|
return;
|
||||||
|
} finally {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
let message;
|
||||||
|
try {
|
||||||
|
if(replace)
|
||||||
|
return (await messageComponent.editReply(payload) as Message);
|
||||||
|
else
|
||||||
|
return (await messageComponent.followUp(payload) as Message);
|
||||||
|
}
|
||||||
|
catch(errorDM) {
|
||||||
|
Logger.error(`Cannot find available destinations to send the message CID: ${messageComponent.channel!.id} UID: ${messageComponent.user.id} DM_ERR: ${errorDM}`);
|
||||||
|
return;
|
||||||
|
} finally {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(data.isMessage()) return await sendReply(data.getMessage(), payload);
|
||||||
|
}
|
||||||
|
|
||||||
export function getEmotes() {
|
export function getEmotes() {
|
||||||
return emotes;
|
return emotes;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,120 @@
|
|||||||
|
import { Guild, Interaction, Message, GuildMember, CommandInteraction, ButtonInteraction, TextBasedChannel, MessageComponentInteraction, User, SelectMenuInteraction } from "discord.js";
|
||||||
|
|
||||||
|
export default class DiscordModule {
|
||||||
|
|
||||||
|
public id?: string;
|
||||||
|
public commands?: (string[] | null) = null;
|
||||||
|
public commandInteractionName?: (string | null) = null;
|
||||||
|
|
||||||
|
constructor({ id, command, commandInteractionName }: {
|
||||||
|
id?: string,
|
||||||
|
command?: (string[] | null),
|
||||||
|
commandInteractionName?: (string | null)
|
||||||
|
} = {}) {
|
||||||
|
this.id = id;
|
||||||
|
this.commands = command;
|
||||||
|
this.commandInteractionName = commandInteractionName;
|
||||||
|
}
|
||||||
|
|
||||||
|
Init(): (void | Promise<void | any>) {}
|
||||||
|
Ready(): (void | Promise<void | any>) {}
|
||||||
|
|
||||||
|
GuildOnCommand(command: string, args: any, message: Message): (void | Promise<void | any>) {}
|
||||||
|
GuildOnModuleCommand(args: any, message: Message): (void | Promise<void | any>) {}
|
||||||
|
|
||||||
|
GuildInteractionCreate(interaction: Interaction): (void | Promise<void | any>) {}
|
||||||
|
GuildModuleInteractionCreate(interaction: Interaction): (void | Promise<void | any>) {}
|
||||||
|
|
||||||
|
GuildCommandInteractionCreate(interaction: CommandInteraction): (void | Promise<void | any>) {}
|
||||||
|
GuildModuleCommandInteractionCreate(interaction: CommandInteraction): (void | Promise<void | any>) {}
|
||||||
|
|
||||||
|
GuildSelectMenuInteractionCreate(interaction: SelectMenuInteraction): (void | Promise<void | any>) {}
|
||||||
|
|
||||||
|
GuildButtonInteractionCreate(interaction: ButtonInteraction): (void | Promise<void | any>) {}
|
||||||
|
|
||||||
|
GuildCreate(guild: Guild): (void | Promise<void | any>) {}
|
||||||
|
GuildMemberAdd(member: GuildMember): (void | Promise<void | any>) {}
|
||||||
|
GuildMessageCreate(message: Message): (void | Promise<void | any>) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class HybridInteractionMessage {
|
||||||
|
public data: Interaction | Message;
|
||||||
|
constructor (data: Interaction | Message) {
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public isInteraction(): boolean {
|
||||||
|
return this.data instanceof Interaction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public isSlashCommand(): boolean {
|
||||||
|
return this.data instanceof CommandInteraction && this.data.isCommand();
|
||||||
|
}
|
||||||
|
|
||||||
|
public isButton(): boolean {
|
||||||
|
return this.data instanceof ButtonInteraction && this.data.isButton();
|
||||||
|
}
|
||||||
|
|
||||||
|
public isSelectMenu(): boolean {
|
||||||
|
return this.data instanceof SelectMenuInteraction && this.data.isSelectMenu();
|
||||||
|
}
|
||||||
|
|
||||||
|
public isMessage(): boolean {
|
||||||
|
return this.data instanceof Message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getChannel(): (TextBasedChannel | null) {
|
||||||
|
return this.data.channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getGuild(): (Guild | null) {
|
||||||
|
return this.data.guild;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getUser(): (User | null) {
|
||||||
|
return (this.isInteraction()) ? this.getInteraction().user : this.getMessage().author
|
||||||
|
}
|
||||||
|
|
||||||
|
public getMember(): (GuildMember | null) {
|
||||||
|
return (this.data.member as GuildMember);
|
||||||
|
}
|
||||||
|
|
||||||
|
public getInteraction(): Interaction {
|
||||||
|
if(this.isMessage())
|
||||||
|
throw new Error("Unable to cast interaction to message");
|
||||||
|
|
||||||
|
return this.data as Interaction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getSlashCommand(): CommandInteraction {
|
||||||
|
if(this.isInteraction() && !(this.data as CommandInteraction))
|
||||||
|
throw new Error("Unable to cast to MessageComponentInteraction");
|
||||||
|
|
||||||
|
return this.data as CommandInteraction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getSelectMenu(): SelectMenuInteraction {
|
||||||
|
if(this.isInteraction() && !(this.data as SelectMenuInteraction))
|
||||||
|
throw new Error("Unable to cast to SelectMenuInteraction");
|
||||||
|
|
||||||
|
return this.data as SelectMenuInteraction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getMessageComponentInteraction(): MessageComponentInteraction {
|
||||||
|
if(this.isInteraction() && !(this.data as MessageComponentInteraction))
|
||||||
|
throw new Error("Unable to cast to MessageComponentInteraction");
|
||||||
|
|
||||||
|
return this.data as MessageComponentInteraction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getMessage(): Message {
|
||||||
|
if(this.isInteraction())
|
||||||
|
throw new Error("Unable to cast message to interaction");
|
||||||
|
|
||||||
|
return this.data as Message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getRaw(): (Interaction | Message) {
|
||||||
|
return this.data;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user