mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 12:25:02 +00:00
More fixes, change rest of stripObjectToScalars to configAccessibleObj
This commit is contained in:
parent
4ad99975de
commit
acb4913495
66 changed files with 623 additions and 192 deletions
|
@ -1,9 +1,10 @@
|
|||
import { Permissions, Snowflake, TextChannel } from "discord.js";
|
||||
import { Permissions, Snowflake, TextChannel, User } from "discord.js";
|
||||
import { GuildPluginData } from "knub";
|
||||
import moment from "moment-timezone";
|
||||
import { channelToConfigAccessibleChannel, userToConfigAccessibleUser } from "src/utils/configAccessibleObjects";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { logger } from "../../../logger";
|
||||
import { resolveUser, stripObjectToScalars, verboseChannelMention } from "../../../utils";
|
||||
import { resolveUser, verboseChannelMention } from "../../../utils";
|
||||
import { hasDiscordPermissions } from "../../../utils/hasDiscordPermissions";
|
||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
|
||||
|
@ -60,8 +61,8 @@ export async function deleteNextItem(pluginData: GuildPluginData<AutoDeletePlugi
|
|||
|
||||
pluginData.state.guildLogs.log(LogType.MESSAGE_DELETE_AUTO, {
|
||||
message: itemToDelete.message,
|
||||
user: stripObjectToScalars(user),
|
||||
channel: stripObjectToScalars(channel),
|
||||
user: userToConfigAccessibleUser(user),
|
||||
channel: channelToConfigAccessibleChannel(channel),
|
||||
messageDate,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
import { MessageOptions, Permissions, Snowflake, TextChannel, User } from "discord.js";
|
||||
import * as t from "io-ts";
|
||||
import { userToConfigAccessibleUser } from "src/utils/configAccessibleObjects";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { renderTemplate } from "../../../templateFormatter";
|
||||
import {
|
||||
convertDelayStringToMS,
|
||||
noop,
|
||||
renderRecursively,
|
||||
stripObjectToScalars,
|
||||
tDelayString,
|
||||
tMessageContent,
|
||||
tNullable,
|
||||
|
@ -48,7 +48,7 @@ export const ReplyAction = automodAction({
|
|||
|
||||
const renderReplyText = async str =>
|
||||
renderTemplate(str, {
|
||||
user: stripObjectToScalars(user),
|
||||
user: userToConfigAccessibleUser(user),
|
||||
});
|
||||
const formatted =
|
||||
typeof actionConfig === "string"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { User } from "discord.js";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { userToConfigAccessibleUser } from "src/utils/configAccessibleObjects";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { stripObjectToScalars } from "../../../utils";
|
||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||
import { runAutomodOnAntiraidLevel } from "../events/runAutomodOnAntiraidLevel";
|
||||
import { AutomodPluginType } from "../types";
|
||||
|
@ -21,7 +21,7 @@ export async function setAntiraidLevel(
|
|||
if (user) {
|
||||
logs.log(LogType.SET_ANTIRAID_USER, {
|
||||
level: newLevel ?? "off",
|
||||
user: stripObjectToScalars(user),
|
||||
user: userToConfigAccessibleUser(user),
|
||||
});
|
||||
} else {
|
||||
logs.log(LogType.SET_ANTIRAID_AUTO, {
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import { Snowflake, TextChannel } from "discord.js";
|
||||
import { Snowflake, TextChannel, User } from "discord.js";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { deactivateMentions, disableCodeBlocks } from "knub/dist/helpers";
|
||||
import { channelToConfigAccessibleChannel, userToConfigAccessibleUser } from "src/utils/configAccessibleObjects";
|
||||
import { SavedMessage } from "../../../data/entities/SavedMessage";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { resolveUser, stripObjectToScalars } from "../../../utils";
|
||||
import { resolveUser } from "../../../utils";
|
||||
import { CensorPluginType } from "../types";
|
||||
|
||||
export async function censorMessage(
|
||||
|
@ -21,11 +22,11 @@ export async function censorMessage(
|
|||
}
|
||||
|
||||
const user = await resolveUser(pluginData.client, savedMessage.user_id);
|
||||
const channel = pluginData.guild.channels.cache.get(savedMessage.channel_id as Snowflake);
|
||||
const channel = pluginData.guild.channels.resolve(savedMessage.channel_id as Snowflake)!;
|
||||
|
||||
pluginData.state.serverLogs.log(LogType.CENSOR, {
|
||||
user: stripObjectToScalars(user),
|
||||
channel: stripObjectToScalars(channel),
|
||||
user: userToConfigAccessibleUser(user),
|
||||
channel: channelToConfigAccessibleChannel(channel),
|
||||
reason,
|
||||
message: savedMessage,
|
||||
messageText: disableCodeBlocks(deactivateMentions(savedMessage.data.content)),
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
import { MessageAttachment, MessageOptions, TextChannel } from "discord.js";
|
||||
import { MessageAttachment, MessageOptions, TextChannel, ThreadChannel } from "discord.js";
|
||||
import fs from "fs";
|
||||
import { downloadFile } from "../../utils";
|
||||
const fsp = fs.promises;
|
||||
|
||||
const MAX_ATTACHMENT_REHOST_SIZE = 1024 * 1024 * 8;
|
||||
|
||||
export async function rehostAttachment(attachment: MessageAttachment, targetChannel: TextChannel): Promise<string> {
|
||||
export async function rehostAttachment(
|
||||
attachment: MessageAttachment,
|
||||
targetChannel: TextChannel | ThreadChannel,
|
||||
): Promise<string> {
|
||||
if (attachment.size > MAX_ATTACHMENT_REHOST_SIZE) {
|
||||
return "Attachment too big to rehost";
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { CooldownManager } from "knub";
|
||||
import { GuildLogs } from "../../../data/GuildLogs";
|
||||
import { GuildLogs } from "../../data/GuildLogs";
|
||||
import { trimPluginDescription } from "../../utils";
|
||||
import { LogsPlugin } from "../Logs/LogsPlugin";
|
||||
import { zeppelinGuildPlugin } from "../ZeppelinPluginBlueprint";
|
||||
|
|
|
@ -2,7 +2,6 @@ import humanizeDuration from "humanize-duration";
|
|||
import moment from "moment-timezone";
|
||||
import { memberToConfigAccessibleMember } from "../../../utils/configAccessibleObjects";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { stripObjectToScalars } from "../../../utils";
|
||||
import { CasesPlugin } from "../../Cases/CasesPlugin";
|
||||
import { logsEvt } from "../types";
|
||||
|
||||
|
@ -20,7 +19,7 @@ export const LogsGuildMemberAddEvt = logsEvt({
|
|||
});
|
||||
|
||||
pluginData.state.guildLogs.log(LogType.MEMBER_JOIN, {
|
||||
member: stripObjectToScalars(member, ["user", "roles"]),
|
||||
member: memberToConfigAccessibleMember(member),
|
||||
new: member.user.createdTimestamp >= newThreshold ? " :new:" : "",
|
||||
account_age: accountAge,
|
||||
});
|
||||
|
|
|
@ -27,8 +27,8 @@ export const LogsGuildMemberUpdateEvt = logsEvt({
|
|||
}
|
||||
|
||||
if (!isEqual(oldMember.roles, member.roles)) {
|
||||
const addedRoles = diff(member.roles, oldMember.roles);
|
||||
const removedRoles = diff(oldMember.roles, member.roles);
|
||||
const addedRoles = diff(member.roles.cache.keyArray(), oldMember.roles.cache.keyArray());
|
||||
const removedRoles = diff(oldMember.roles.cache.keyArray(), member.roles.cache.keyArray());
|
||||
let skip = false;
|
||||
|
||||
if (
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
import { MessageAttachment, Snowflake } from "discord.js";
|
||||
import { MessageAttachment, Snowflake, User } from "discord.js";
|
||||
import { GuildPluginData } from "knub";
|
||||
import moment from "moment-timezone";
|
||||
import { channelToConfigAccessibleChannel, userToConfigAccessibleUser } from "src/utils/configAccessibleObjects";
|
||||
import { SavedMessage } from "../../../data/entities/SavedMessage";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { resolveUser, stripObjectToScalars, useMediaUrls } from "../../../utils";
|
||||
import { resolveUser, useMediaUrls } from "../../../utils";
|
||||
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
|
||||
import { FORMAT_NO_TIMESTAMP, LogsPluginType } from "../types";
|
||||
|
||||
export async function onMessageDelete(pluginData: GuildPluginData<LogsPluginType>, savedMessage: SavedMessage) {
|
||||
const user = await resolveUser(pluginData.client, savedMessage.user_id);
|
||||
const channel = pluginData.guild.channels.cache.get(savedMessage.channel_id as Snowflake);
|
||||
const channel = pluginData.guild.channels.resolve(savedMessage.channel_id as Snowflake)!;
|
||||
|
||||
if (user) {
|
||||
// Replace attachment URLs with media URLs
|
||||
|
@ -27,8 +28,8 @@ export async function onMessageDelete(pluginData: GuildPluginData<LogsPluginType
|
|||
pluginData.state.guildLogs.log(
|
||||
LogType.MESSAGE_DELETE,
|
||||
{
|
||||
user: stripObjectToScalars(user),
|
||||
channel: stripObjectToScalars(channel),
|
||||
user: userToConfigAccessibleUser(user),
|
||||
channel: channelToConfigAccessibleChannel(channel),
|
||||
messageDate: pluginData
|
||||
.getPlugin(TimeAndDatePlugin)
|
||||
.inGuildTz(moment.utc(savedMessage.data.timestamp, "x"))
|
||||
|
@ -42,7 +43,7 @@ export async function onMessageDelete(pluginData: GuildPluginData<LogsPluginType
|
|||
LogType.MESSAGE_DELETE_BARE,
|
||||
{
|
||||
messageId: savedMessage.id,
|
||||
channel: stripObjectToScalars(channel),
|
||||
channel: channelToConfigAccessibleChannel(channel),
|
||||
},
|
||||
savedMessage.id,
|
||||
);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { MessageEmbed, Snowflake } from "discord.js";
|
||||
import { MessageEmbed, Snowflake, User } from "discord.js";
|
||||
import { GuildPluginData } from "knub";
|
||||
import cloneDeep from "lodash.clonedeep";
|
||||
import { channelToConfigAccessibleChannel, userToConfigAccessibleUser } from "src/utils/configAccessibleObjects";
|
||||
import { SavedMessage } from "../../../data/entities/SavedMessage";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { resolveUser, stripObjectToScalars } from "../../../utils";
|
||||
|
@ -47,11 +48,11 @@ export async function onMessageUpdate(
|
|||
}
|
||||
|
||||
const user = await resolveUser(pluginData.client, savedMessage.user_id);
|
||||
const channel = pluginData.guild.channels.cache.get(savedMessage.channel_id as Snowflake);
|
||||
const channel = pluginData.guild.channels.resolve(savedMessage.channel_id as Snowflake)!;
|
||||
|
||||
pluginData.state.guildLogs.log(LogType.MESSAGE_EDIT, {
|
||||
user: stripObjectToScalars(user),
|
||||
channel: stripObjectToScalars(channel),
|
||||
user: userToConfigAccessibleUser(user),
|
||||
channel: channelToConfigAccessibleChannel(channel),
|
||||
before: oldSavedMessage,
|
||||
after: savedMessage,
|
||||
});
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { Message, Snowflake, TextChannel } from "discord.js";
|
||||
import { Message, Snowflake, TextChannel, ThreadChannel } from "discord.js";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { MessageSaverPluginType } from "./types";
|
||||
|
||||
export async function saveMessagesToDB(
|
||||
pluginData: GuildPluginData<MessageSaverPluginType>,
|
||||
channel: TextChannel,
|
||||
channel: TextChannel | ThreadChannel,
|
||||
ids: string[],
|
||||
) {
|
||||
const failed: string[] = [];
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
import { userToConfigAccessibleUser } from "src/utils/configAccessibleObjects";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import { Case } from "../../../data/entities/Case";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { CasesPlugin } from "../../../plugins/Cases/CasesPlugin";
|
||||
import { canActOn, hasPermission, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
import { resolveMember, resolveUser, stripObjectToScalars } from "../../../utils";
|
||||
import { resolveMember, resolveUser } from "../../../utils";
|
||||
import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments";
|
||||
import { modActionsCmd } from "../types";
|
||||
|
||||
|
@ -83,7 +84,7 @@ export const AddCaseCmd = modActionsCmd({
|
|||
|
||||
// Log the action
|
||||
pluginData.state.serverLogs.log(LogType.CASE_CREATE, {
|
||||
mod: stripObjectToScalars(mod.user),
|
||||
mod: userToConfigAccessibleUser(mod.user),
|
||||
userId: user.id,
|
||||
caseNum: theCase.case_number,
|
||||
caseType: type.toUpperCase(),
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
import { User } from "discord.js";
|
||||
import humanizeDuration from "humanize-duration";
|
||||
import { getMemberLevel } from "knub/dist/helpers";
|
||||
import { userToConfigAccessibleUser } from "src/utils/configAccessibleObjects";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { CasesPlugin } from "../../../plugins/Cases/CasesPlugin";
|
||||
import { canActOn, hasPermission, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
import { resolveMember, resolveUser, stripObjectToScalars } from "../../../utils";
|
||||
import { resolveMember, resolveUser } from "../../../utils";
|
||||
import { banLock } from "../../../utils/lockNameHelpers";
|
||||
import { waitForButtonConfirm } from "../../../utils/waitForInteraction";
|
||||
import { banUserId } from "../functions/banUserId";
|
||||
|
@ -109,8 +111,8 @@ export const BanCmd = modActionsCmd({
|
|||
});
|
||||
const logtype = time ? LogType.MEMBER_TIMED_BAN : LogType.MEMBER_BAN;
|
||||
pluginData.state.serverLogs.log(logtype, {
|
||||
mod: stripObjectToScalars(mod.user),
|
||||
user: stripObjectToScalars(user),
|
||||
mod: userToConfigAccessibleUser(mod.user),
|
||||
user: userToConfigAccessibleUser(user),
|
||||
caseNumber: createdCase.case_number,
|
||||
reason,
|
||||
banTime: time ? humanizeDuration(time) : null,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { TextChannel } from "discord.js";
|
||||
import { helpers } from "knub";
|
||||
import { memberToConfigAccessibleMember } from "src/utils/configAccessibleObjects";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { Case } from "../../../data/entities/Case";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
|
@ -81,7 +82,7 @@ export const DeleteCaseCmd = modActionsCmd({
|
|||
|
||||
const logs = pluginData.getPlugin(LogsPlugin);
|
||||
logs.log(LogType.CASE_DELETE, {
|
||||
mod: stripObjectToScalars(message.member, ["user", "roles"]),
|
||||
mod: memberToConfigAccessibleMember(message.member),
|
||||
case: stripObjectToScalars(theCase),
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
import { Snowflake } from "discord.js";
|
||||
import { userToConfigAccessibleUser } from "src/utils/configAccessibleObjects";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { CasesPlugin } from "../../../plugins/Cases/CasesPlugin";
|
||||
import { canActOn, hasPermission, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
import { resolveMember, resolveUser, stripObjectToScalars } from "../../../utils";
|
||||
import { resolveMember, resolveUser } from "../../../utils";
|
||||
import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments";
|
||||
import { ignoreEvent } from "../functions/ignoreEvent";
|
||||
import { isBanned } from "../functions/isBanned";
|
||||
|
@ -91,7 +92,7 @@ export const ForcebanCmd = modActionsCmd({
|
|||
|
||||
// Log the action
|
||||
pluginData.state.serverLogs.log(LogType.MEMBER_FORCEBAN, {
|
||||
mod: stripObjectToScalars(mod.user),
|
||||
mod: userToConfigAccessibleUser(mod.user),
|
||||
userId: user.id,
|
||||
caseNumber: createdCase.case_number,
|
||||
reason,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { Snowflake, TextChannel } from "discord.js";
|
||||
import { waitForReply } from "knub/dist/helpers";
|
||||
import { performance } from "perf_hooks";
|
||||
import { userToConfigAccessibleUser } from "src/utils/configAccessibleObjects";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
|
@ -80,6 +81,7 @@ export const MassbanCmd = modActionsCmd({
|
|||
const startTime = performance.now();
|
||||
const failedBans: string[] = [];
|
||||
const casesPlugin = pluginData.getPlugin(CasesPlugin);
|
||||
const deleteDays = (await pluginData.config.getForMessage(msg)).ban_delete_message_days;
|
||||
for (const [i, userId] of args.userIds.entries()) {
|
||||
if (pluginData.state.unloaded) {
|
||||
break;
|
||||
|
@ -92,7 +94,7 @@ export const MassbanCmd = modActionsCmd({
|
|||
pluginData.state.serverLogs.ignoreLog(LogType.MEMBER_BAN, userId, 120 * 1000);
|
||||
|
||||
await pluginData.guild.bans.create(userId as Snowflake, {
|
||||
days: 1,
|
||||
days: deleteDays,
|
||||
reason: banReason != null ? encodeURIComponent(banReason) : undefined,
|
||||
});
|
||||
|
||||
|
@ -128,7 +130,7 @@ export const MassbanCmd = modActionsCmd({
|
|||
} 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: stripObjectToScalars(msg.author),
|
||||
mod: userToConfigAccessibleUser(msg.author),
|
||||
count: successfulBanCount,
|
||||
reason: banReason,
|
||||
});
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { Snowflake, TextChannel } from "discord.js";
|
||||
import { waitForReply } from "knub/dist/helpers";
|
||||
import { userToConfigAccessibleUser } from "src/utils/configAccessibleObjects";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
|
@ -87,7 +88,7 @@ export const MassunbanCmd = modActionsCmd({
|
|||
} 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: stripObjectToScalars(msg.author),
|
||||
mod: userToConfigAccessibleUser(msg.author),
|
||||
count: successfulUnbanCount,
|
||||
reason: unbanReason,
|
||||
});
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { Snowflake, TextChannel } from "discord.js";
|
||||
import { waitForReply } from "knub/dist/helpers";
|
||||
import { userToConfigAccessibleUser } from "src/utils/configAccessibleObjects";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { logger } from "../../../logger";
|
||||
|
@ -87,7 +88,7 @@ export const MassmuteCmd = modActionsCmd({
|
|||
} else {
|
||||
// Success on all or some mutes
|
||||
pluginData.state.serverLogs.log(LogType.MASSMUTE, {
|
||||
mod: stripObjectToScalars(msg.author),
|
||||
mod: userToConfigAccessibleUser(msg.author),
|
||||
count: successfulMuteCount,
|
||||
});
|
||||
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
import { User } from "discord.js";
|
||||
import { userToConfigAccessibleUser } from "src/utils/configAccessibleObjects";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
import { resolveUser, stripObjectToScalars } from "../../../utils";
|
||||
import { resolveUser } from "../../../utils";
|
||||
import { CasesPlugin } from "../../Cases/CasesPlugin";
|
||||
import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments";
|
||||
import { modActionsCmd } from "../types";
|
||||
|
@ -41,8 +43,8 @@ export const NoteCmd = modActionsCmd({
|
|||
});
|
||||
|
||||
pluginData.state.serverLogs.log(LogType.MEMBER_NOTE, {
|
||||
mod: stripObjectToScalars(msg.author),
|
||||
user: stripObjectToScalars(user, ["user", "roles"]),
|
||||
mod: userToConfigAccessibleUser(msg.author),
|
||||
user: userToConfigAccessibleUser(user),
|
||||
caseNumber: createdCase.case_number,
|
||||
reason,
|
||||
});
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
import { Snowflake } from "discord.js";
|
||||
import { userToConfigAccessibleUser } from "src/utils/configAccessibleObjects";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { CasesPlugin } from "../../../plugins/Cases/CasesPlugin";
|
||||
import { hasPermission, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
import { resolveUser, stripObjectToScalars } from "../../../utils";
|
||||
import { resolveUser } from "../../../utils";
|
||||
import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments";
|
||||
import { ignoreEvent } from "../functions/ignoreEvent";
|
||||
import { IgnoredEventType, modActionsCmd } from "../types";
|
||||
|
@ -73,7 +74,7 @@ export const UnbanCmd = modActionsCmd({
|
|||
|
||||
// Log the action
|
||||
pluginData.state.serverLogs.log(LogType.MEMBER_UNBAN, {
|
||||
mod: stripObjectToScalars(mod.user),
|
||||
mod: userToConfigAccessibleUser(mod.user),
|
||||
userId: user.id,
|
||||
caseNumber: createdCase.case_number,
|
||||
reason,
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { GuildAuditLogs, User } from "discord.js";
|
||||
import { userToConfigAccessibleUser } from "src/utils/configAccessibleObjects";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import { Case } from "../../../data/entities/Case";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
|
@ -65,8 +66,8 @@ export const CreateBanCaseOnManualBanEvt = modActionsEvt({
|
|||
}
|
||||
|
||||
pluginData.state.serverLogs.log(LogType.MEMBER_BAN, {
|
||||
mod: mod ? stripObjectToScalars(mod, ["user"]) : null,
|
||||
user: stripObjectToScalars(user, ["user"]),
|
||||
mod: mod ? userToConfigAccessibleUser(mod) : null,
|
||||
user: userToConfigAccessibleUser(user),
|
||||
caseNumber: createdCase?.case_number ?? 0,
|
||||
reason,
|
||||
});
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import { GuildAuditLogs, User } from "discord.js";
|
||||
import { userToConfigAccessibleUser } from "src/utils/configAccessibleObjects";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import { Case } from "../../../data/entities/Case";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { logger } from "../../../logger";
|
||||
import { resolveUser, stripObjectToScalars, UnknownUser } from "../../../utils";
|
||||
import { resolveUser, UnknownUser } from "../../../utils";
|
||||
import { safeFindRelevantAuditLogEntry } from "../../../utils/safeFindRelevantAuditLogEntry";
|
||||
import { CasesPlugin } from "../../Cases/CasesPlugin";
|
||||
import { clearIgnoredEvents } from "../functions/clearIgnoredEvents";
|
||||
|
@ -58,8 +59,8 @@ export const CreateKickCaseOnManualKickEvt = modActionsEvt({
|
|||
}
|
||||
|
||||
pluginData.state.serverLogs.log(LogType.MEMBER_KICK, {
|
||||
user: stripObjectToScalars(member.user),
|
||||
mod: mod ? stripObjectToScalars(mod) : null,
|
||||
user: userToConfigAccessibleUser(member.user!),
|
||||
mod: mod ? userToConfigAccessibleUser(mod) : null,
|
||||
caseNumber: createdCase?.case_number ?? 0,
|
||||
reason: kickAuditLogEntry.reason || "",
|
||||
});
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import { GuildAuditLogs, User } from "discord.js";
|
||||
import { userToConfigAccessibleUser } from "src/utils/configAccessibleObjects";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import { Case } from "../../../data/entities/Case";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { resolveUser, stripObjectToScalars, UnknownUser } from "../../../utils";
|
||||
import { resolveUser, UnknownUser } from "../../../utils";
|
||||
import { safeFindRelevantAuditLogEntry } from "../../../utils/safeFindRelevantAuditLogEntry";
|
||||
import { CasesPlugin } from "../../Cases/CasesPlugin";
|
||||
import { clearIgnoredEvents } from "../functions/clearIgnoredEvents";
|
||||
|
@ -63,7 +64,7 @@ export const CreateUnbanCaseOnManualUnbanEvt = modActionsEvt({
|
|||
}
|
||||
|
||||
pluginData.state.serverLogs.log(LogType.MEMBER_UNBAN, {
|
||||
mod: mod ? stripObjectToScalars(mod, ["user"]) : null,
|
||||
mod: mod ? userToConfigAccessibleUser(mod) : null,
|
||||
userId: user.id,
|
||||
caseNumber: createdCase?.case_number ?? 0,
|
||||
});
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { GuildMember, TextChannel } from "discord.js";
|
||||
import { GuildMember, TextChannel, ThreadChannel } from "discord.js";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { hasPermission } from "knub/dist/helpers";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
|
@ -19,7 +19,7 @@ export async function actualKickMemberCmd(
|
|||
reason: string;
|
||||
mod: GuildMember;
|
||||
notify?: string;
|
||||
"notify-channel"?: TextChannel;
|
||||
"notify-channel"?: TextChannel | ThreadChannel;
|
||||
clean?: boolean;
|
||||
},
|
||||
) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { GuildMember, Message, TextChannel, User } from "discord.js";
|
||||
import { GuildMember, Message, TextChannel, ThreadChannel, User } from "discord.js";
|
||||
import humanizeDuration from "humanize-duration";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { logger } from "../../../logger";
|
||||
|
@ -19,7 +19,13 @@ export async function actualMuteUserCmd(
|
|||
pluginData: GuildPluginData<ModActionsPluginType>,
|
||||
user: User | UnknownUser,
|
||||
msg: Message,
|
||||
args: { time?: number; reason?: string; mod: GuildMember; notify?: string; "notify-channel"?: TextChannel },
|
||||
args: {
|
||||
time?: number;
|
||||
reason?: string;
|
||||
mod: GuildMember;
|
||||
notify?: string;
|
||||
"notify-channel"?: TextChannel | ThreadChannel;
|
||||
},
|
||||
) {
|
||||
// The moderator who did the action is the message author or, if used, the specified -mod
|
||||
let mod: GuildMember = msg.member!;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { DiscordAPIError, Snowflake, User } from "discord.js";
|
||||
import humanizeDuration from "humanize-duration";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { userToConfigAccessibleUser } from "src/utils/configAccessibleObjects";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { logger } from "../../../logger";
|
||||
|
@ -129,8 +130,8 @@ export async function banUserId(
|
|||
const mod = await resolveUser(pluginData.client, modId);
|
||||
const logtype = banTime ? LogType.MEMBER_TIMED_BAN : LogType.MEMBER_BAN;
|
||||
pluginData.state.serverLogs.log(logtype, {
|
||||
mod: stripObjectToScalars(mod),
|
||||
user: stripObjectToScalars(user),
|
||||
mod: userToConfigAccessibleUser(mod),
|
||||
user: userToConfigAccessibleUser(user),
|
||||
caseNumber: createdCase.case_number,
|
||||
reason,
|
||||
banTime: banTime ? humanizeDuration(banTime) : null,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { GuildMember } from "discord.js";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { userToConfigAccessibleUser } from "src/utils/configAccessibleObjects";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { renderTemplate } from "../../../templateFormatter";
|
||||
|
@ -40,7 +41,7 @@ export async function kickMember(
|
|||
guildName: pluginData.guild.name,
|
||||
reason,
|
||||
moderator: kickOptions.caseArgs?.modId
|
||||
? stripObjectToScalars(await resolveUser(pluginData.client, kickOptions.caseArgs.modId))
|
||||
? userToConfigAccessibleUser(await resolveUser(pluginData.client, kickOptions.caseArgs.modId))
|
||||
: {},
|
||||
});
|
||||
|
||||
|
@ -79,8 +80,8 @@ export async function kickMember(
|
|||
// Log the action
|
||||
const mod = await resolveUser(pluginData.client, modId);
|
||||
pluginData.state.serverLogs.log(LogType.MEMBER_KICK, {
|
||||
mod: stripObjectToScalars(mod),
|
||||
user: stripObjectToScalars(member.user),
|
||||
mod: userToConfigAccessibleUser(mod),
|
||||
user: userToConfigAccessibleUser(member.user),
|
||||
caseNumber: createdCase.case_number,
|
||||
reason,
|
||||
});
|
||||
|
|
|
@ -4,6 +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 "src/utils/configAccessibleObjects";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import { resolveUser, SECONDS, stripObjectToScalars } from "../../../utils";
|
||||
import { CasesPlugin } from "../../Cases/CasesPlugin";
|
||||
|
@ -57,7 +58,7 @@ 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: stripObjectToScalars(await resolveUser(pluginData.client, tempban.mod_id)),
|
||||
mod: userToConfigAccessibleUser(await resolveUser(pluginData.client, tempban.mod_id)),
|
||||
userId: tempban.user_id,
|
||||
caseNumber: createdCase.case_number,
|
||||
reason,
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { TextChannel } from "discord.js";
|
||||
import { TextChannel, ThreadChannel } from "discord.js";
|
||||
import { disableUserNotificationStrings, UserNotificationMethod } from "../../../utils";
|
||||
|
||||
export function readContactMethodsFromArgs(args: {
|
||||
notify?: string;
|
||||
"notify-channel"?: TextChannel;
|
||||
"notify-channel"?: TextChannel | ThreadChannel;
|
||||
}): null | UserNotificationMethod[] {
|
||||
if (args.notify) {
|
||||
if (args.notify === "dm") {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { GuildMember, Snowflake } from "discord.js";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { memberToConfigAccessibleMember, userToConfigAccessibleUser } from "src/utils/configAccessibleObjects";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { renderTemplate } from "../../../templateFormatter";
|
||||
|
@ -30,7 +31,7 @@ export async function warnMember(
|
|||
guildName: pluginData.guild.name,
|
||||
reason,
|
||||
moderator: warnOptions.caseArgs?.modId
|
||||
? stripObjectToScalars(await resolveUser(pluginData.client, warnOptions.caseArgs.modId))
|
||||
? userToConfigAccessibleUser(await resolveUser(pluginData.client, warnOptions.caseArgs.modId))
|
||||
: {},
|
||||
});
|
||||
const contactMethods = warnOptions?.contactMethods
|
||||
|
@ -77,8 +78,8 @@ export async function warnMember(
|
|||
|
||||
const mod = await pluginData.guild.members.fetch(modId as Snowflake);
|
||||
pluginData.state.serverLogs.log(LogType.MEMBER_WARN, {
|
||||
mod: stripObjectToScalars(mod),
|
||||
member: stripObjectToScalars(member, ["user", "roles"]),
|
||||
mod: memberToConfigAccessibleMember(mod),
|
||||
member: memberToConfigAccessibleMember(member),
|
||||
caseNumber: createdCase.case_number,
|
||||
reason,
|
||||
});
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { Snowflake } from "discord.js";
|
||||
import { memberToConfigAccessibleMember } from "src/utils/configAccessibleObjects";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { stripObjectToScalars } from "../../../utils";
|
||||
import { memberRolesLock } from "../../../utils/lockNameHelpers";
|
||||
|
@ -21,7 +22,7 @@ export const ReapplyActiveMuteOnJoinEvt = mutesEvt({
|
|||
}
|
||||
|
||||
pluginData.state.serverLogs.log(LogType.MEMBER_MUTE_REJOIN, {
|
||||
member: stripObjectToScalars(member, ["user", "roles"]),
|
||||
member: memberToConfigAccessibleMember(member),
|
||||
});
|
||||
}
|
||||
},
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { Snowflake } from "discord.js";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { memberToConfigAccessibleMember } from "src/utils/configAccessibleObjects";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { resolveMember, stripObjectToScalars, UnknownUser } from "../../../utils";
|
||||
import { memberRolesLock } from "../../../utils/lockNameHelpers";
|
||||
|
@ -33,7 +34,7 @@ export async function clearExpiredMutes(pluginData: GuildPluginData<MutesPluginT
|
|||
} catch {
|
||||
pluginData.state.serverLogs.log(LogType.BOT_ALERT, {
|
||||
body: `Failed to remove mute role from {userMention(member)}`,
|
||||
member: stripObjectToScalars(member),
|
||||
member: memberToConfigAccessibleMember(member),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +43,7 @@ export async function clearExpiredMutes(pluginData: GuildPluginData<MutesPluginT
|
|||
|
||||
pluginData.state.serverLogs.log(LogType.MEMBER_MUTE_EXPIRED, {
|
||||
member: member
|
||||
? stripObjectToScalars(member, ["user", "roles"])
|
||||
? memberToConfigAccessibleMember(member)
|
||||
: { id: mute.user_id, user: new UnknownUser({ id: mute.user_id }) },
|
||||
});
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { Snowflake, TextChannel, User } from "discord.js";
|
||||
import humanizeDuration from "humanize-duration";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { userToConfigAccessibleUser } from "src/utils/configAccessibleObjects";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import { Case } from "../../../data/entities/Case";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
|
@ -156,7 +157,7 @@ export async function muteUser(
|
|||
reason: reason || "None",
|
||||
time: timeUntilUnmute,
|
||||
moderator: muteOptions.caseArgs?.modId
|
||||
? stripObjectToScalars(await resolveUser(pluginData.client, muteOptions.caseArgs.modId))
|
||||
? userToConfigAccessibleUser(await resolveUser(pluginData.client, muteOptions.caseArgs.modId))
|
||||
: "",
|
||||
}));
|
||||
|
||||
|
@ -225,16 +226,16 @@ export async function muteUser(
|
|||
const mod = await resolveUser(pluginData.client, muteOptions.caseArgs?.modId);
|
||||
if (muteTime) {
|
||||
pluginData.state.serverLogs.log(LogType.MEMBER_TIMED_MUTE, {
|
||||
mod: stripObjectToScalars(mod),
|
||||
user: stripObjectToScalars(user),
|
||||
mod: userToConfigAccessibleUser(mod),
|
||||
user: userToConfigAccessibleUser(user),
|
||||
time: timeUntilUnmute,
|
||||
caseNumber: theCase.case_number,
|
||||
reason,
|
||||
});
|
||||
} else {
|
||||
pluginData.state.serverLogs.log(LogType.MEMBER_MUTE, {
|
||||
mod: stripObjectToScalars(mod),
|
||||
user: stripObjectToScalars(user),
|
||||
mod: userToConfigAccessibleUser(mod),
|
||||
user: userToConfigAccessibleUser(user),
|
||||
caseNumber: theCase.case_number,
|
||||
reason,
|
||||
});
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { Snowflake } from "discord.js";
|
||||
import humanizeDuration from "humanize-duration";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { userToConfigAccessibleUser } from "src/utils/configAccessibleObjects";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { resolveMember, resolveUser, stripObjectToScalars } from "../../../utils";
|
||||
|
@ -84,19 +85,19 @@ export async function unmuteUser(
|
|||
});
|
||||
|
||||
// Log the action
|
||||
const mod = pluginData.client.users.fetch(modId as Snowflake);
|
||||
const mod = await pluginData.client.users.fetch(modId as Snowflake);
|
||||
if (unmuteTime) {
|
||||
pluginData.state.serverLogs.log(LogType.MEMBER_TIMED_UNMUTE, {
|
||||
mod: stripObjectToScalars(mod),
|
||||
user: stripObjectToScalars(user),
|
||||
mod: userToConfigAccessibleUser(mod),
|
||||
user: userToConfigAccessibleUser(user),
|
||||
caseNumber: createdCase.case_number,
|
||||
time: timeUntilUnmute,
|
||||
reason: caseArgs.reason,
|
||||
});
|
||||
} else {
|
||||
pluginData.state.serverLogs.log(LogType.MEMBER_UNMUTE, {
|
||||
mod: stripObjectToScalars(mod),
|
||||
user: stripObjectToScalars(user),
|
||||
mod: userToConfigAccessibleUser(mod),
|
||||
user: userToConfigAccessibleUser(user),
|
||||
caseNumber: createdCase.case_number,
|
||||
reason: caseArgs.reason,
|
||||
});
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { GuildMemberEditData, Permissions } from "discord.js";
|
||||
import intersection from "lodash.intersection";
|
||||
import { memberToConfigAccessibleMember } from "src/utils/configAccessibleObjects";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { stripObjectToScalars } from "../../../utils";
|
||||
import { canAssignRole } from "../../../utils/canAssignRole";
|
||||
|
@ -75,7 +76,7 @@ export const LoadDataEvt = persistEvt({
|
|||
await pluginData.state.persistedData.clear(member.id);
|
||||
|
||||
pluginData.state.logs.log(LogType.MEMBER_RESTORE, {
|
||||
member: stripObjectToScalars(member, ["user", "roles"]),
|
||||
member: memberToConfigAccessibleMember(member),
|
||||
restoredData: restoredData.join(", "),
|
||||
});
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ import { Channel, Message, TextChannel } from "discord.js";
|
|||
import humanizeDuration from "humanize-duration";
|
||||
import { GuildPluginData } from "knub";
|
||||
import moment from "moment-timezone";
|
||||
import { channelToConfigAccessibleChannel, userToConfigAccessibleUser } from "src/utils/configAccessibleObjects";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
import { DBDateFormat, errorMessage, MINUTES, StrictMessageContent, stripObjectToScalars } from "../../../utils";
|
||||
|
@ -158,8 +159,8 @@ export async function actualPostCmd(
|
|||
|
||||
if (opts.repeat) {
|
||||
pluginData.state.logs.log(LogType.SCHEDULED_REPEATED_MESSAGE, {
|
||||
author: stripObjectToScalars(msg.author),
|
||||
channel: stripObjectToScalars(targetChannel),
|
||||
author: userToConfigAccessibleUser(msg.author),
|
||||
channel: channelToConfigAccessibleChannel(targetChannel),
|
||||
datetime: postAt.format(timeAndDate.getDateFormat("pretty_datetime")),
|
||||
date: postAt.format(timeAndDate.getDateFormat("date")),
|
||||
time: postAt.format(timeAndDate.getDateFormat("time")),
|
||||
|
@ -168,8 +169,8 @@ export async function actualPostCmd(
|
|||
});
|
||||
} else {
|
||||
pluginData.state.logs.log(LogType.SCHEDULED_MESSAGE, {
|
||||
author: stripObjectToScalars(msg.author),
|
||||
channel: stripObjectToScalars(targetChannel),
|
||||
author: userToConfigAccessibleUser(msg.author),
|
||||
channel: channelToConfigAccessibleChannel(targetChannel),
|
||||
datetime: postAt.format(timeAndDate.getDateFormat("pretty_datetime")),
|
||||
date: postAt.format(timeAndDate.getDateFormat("date")),
|
||||
time: postAt.format(timeAndDate.getDateFormat("time")),
|
||||
|
@ -184,8 +185,8 @@ export async function actualPostCmd(
|
|||
|
||||
if (opts.repeat) {
|
||||
pluginData.state.logs.log(LogType.REPEATED_MESSAGE, {
|
||||
author: stripObjectToScalars(msg.author),
|
||||
channel: stripObjectToScalars(targetChannel),
|
||||
author: userToConfigAccessibleUser(msg.author),
|
||||
channel: channelToConfigAccessibleChannel(targetChannel),
|
||||
datetime: postAt.format(timeAndDate.getDateFormat("pretty_datetime")),
|
||||
date: postAt.format(timeAndDate.getDateFormat("date")),
|
||||
time: postAt.format(timeAndDate.getDateFormat("time")),
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { Snowflake, TextChannel, User } from "discord.js";
|
||||
import { GuildPluginData } from "knub";
|
||||
import moment from "moment-timezone";
|
||||
import { channelToConfigAccessibleChannel, userToConfigAccessibleUser } from "src/utils/configAccessibleObjects";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { logger } from "../../../logger";
|
||||
import { DBDateFormat, SECONDS, stripObjectToScalars } from "../../../utils";
|
||||
|
@ -30,15 +31,15 @@ export async function scheduledPostLoop(pluginData: GuildPluginData<PostPluginTy
|
|||
post.enable_mentions,
|
||||
);
|
||||
pluginData.state.logs.log(LogType.POSTED_SCHEDULED_MESSAGE, {
|
||||
author: stripObjectToScalars(author),
|
||||
channel: stripObjectToScalars(channel),
|
||||
author: userToConfigAccessibleUser(author),
|
||||
channel: channelToConfigAccessibleChannel(channel),
|
||||
messageId: postedMessage.id,
|
||||
});
|
||||
} catch {
|
||||
pluginData.state.logs.log(LogType.BOT_ALERT, {
|
||||
body: `Failed to post scheduled message by {userMention(author)} to {channelMention(channel)}`,
|
||||
channel: stripObjectToScalars(channel),
|
||||
author: stripObjectToScalars(author),
|
||||
channel: channelToConfigAccessibleChannel(channel),
|
||||
author: userToConfigAccessibleUser(author),
|
||||
});
|
||||
logger.warn(
|
||||
`Failed to post scheduled message to #${channel.name} (${channel.id}) on ${pluginData.guild.name} (${pluginData.guild.id})`,
|
||||
|
|
|
@ -30,6 +30,7 @@ export async function resolveStatefulCustomId(pluginData: GuildPluginData<Reacti
|
|||
|
||||
if (button) {
|
||||
const group = pluginData.config.get().button_groups[button.button_group];
|
||||
if (!group) return null;
|
||||
const cfgButton = group.default_buttons[button.button_name];
|
||||
|
||||
return {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { GuildChannel } from "discord.js";
|
||||
import { memberToConfigAccessibleMember, userToConfigAccessibleUser } from "src/utils/configAccessibleObjects";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { canActOn, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
|
@ -53,9 +54,9 @@ export const AddRoleCmd = rolesCmd({
|
|||
await args.member.roles.add(roleId);
|
||||
|
||||
pluginData.state.logs.log(LogType.MEMBER_ROLE_ADD, {
|
||||
member: stripObjectToScalars(args.member, ["user", "roles"]),
|
||||
member: memberToConfigAccessibleMember(args.member),
|
||||
roles: role.name,
|
||||
mod: stripObjectToScalars(msg.author),
|
||||
mod: userToConfigAccessibleUser(msg.author),
|
||||
});
|
||||
|
||||
sendSuccessMessage(
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { GuildMember } from "discord.js";
|
||||
import { memberToConfigAccessibleMember, userToConfigAccessibleUser } from "src/utils/configAccessibleObjects";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { logger } from "../../../logger";
|
||||
|
@ -74,9 +75,9 @@ export const MassAddRoleCmd = rolesCmd({
|
|||
pluginData.state.logs.ignoreLog(LogType.MEMBER_ROLE_ADD, member.id);
|
||||
await member.roles.add(roleId);
|
||||
pluginData.state.logs.log(LogType.MEMBER_ROLE_ADD, {
|
||||
member: stripObjectToScalars(member, ["user", "roles"]),
|
||||
member: memberToConfigAccessibleMember(member),
|
||||
roles: role.name,
|
||||
mod: stripObjectToScalars(msg.author),
|
||||
mod: userToConfigAccessibleUser(msg.author),
|
||||
});
|
||||
assigned++;
|
||||
} catch (e) {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { GuildMember } from "discord.js";
|
||||
import { memberToConfigAccessibleMember, userToConfigAccessibleUser } from "src/utils/configAccessibleObjects";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { logger } from "../../../logger";
|
||||
|
@ -74,9 +75,9 @@ export const MassRemoveRoleCmd = rolesCmd({
|
|||
pluginData.state.logs.ignoreLog(LogType.MEMBER_ROLE_REMOVE, member.id);
|
||||
await member.roles.remove(roleId);
|
||||
pluginData.state.logs.log(LogType.MEMBER_ROLE_REMOVE, {
|
||||
member: stripObjectToScalars(member, ["user", "roles"]),
|
||||
member: memberToConfigAccessibleMember(member),
|
||||
roles: role.name,
|
||||
mod: stripObjectToScalars(msg.author),
|
||||
mod: userToConfigAccessibleUser(msg.author),
|
||||
});
|
||||
assigned++;
|
||||
} catch (e) {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { GuildChannel } from "discord.js";
|
||||
import { memberToConfigAccessibleMember, userToConfigAccessibleUser } from "src/utils/configAccessibleObjects";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { canActOn, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
|
@ -53,9 +54,9 @@ export const RemoveRoleCmd = rolesCmd({
|
|||
await args.member.roles.remove(roleId);
|
||||
|
||||
pluginData.state.logs.log(LogType.MEMBER_ROLE_REMOVE, {
|
||||
member: stripObjectToScalars(args.member, ["user", "roles"]),
|
||||
member: memberToConfigAccessibleMember(args.member),
|
||||
roles: role.name,
|
||||
mod: stripObjectToScalars(msg.author),
|
||||
mod: userToConfigAccessibleUser(msg.author),
|
||||
});
|
||||
|
||||
sendSuccessMessage(
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ChannelTypeStrings } from "src/types";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
import { asSingleLine, disableInlineCode } from "../../../utils";
|
||||
|
@ -37,7 +38,19 @@ export const SlowmodeClearCmd = slowmodeCmd({
|
|||
}
|
||||
|
||||
try {
|
||||
await clearBotSlowmodeFromUserId(pluginData, args.channel, args.user.id, args.force);
|
||||
if (args.channel.type === ChannelTypeStrings.TEXT) {
|
||||
await clearBotSlowmodeFromUserId(pluginData, args.channel, args.user.id, args.force);
|
||||
} else {
|
||||
sendErrorMessage(
|
||||
pluginData,
|
||||
msg.channel,
|
||||
asSingleLine(`
|
||||
Failed to clear slowmode from **${args.user.username}#${args.user.discriminator}** in <#${args.channel.id}>:
|
||||
Threads cannot have Bot Slowmode
|
||||
`),
|
||||
);
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
sendErrorMessage(
|
||||
pluginData,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { Permissions, TextChannel } from "discord.js";
|
||||
import { Permissions, TextChannel, ThreadChannel } from "discord.js";
|
||||
import humanizeDuration from "humanize-duration";
|
||||
import { ChannelTypeStrings } from "src/types";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
import { asSingleLine, DAYS, disableInlineCode, HOURS, MINUTES } from "../../../utils";
|
||||
|
@ -38,7 +39,7 @@ export const SlowmodeSetCmd = slowmodeCmd({
|
|||
],
|
||||
|
||||
async run({ message: msg, args, pluginData }) {
|
||||
const channel: TextChannel = args.channel || msg.channel;
|
||||
const channel: TextChannel | ThreadChannel = args.channel || msg.channel;
|
||||
|
||||
if (args.time === 0) {
|
||||
// Workaround until we can call SlowmodeDisableCmd from here
|
||||
|
@ -122,7 +123,7 @@ export const SlowmodeSetCmd = slowmodeCmd({
|
|||
if (mode === "native") {
|
||||
// If there is an existing bot-maintained slowmode, disable that first
|
||||
const existingBotSlowmode = await pluginData.state.slowmodes.getChannelSlowmode(channel.id);
|
||||
if (existingBotSlowmode) {
|
||||
if (existingBotSlowmode && channel.type === ChannelTypeStrings.TEXT) {
|
||||
await disableBotSlowmodeForChannel(pluginData, channel);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { GuildChannel, Permissions, Snowflake, TextChannel } from "discord.js";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { channelToConfigAccessibleChannel, userToConfigAccessibleUser } from "src/utils/configAccessibleObjects";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { logger } from "../../../logger";
|
||||
import { isDiscordAPIError, stripObjectToScalars, UnknownUser } from "../../../utils";
|
||||
|
@ -20,7 +21,7 @@ export async function applyBotSlowmodeToUserId(
|
|||
await channel.permissionOverwrites.create(userId as Snowflake, { SEND_MESSAGES: false }, { type: 1 });
|
||||
}
|
||||
} catch (e) {
|
||||
const user = pluginData.client.users.fetch(userId as Snowflake) || new UnknownUser({ id: userId });
|
||||
const user = (await pluginData.client.users.fetch(userId as Snowflake)) || new UnknownUser({ id: userId });
|
||||
|
||||
if (isDiscordAPIError(e) && e.code === 50013) {
|
||||
logger.warn(
|
||||
|
@ -28,14 +29,14 @@ export async function applyBotSlowmodeToUserId(
|
|||
);
|
||||
pluginData.state.logs.log(LogType.BOT_ALERT, {
|
||||
body: `Missing permissions to apply bot slowmode to {userMention(user)} in {channelMention(channel)}`,
|
||||
user: stripObjectToScalars(user),
|
||||
channel: stripObjectToScalars(channel),
|
||||
user: userToConfigAccessibleUser(user),
|
||||
channel: channelToConfigAccessibleChannel(channel),
|
||||
});
|
||||
} else {
|
||||
pluginData.state.logs.log(LogType.BOT_ALERT, {
|
||||
body: `Failed to apply bot slowmode to {userMention(user)} in {channelMention(channel)}`,
|
||||
user: stripObjectToScalars(user),
|
||||
channel: stripObjectToScalars(channel),
|
||||
user: userToConfigAccessibleUser(user),
|
||||
channel: channelToConfigAccessibleChannel(channel),
|
||||
});
|
||||
throw e;
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { GuildChannel, Snowflake, TextChannel } from "discord.js";
|
||||
import { GuildChannel, Snowflake, TextChannel, ThreadChannel } from "discord.js";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { SlowmodePluginType } from "../types";
|
||||
|
||||
export async function clearBotSlowmodeFromUserId(
|
||||
pluginData: GuildPluginData<SlowmodePluginType>,
|
||||
channel: GuildChannel & TextChannel,
|
||||
channel: TextChannel,
|
||||
userId: string,
|
||||
force = false,
|
||||
) {
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { GuildChannel, TextChannel } from "discord.js";
|
||||
import { GuildChannel, TextChannel, ThreadChannel } from "discord.js";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { SlowmodePluginType } from "../types";
|
||||
import { clearBotSlowmodeFromUserId } from "./clearBotSlowmodeFromUserId";
|
||||
|
||||
export async function disableBotSlowmodeForChannel(
|
||||
pluginData: GuildPluginData<SlowmodePluginType>,
|
||||
channel: GuildChannel & TextChannel,
|
||||
channel: TextChannel,
|
||||
) {
|
||||
// Disable channel slowmode
|
||||
await pluginData.state.slowmodes.deleteChannelSlowmode(channel.id);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { Snowflake, TextChannel } from "discord.js";
|
||||
import { GuildPluginData } from "knub";
|
||||
import moment from "moment-timezone";
|
||||
import { channelToConfigAccessibleChannel, memberToConfigAccessibleMember } from "src/utils/configAccessibleObjects";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import { SavedMessage } from "../../../data/entities/SavedMessage";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
|
@ -185,8 +186,8 @@ export async function logAndDetectMessageSpam(
|
|||
|
||||
// Create a log entry
|
||||
logs.log(LogType.MESSAGE_SPAM_DETECTED, {
|
||||
member: stripObjectToScalars(member, ["user", "roles"]),
|
||||
channel: stripObjectToScalars(channel),
|
||||
member: memberToConfigAccessibleMember(member!),
|
||||
channel: channelToConfigAccessibleChannel(channel!),
|
||||
description,
|
||||
limit: spamConfig.count,
|
||||
interval: spamConfig.interval,
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { GuildPluginData } from "knub";
|
||||
import { memberToConfigAccessibleMember } from "src/utils/configAccessibleObjects";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { CasesPlugin } from "../../../plugins/Cases/CasesPlugin";
|
||||
|
@ -78,7 +79,7 @@ export async function logAndDetectOtherSpam(
|
|||
clearRecentUserActions(pluginData, RecentActionType.VoiceChannelMove, userId, actionGroupId);
|
||||
|
||||
logs.log(LogType.OTHER_SPAM_DETECTED, {
|
||||
member: stripObjectToScalars(member, ["user", "roles"]),
|
||||
member: memberToConfigAccessibleMember(member!),
|
||||
description,
|
||||
limit: spamConfig.count,
|
||||
interval: spamConfig.interval,
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { memberToConfigAccessibleMember, userToConfigAccessibleUser } from "src/utils/configAccessibleObjects";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { sendErrorMessage } from "../../../pluginUtils";
|
||||
import { TemplateParseError } from "../../../templateFormatter";
|
||||
|
@ -20,8 +21,8 @@ export const TagEvalCmd = tagsCmd({
|
|||
args.body,
|
||||
[],
|
||||
{
|
||||
member: stripObjectToScalars(msg.member, ["user"]),
|
||||
user: stripObjectToScalars(msg.member.user),
|
||||
member: memberToConfigAccessibleMember(msg.member),
|
||||
user: userToConfigAccessibleUser(msg.member.user),
|
||||
},
|
||||
{ member: msg.member },
|
||||
);
|
||||
|
|
|
@ -2,6 +2,7 @@ import { GuildMember } from "discord.js";
|
|||
import * as t from "io-ts";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { parseArguments } from "knub-command-manager";
|
||||
import { memberToConfigAccessibleMember, userToConfigAccessibleUser } from "src/utils/configAccessibleObjects";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { TemplateParseError } from "../../../templateFormatter";
|
||||
import { StrictMessageContent, stripObjectToScalars } from "../../../utils";
|
||||
|
@ -27,8 +28,8 @@ export async function renderTagFromString(
|
|||
tagBody,
|
||||
tagArgs,
|
||||
{
|
||||
member: stripObjectToScalars(member, ["user"]),
|
||||
user: stripObjectToScalars(member.user),
|
||||
member: memberToConfigAccessibleMember(member),
|
||||
user: userToConfigAccessibleUser(member.user),
|
||||
},
|
||||
{ member },
|
||||
);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { Message, Snowflake, TextChannel, User } from "discord.js";
|
||||
import { GuildPluginData } from "knub";
|
||||
import moment from "moment-timezone";
|
||||
import { channelToConfigAccessibleChannel, userToConfigAccessibleUser } from "src/utils/configAccessibleObjects";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { SavedMessage } from "../../../data/entities/SavedMessage";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
|
@ -41,8 +42,8 @@ async function cleanMessages(
|
|||
const archiveUrl = pluginData.state.archives.getUrl(baseUrl, archiveId);
|
||||
|
||||
pluginData.state.logs.log(LogType.CLEAN, {
|
||||
mod: stripObjectToScalars(mod),
|
||||
channel: stripObjectToScalars(channel),
|
||||
mod: userToConfigAccessibleUser(mod),
|
||||
channel: channelToConfigAccessibleChannel(channel),
|
||||
count: savedMessages.length,
|
||||
archiveUrl,
|
||||
});
|
||||
|
@ -172,7 +173,7 @@ export const CleanCmd = utilityCmd({
|
|||
|
||||
let responseText = `Cleaned ${messagesToClean.length} ${messagesToClean.length === 1 ? "message" : "messages"}`;
|
||||
if (targetChannel.id !== msg.channel.id) {
|
||||
responseText += ` in <#${targetChannel.id}>\n${cleanResult.archiveUrl}`;
|
||||
responseText += ` in <#${targetChannel.id}>: ${cleanResult.archiveUrl}`;
|
||||
}
|
||||
|
||||
if (args.update) {
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
import { VoiceChannel } from "discord.js";
|
||||
import {
|
||||
channelToConfigAccessibleChannel,
|
||||
memberToConfigAccessibleMember,
|
||||
userToConfigAccessibleUser,
|
||||
} from "src/utils/configAccessibleObjects";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { canActOn, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
|
@ -35,9 +40,9 @@ export const VcdisconnectCmd = utilityCmd({
|
|||
}
|
||||
|
||||
pluginData.state.logs.log(LogType.VOICE_CHANNEL_FORCE_DISCONNECT, {
|
||||
mod: stripObjectToScalars(msg.author),
|
||||
member: stripObjectToScalars(args.member, ["user", "roles"]),
|
||||
oldChannel: stripObjectToScalars(channel),
|
||||
mod: userToConfigAccessibleUser(msg.author),
|
||||
member: memberToConfigAccessibleMember(args.member),
|
||||
oldChannel: channelToConfigAccessibleChannel(channel),
|
||||
});
|
||||
|
||||
sendSuccessMessage(
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
import { Snowflake, VoiceChannel } from "discord.js";
|
||||
import {
|
||||
channelToConfigAccessibleChannel,
|
||||
memberToConfigAccessibleMember,
|
||||
userToConfigAccessibleUser,
|
||||
} from "src/utils/configAccessibleObjects";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { canActOn, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
|
@ -74,10 +79,10 @@ export const VcmoveCmd = utilityCmd({
|
|||
}
|
||||
|
||||
pluginData.state.logs.log(LogType.VOICE_CHANNEL_FORCE_MOVE, {
|
||||
mod: stripObjectToScalars(msg.author),
|
||||
member: stripObjectToScalars(args.member, ["user", "roles"]),
|
||||
oldChannel: stripObjectToScalars(oldVoiceChannel),
|
||||
newChannel: stripObjectToScalars(channel),
|
||||
mod: userToConfigAccessibleUser(msg.author),
|
||||
member: memberToConfigAccessibleMember(args.member),
|
||||
oldChannel: channelToConfigAccessibleChannel(oldVoiceChannel!),
|
||||
newChannel: channelToConfigAccessibleChannel(channel),
|
||||
});
|
||||
|
||||
sendSuccessMessage(
|
||||
|
@ -182,10 +187,10 @@ export const VcmoveAllCmd = utilityCmd({
|
|||
}
|
||||
|
||||
pluginData.state.logs.log(LogType.VOICE_CHANNEL_FORCE_MOVE, {
|
||||
mod: stripObjectToScalars(msg.author),
|
||||
member: stripObjectToScalars(currMember, ["user", "roles"]),
|
||||
oldChannel: stripObjectToScalars(args.oldChannel),
|
||||
newChannel: stripObjectToScalars(channel),
|
||||
mod: userToConfigAccessibleUser(msg.author),
|
||||
member: memberToConfigAccessibleMember(currMember),
|
||||
oldChannel: channelToConfigAccessibleChannel(args.oldChannel),
|
||||
newChannel: channelToConfigAccessibleChannel(channel),
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
import { Snowflake, TextChannel } from "discord.js";
|
||||
import {
|
||||
channelToConfigAccessibleChannel,
|
||||
memberToConfigAccessibleMember,
|
||||
userToConfigAccessibleUser,
|
||||
} from "src/utils/configAccessibleObjects";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { renderTemplate, TemplateParseError } from "../../../templateFormatter";
|
||||
import { createChunkedMessage, stripObjectToScalars } from "../../../utils";
|
||||
|
@ -49,7 +54,7 @@ export const SendWelcomeMessageEvt = welcomeMessageEvt({
|
|||
} catch {
|
||||
pluginData.state.logs.log(LogType.DM_FAILED, {
|
||||
source: "welcome message",
|
||||
user: stripObjectToScalars(member.user),
|
||||
user: userToConfigAccessibleUser(member.user),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -63,8 +68,8 @@ export const SendWelcomeMessageEvt = welcomeMessageEvt({
|
|||
} catch {
|
||||
pluginData.state.logs.log(LogType.BOT_ALERT, {
|
||||
body: `Failed send a welcome message for {userMention(member)} to {channelMention(channel)}`,
|
||||
member: stripObjectToScalars(member),
|
||||
channel: stripObjectToScalars(channel),
|
||||
member: memberToConfigAccessibleMember(member),
|
||||
channel: channelToConfigAccessibleChannel(channel),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue