vylbot-app/src/events/MessageEvents/MessageUpdate.ts
Vylpes e6c845e3b2
Some checks failed
continuous-integration/drone/push Build is failing
Switch to TypeORM's DataSource API (#299)
- Switch to TypeORM's DataSource API, rather than using the now deprecated ormconfig.json
- This will fix stage deployment not knowing how to deploy the database migrations

#297

> **NOTE:** This change requires the deployment scripts to be updated, please update them on the server before merging

Co-authored-by: Ethan Lane <ethan@vylpes.com>
Reviewed-on: https://gitea.vylpes.xyz/RabbitLabs/vylbot-app/pulls/299
2023-05-26 17:59:22 +01:00

49 lines
1.8 KiB
TypeScript

import { EmbedBuilder, Message, TextChannel } from "discord.js";
import EmbedColours from "../../constants/EmbedColours";
import IgnoredChannel from "../../database/entities/IgnoredChannel";
import SettingsHelper from "../../helpers/SettingsHelper";
export default async function MessageUpdate(oldMessage: Message, newMessage: Message) {
if (!newMessage.guild) return;
if (newMessage.author.bot) return;
if (oldMessage.content == newMessage.content) return;
const enabled = await SettingsHelper.GetSetting("event.message.update.enabled", newMessage.guild.id);
if (!enabled || enabled.toLowerCase() != "true") return;
const ignored = await IgnoredChannel.IsChannelIgnored(newMessage.channel.id);
if (ignored) return;
const embed = new EmbedBuilder()
.setColor(EmbedColours.Ok)
.setTitle("Message Edited")
.setDescription(`${newMessage.author} \`${newMessage.author.tag}\``)
.setThumbnail(newMessage.author.avatarURL())
.addFields([
{
name: "Channel",
value: newMessage.channel.toString(),
inline: true,
},
{
name: "Before",
value: `\`\`\`${oldMessage.content || "*none*"}\`\`\``,
},
{
name: "After",
value: `\`\`\`${newMessage.content || "*none*"}\`\`\``,
}
]);
const channelSetting = await SettingsHelper.GetSetting("event.message.delete.channel", newMessage.guild.id);
if (!channelSetting) return;
const channel = newMessage.guild.channels.cache.find(x => x.name == channelSetting);
if (!channel) return;
const guildChannel = channel as TextChannel;
await guildChannel.send({ embeds: [ embed ]});
}