2022-06-06 14:59:53 +07:00
|
|
|
import { Message, Permissions, Interaction, CommandInteraction } from 'discord.js';
|
2022-03-03 20:56:49 +07:00
|
|
|
|
2022-06-06 14:59:53 +07:00
|
|
|
import DiscordModule, { HybridInteractionMessage } from '../utils/DiscordModule';
|
|
|
|
|
import {
|
|
|
|
|
makeSuccessEmbed,
|
|
|
|
|
sendHybridInteractionMessageResponse,
|
|
|
|
|
makeErrorEmbed,
|
|
|
|
|
makeInfoEmbed
|
|
|
|
|
} from '../utils/DiscordMessage';
|
2021-09-15 04:10:42 -07:00
|
|
|
|
2021-09-19 04:02:50 -07:00
|
|
|
const EMBEDS = {
|
|
|
|
|
SAY_INFO: (data: Message | Interaction) => {
|
2022-06-06 14:59:53 +07:00
|
|
|
return makeInfoEmbed({
|
2021-09-19 04:02:50 -07:00
|
|
|
title: 'Say',
|
|
|
|
|
description: `Make me say something!`,
|
|
|
|
|
fields: [
|
|
|
|
|
{
|
|
|
|
|
name: 'Available arguments',
|
|
|
|
|
value: '``Your message``'
|
|
|
|
|
}
|
|
|
|
|
],
|
2022-06-06 14:59:53 +07:00
|
|
|
user: data instanceof Interaction ? data.user : data.author
|
2021-09-19 04:02:50 -07:00
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
NO_PERMISSION: (data: Message | Interaction) => {
|
2022-06-06 14:59:53 +07:00
|
|
|
return makeErrorEmbed({
|
2021-09-19 04:02:50 -07:00
|
|
|
title: 'You need ``VIEW_CHANNEL, SEND_MESSAGES and MANAGE_CHANNELS`` permission on this guild!',
|
2022-06-06 14:59:53 +07:00
|
|
|
user: data instanceof Interaction ? data.user : data.author
|
2021-09-19 04:02:50 -07:00
|
|
|
});
|
|
|
|
|
},
|
2022-06-06 15:13:14 +07:00
|
|
|
SAY_ERROR: (data: Message | Interaction, error: any) => {
|
|
|
|
|
return makeErrorEmbed({
|
|
|
|
|
title: `Unable to say`,
|
|
|
|
|
description: error.message,
|
|
|
|
|
user: data instanceof Interaction ? data.user : data.author
|
|
|
|
|
});
|
|
|
|
|
},
|
2021-09-19 04:02:50 -07:00
|
|
|
SUCCESSFULLY_SAID: (data: Message | Interaction) => {
|
2022-06-06 14:59:53 +07:00
|
|
|
return makeSuccessEmbed({
|
2021-09-19 04:02:50 -07:00
|
|
|
title: 'Successfully said',
|
2022-06-06 14:59:53 +07:00
|
|
|
user: data instanceof Interaction ? data.user : data.author
|
2021-09-19 04:02:50 -07:00
|
|
|
});
|
|
|
|
|
}
|
2022-06-06 14:59:53 +07:00
|
|
|
};
|
2021-09-19 04:02:50 -07:00
|
|
|
|
2022-03-03 20:56:49 +07:00
|
|
|
export default class Say extends DiscordModule {
|
2022-06-06 14:59:53 +07:00
|
|
|
public id = 'Discord_Say';
|
|
|
|
|
public commands = ['say'];
|
|
|
|
|
public commandInteractionName = 'say';
|
2022-03-03 20:56:49 +07:00
|
|
|
|
|
|
|
|
async GuildOnModuleCommand(args: any, message: Message) {
|
|
|
|
|
await this.run(new HybridInteractionMessage(message), args);
|
2021-09-17 05:21:01 -07:00
|
|
|
}
|
|
|
|
|
|
2022-06-06 14:59:53 +07:00
|
|
|
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
2022-03-03 20:56:49 +07:00
|
|
|
await this.run(new HybridInteractionMessage(interaction), interaction.options);
|
2021-09-17 05:21:01 -07:00
|
|
|
}
|
|
|
|
|
|
2022-03-03 20:56:49 +07:00
|
|
|
async run(data: HybridInteractionMessage, args: any) {
|
2021-09-19 04:02:50 -07:00
|
|
|
let query;
|
2021-09-15 04:10:42 -07:00
|
|
|
|
2022-06-06 14:59:53 +07:00
|
|
|
if (data.isMessage()) {
|
2022-03-03 20:56:49 +07:00
|
|
|
const message = data.getMessage();
|
|
|
|
|
|
2022-06-06 14:59:53 +07:00
|
|
|
if (!message.member) return;
|
2022-03-03 20:56:49 +07:00
|
|
|
|
2022-06-06 14:59:53 +07:00
|
|
|
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())]
|
|
|
|
|
});
|
2022-03-03 20:56:49 +07:00
|
|
|
|
2022-06-06 14:59:53 +07:00
|
|
|
if (args.length === 0)
|
|
|
|
|
return await sendHybridInteractionMessageResponse(data, {
|
|
|
|
|
embeds: [EMBEDS.SAY_INFO(data.getRaw())]
|
|
|
|
|
});
|
2021-09-17 05:21:01 -07:00
|
|
|
|
2022-06-06 14:59:53 +07:00
|
|
|
query = args.join(' ');
|
|
|
|
|
} else if (data.isSlashCommand()) {
|
2022-03-03 20:56:49 +07:00
|
|
|
const interaction = data.getSlashCommand();
|
2022-06-06 14:59:53 +07:00
|
|
|
if (
|
|
|
|
|
!data
|
|
|
|
|
.getGuild()!
|
|
|
|
|
.members.cache.get(interaction.user.id)
|
|
|
|
|
?.permissions.has([Permissions.FLAGS.ADMINISTRATOR])
|
|
|
|
|
)
|
|
|
|
|
return await sendHybridInteractionMessageResponse(data, {
|
|
|
|
|
embeds: [EMBEDS.NO_PERMISSION(data.getRaw())]
|
|
|
|
|
});
|
2021-09-19 04:02:50 -07:00
|
|
|
|
2022-03-03 20:56:49 +07:00
|
|
|
query = interaction.options.getString('message');
|
2021-09-19 04:02:50 -07:00
|
|
|
}
|
2021-09-15 04:10:42 -07:00
|
|
|
|
2022-06-06 14:59:53 +07:00
|
|
|
if (data.isSlashCommand() && data.getChannel()) {
|
2022-06-06 15:13:14 +07:00
|
|
|
try {
|
|
|
|
|
await data.getChannel()!.send({ content: query });
|
|
|
|
|
await data
|
|
|
|
|
.getMessageComponentInteraction()
|
|
|
|
|
.reply({ ephemeral: true, embeds: [EMBEDS.SUCCESSFULLY_SAID(data.getRaw())] });
|
|
|
|
|
} catch (err: any) {
|
|
|
|
|
return await sendHybridInteractionMessageResponse(data, {
|
|
|
|
|
embeds: [EMBEDS.SAY_ERROR(data.getRaw(), err)]
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-06-06 14:59:53 +07:00
|
|
|
} else if (data.isMessage()) {
|
2022-03-03 20:56:49 +07:00
|
|
|
const message = data.getMessage();
|
2022-06-06 14:59:53 +07:00
|
|
|
if (message.deletable) await message.delete();
|
2021-09-19 04:02:50 -07:00
|
|
|
|
2022-06-06 15:13:14 +07:00
|
|
|
try {
|
|
|
|
|
await data.getChannel()!.send({ content: query });
|
|
|
|
|
} catch (err: any) {
|
|
|
|
|
return await sendHybridInteractionMessageResponse(data, {
|
|
|
|
|
embeds: [EMBEDS.SAY_ERROR(data.getRaw(), err)]
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-09-17 05:21:01 -07:00
|
|
|
}
|
2021-09-15 04:10:42 -07:00
|
|
|
}
|
2022-06-06 14:59:53 +07:00
|
|
|
}
|