mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-11 20:55:01 +00:00
Typed log functions + more
This commit is contained in:
parent
d2ac700143
commit
bed6589d48
166 changed files with 4021 additions and 869 deletions
|
@ -1,7 +1,7 @@
|
|||
import { DiscordAPIError, Snowflake, User } from "discord.js";
|
||||
import humanizeDuration from "humanize-duration";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { userToConfigAccessibleUser } from "../../../utils/configAccessibleObjects";
|
||||
import { userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { logger } from "../../../logger";
|
||||
|
@ -18,6 +18,7 @@ import { CasesPlugin } from "../../Cases/CasesPlugin";
|
|||
import { BanOptions, BanResult, IgnoredEventType, ModActionsPluginType } from "../types";
|
||||
import { getDefaultContactMethods } from "./getDefaultContactMethods";
|
||||
import { ignoreEvent } from "./ignoreEvent";
|
||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||
|
||||
/**
|
||||
* Ban the specified user id, whether or not they're actually on the server at the time. Generates a case.
|
||||
|
@ -128,14 +129,23 @@ export async function banUserId(
|
|||
|
||||
// Log the action
|
||||
const mod = await resolveUser(pluginData.client, modId);
|
||||
const logtype = banTime ? LogType.MEMBER_TIMED_BAN : LogType.MEMBER_BAN;
|
||||
pluginData.state.serverLogs.log(logtype, {
|
||||
mod: userToConfigAccessibleUser(mod),
|
||||
user: userToConfigAccessibleUser(user),
|
||||
caseNumber: createdCase.case_number,
|
||||
reason,
|
||||
banTime: banTime ? humanizeDuration(banTime) : null,
|
||||
});
|
||||
|
||||
if (banTime) {
|
||||
pluginData.getPlugin(LogsPlugin).logMemberTimedBan({
|
||||
mod,
|
||||
user,
|
||||
caseNumber: createdCase.case_number,
|
||||
reason: reason ?? "",
|
||||
banTime: humanizeDuration(banTime),
|
||||
});
|
||||
} else {
|
||||
pluginData.getPlugin(LogsPlugin).logMemberBan({
|
||||
mod,
|
||||
user,
|
||||
caseNumber: createdCase.case_number,
|
||||
reason: reason ?? "",
|
||||
});
|
||||
}
|
||||
|
||||
pluginData.state.events.emit("ban", user.id, reason, banOptions.isAutomodAction);
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ export async function isBanned(
|
|||
): Promise<boolean> {
|
||||
const botMember = pluginData.guild.members.cache.get(pluginData.client.user!.id);
|
||||
if (botMember && !hasDiscordPermissions(botMember.permissions, Permissions.FLAGS.BAN_MEMBERS)) {
|
||||
pluginData.getPlugin(LogsPlugin).log(LogType.BOT_ALERT, {
|
||||
pluginData.getPlugin(LogsPlugin).logBotAlert({
|
||||
body: `Missing "Ban Members" permission to check for existing bans`,
|
||||
});
|
||||
return false;
|
||||
|
@ -37,7 +37,7 @@ export async function isBanned(
|
|||
}
|
||||
|
||||
if (isDiscordAPIError(e) && e.code === 50013) {
|
||||
pluginData.getPlugin(LogsPlugin).log(LogType.BOT_ALERT, {
|
||||
pluginData.getPlugin(LogsPlugin).logBotAlert({
|
||||
body: `Missing "Ban Members" permission to check for existing bans`,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { GuildMember } from "discord.js";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { userToConfigAccessibleUser } from "../../../utils/configAccessibleObjects";
|
||||
import { userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { renderTemplate } from "../../../templateFormatter";
|
||||
|
@ -9,6 +9,7 @@ import { CasesPlugin } from "../../Cases/CasesPlugin";
|
|||
import { IgnoredEventType, KickOptions, KickResult, ModActionsPluginType } from "../types";
|
||||
import { getDefaultContactMethods } from "./getDefaultContactMethods";
|
||||
import { ignoreEvent } from "./ignoreEvent";
|
||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||
|
||||
/**
|
||||
* Kick the specified server member. Generates a case.
|
||||
|
@ -34,7 +35,7 @@ export async function kickMember(
|
|||
guildName: pluginData.guild.name,
|
||||
reason,
|
||||
moderator: kickOptions.caseArgs?.modId
|
||||
? userToConfigAccessibleUser(await resolveUser(pluginData.client, kickOptions.caseArgs.modId))
|
||||
? userToTemplateSafeUser(await resolveUser(pluginData.client, kickOptions.caseArgs.modId))
|
||||
: {},
|
||||
});
|
||||
|
||||
|
@ -72,11 +73,11 @@ export async function kickMember(
|
|||
|
||||
// Log the action
|
||||
const mod = await resolveUser(pluginData.client, modId);
|
||||
pluginData.state.serverLogs.log(LogType.MEMBER_KICK, {
|
||||
mod: userToConfigAccessibleUser(mod),
|
||||
user: userToConfigAccessibleUser(member.user),
|
||||
pluginData.getPlugin(LogsPlugin).logMemberKick({
|
||||
mod,
|
||||
user: member.user,
|
||||
caseNumber: createdCase.case_number,
|
||||
reason,
|
||||
reason: reason ?? "",
|
||||
});
|
||||
|
||||
pluginData.state.events.emit("kick", member.id, reason, kickOptions.isAutomodAction);
|
||||
|
|
|
@ -4,7 +4,7 @@ import { GuildPluginData } from "knub";
|
|||
import moment from "moment-timezone";
|
||||
import { LogType } from "src/data/LogType";
|
||||
import { logger } from "src/logger";
|
||||
import { userToConfigAccessibleUser } from "../../../utils/configAccessibleObjects";
|
||||
import { userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import { resolveUser, SECONDS } from "../../../utils";
|
||||
import { CasesPlugin } from "../../Cases/CasesPlugin";
|
||||
|
@ -12,6 +12,7 @@ import { IgnoredEventType, ModActionsPluginType } from "../types";
|
|||
import { formatReasonWithAttachments } from "./formatReasonWithAttachments";
|
||||
import { ignoreEvent } from "./ignoreEvent";
|
||||
import { isBanned } from "./isBanned";
|
||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||
|
||||
const TEMPBAN_LOOP_TIME = 60 * SECONDS;
|
||||
|
||||
|
@ -34,7 +35,7 @@ export async function outdatedTempbansLoop(pluginData: GuildPluginData<ModAction
|
|||
ignoreEvent(pluginData, IgnoredEventType.Unban, tempban.user_id);
|
||||
await pluginData.guild.bans.remove(tempban.user_id as Snowflake, reason ?? undefined);
|
||||
} catch (e) {
|
||||
pluginData.state.serverLogs.log(LogType.BOT_ALERT, {
|
||||
pluginData.getPlugin(LogsPlugin).logBotAlert({
|
||||
body: `Encountered an error trying to automatically unban ${tempban.user_id} after tempban timeout`,
|
||||
});
|
||||
logger.warn(`Error automatically unbanning ${tempban.user_id} (tempban timeout): ${e}`);
|
||||
|
@ -54,8 +55,8 @@ export async function outdatedTempbansLoop(pluginData: GuildPluginData<ModAction
|
|||
|
||||
// Log the unban
|
||||
const banTime = moment(tempban.created_at).diff(moment(tempban.expires_at));
|
||||
pluginData.state.serverLogs.log(LogType.MEMBER_TIMED_UNBAN, {
|
||||
mod: userToConfigAccessibleUser(await resolveUser(pluginData.client, tempban.mod_id)),
|
||||
pluginData.getPlugin(LogsPlugin).logMemberTimedUnban({
|
||||
mod: await resolveUser(pluginData.client, tempban.mod_id),
|
||||
userId: tempban.user_id,
|
||||
caseNumber: createdCase.case_number,
|
||||
reason,
|
||||
|
|
|
@ -5,6 +5,7 @@ import { LogType } from "../../../data/LogType";
|
|||
import { CasesPlugin } from "../../../plugins/Cases/CasesPlugin";
|
||||
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
import { formatReasonWithAttachments } from "./formatReasonWithAttachments";
|
||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||
|
||||
export async function updateCase(pluginData, msg: Message, args) {
|
||||
let theCase: Case | undefined;
|
||||
|
@ -33,7 +34,7 @@ export async function updateCase(pluginData, msg: Message, args) {
|
|||
body: note,
|
||||
});
|
||||
|
||||
pluginData.state.serverLogs.log(LogType.CASE_UPDATE, {
|
||||
pluginData.getPlugin(LogsPlugin).logCaseUpdate({
|
||||
mod: msg.author,
|
||||
caseNumber: theCase.case_number,
|
||||
caseType: CaseTypes[theCase.type],
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { GuildMember, Snowflake } from "discord.js";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { memberToConfigAccessibleMember, userToConfigAccessibleUser } from "../../../utils/configAccessibleObjects";
|
||||
import { memberToTemplateSafeMember, userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { renderTemplate } from "../../../templateFormatter";
|
||||
|
@ -9,6 +9,7 @@ import { waitForButtonConfirm } from "../../../utils/waitForInteraction";
|
|||
import { CasesPlugin } from "../../Cases/CasesPlugin";
|
||||
import { ModActionsPluginType, WarnOptions, WarnResult } from "../types";
|
||||
import { getDefaultContactMethods } from "./getDefaultContactMethods";
|
||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||
|
||||
export async function warnMember(
|
||||
pluginData: GuildPluginData<ModActionsPluginType>,
|
||||
|
@ -24,7 +25,7 @@ export async function warnMember(
|
|||
guildName: pluginData.guild.name,
|
||||
reason,
|
||||
moderator: warnOptions.caseArgs?.modId
|
||||
? userToConfigAccessibleUser(await resolveUser(pluginData.client, warnOptions.caseArgs.modId))
|
||||
? userToTemplateSafeUser(await resolveUser(pluginData.client, warnOptions.caseArgs.modId))
|
||||
: {},
|
||||
});
|
||||
const contactMethods = warnOptions?.contactMethods
|
||||
|
@ -70,11 +71,11 @@ export async function warnMember(
|
|||
});
|
||||
|
||||
const mod = await pluginData.guild.members.fetch(modId as Snowflake);
|
||||
pluginData.state.serverLogs.log(LogType.MEMBER_WARN, {
|
||||
mod: memberToConfigAccessibleMember(mod),
|
||||
member: memberToConfigAccessibleMember(member),
|
||||
pluginData.getPlugin(LogsPlugin).logMemberWarn({
|
||||
mod,
|
||||
member,
|
||||
caseNumber: createdCase.case_number,
|
||||
reason,
|
||||
reason: reason ?? "",
|
||||
});
|
||||
|
||||
pluginData.state.events.emit("warn", member.id, reason, warnOptions.isAutomodAction);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue