Files
illegitimate-bot/src/events/server/messages/snipecache.ts
2024-01-15 11:00:11 +01:00

35 lines
1.0 KiB
TypeScript

import { ChannelType, Message } from "discord.js"
import { Event } from "interfaces"
import snipeCacheSchema from "schemas/snipeCacheSchema"
import mongoose from "mongoose"
import { SnipeCache } from "typings"
export = {
name: "snipecache",
description: "Logs messages for the snipe command",
type: "event",
event: "messageDelete",
async execute(message: Message) {
if (message.channel.type !== ChannelType.GuildText) return
if (message.author.bot) return
const msg: SnipeCache = {
author: message.author.id,
content: message.content,
channel: message.channel.id,
createdAt: message.createdTimestamp,
deletedAt: Date.now(),
attachments: message.attachments.map(a => a.url) || [],
}
const snipeCache = new snipeCacheSchema({
_id: new mongoose.Types.ObjectId,
userid: message.author.id,
channelid: message.channel.id,
data: msg,
})
await snipeCache.save()
}
} as Event