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