Merge branch 'main' of https://github.com/pandaninjas/bot into main
This commit is contained in:
commit
5181e31012
2 changed files with 21 additions and 10 deletions
|
@ -10,14 +10,14 @@ import { reuploadCommands } from './_reupload';
|
|||
import * as BuildConfig from './constants';
|
||||
import { parseLog } from './logs';
|
||||
import { getLatestMinecraftVersion } from './utils/remoteVersions';
|
||||
import { expandDiscordLink } from "./utils/resolveMessage";
|
||||
import { expandDiscordLink } from './utils/resolveMessage';
|
||||
|
||||
import { membersCommand } from './commands/members';
|
||||
import { starsCommand } from './commands/stars';
|
||||
import { modrinthCommand } from './commands/modrinth';
|
||||
import { tagsCommand } from './commands/tags';
|
||||
import { jokeCommand } from './commands/joke';
|
||||
import { roryCommand } from "./commands/rory";
|
||||
import { roryCommand } from './commands/rory';
|
||||
|
||||
import random from 'just-random';
|
||||
import { green, bold, yellow, cyan } from 'kleur/colors';
|
||||
|
@ -122,7 +122,7 @@ client.on('interactionCreate', async (interaction) => {
|
|||
await tagsCommand(interaction);
|
||||
} else if (commandName === 'joke') {
|
||||
await jokeCommand(interaction);
|
||||
} else if (commandName === "rory") {
|
||||
} else if (commandName === 'rory') {
|
||||
await roryCommand(interaction);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,11 +6,11 @@ import {
|
|||
EmbedBuilder,
|
||||
type Message,
|
||||
ThreadChannel,
|
||||
} from "discord.js";
|
||||
} from 'discord.js';
|
||||
|
||||
function findFirstImage(message: Message): string | undefined {
|
||||
const result = message.attachments.find((attach) => {
|
||||
return attach.contentType?.startsWith("image/");
|
||||
return attach.contentType?.startsWith('image/');
|
||||
});
|
||||
if (result == undefined) {
|
||||
return undefined;
|
||||
|
@ -23,16 +23,20 @@ export async function expandDiscordLink(message: Message): Promise<void> {
|
|||
const re =
|
||||
/(https?:\/\/)?(?:canary\.|ptb\.)?discord(?:app)?\.com\/channels\/(?<server_id>\d+)\/(?<channel_id>\d+)\/(?<message_id>\d+)/g;
|
||||
let execResult = re.exec(message.content);
|
||||
|
||||
while (!(execResult == null || execResult.groups == undefined)) {
|
||||
if (execResult.groups.server_id != message.guildId) {
|
||||
continue; // do not let the bot leak messages from one server to another
|
||||
}
|
||||
|
||||
const channel = await message.guild?.channels.fetch(
|
||||
execResult.groups.channel_id
|
||||
);
|
||||
|
||||
if (channel == undefined || channel == null || !channel.isTextBased()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (channel instanceof ThreadChannel) {
|
||||
if (
|
||||
!channel.parent?.members?.some((user) => user.id == message.author.id)
|
||||
|
@ -44,10 +48,12 @@ export async function expandDiscordLink(message: Message): Promise<void> {
|
|||
continue; // do not reveal a message to a user who can't see it
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const messageToShow = await channel.messages.fetch(
|
||||
execResult.groups.message_id
|
||||
);
|
||||
|
||||
const builder = new EmbedBuilder()
|
||||
.setAuthor({
|
||||
name: `${messageToShow.author.username}#${messageToShow.author.discriminator}`,
|
||||
|
@ -58,27 +64,32 @@ export async function expandDiscordLink(message: Message): Promise<void> {
|
|||
builder.setDescription(messageToShow.content);
|
||||
}
|
||||
if (messageToShow.attachments.size > 0) {
|
||||
let attachmentsString = "";
|
||||
let attachmentsString = '';
|
||||
messageToShow.attachments.forEach((value) => {
|
||||
attachmentsString += `[${value.name}](${value.url}) `;
|
||||
});
|
||||
builder.addFields({ name: "Attachments", value: attachmentsString });
|
||||
|
||||
builder.addFields({ name: 'Attachments', value: attachmentsString });
|
||||
|
||||
const firstImage = findFirstImage(messageToShow);
|
||||
if (firstImage != undefined) {
|
||||
builder.setImage(firstImage);
|
||||
}
|
||||
}
|
||||
const row = new ActionRowBuilder().addComponents(
|
||||
|
||||
const row = new ActionRowBuilder<ButtonBuilder>().addComponents(
|
||||
new ButtonBuilder()
|
||||
.setLabel("Jump to original message")
|
||||
.setLabel('Jump to original message')
|
||||
.setStyle(ButtonStyle.Link)
|
||||
.setURL(messageToShow.url)
|
||||
);
|
||||
message.channel.send({ embeds: [builder], components: [row] });
|
||||
|
||||
await message.channel.send({ embeds: [builder], components: [row] });
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
continue;
|
||||
}
|
||||
|
||||
execResult = re.exec(message.content);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue