Partial Message Action Support
This commit is contained in:
parent
8e48a44946
commit
7a88d053e1
19
src/index.js
19
src/index.js
|
@ -44,6 +44,24 @@ async function initMessageManager(database) {
|
|||
|
||||
database.build();
|
||||
|
||||
client.on(Events.InteractionCreate , (interaction) => {
|
||||
require("./messageManager/messageActionManager")(database,client , (fun) => {
|
||||
if(interaction.isButton()){
|
||||
if(interaction.customId == "DELETE_MESSAGE"){
|
||||
fun.find_uuid(interaction.message.id, interaction.member.id ,(uuid) => {
|
||||
if(uuid == null){
|
||||
interaction.reply({ content: "Access Denied", ephemeral: true });
|
||||
return;
|
||||
}
|
||||
fun.delete(uuid);
|
||||
|
||||
interaction.reply({ content: "Message Deleted Successfull!", ephemeral: true });
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
require("./messageManager/messageManager")(database , client);
|
||||
}
|
||||
|
||||
|
@ -79,6 +97,7 @@ client.once(Events.ClientReady, readyClient => {
|
|||
}
|
||||
|
||||
client.on(Events.InteractionCreate, async interaction => {
|
||||
|
||||
if (!interaction.isChatInputCommand()) return;
|
||||
|
||||
const command = interaction.client.commands.get(interaction.commandName);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const { Client } = require("discord.js");
|
||||
const { Client, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require("discord.js");
|
||||
const Message = require("../../Message");
|
||||
const { EmbedBuilder } = require("@discordjs/builders");
|
||||
|
||||
|
@ -21,13 +21,23 @@ const send = (message, database, channelId , uuid , discord) => {
|
|||
text: message.serverName,
|
||||
iconURL: message.serverIcon || discord.user.displayAvatarURL()
|
||||
})
|
||||
],
|
||||
components: [
|
||||
new ActionRowBuilder()
|
||||
.addComponents(
|
||||
new ButtonBuilder()
|
||||
.setCustomId("DELETE_MESSAGE")
|
||||
.setLabel("Delete")
|
||||
.setEmoji('🗑')
|
||||
.setStyle(ButtonStyle.Secondary)
|
||||
)
|
||||
]
|
||||
}).catch((error) => {
|
||||
console.log(`Unable to Send Message to Channel [${channelId}]`);
|
||||
}).then((_message) => {
|
||||
database.insert("xan.messageDelivery" ,{
|
||||
channelId: channelId,
|
||||
messageId : _message.id,
|
||||
channelId: _message.channelId,
|
||||
messageId : `${_message.id}`,
|
||||
client: "discord",
|
||||
link: uuid
|
||||
}, (uuid) => {});
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
const { Client, Events } = require("discord.js");
|
||||
const Message = require("./Message");
|
||||
const discordSend = require("./client/discord/send");
|
||||
const { data } = require("../commands/servers/setup");
|
||||
/**
|
||||
*
|
||||
* @param {Client} discord
|
||||
*/
|
||||
const actionMessageManager = async (
|
||||
database,
|
||||
discord,
|
||||
callback
|
||||
) => {
|
||||
var d_data = {
|
||||
find_uuid: (messageId, authorId , cb) => {
|
||||
database.search("xan.messageDelivery" , { messageId: messageId } , (dataUid) => {
|
||||
database.search("xan.messages" , { uuid: dataUid.link } , (data) => {
|
||||
if(data.authorId.toString() == authorId.toString()){
|
||||
cb(dataUid.link);
|
||||
}else{
|
||||
cb(null)
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
|
||||
delete: (uuid) => {
|
||||
database.list("xan.messageDelivery", {
|
||||
link: uuid
|
||||
} , (data) => {
|
||||
for(var message of data) {
|
||||
discord.channels.fetch(message['channelId']).then((channel) => {
|
||||
channel.messages.delete(message['messageId']).catch(e => {
|
||||
console.error(e);
|
||||
console.log(`Unable to Delete Message from ${channel.name} in ${channel.guild.name}`);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
callback(d_data);
|
||||
};
|
||||
|
||||
module.exports = actionMessageManager;
|
|
@ -13,7 +13,6 @@ const initMessageManager = async (
|
|||
function postMessage(message, uuid){
|
||||
database.list("xan.guilds" , {} , (list) => {
|
||||
for(var element of list){
|
||||
|
||||
if(element.client == "discord") discordSend(message , database , element.channelId ,uuid , discord);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue