3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-13 13:25:03 +00:00

Typed log functions + more

This commit is contained in:
Dragory 2021-08-18 01:51:42 +03:00
parent d2ac700143
commit bed6589d48
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
166 changed files with 4021 additions and 869 deletions

View file

@ -1,51 +1,33 @@
import { MessageAttachment, Snowflake } from "discord.js";
import { BaseGuildTextChannel, Snowflake, ThreadChannel } from "discord.js";
import { GuildPluginData } from "knub";
import moment from "moment-timezone";
import { channelToConfigAccessibleChannel, userToConfigAccessibleUser } from "../../../utils/configAccessibleObjects";
import { SavedMessage } from "../../../data/entities/SavedMessage";
import { LogType } from "../../../data/LogType";
import { resolveUser, useMediaUrls } from "../../../utils";
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
import { FORMAT_NO_TIMESTAMP, LogsPluginType } from "../types";
import { resolveUser } from "../../../utils";
import { LogsPluginType } from "../types";
import { logMessageDelete } from "../logFunctions/logMessageDelete";
import { isLogIgnored } from "./isLogIgnored";
import { logMessageDeleteBare } from "../logFunctions/logMessageDeleteBare";
export async function onMessageDelete(pluginData: GuildPluginData<LogsPluginType>, savedMessage: SavedMessage) {
const user = await resolveUser(pluginData.client, savedMessage.user_id);
const channel = pluginData.guild.channels.resolve(savedMessage.channel_id as Snowflake)!;
const channel = pluginData.guild.channels.resolve(savedMessage.channel_id as Snowflake)! as
| BaseGuildTextChannel
| ThreadChannel;
if (isLogIgnored(pluginData, LogType.MESSAGE_DELETE, savedMessage.id)) {
return;
}
if (user) {
// Replace attachment URLs with media URLs
if (savedMessage.data.attachments) {
for (const attachment of savedMessage.data.attachments as MessageAttachment[]) {
attachment.url = useMediaUrls(attachment.url);
}
}
// See comment on FORMAT_NO_TIMESTAMP in types.ts
const config = pluginData.config.get();
const timestampFormat =
(config.format.timestamp !== FORMAT_NO_TIMESTAMP ? config.format.timestamp : null) ?? config.timestamp_format;
pluginData.state.guildLogs.log(
LogType.MESSAGE_DELETE,
{
user: userToConfigAccessibleUser(user),
channel: channelToConfigAccessibleChannel(channel),
messageDate: pluginData
.getPlugin(TimeAndDatePlugin)
.inGuildTz(moment.utc(savedMessage.data.timestamp, "x"))
.format(timestampFormat),
message: savedMessage,
},
savedMessage.id,
);
logMessageDelete(pluginData, {
user,
channel,
message: savedMessage,
});
} else {
pluginData.state.guildLogs.log(
LogType.MESSAGE_DELETE_BARE,
{
messageId: savedMessage.id,
channel: channelToConfigAccessibleChannel(channel),
},
savedMessage.id,
);
logMessageDeleteBare(pluginData, {
messageId: savedMessage.id,
channel,
});
}
}