parent
985db250d9
commit
52c1420508
|
@ -61,6 +61,29 @@ export default new NamedCommand({
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
|
messageembeds: new NamedCommand({
|
||||||
|
description: "Enable or disable sending message previews.",
|
||||||
|
usage: "enable/disable",
|
||||||
|
run: "Please specify `enable` or `disable`.",
|
||||||
|
subcommands: {
|
||||||
|
true: new NamedCommand({
|
||||||
|
description: "Enable sending of message previews.",
|
||||||
|
async run({send, guild}) {
|
||||||
|
Storage.getGuild(guild!.id).messageEmbeds = true;
|
||||||
|
Storage.save();
|
||||||
|
send("Sending of message previews has been enabled.");
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
false: new NamedCommand({
|
||||||
|
description: "Disable sending of message previews.",
|
||||||
|
async run({send, guild}) {
|
||||||
|
Storage.getGuild(guild!.id).messageEmbeds = false;
|
||||||
|
Storage.save();
|
||||||
|
send("Sending of message previews has been disabled.");
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}),
|
||||||
autoroles: new NamedCommand({
|
autoroles: new NamedCommand({
|
||||||
description: "Configure your server's autoroles.",
|
description: "Configure your server's autoroles.",
|
||||||
usage: "<roles...>",
|
usage: "<roles...>",
|
||||||
|
|
|
@ -2,50 +2,55 @@ import {client} from "../index";
|
||||||
import {MessageEmbed} from "discord.js";
|
import {MessageEmbed} from "discord.js";
|
||||||
import {getPrefix} from "../structures";
|
import {getPrefix} from "../structures";
|
||||||
import {getMessageByID} from "onion-lasers";
|
import {getMessageByID} from "onion-lasers";
|
||||||
|
import {Storage} from "../structures";
|
||||||
|
|
||||||
client.on("message", async (message) => {
|
client.on("message", async (message) => {
|
||||||
// Only execute if the message is from a user and isn't a command.
|
const {messageEmbeds} = Storage.getGuild(message.guild!.id);
|
||||||
if (message.content.startsWith(getPrefix(message.guild)) || message.author.bot) return;
|
|
||||||
const messageLink = extractFirstMessageLink(message.content);
|
|
||||||
if (!messageLink) return;
|
|
||||||
const [guildID, channelID, messageID] = messageLink;
|
|
||||||
|
|
||||||
const linkMessage = await getMessageByID(channelID, messageID);
|
if (messageEmbeds) {
|
||||||
|
// Only execute if the message is from a user and isn't a command.
|
||||||
|
if (message.content.startsWith(getPrefix(message.guild)) || message.author.bot) return;
|
||||||
|
const messageLink = extractFirstMessageLink(message.content);
|
||||||
|
if (!messageLink) return;
|
||||||
|
const [guildID, channelID, messageID] = messageLink;
|
||||||
|
|
||||||
// If it's an invalid link (or the bot doesn't have access to it).
|
const linkMessage = await getMessageByID(channelID, messageID);
|
||||||
if (typeof linkMessage === "string") {
|
|
||||||
return message.channel.send("I don't have access to that channel!");
|
|
||||||
}
|
|
||||||
|
|
||||||
const embeds = [
|
// If it's an invalid link (or the bot doesn't have access to it).
|
||||||
...linkMessage.embeds.filter((embed) => embed.type === "rich"),
|
if (typeof linkMessage === "string") {
|
||||||
...linkMessage.attachments.values()
|
return message.channel.send("I don't have access to that channel!");
|
||||||
];
|
}
|
||||||
|
|
||||||
if (!linkMessage.cleanContent && embeds.length === 0) {
|
const embeds = [
|
||||||
return message.channel.send(new MessageEmbed().setDescription("🚫 The message is empty."));
|
...linkMessage.embeds.filter((embed) => embed.type === "rich"),
|
||||||
}
|
...linkMessage.attachments.values()
|
||||||
|
];
|
||||||
|
|
||||||
if (linkMessage.cleanContent.length > 2048) {
|
if (!linkMessage.cleanContent && embeds.length === 0) {
|
||||||
return message.channel.send(new MessageEmbed().setDescription("🚫 This message is too long."));
|
return message.channel.send(new MessageEmbed().setDescription("🚫 The message is empty."));
|
||||||
}
|
}
|
||||||
|
|
||||||
const infoEmbed = new MessageEmbed()
|
if (linkMessage.cleanContent.length > 2048) {
|
||||||
.setAuthor(
|
return message.channel.send(new MessageEmbed().setDescription("🚫 This message is too long."));
|
||||||
linkMessage.author.username,
|
}
|
||||||
linkMessage.author.displayAvatarURL({format: "png", dynamic: true, size: 4096})
|
|
||||||
)
|
|
||||||
.setTimestamp(linkMessage.createdTimestamp)
|
|
||||||
.setDescription(
|
|
||||||
`${linkMessage.cleanContent}\n\nSent in **${linkMessage.guild?.name}** | <#${linkMessage.channel.id}> ([link](https://discord.com/channels/${guildID}/${channelID}/${messageID}))`
|
|
||||||
);
|
|
||||||
|
|
||||||
if (linkMessage.attachments.size !== 0) {
|
const infoEmbed = new MessageEmbed()
|
||||||
const image = linkMessage.attachments.first();
|
.setAuthor(
|
||||||
infoEmbed.setImage(image!.url);
|
linkMessage.author.username,
|
||||||
}
|
linkMessage.author.displayAvatarURL({format: "png", dynamic: true, size: 4096})
|
||||||
|
)
|
||||||
|
.setTimestamp(linkMessage.createdTimestamp)
|
||||||
|
.setDescription(
|
||||||
|
`${linkMessage.cleanContent}\n\nSent in **${linkMessage.guild?.name}** | <#${linkMessage.channel.id}> ([link](https://discord.com/channels/${guildID}/${channelID}/${messageID}))`
|
||||||
|
);
|
||||||
|
|
||||||
return await message.channel.send(infoEmbed);
|
if (linkMessage.attachments.size !== 0) {
|
||||||
|
const image = linkMessage.attachments.first();
|
||||||
|
infoEmbed.setImage(image!.url);
|
||||||
|
}
|
||||||
|
|
||||||
|
return await message.channel.send(infoEmbed);
|
||||||
|
} else return;
|
||||||
});
|
});
|
||||||
|
|
||||||
export function extractFirstMessageLink(message: string): [string, string, string] | null {
|
export function extractFirstMessageLink(message: string): [string, string, string] | null {
|
||||||
|
|
|
@ -79,6 +79,7 @@ class Member {
|
||||||
|
|
||||||
class Guild {
|
class Guild {
|
||||||
public prefix: string | null;
|
public prefix: string | null;
|
||||||
|
public messageEmbeds: boolean | null;
|
||||||
public welcomeType: "none" | "text" | "graphical";
|
public welcomeType: "none" | "text" | "graphical";
|
||||||
public welcomeChannel: string | null;
|
public welcomeChannel: string | null;
|
||||||
public welcomeMessage: string | null;
|
public welcomeMessage: string | null;
|
||||||
|
@ -90,6 +91,7 @@ class Guild {
|
||||||
|
|
||||||
constructor(data?: GenericJSON) {
|
constructor(data?: GenericJSON) {
|
||||||
this.prefix = select(data?.prefix, null, String);
|
this.prefix = select(data?.prefix, null, String);
|
||||||
|
this.messageEmbeds = select(data?.messageLinks, true, Boolean);
|
||||||
this.welcomeChannel = select(data?.welcomeChannel, null, String);
|
this.welcomeChannel = select(data?.welcomeChannel, null, String);
|
||||||
this.welcomeMessage = select(data?.welcomeMessage, null, String);
|
this.welcomeMessage = select(data?.welcomeMessage, null, String);
|
||||||
this.autoRoles = select(data?.autoRoles, null, String, true);
|
this.autoRoles = select(data?.autoRoles, null, String, true);
|
||||||
|
|
Loading…
Reference in New Issue