mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 12:25:02 +00:00
More rework progress, mostly done up to ModActions
This commit is contained in:
parent
52839cc9f3
commit
57893e7f76
38 changed files with 199 additions and 241 deletions
|
@ -3,20 +3,21 @@ import { stripObjectToScalars, UnknownUser } from "../../../utils";
|
|||
import { LogType } from "../../../data/LogType";
|
||||
|
||||
import { safeFindRelevantAuditLogEntry } from "../../../utils/safeFindRelevantAuditLogEntry";
|
||||
import { GuildAuditLogs } from "discord.js";
|
||||
|
||||
export const LogsGuildBanAddEvt = logsEvt({
|
||||
event: "guildBanAdd",
|
||||
|
||||
async listener(meta) {
|
||||
const pluginData = meta.pluginData;
|
||||
const user = meta.args.user;
|
||||
const user = meta.args.ban.user;
|
||||
|
||||
const relevantAuditLogEntry = await safeFindRelevantAuditLogEntry(
|
||||
pluginData,
|
||||
ErisConstants.AuditLogActions.MEMBER_BAN_ADD,
|
||||
GuildAuditLogs.Actions.MEMBER_BAN_ADD as number,
|
||||
user.id,
|
||||
);
|
||||
const mod = relevantAuditLogEntry ? relevantAuditLogEntry.user : new UnknownUser();
|
||||
const mod = relevantAuditLogEntry ? relevantAuditLogEntry.executor : new UnknownUser();
|
||||
|
||||
pluginData.state.guildLogs.log(
|
||||
LogType.MEMBER_BAN,
|
||||
|
@ -34,14 +35,14 @@ export const LogsGuildBanRemoveEvt = logsEvt({
|
|||
|
||||
async listener(meta) {
|
||||
const pluginData = meta.pluginData;
|
||||
const user = meta.args.user;
|
||||
const user = meta.args.ban.user;
|
||||
|
||||
const relevantAuditLogEntry = await safeFindRelevantAuditLogEntry(
|
||||
pluginData,
|
||||
ErisConstants.AuditLogActions.MEMBER_BAN_REMOVE,
|
||||
GuildAuditLogs.Actions.MEMBER_BAN_REMOVE as number,
|
||||
user.id,
|
||||
);
|
||||
const mod = relevantAuditLogEntry ? relevantAuditLogEntry.user : new UnknownUser();
|
||||
const mod = relevantAuditLogEntry ? relevantAuditLogEntry.executor : new UnknownUser();
|
||||
|
||||
pluginData.state.guildLogs.log(
|
||||
LogType.MEMBER_UNBAN,
|
||||
|
|
|
@ -13,14 +13,14 @@ export const LogsGuildMemberAddEvt = logsEvt({
|
|||
const member = meta.args.member;
|
||||
|
||||
const newThreshold = moment.utc().valueOf() - 1000 * 60 * 60;
|
||||
const accountAge = humanizeDuration(moment.utc().valueOf() - member.createdAt, {
|
||||
const accountAge = humanizeDuration(moment.utc().valueOf() - member.user.createdTimestamp, {
|
||||
largest: 2,
|
||||
round: true,
|
||||
});
|
||||
|
||||
pluginData.state.guildLogs.log(LogType.MEMBER_JOIN, {
|
||||
member: stripObjectToScalars(member, ["user", "roles"]),
|
||||
new: member.createdAt >= newThreshold ? " :new:" : "",
|
||||
new: member.user.createdTimestamp >= newThreshold ? " :new:" : "",
|
||||
account_age: accountAge,
|
||||
});
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import { LogType } from "../../../data/LogType";
|
|||
import isEqual from "lodash.isequal";
|
||||
import diff from "lodash.difference";
|
||||
import { safeFindRelevantAuditLogEntry } from "../../../utils/safeFindRelevantAuditLogEntry";
|
||||
import { GuildAuditLogs } from "discord.js";
|
||||
|
||||
export const LogsGuildMemberUpdateEvt = logsEvt({
|
||||
event: "guildMemberUpdate",
|
||||
|
@ -12,17 +13,17 @@ export const LogsGuildMemberUpdateEvt = logsEvt({
|
|||
async listener(meta) {
|
||||
const pluginData = meta.pluginData;
|
||||
const oldMember = meta.args.oldMember;
|
||||
const member = meta.args.member;
|
||||
const member = meta.args.newMember;
|
||||
|
||||
if (!oldMember) return;
|
||||
|
||||
const logMember = stripObjectToScalars(member, ["user", "roles"]);
|
||||
|
||||
if (member.nick !== oldMember.nick) {
|
||||
if (member.nickname !== oldMember.nickname) {
|
||||
pluginData.state.guildLogs.log(LogType.MEMBER_NICK_CHANGE, {
|
||||
member: logMember,
|
||||
oldNick: oldMember.nick != null ? oldMember.nick : "<none>",
|
||||
newNick: member.nick != null ? member.nick : "<none>",
|
||||
oldNick: oldMember.nickname != null ? oldMember.nickname : "<none>",
|
||||
newNick: member.nickname != null ? member.nickname : "<none>",
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -49,10 +50,10 @@ export const LogsGuildMemberUpdateEvt = logsEvt({
|
|||
if (!skip) {
|
||||
const relevantAuditLogEntry = await safeFindRelevantAuditLogEntry(
|
||||
pluginData,
|
||||
ErisConstants.AuditLogActions.MEMBER_ROLE_UPDATE,
|
||||
GuildAuditLogs.Actions.MEMBER_ROLE_UPDATE as number,
|
||||
member.id,
|
||||
);
|
||||
const mod = relevantAuditLogEntry ? relevantAuditLogEntry.user : new UnknownUser();
|
||||
const mod = relevantAuditLogEntry ? relevantAuditLogEntry.executor : new UnknownUser();
|
||||
|
||||
if (addedRoles.length && removedRoles.length) {
|
||||
// Roles added *and* removed
|
||||
|
|
|
@ -1,46 +1,34 @@
|
|||
import { logsEvt } from "../types";
|
||||
import { stripObjectToScalars } from "../../../utils";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
/** Merge into single event
|
||||
export const LogsVoiceJoinEvt = logsEvt({
|
||||
event: "voiceChannelJoin",
|
||||
|
||||
async listener(meta) {
|
||||
meta.pluginData.state.guildLogs.log(LogType.VOICE_CHANNEL_JOIN, {
|
||||
member: stripObjectToScalars(meta.args.member, ["user", "roles"]),
|
||||
channel: stripObjectToScalars(meta.args.newChannel),
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export const LogsVoiceLeaveEvt = logsEvt({
|
||||
event: "voiceChannelLeave",
|
||||
|
||||
async listener(meta) {
|
||||
meta.pluginData.state.guildLogs.log(LogType.VOICE_CHANNEL_LEAVE, {
|
||||
member: stripObjectToScalars(meta.args.member, ["user", "roles"]),
|
||||
channel: stripObjectToScalars(meta.args.oldChannel),
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export const LogsVoiceSwitchEvt = logsEvt({
|
||||
event: "voiceChannelSwitch",
|
||||
|
||||
async listener(meta) {
|
||||
meta.pluginData.state.guildLogs.log(LogType.VOICE_CHANNEL_MOVE, {
|
||||
member: stripObjectToScalars(meta.args.member, ["user", "roles"]),
|
||||
oldChannel: stripObjectToScalars(meta.args.oldChannel),
|
||||
newChannel: stripObjectToScalars(meta.args.newChannel),
|
||||
});
|
||||
},
|
||||
});
|
||||
**/
|
||||
|
||||
export const LogsVoiceStateUpdateEvt = logsEvt({
|
||||
event: "voiceStateUpdate",
|
||||
|
||||
async listener(meta) {
|
||||
console.error(`Fixme @LogsVoiceChannelEvts.ts`);
|
||||
const oldChannel = meta.args.oldState.channel;
|
||||
const newChannel = meta.args.newState.channel;
|
||||
const member = meta.args.newState.member ?? meta.args.oldState.member!;
|
||||
|
||||
if (!newChannel) { // Leave evt
|
||||
meta.pluginData.state.guildLogs.log(LogType.VOICE_CHANNEL_LEAVE, {
|
||||
member: stripObjectToScalars(member, ["user", "roles"]),
|
||||
oldChannel: stripObjectToScalars(oldChannel),
|
||||
newChannel: stripObjectToScalars(newChannel),
|
||||
});
|
||||
} else if (!oldChannel) { // Join Evt
|
||||
meta.pluginData.state.guildLogs.log(LogType.VOICE_CHANNEL_JOIN, {
|
||||
member: stripObjectToScalars(member, ["user", "roles"]),
|
||||
oldChannel: stripObjectToScalars(oldChannel),
|
||||
newChannel: stripObjectToScalars(newChannel),
|
||||
});
|
||||
} else {
|
||||
meta.pluginData.state.guildLogs.log(LogType.VOICE_CHANNEL_MOVE, {
|
||||
member: stripObjectToScalars(member, ["user", "roles"]),
|
||||
oldChannel: stripObjectToScalars(oldChannel),
|
||||
newChannel: stripObjectToScalars(newChannel),
|
||||
});
|
||||
}
|
||||
|
||||
},
|
||||
});
|
||||
|
|
|
@ -12,15 +12,15 @@ import {
|
|||
import { SavedMessage } from "../../../data/entities/SavedMessage";
|
||||
import { renderTemplate, TemplateParseError } from "../../../templateFormatter";
|
||||
import { logger } from "../../../logger";
|
||||
import moment from "moment-timezone";
|
||||
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
|
||||
import { MessageOptions } from "discord.js";
|
||||
|
||||
export async function getLogMessage(
|
||||
pluginData: GuildPluginData<LogsPluginType>,
|
||||
type: LogType,
|
||||
data: any,
|
||||
opts?: Pick<TLogChannel, "format" | "timestamp_format" | "include_embed_timestamp">,
|
||||
): Promise<MessageContent | null> {
|
||||
): Promise<MessageOptions | null> {
|
||||
const config = pluginData.config.get();
|
||||
const format = opts?.format?.[LogType[type]] || config.format[LogType[type]] || "";
|
||||
if (format === "" || format == null) return null;
|
||||
|
|
|
@ -6,6 +6,7 @@ import { createChunkedMessage, get, noop } from "../../../utils";
|
|||
import { getLogMessage } from "./getLogMessage";
|
||||
import { allowTimeout } from "../../../RegExpRunner";
|
||||
import { SavedMessage } from "../../../data/entities/SavedMessage";
|
||||
import { MessageMentionTypes, TextChannel } from "discord.js";
|
||||
|
||||
const excludedUserProps = ["user", "member", "mod"];
|
||||
const excludedRoleProps = ["message.member.roles", "member.roles"];
|
||||
|
@ -46,8 +47,8 @@ export async function log(pluginData: GuildPluginData<LogsPluginType>, type: Log
|
|||
for (const value of Object.values(data || {})) {
|
||||
if (value instanceof SavedMessage) {
|
||||
const member = pluginData.guild.members.cache.get(value.user_id);
|
||||
for (const role of member?.roles || []) {
|
||||
if (opts.excluded_roles.includes(role)) {
|
||||
for (const role of member?.roles.cache || []) {
|
||||
if (opts.excluded_roles.includes(role[0])) {
|
||||
continue logChannelLoop;
|
||||
}
|
||||
}
|
||||
|
@ -128,7 +129,7 @@ export async function log(pluginData: GuildPluginData<LogsPluginType>, type: Log
|
|||
if (message) {
|
||||
// For non-string log messages (i.e. embeds) batching or chunking is not possible, so send them immediately
|
||||
if (typeof message !== "string") {
|
||||
await channel.createMessage(message).catch(noop);
|
||||
await channel.send(message).catch(noop);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -136,6 +137,7 @@ export async function log(pluginData: GuildPluginData<LogsPluginType>, type: Log
|
|||
const batched = opts.batched ?? true;
|
||||
const batchTime = opts.batch_time ?? 1000;
|
||||
const cfg = pluginData.config.get();
|
||||
const parse: MessageMentionTypes[] | undefined = cfg.allow_user_mentions ? ["users"] : undefined;
|
||||
|
||||
if (batched) {
|
||||
// If we're batching log messages, gather all log messages within the set batch_time into a single message
|
||||
|
@ -144,14 +146,14 @@ export async function log(pluginData: GuildPluginData<LogsPluginType>, type: Log
|
|||
setTimeout(async () => {
|
||||
const batchedMessage = pluginData.state.batches.get(channel.id)!.join("\n");
|
||||
pluginData.state.batches.delete(channel.id);
|
||||
createChunkedMessage(channel, batchedMessage, { users: cfg.allow_user_mentions }).catch(noop);
|
||||
createChunkedMessage(channel, batchedMessage, { parse }).catch(noop);
|
||||
}, batchTime);
|
||||
}
|
||||
|
||||
pluginData.state.batches.get(channel.id)!.push(message);
|
||||
} else {
|
||||
// If we're not batching log messages, just send them immediately
|
||||
await createChunkedMessage(channel, message, { users: cfg.allow_user_mentions }).catch(noop);
|
||||
await createChunkedMessage(channel, message, { parse }).catch(noop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import moment from "moment-timezone";
|
|||
import { GuildPluginData } from "knub";
|
||||
import { FORMAT_NO_TIMESTAMP, LogsPluginType } from "../types";
|
||||
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
|
||||
import { MessageAttachment } from "discord.js";
|
||||
|
||||
export async function onMessageDelete(pluginData: GuildPluginData<LogsPluginType>, savedMessage: SavedMessage) {
|
||||
const user = await resolveUser(pluginData.client, savedMessage.user_id);
|
||||
|
@ -14,7 +15,7 @@ export async function onMessageDelete(pluginData: GuildPluginData<LogsPluginType
|
|||
if (user) {
|
||||
// Replace attachment URLs with media URLs
|
||||
if (savedMessage.data.attachments) {
|
||||
for (const attachment of savedMessage.data.attachments as Attachment[]) {
|
||||
for (const attachment of savedMessage.data.attachments as MessageAttachment[]) {
|
||||
attachment.url = useMediaUrls(attachment.url);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import { SavedMessage } from "../../../data/entities/SavedMessage";
|
|||
import { LogType } from "../../../data/LogType";
|
||||
import { stripObjectToScalars, resolveUser } from "../../../utils";
|
||||
import cloneDeep from "lodash.clonedeep";
|
||||
import { MessageEmbed } from "discord.js";
|
||||
|
||||
export async function onMessageUpdate(
|
||||
pluginData: GuildPluginData<LogsPluginType>,
|
||||
|
@ -14,13 +15,13 @@ export async function onMessageUpdate(
|
|||
// To log a message update, either the message content or a rich embed has to change
|
||||
let logUpdate = false;
|
||||
|
||||
const oldEmbedsToCompare = ((oldSavedMessage.data.embeds || []) as Embed[])
|
||||
const oldEmbedsToCompare = ((oldSavedMessage.data.embeds || []) as MessageEmbed[])
|
||||
.map(e => cloneDeep(e))
|
||||
.filter(e => (e as Embed).type === "rich");
|
||||
.filter(e => (e as MessageEmbed).type === "rich");
|
||||
|
||||
const newEmbedsToCompare = ((savedMessage.data.embeds || []) as Embed[])
|
||||
const newEmbedsToCompare = ((savedMessage.data.embeds || []) as MessageEmbed[])
|
||||
.map(e => cloneDeep(e))
|
||||
.filter(e => (e as Embed).type === "rich");
|
||||
.filter(e => (e as MessageEmbed).type === "rich");
|
||||
|
||||
for (const embed of [...oldEmbedsToCompare, ...newEmbedsToCompare]) {
|
||||
if (embed.thumbnail) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue