mirror of
https://github.com/kirameki-cafe/Yumi.git
synced 2026-09-13 18:59:19 +00:00
Better interaction
This commit is contained in:
+62
-29
@@ -1,52 +1,85 @@
|
|||||||
import { Message, Permissions, CommandInteraction } from "discord.js";
|
import { Message, Permissions, Interaction, CommandInteraction } from "discord.js";
|
||||||
import { getEmotes, makeSuccessEmbed, makeProcessingEmbed, sendMessage, sendReply, makeErrorEmbed } from "../utils/DiscordMessage";
|
import { getEmotes, makeSuccessEmbed, makeProcessingEmbed, sendMessageOrInteractionResponse, sendReply, makeErrorEmbed, makeInfoEmbed } from "../utils/DiscordMessage";
|
||||||
import DiscordProvider from "../providers/Discord";
|
import DiscordProvider from "../providers/Discord";
|
||||||
|
|
||||||
|
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
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default class Say {
|
export default class Say {
|
||||||
|
|
||||||
async onCommand(command: string, args: any, message: Message) {
|
async onCommand(command: string, args: any, message: Message) {
|
||||||
if(command.toLowerCase() !== 'say') return;
|
if(command.toLowerCase() !== 'say') return;
|
||||||
|
await this.process(message, args);
|
||||||
if(!message.guildId) return;
|
|
||||||
if(message.member === null) return;
|
|
||||||
if(message.guild === null) return;
|
|
||||||
|
|
||||||
await this.sendSayMessage(false, message, args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async interactionCreate(interaction: CommandInteraction) {
|
async interactionCreate(interaction: CommandInteraction) {
|
||||||
|
if(interaction.isCommand()) {
|
||||||
if(typeof interaction.commandName === 'undefined') return;
|
if(typeof interaction.commandName === 'undefined') return;
|
||||||
if((interaction.commandName).toLowerCase() !== 'say') return;
|
if((interaction.commandName).toLowerCase() !== 'say') return;
|
||||||
await this.sendSayMessage(true, interaction, interaction.options.getString('message'));
|
await this.process(interaction, interaction.options);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async sendSayMessage(isSlashCommand: boolean, data: any, args: any) {
|
async process(data: Interaction | Message, args: any) {
|
||||||
|
const isSlashCommand = data instanceof CommandInteraction && data.isCommand();
|
||||||
|
const isMessage = data instanceof Message;
|
||||||
|
|
||||||
|
if(!isSlashCommand && !isMessage) return;
|
||||||
|
|
||||||
|
let query;
|
||||||
|
|
||||||
|
if(isMessage) {
|
||||||
|
if(data === null || !data.guildId || data.member === null || data.guild === null) return;
|
||||||
if (!data.member.permissions.has([Permissions.FLAGS.VIEW_CHANNEL, Permissions.FLAGS.SEND_MESSAGES, Permissions.FLAGS.MANAGE_CHANNELS]))
|
if (!data.member.permissions.has([Permissions.FLAGS.VIEW_CHANNEL, Permissions.FLAGS.SEND_MESSAGES, Permissions.FLAGS.MANAGE_CHANNELS]))
|
||||||
return await sendReply(data, {
|
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.NO_PERMISSION(data)] });
|
||||||
embeds: [makeErrorEmbed ({
|
|
||||||
title: 'You need ``VIEW_CHANNEL, SEND_MESSAGES and MANAGE_CHANNELS`` permission on this guild!',
|
|
||||||
user: isSlashCommand ? data.user : data.author
|
|
||||||
})]
|
|
||||||
});
|
|
||||||
|
|
||||||
|
if(args.length === 0) {
|
||||||
|
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.SAY_INFO(data)] });
|
||||||
|
}
|
||||||
|
query = args.join(" ");
|
||||||
|
|
||||||
if(args.length === 0)
|
}
|
||||||
return await sendReply(data, {
|
else if(isSlashCommand) {
|
||||||
embeds: [makeErrorEmbed({
|
if(!data.guild!.members.cache.get(data.user.id)?.permissions.has([Permissions.FLAGS.ADMINISTRATOR]))
|
||||||
title: `No message defined`,
|
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.NO_PERMISSION(data)] });
|
||||||
user: isSlashCommand ? data.user : data.author
|
|
||||||
})]
|
query = data.options.getString('message');
|
||||||
});
|
}
|
||||||
|
|
||||||
if(isSlashCommand) {
|
if(isSlashCommand) {
|
||||||
await data.channel.send({ content: args });
|
await data.channel!.send({ content: query });
|
||||||
await data.reply({ ephemeral: true, embeds: [makeSuccessEmbed({
|
await data.reply({ ephemeral: true, embeds: [EMBEDS.SUCCESSFULLY_SAID(data)] });
|
||||||
title: `Successfully said`,
|
|
||||||
user: isSlashCommand ? data.user : data.author
|
|
||||||
})] });
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
await data.channel.send({ content: args.join(" ") });
|
if(data.deletable)
|
||||||
|
await data.delete();
|
||||||
|
|
||||||
|
await data.channel.send({ content: query });
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user