Updated import
This commit is contained in:
75
src/commands/snipe.ts
Normal file
75
src/commands/snipe.ts
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
import { GuildMember, SlashCommandBuilder } from "discord.js"
|
||||||
|
import snipeCacheSchema from "../schemas/snipeCacheSchema"
|
||||||
|
import Command from "../interfaces/Command"
|
||||||
|
import { color } from "../../config/options.json"
|
||||||
|
import { SnipeCache } from "../utils/Types"
|
||||||
|
|
||||||
|
export = {
|
||||||
|
name: "snipe",
|
||||||
|
description: "Snipes the last deleted message of a user",
|
||||||
|
type: "slash",
|
||||||
|
public: true,
|
||||||
|
dev: false,
|
||||||
|
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName("snipe")
|
||||||
|
.setDescription("Snipes the last deleted message of a user")
|
||||||
|
.addUserOption(option =>
|
||||||
|
option
|
||||||
|
.setName("user")
|
||||||
|
.setDescription("The user to snipe")
|
||||||
|
.setRequired(true))
|
||||||
|
.setDMPermission(false),
|
||||||
|
|
||||||
|
async execute(interaction) {
|
||||||
|
await interaction.deferReply()
|
||||||
|
const member = interaction.options.getMember("user") as GuildMember
|
||||||
|
const snipeCache = await snipeCacheSchema.find({
|
||||||
|
userid: member.user.id,
|
||||||
|
channelid: interaction.channel!.id
|
||||||
|
})
|
||||||
|
const embedColor = Number(color.replace("#", "0x"))
|
||||||
|
const messages: string[] = []
|
||||||
|
|
||||||
|
if (!snipeCache.length) {
|
||||||
|
await interaction.editReply({
|
||||||
|
embeds: [{
|
||||||
|
description: "No messages to snipe",
|
||||||
|
color: embedColor
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let i = 1
|
||||||
|
for (const msg of snipeCache) {
|
||||||
|
const data: SnipeCache = msg.data
|
||||||
|
if (!data.attachments.length) {
|
||||||
|
messages.push(`**Message #${i}:** ${data.content}\n`)
|
||||||
|
} else {
|
||||||
|
messages.push(`**Message #${i}:** ${data.content}`)
|
||||||
|
messages.push(`**Attachments:** ${data.attachments.join(", ")}\n`)
|
||||||
|
}
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
|
||||||
|
await interaction.editReply({
|
||||||
|
embeds: [{
|
||||||
|
author: {
|
||||||
|
name: member.user.username,
|
||||||
|
icon_url: member.user.avatarURL() || undefined
|
||||||
|
},
|
||||||
|
description: messages.join("\n"),
|
||||||
|
thumbnail: {
|
||||||
|
url: member.user.avatarURL() || ""
|
||||||
|
},
|
||||||
|
color: embedColor,
|
||||||
|
footer: {
|
||||||
|
text: "ID: " + member.user.id,
|
||||||
|
icon_url: interaction.guild!.iconURL() || undefined
|
||||||
|
},
|
||||||
|
timestamp: new Date().toISOString()
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} as Command
|
||||||
37
src/events/server/messages/snipecache.ts
Normal file
37
src/events/server/messages/snipecache.ts
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import { ChannelType, Message } from "discord.js"
|
||||||
|
import { Event } from "../../../interfaces"
|
||||||
|
import snipeCacheSchema from "../../../schemas/snipeCacheSchema"
|
||||||
|
import mongoose from "mongoose"
|
||||||
|
import { SnipeCache } from "../../../utils/Types"
|
||||||
|
import env from "../../../utils/Env"
|
||||||
|
|
||||||
|
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
|
||||||
|
if (message.author.id !== env.prod.dev) 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
|
||||||
11
src/schemas/snipeCacheSchema.ts
Normal file
11
src/schemas/snipeCacheSchema.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import { model, Schema } from "mongoose"
|
||||||
|
|
||||||
|
const snipeCacheSchema = new Schema({
|
||||||
|
_id: Schema.Types.ObjectId,
|
||||||
|
userid: { type: String, required: true },
|
||||||
|
channelid: { type: String, required: true },
|
||||||
|
data: { type: Object, required: true },
|
||||||
|
date: { type: Date, default: Date.now(), expires: 600 }
|
||||||
|
})
|
||||||
|
|
||||||
|
export default model("snipeCache", snipeCacheSchema, "snipeCache")
|
||||||
@@ -5,7 +5,7 @@ import { Button } from "../interfaces"
|
|||||||
import { Modal } from "../interfaces"
|
import { Modal } from "../interfaces"
|
||||||
import { Autocomplete } from "../interfaces"
|
import { Autocomplete } from "../interfaces"
|
||||||
import env from "./Env"
|
import env from "./Env"
|
||||||
import { autoDeployCommands } from "./Autodeploy"
|
import autoDeployCommands from "./Autodeploy"
|
||||||
import { loadAllEvents } from "./Events"
|
import { loadAllEvents } from "./Events"
|
||||||
|
|
||||||
export class ExtendedClient extends Client {
|
export class ExtendedClient extends Client {
|
||||||
|
|||||||
8
src/utils/Types.ts
Normal file
8
src/utils/Types.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
export type SnipeCache = {
|
||||||
|
author: string
|
||||||
|
content: string
|
||||||
|
channel: string
|
||||||
|
createdAt: number
|
||||||
|
deletedAt: number
|
||||||
|
attachments: string[]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user