add discord 'Message Info' context menu entry
This commit is contained in:
parent
ccb652f737
commit
755609901c
1 changed files with 134 additions and 50 deletions
|
@ -3,13 +3,16 @@
|
|||
import { client } from "./client";
|
||||
import { REST } from '@discordjs/rest';
|
||||
import { Routes } from 'discord-api-types/v9';
|
||||
import { BRIDGE_CONFIG, BRIDGE_REQUESTS, logger } from "..";
|
||||
import { TextChannel } from "discord.js";
|
||||
import { BRIDGED_MESSAGES, BRIDGE_CONFIG, BRIDGE_REQUESTS, logger } from "..";
|
||||
import { MessageEmbed, TextChannel } from "discord.js";
|
||||
import { revoltFetchMessage, revoltFetchUser } from "../util";
|
||||
import { client as revoltClient } from "../revolt/client";
|
||||
|
||||
const COMMANDS: any[] = [
|
||||
{
|
||||
name: 'bridge',
|
||||
description: 'Confirm or delete Revolt bridges',
|
||||
type: 1, // Slash command
|
||||
options: [
|
||||
{
|
||||
name: 'confirm',
|
||||
|
@ -30,6 +33,11 @@ const COMMANDS: any[] = [
|
|||
type: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'Message Info',
|
||||
description: '',
|
||||
type: 3, // Message context menu
|
||||
}
|
||||
];
|
||||
|
||||
|
@ -59,8 +67,7 @@ client.once('ready', async () => {
|
|||
|
||||
client.on('interactionCreate', async interaction => {
|
||||
try {
|
||||
if (!interaction.isCommand()) return;
|
||||
|
||||
if (interaction.isCommand()) {
|
||||
logger.debug(`Command received: /${interaction.commandName}`);
|
||||
|
||||
// The revolutionary Jan command handler
|
||||
|
@ -117,6 +124,83 @@ client.on('interactionCreate', async interaction => {
|
|||
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (interaction.isMessageContextMenu()) {
|
||||
logger.debug(`Received context menu: ${interaction.targetMessage.id}`);
|
||||
|
||||
switch(interaction.commandName) {
|
||||
case 'Message Info':
|
||||
const message = interaction.targetMessage;
|
||||
const bridgeInfo = await BRIDGED_MESSAGES.findOne({ "discord.messageId": message.id });
|
||||
const messageUrl = `https://discord.com/channels/${interaction.guildId}/${interaction.channelId}/${message.id}`;
|
||||
|
||||
if (!bridgeInfo) return await interaction.reply({
|
||||
ephemeral: true,
|
||||
embeds: [
|
||||
new MessageEmbed()
|
||||
.setAuthor({ name: 'Message info', url: messageUrl })
|
||||
.setDescription('This message has not been bridged.')
|
||||
.setColor('#7e96ff'),
|
||||
],
|
||||
});
|
||||
else {
|
||||
const embed = new MessageEmbed();
|
||||
|
||||
embed.setColor('#7e96ff');
|
||||
embed.setAuthor({ name: 'Message info', url: messageUrl });
|
||||
|
||||
embed.addField('Origin', bridgeInfo.origin == 'discord' ? 'Discord' : 'Revolt', true);
|
||||
|
||||
if (bridgeInfo.origin == 'discord') {
|
||||
embed.addField(
|
||||
'Bridge Status',
|
||||
bridgeInfo.revolt.messageId
|
||||
? 'Bridged'
|
||||
: bridgeInfo.revolt.nonce
|
||||
? 'ID unknown'
|
||||
: 'Unbridged',
|
||||
true
|
||||
);
|
||||
} else {
|
||||
embed.addField(
|
||||
'Bridge Status',
|
||||
bridgeInfo.discord.messageId
|
||||
? 'Bridged'
|
||||
: 'Unbridged',
|
||||
true
|
||||
);
|
||||
|
||||
if (bridgeInfo.channels?.revolt) {
|
||||
const channel = await revoltClient.channels.get(bridgeInfo.channels.revolt);
|
||||
const revoltMsg = await revoltFetchMessage(bridgeInfo.revolt.messageId, channel);
|
||||
|
||||
if (revoltMsg) {
|
||||
const author = await revoltFetchUser(revoltMsg.author_id);
|
||||
embed.addField(
|
||||
'Message Author',
|
||||
`**@${author?.username}** (${revoltMsg.author_id})`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
embed.addField(
|
||||
'Bridge Data',
|
||||
`Origin: \`${bridgeInfo.origin}\`\n` +
|
||||
`Discord ID: \`${bridgeInfo.discord.messageId}\`\n` +
|
||||
`Revolt ID: \`${bridgeInfo.revolt.messageId}\`\n` +
|
||||
`Revolt Nonce: \`${bridgeInfo.revolt.nonce}\`\n` +
|
||||
`Discord Channel: \`${bridgeInfo.channels?.discord}\`\n` +
|
||||
`Revolt Channel: \`${bridgeInfo.channels?.revolt}\``
|
||||
);
|
||||
|
||||
return await interaction.reply({
|
||||
ephemeral: true,
|
||||
embeds: [ embed ],
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch(e) {
|
||||
console.error(e);
|
||||
if (interaction.isCommand()) interaction.reply('An error has occurred: ' + e).catch(() => {});
|
||||
|
|
Loading…
Reference in a new issue