3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 04:25:01 +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,4 +1,4 @@
import { userToConfigAccessibleUser } from "../../../utils/configAccessibleObjects";
import { userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { CaseTypes } from "../../../data/CaseTypes";
import { Case } from "../../../data/entities/Case";
@ -8,6 +8,7 @@ import { canActOn, hasPermission, sendErrorMessage, sendSuccessMessage } from ".
import { resolveMember, resolveUser } from "../../../utils";
import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments";
import { modActionsCmd } from "../types";
import { LogsPlugin } from "../../Logs/LogsPlugin";
const opts = {
mod: ct.member({ option: true }),
@ -79,8 +80,8 @@ export const AddCaseCmd = modActionsCmd({
}
// Log the action
pluginData.state.serverLogs.log(LogType.CASE_CREATE, {
mod: userToConfigAccessibleUser(mod.user),
pluginData.getPlugin(LogsPlugin).logCaseCreate({
mod: mod.user,
userId: user.id,
caseNum: theCase.case_number,
caseType: type.toUpperCase(),

View file

@ -1,6 +1,6 @@
import humanizeDuration from "humanize-duration";
import { getMemberLevel } from "knub/dist/helpers";
import { userToConfigAccessibleUser } from "../../../utils/configAccessibleObjects";
import { userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { CaseTypes } from "../../../data/CaseTypes";
import { LogType } from "../../../data/LogType";
@ -14,6 +14,7 @@ import { formatReasonWithAttachments } from "../functions/formatReasonWithAttach
import { isBanned } from "../functions/isBanned";
import { readContactMethodsFromArgs } from "../functions/readContactMethodsFromArgs";
import { modActionsCmd } from "../types";
import { LogsPlugin } from "../../Logs/LogsPlugin";
const opts = {
mod: ct.member({ option: true }),
@ -108,14 +109,22 @@ export const BanCmd = modActionsCmd({
reason,
noteDetails: [`Ban updated to ${time ? humanizeDuration(time) : "indefinite"}`],
});
const logtype = time ? LogType.MEMBER_TIMED_BAN : LogType.MEMBER_BAN;
pluginData.state.serverLogs.log(logtype, {
mod: userToConfigAccessibleUser(mod.user),
user: userToConfigAccessibleUser(user),
caseNumber: createdCase.case_number,
reason,
banTime: time ? humanizeDuration(time) : null,
});
if (time) {
pluginData.getPlugin(LogsPlugin).logMemberTimedBan({
mod: mod.user,
user,
caseNumber: createdCase.case_number,
reason,
banTime: humanizeDuration(time),
});
} else {
pluginData.getPlugin(LogsPlugin).logMemberBan({
mod,
user,
caseNumber: createdCase.case_number,
reason,
});
}
sendSuccessMessage(
pluginData,

View file

@ -1,6 +1,6 @@
import { TextChannel } from "discord.js";
import { helpers } from "knub";
import { memberToConfigAccessibleMember } from "../../../utils/configAccessibleObjects";
import { memberToTemplateSafeMember } from "../../../utils/templateSafeObjects";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { Case } from "../../../data/entities/Case";
import { LogType } from "../../../data/LogType";
@ -81,9 +81,9 @@ export const DeleteCaseCmd = modActionsCmd({
);
const logs = pluginData.getPlugin(LogsPlugin);
logs.log(LogType.CASE_DELETE, {
mod: memberToConfigAccessibleMember(message.member),
case: stripObjectToScalars(theCase),
logs.logCaseDelete({
mod: message.member,
case: theCase,
});
}

View file

@ -1,5 +1,5 @@
import { Snowflake } from "discord.js";
import { userToConfigAccessibleUser } from "../../../utils/configAccessibleObjects";
import { userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { CaseTypes } from "../../../data/CaseTypes";
import { LogType } from "../../../data/LogType";
@ -10,6 +10,7 @@ import { formatReasonWithAttachments } from "../functions/formatReasonWithAttach
import { ignoreEvent } from "../functions/ignoreEvent";
import { isBanned } from "../functions/isBanned";
import { IgnoredEventType, modActionsCmd } from "../types";
import { LogsPlugin } from "../../Logs/LogsPlugin";
const opts = {
mod: ct.member({ option: true }),
@ -91,8 +92,8 @@ export const ForcebanCmd = modActionsCmd({
sendSuccessMessage(pluginData, msg.channel, `Member forcebanned (Case #${createdCase.case_number})`);
// Log the action
pluginData.state.serverLogs.log(LogType.MEMBER_FORCEBAN, {
mod: userToConfigAccessibleUser(mod.user),
pluginData.getPlugin(LogsPlugin).logMemberForceban({
mod,
userId: user.id,
caseNumber: createdCase.case_number,
reason,

View file

@ -1,7 +1,7 @@
import { Snowflake, TextChannel } from "discord.js";
import { waitForReply } from "knub/dist/helpers";
import { performance } from "perf_hooks";
import { userToConfigAccessibleUser } from "../../../utils/configAccessibleObjects";
import { userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { CaseTypes } from "../../../data/CaseTypes";
import { LogType } from "../../../data/LogType";
@ -12,6 +12,7 @@ import { MINUTES, noop } from "../../../utils";
import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments";
import { ignoreEvent } from "../functions/ignoreEvent";
import { IgnoredEventType, modActionsCmd } from "../types";
import { LogsPlugin } from "../../Logs/LogsPlugin";
export const MassbanCmd = modActionsCmd({
trigger: "massban",
@ -129,8 +130,8 @@ export const MassbanCmd = modActionsCmd({
sendErrorMessage(pluginData, msg.channel, "All bans failed. Make sure the IDs are valid.");
} else {
// Some or all bans were successful. Create a log entry for the mass ban and notify the user.
pluginData.state.serverLogs.log(LogType.MASSBAN, {
mod: userToConfigAccessibleUser(msg.author),
pluginData.getPlugin(LogsPlugin).logMassBan({
mod: msg.author,
count: successfulBanCount,
reason: banReason,
});

View file

@ -1,6 +1,6 @@
import { Snowflake, TextChannel } from "discord.js";
import { waitForReply } from "knub/dist/helpers";
import { userToConfigAccessibleUser } from "../../../utils/configAccessibleObjects";
import { userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { CaseTypes } from "../../../data/CaseTypes";
import { LogType } from "../../../data/LogType";
@ -10,6 +10,7 @@ import { formatReasonWithAttachments } from "../functions/formatReasonWithAttach
import { ignoreEvent } from "../functions/ignoreEvent";
import { isBanned } from "../functions/isBanned";
import { IgnoredEventType, modActionsCmd } from "../types";
import { LogsPlugin } from "../../Logs/LogsPlugin";
export const MassunbanCmd = modActionsCmd({
trigger: "massunban",
@ -83,8 +84,8 @@ export const MassunbanCmd = modActionsCmd({
sendErrorMessage(pluginData, msg.channel, "All unbans failed. Make sure the IDs are valid and banned.");
} else {
// Some or all unbans were successful. Create a log entry for the mass unban and notify the user.
pluginData.state.serverLogs.log(LogType.MASSUNBAN, {
mod: userToConfigAccessibleUser(msg.author),
pluginData.getPlugin(LogsPlugin).logMassUnban({
mod: msg.author,
count: successfulUnbanCount,
reason: unbanReason,
});

View file

@ -1,6 +1,6 @@
import { Snowflake, TextChannel } from "discord.js";
import { waitForReply } from "knub/dist/helpers";
import { userToConfigAccessibleUser } from "../../../utils/configAccessibleObjects";
import { userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { LogType } from "../../../data/LogType";
import { logger } from "../../../logger";
@ -8,6 +8,7 @@ import { MutesPlugin } from "../../../plugins/Mutes/MutesPlugin";
import { canActOn, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments";
import { modActionsCmd } from "../types";
import { LogsPlugin } from "../../Logs/LogsPlugin";
export const MassmuteCmd = modActionsCmd({
trigger: "massmute",
@ -86,8 +87,8 @@ export const MassmuteCmd = modActionsCmd({
sendErrorMessage(pluginData, msg.channel, "All mutes failed. Make sure the IDs are valid.");
} else {
// Success on all or some mutes
pluginData.state.serverLogs.log(LogType.MASSMUTE, {
mod: userToConfigAccessibleUser(msg.author),
pluginData.getPlugin(LogsPlugin).logMassMute({
mod: msg.author,
count: successfulMuteCount,
});

View file

@ -1,4 +1,4 @@
import { userToConfigAccessibleUser } from "../../../utils/configAccessibleObjects";
import { userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { CaseTypes } from "../../../data/CaseTypes";
import { LogType } from "../../../data/LogType";
@ -7,6 +7,7 @@ import { resolveUser } from "../../../utils";
import { CasesPlugin } from "../../Cases/CasesPlugin";
import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments";
import { modActionsCmd } from "../types";
import { LogsPlugin } from "../../Logs/LogsPlugin";
export const NoteCmd = modActionsCmd({
trigger: "note",
@ -41,9 +42,9 @@ export const NoteCmd = modActionsCmd({
reason,
});
pluginData.state.serverLogs.log(LogType.MEMBER_NOTE, {
mod: userToConfigAccessibleUser(msg.author),
user: userToConfigAccessibleUser(user),
pluginData.getPlugin(LogsPlugin).logMemberNote({
mod: msg.author,
user,
caseNumber: createdCase.case_number,
reason,
});

View file

@ -1,5 +1,5 @@
import { Snowflake } from "discord.js";
import { userToConfigAccessibleUser } from "../../../utils/configAccessibleObjects";
import { userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { CaseTypes } from "../../../data/CaseTypes";
import { LogType } from "../../../data/LogType";
@ -9,6 +9,7 @@ import { resolveUser } from "../../../utils";
import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments";
import { ignoreEvent } from "../functions/ignoreEvent";
import { IgnoredEventType, modActionsCmd } from "../types";
import { LogsPlugin } from "../../Logs/LogsPlugin";
const opts = {
mod: ct.member({ option: true }),
@ -73,11 +74,11 @@ export const UnbanCmd = modActionsCmd({
sendSuccessMessage(pluginData, msg.channel, `Member unbanned (Case #${createdCase.case_number})`);
// Log the action
pluginData.state.serverLogs.log(LogType.MEMBER_UNBAN, {
mod: userToConfigAccessibleUser(mod.user),
pluginData.getPlugin(LogsPlugin).logMemberUnban({
mod: mod.user,
userId: user.id,
caseNumber: createdCase.case_number,
reason,
reason: reason ?? "",
});
pluginData.state.events.emit("unban", user.id);