mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-11 12:55:01 +00:00
Migrate Logs to new Plugin structure, also dont ignore it
This commit is contained in:
parent
140ba84544
commit
aea019181c
16 changed files with 764 additions and 1 deletions
41
backend/src/plugins/Logs/util/onMessageDelete.ts
Normal file
41
backend/src/plugins/Logs/util/onMessageDelete.ts
Normal file
|
@ -0,0 +1,41 @@
|
|||
import { SavedMessage } from "src/data/entities/SavedMessage";
|
||||
import { Attachment } from "eris";
|
||||
import { useMediaUrls, stripObjectToScalars, resolveUser } from "src/utils";
|
||||
import { LogType } from "src/data/LogType";
|
||||
import moment from "moment-timezone";
|
||||
import { PluginData } from "knub";
|
||||
import { LogsPluginType } from "../types";
|
||||
|
||||
export async function onMessageDelete(pluginData: PluginData<LogsPluginType>, savedMessage: SavedMessage) {
|
||||
const user = await resolveUser(pluginData.client, savedMessage.user_id);
|
||||
const channel = pluginData.guild.channels.get(savedMessage.channel_id);
|
||||
|
||||
if (user) {
|
||||
// Replace attachment URLs with media URLs
|
||||
if (savedMessage.data.attachments) {
|
||||
for (const attachment of savedMessage.data.attachments as Attachment[]) {
|
||||
attachment.url = useMediaUrls(attachment.url);
|
||||
}
|
||||
}
|
||||
|
||||
pluginData.state.guildLogs.log(
|
||||
LogType.MESSAGE_DELETE,
|
||||
{
|
||||
user: stripObjectToScalars(user),
|
||||
channel: stripObjectToScalars(channel),
|
||||
messageDate: moment(savedMessage.data.timestamp, "x").format(pluginData.config.get().format.timestamp),
|
||||
message: savedMessage,
|
||||
},
|
||||
savedMessage.id,
|
||||
);
|
||||
} else {
|
||||
pluginData.state.guildLogs.log(
|
||||
LogType.MESSAGE_DELETE_BARE,
|
||||
{
|
||||
messageId: savedMessage.id,
|
||||
channel: stripObjectToScalars(channel),
|
||||
},
|
||||
savedMessage.id,
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue