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

Turn on strict TS compilation. Fix up and tweak types accordingly.

This commit is contained in:
Dragory 2020-11-09 20:03:57 +02:00
parent 690955a399
commit 629002b8d9
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
172 changed files with 720 additions and 534 deletions

View file

@ -158,7 +158,7 @@ export const AutomodPlugin = zeppelinGuildPlugin<AutomodPluginType>()("automod",
configPreprocessor,
customOverrideMatcher(pluginData, criteria, matchParams) {
return criteria?.antiraid_level && criteria.antiraid_level === pluginData.state.cachedAntiraidLevel;
return criteria?.antiraid_level ? criteria.antiraid_level === pluginData.state.cachedAntiraidLevel : false;
},
events: [

View file

@ -1,7 +1,7 @@
import * as t from "io-ts";
import { automodAction } from "../helpers";
import { LogType } from "../../../data/LogType";
import { unique } from "../../../utils";
import { nonNullish, unique } from "../../../utils";
import { Constants } from "eris";
import { hasDiscordPermissions } from "../../../utils/hasDiscordPermissions";
import { LogsPlugin } from "../../Logs/LogsPlugin";
@ -17,8 +17,8 @@ export const AddRolesAction = automodAction({
defaultConfig: [],
async apply({ pluginData, contexts, actionConfig, ruleName }) {
const members = unique(contexts.map(c => c.member).filter(Boolean));
const me = pluginData.guild.members.get(pluginData.client.user.id);
const members = unique(contexts.map(c => c.member).filter(nonNullish));
const me = pluginData.guild.members.get(pluginData.client.user.id)!;
const missingPermissions = getMissingPermissions(me.permission, p.manageRoles);
if (missingPermissions) {
@ -29,8 +29,8 @@ export const AddRolesAction = automodAction({
return;
}
const rolesToAssign = [];
const rolesWeCannotAssign = [];
const rolesToAssign: string[] = [];
const rolesWeCannotAssign: string[] = [];
for (const roleId of actionConfig) {
if (canAssignRole(pluginData.guild, me, roleId)) {
rolesToAssign.push(roleId);

View file

@ -1,7 +1,7 @@
import * as t from "io-ts";
import { automodAction } from "../helpers";
import { LogType } from "../../../data/LogType";
import { asyncMap, resolveMember, tNullable, unique } from "../../../utils";
import { asyncMap, nonNullish, resolveMember, tNullable, unique } from "../../../utils";
import { resolveActionContactMethods } from "../functions/resolveActionContactMethods";
import { ModActionsPlugin } from "../../ModActions/ModActionsPlugin";
@ -20,14 +20,14 @@ export const BanAction = automodAction({
async apply({ pluginData, contexts, actionConfig, matchResult }) {
const reason = actionConfig.reason || "Kicked automatically";
const contactMethods = resolveActionContactMethods(pluginData, actionConfig);
const deleteMessageDays = actionConfig.deleteMessageDays;
const deleteMessageDays = actionConfig.deleteMessageDays || undefined;
const caseArgs = {
modId: pluginData.client.user.id,
extraNotes: [matchResult.fullSummary],
extraNotes: matchResult.fullSummary ? [matchResult.fullSummary] : [],
};
const userIdsToBan = unique(contexts.map(c => c.user?.id).filter(Boolean));
const userIdsToBan = unique(contexts.map(c => c.user?.id).filter(nonNullish));
const modActions = pluginData.getPlugin(ModActionsPlugin);
for (const userId of userIdsToBan) {

View file

@ -2,7 +2,7 @@ import * as t from "io-ts";
import { automodAction } from "../helpers";
import { LogType } from "../../../data/LogType";
import { LogsPlugin } from "../../Logs/LogsPlugin";
import { unique } from "../../../utils";
import { nonNullish, unique } from "../../../utils";
export const ChangeNicknameAction = automodAction({
configType: t.union([
@ -15,7 +15,7 @@ export const ChangeNicknameAction = automodAction({
defaultConfig: {},
async apply({ pluginData, contexts, actionConfig }) {
const members = unique(contexts.map(c => c.member).filter(Boolean));
const members = unique(contexts.map(c => c.member).filter(nonNullish));
for (const member of members) {
if (pluginData.state.recentNicknameChanges.has(member.id)) continue;

View file

@ -15,12 +15,12 @@ export const CleanAction = automodAction({
messageIdsToDeleteByChannelId.set(context.message.channel_id, []);
}
if (messageIdsToDeleteByChannelId.get(context.message.channel_id).includes(context.message.id)) {
if (messageIdsToDeleteByChannelId.get(context.message.channel_id)!.includes(context.message.id)) {
console.warn(`Message ID to delete was already present: ${pluginData.guild.name}, rule ${ruleName}`);
continue;
}
messageIdsToDeleteByChannelId.get(context.message.channel_id).push(context.message.id);
messageIdsToDeleteByChannelId.get(context.message.channel_id)!.push(context.message.id);
}
}

View file

@ -1,7 +1,7 @@
import * as t from "io-ts";
import { automodAction } from "../helpers";
import { LogType } from "../../../data/LogType";
import { asyncMap, resolveMember, tNullable, unique } from "../../../utils";
import { asyncMap, nonNullish, resolveMember, tNullable, unique } from "../../../utils";
import { resolveActionContactMethods } from "../functions/resolveActionContactMethods";
import { ModActionsPlugin } from "../../ModActions/ModActionsPlugin";
@ -22,14 +22,15 @@ export const KickAction = automodAction({
const caseArgs = {
modId: pluginData.client.user.id,
extraNotes: [matchResult.fullSummary],
extraNotes: matchResult.fullSummary ? [matchResult.fullSummary] : [],
};
const userIdsToKick = unique(contexts.map(c => c.user?.id).filter(Boolean));
const userIdsToKick = unique(contexts.map(c => c.user?.id).filter(nonNullish));
const membersToKick = await asyncMap(userIdsToKick, id => resolveMember(pluginData.client, pluginData.guild, id));
const modActions = pluginData.getPlugin(ModActionsPlugin);
for (const member of membersToKick) {
if (!member) continue;
await modActions.kickMember(member, reason, { contactMethods, caseArgs });
}
},

View file

@ -1,7 +1,15 @@
import * as t from "io-ts";
import { automodAction } from "../helpers";
import { LogType } from "../../../data/LogType";
import { asyncMap, convertDelayStringToMS, resolveMember, tDelayString, tNullable, unique } from "../../../utils";
import {
asyncMap,
convertDelayStringToMS,
nonNullish,
resolveMember,
tDelayString,
tNullable,
unique,
} from "../../../utils";
import { resolveActionContactMethods } from "../functions/resolveActionContactMethods";
import { ModActionsPlugin } from "../../ModActions/ModActionsPlugin";
import { MutesPlugin } from "../../Mutes/MutesPlugin";
@ -21,16 +29,16 @@ export const MuteAction = automodAction({
},
async apply({ pluginData, contexts, actionConfig, ruleName, matchResult }) {
const duration = actionConfig.duration ? convertDelayStringToMS(actionConfig.duration) : null;
const duration = actionConfig.duration ? convertDelayStringToMS(actionConfig.duration)! : undefined;
const reason = actionConfig.reason || "Muted automatically";
const contactMethods = resolveActionContactMethods(pluginData, actionConfig);
const caseArgs = {
modId: pluginData.client.user.id,
extraNotes: [matchResult.fullSummary],
extraNotes: matchResult.fullSummary ? [matchResult.fullSummary] : [],
};
const userIdsToMute = unique(contexts.map(c => c.user?.id).filter(Boolean));
const userIdsToMute = unique(contexts.map(c => c.user?.id).filter(nonNullish));
const mutes = pluginData.getPlugin(MutesPlugin);
for (const userId of userIdsToMute) {

View file

@ -1,7 +1,7 @@
import * as t from "io-ts";
import { automodAction } from "../helpers";
import { LogType } from "../../../data/LogType";
import { asyncMap, resolveMember, tNullable, unique } from "../../../utils";
import { asyncMap, nonNullish, resolveMember, tNullable, unique } from "../../../utils";
import { resolveActionContactMethods } from "../functions/resolveActionContactMethods";
import { ModActionsPlugin } from "../../ModActions/ModActionsPlugin";
import { getMissingPermissions } from "../../../utils/getMissingPermissions";
@ -19,8 +19,8 @@ export const RemoveRolesAction = automodAction({
defaultConfig: [],
async apply({ pluginData, contexts, actionConfig, ruleName }) {
const members = unique(contexts.map(c => c.member).filter(Boolean));
const me = pluginData.guild.members.get(pluginData.client.user.id);
const members = unique(contexts.map(c => c.member).filter(nonNullish));
const me = pluginData.guild.members.get(pluginData.client.user.id)!;
const missingPermissions = getMissingPermissions(me.permission, p.manageRoles);
if (missingPermissions) {
@ -31,8 +31,8 @@ export const RemoveRolesAction = automodAction({
return;
}
const rolesToRemove = [];
const rolesWeCannotRemove = [];
const rolesToRemove: string[] = [];
const rolesWeCannotRemove: string[] = [];
for (const roleId of actionConfig) {
if (canAssignRole(pluginData.guild, me, roleId)) {
rolesToRemove.push(roleId);

View file

@ -28,14 +28,14 @@ export const ReplyAction = automodAction({
async apply({ pluginData, contexts, actionConfig }) {
const contextsWithTextChannels = contexts
.filter(c => c.message?.channel_id)
.filter(c => pluginData.guild.channels.get(c.message.channel_id) instanceof TextChannel);
.filter(c => pluginData.guild.channels.get(c.message!.channel_id) instanceof TextChannel);
const contextsByChannelId = contextsWithTextChannels.reduce((map: Map<string, AutomodContext[]>, context) => {
if (!map.has(context.message.channel_id)) {
map.set(context.message.channel_id, []);
if (!map.has(context.message!.channel_id)) {
map.set(context.message!.channel_id, []);
}
map.get(context.message.channel_id).push(context);
map.get(context.message!.channel_id)!.push(context);
return map;
}, new Map());
@ -57,7 +57,7 @@ export const ReplyAction = automodAction({
const replyMsg = await channel.createMessage(formatted);
if (typeof actionConfig === "object" && actionConfig.auto_delete) {
const delay = convertDelayStringToMS(String(actionConfig.auto_delete));
const delay = convertDelayStringToMS(String(actionConfig.auto_delete))!;
setTimeout(() => replyMsg.delete().catch(noop), delay);
}
}

View file

@ -4,7 +4,7 @@ import { setAntiraidLevel } from "../functions/setAntiraidLevel";
export const SetAntiraidLevelAction = automodAction({
configType: t.string,
defaultConfig: null,
defaultConfig: "",
async apply({ pluginData, contexts, actionConfig }) {
setAntiraidLevel(pluginData, actionConfig);

View file

@ -1,7 +1,7 @@
import * as t from "io-ts";
import { automodAction } from "../helpers";
import { LogType } from "../../../data/LogType";
import { asyncMap, resolveMember, tNullable, unique } from "../../../utils";
import { asyncMap, nonNullish, resolveMember, tNullable, unique } from "../../../utils";
import { resolveActionContactMethods } from "../functions/resolveActionContactMethods";
import { ModActionsPlugin } from "../../ModActions/ModActionsPlugin";
@ -22,14 +22,15 @@ export const WarnAction = automodAction({
const caseArgs = {
modId: pluginData.client.user.id,
extraNotes: [matchResult.fullSummary],
extraNotes: matchResult.fullSummary ? [matchResult.fullSummary] : [],
};
const userIdsToWarn = unique(contexts.map(c => c.user?.id).filter(Boolean));
const userIdsToWarn = unique(contexts.map(c => c.user?.id).filter(nonNullish));
const membersToWarn = await asyncMap(userIdsToWarn, id => resolveMember(pluginData.client, pluginData.guild, id));
const modActions = pluginData.getPlugin(ModActionsPlugin);
for (const member of membersToWarn) {
if (!member) continue;
await modActions.warnMember(member, reason, { contactMethods, caseArgs });
}
},

View file

@ -4,8 +4,9 @@ import { RECENT_ACTION_EXPIRY_TIME, RecentActionType } from "../constants";
import { getEmojiInString, getRoleMentions, getUrlsInString, getUserMentions } from "../../../utils";
export function addRecentActionsFromMessage(pluginData: GuildPluginData<AutomodPluginType>, context: AutomodContext) {
const globalIdentifier = context.message.user_id;
const perChannelIdentifier = `${context.message.channel_id}-${context.message.user_id}`;
const message = context.message!;
const globalIdentifier = message.user_id;
const perChannelIdentifier = `${message.channel_id}-${message.user_id}`;
const expiresAt = Date.now() + RECENT_ACTION_EXPIRY_TIME;
pluginData.state.recentActions.push({
@ -23,8 +24,7 @@ export function addRecentActionsFromMessage(pluginData: GuildPluginData<AutomodP
});
const mentionCount =
getUserMentions(context.message.data.content || "").length +
getRoleMentions(context.message.data.content || "").length;
getUserMentions(message.data.content || "").length + getRoleMentions(message.data.content || "").length;
if (mentionCount) {
pluginData.state.recentActions.push({
context,
@ -41,7 +41,7 @@ export function addRecentActionsFromMessage(pluginData: GuildPluginData<AutomodP
});
}
const linkCount = getUrlsInString(context.message.data.content || "").length;
const linkCount = getUrlsInString(message.data.content || "").length;
if (linkCount) {
pluginData.state.recentActions.push({
context,
@ -58,7 +58,7 @@ export function addRecentActionsFromMessage(pluginData: GuildPluginData<AutomodP
});
}
const attachmentCount = context.message.data.attachments && context.message.data.attachments.length;
const attachmentCount = message.data.attachments && message.data.attachments.length;
if (attachmentCount) {
pluginData.state.recentActions.push({
context,
@ -75,7 +75,7 @@ export function addRecentActionsFromMessage(pluginData: GuildPluginData<AutomodP
});
}
const emojiCount = getEmojiInString(context.message.data.content || "").length;
const emojiCount = getEmojiInString(message.data.content || "").length;
if (emojiCount) {
pluginData.state.recentActions.push({
context,
@ -93,7 +93,7 @@ export function addRecentActionsFromMessage(pluginData: GuildPluginData<AutomodP
}
// + 1 is for the first line of the message (which doesn't have a line break)
const lineCount = context.message.data.content ? (context.message.data.content.match(/\n/g) || []).length + 1 : 0;
const lineCount = message.data.content ? (message.data.content.match(/\n/g) || []).length + 1 : 0;
if (lineCount) {
pluginData.state.recentActions.push({
context,
@ -110,7 +110,7 @@ export function addRecentActionsFromMessage(pluginData: GuildPluginData<AutomodP
});
}
const characterCount = [...(context.message.data.content || "")].length;
const characterCount = [...(message.data.content || "")].length;
if (characterCount) {
pluginData.state.recentActions.push({
context,
@ -127,7 +127,7 @@ export function addRecentActionsFromMessage(pluginData: GuildPluginData<AutomodP
});
}
const stickerCount = (context.message.data.stickers || []).length;
const stickerCount = (message.data.stickers || []).length;
if (stickerCount) {
pluginData.state.recentActions.push({
context,

View file

@ -4,8 +4,9 @@ import { RECENT_ACTION_EXPIRY_TIME, RecentActionType } from "../constants";
import { getEmojiInString, getRoleMentions, getUrlsInString, getUserMentions } from "../../../utils";
export function clearRecentActionsForMessage(pluginData: GuildPluginData<AutomodPluginType>, context: AutomodContext) {
const globalIdentifier = context.message.user_id;
const perChannelIdentifier = `${context.message.channel_id}-${context.message.user_id}`;
const message = context.message!;
const globalIdentifier = message.user_id;
const perChannelIdentifier = `${message.channel_id}-${message.user_id}`;
pluginData.state.recentActions = pluginData.state.recentActions.filter(act => {
return act.identifier !== globalIdentifier && act.identifier !== perChannelIdentifier;

View file

@ -7,6 +7,7 @@ import { findRecentSpam } from "./findRecentSpam";
import { getMatchingMessageRecentActions } from "./getMatchingMessageRecentActions";
import * as t from "io-ts";
import { getMessageSpamIdentifier } from "./getSpamIdentifier";
import { SavedMessage } from "../../../data/entities/SavedMessage";
const MessageSpamTriggerConfig = t.type({
amount: t.number,
@ -29,22 +30,25 @@ export function createMessageSpamTrigger(spamType: RecentActionType, prettyName:
return;
}
const spamIdentifier = getMessageSpamIdentifier(context.message, triggerConfig.per_channel);
const spamIdentifier = getMessageSpamIdentifier(context.message, Boolean(triggerConfig.per_channel));
const recentSpam = findRecentSpam(pluginData, spamType, spamIdentifier);
if (recentSpam) {
await pluginData.state.archives.addSavedMessagesToArchive(
recentSpam.archiveId,
[context.message],
pluginData.guild,
);
if (recentSpam.archiveId) {
await pluginData.state.archives.addSavedMessagesToArchive(
recentSpam.archiveId,
[context.message],
pluginData.guild,
);
}
return {
silentClean: true,
extra: { archiveId: "" }, // FIXME: Fix up automod trigger match() typings so extra is not required when doing a silentClean
};
}
const within = convertDelayStringToMS(triggerConfig.within);
const within = convertDelayStringToMS(triggerConfig.within) ?? 0;
const matchedSpam = getMatchingMessageRecentActions(
pluginData,
context.message,
@ -58,7 +62,7 @@ export function createMessageSpamTrigger(spamType: RecentActionType, prettyName:
const messages = matchedSpam.recentActions
.map(action => action.context.message)
.filter(Boolean)
.sort(sorter("posted_at"));
.sort(sorter("posted_at")) as SavedMessage[];
const archiveId = await pluginData.state.archives.createFromSavedMessages(messages, pluginData.guild);

View file

@ -16,7 +16,7 @@ export function getMatchingRecentActions(
action.type === type &&
(!identifier || action.identifier === identifier) &&
action.context.timestamp >= since &&
action.context.timestamp <= to &&
action.context.timestamp <= to! &&
!action.context.actioned
);
});

View file

@ -10,23 +10,25 @@ export function getTextMatchPartialSummary(
context: AutomodContext,
) {
if (type === "message") {
const channel = pluginData.guild.channels.get(context.message.channel_id);
const channelMention = channel ? verboseChannelMention(channel) : `\`#${context.message.channel_id}\``;
const message = context.message!;
const channel = pluginData.guild.channels.get(message.channel_id);
const channelMention = channel ? verboseChannelMention(channel) : `\`#${message.channel_id}\``;
return `message in ${channelMention}:\n${messageSummary(context.message)}`;
return `message in ${channelMention}:\n${messageSummary(message)}`;
} else if (type === "embed") {
const channel = pluginData.guild.channels.get(context.message.channel_id);
const channelMention = channel ? verboseChannelMention(channel) : `\`#${context.message.channel_id}\``;
const message = context.message!;
const channel = pluginData.guild.channels.get(message.channel_id);
const channelMention = channel ? verboseChannelMention(channel) : `\`#${message.channel_id}\``;
return `message embed in ${channelMention}:\n${messageSummary(context.message)}`;
return `message embed in ${channelMention}:\n${messageSummary(message)}`;
} else if (type === "username") {
return `username: ${context.user.username}`;
return `username: ${context.user!.username}`;
} else if (type === "nickname") {
return `nickname: ${context.member.nick}`;
return `nickname: ${context.member!.nick}`;
} else if (type === "visiblename") {
const visibleName = context.member?.nick || context.user.username;
const visibleName = context.member?.nick || context.user!.username;
return `visible name: ${visibleName}`;
} else if (type === "customstatus") {
return `custom status: ${context.member.game.state}`;
return `custom status: ${context.member!.game!.state}`;
}
}

View file

@ -7,10 +7,10 @@ import { AutomodPluginType } from "../types";
export function resolveActionContactMethods(
pluginData: GuildPluginData<AutomodPluginType>,
actionConfig: {
notify?: string;
notifyChannel?: string;
notify?: string | null;
notifyChannel?: string | null;
},
): UserNotificationMethod[] | null {
): UserNotificationMethod[] {
if (actionConfig.notify === "dm") {
return [{ type: "dm" }];
} else if (actionConfig.notify === "channel") {
@ -28,5 +28,5 @@ export function resolveActionContactMethods(
return [];
}
return null;
return [];
}

View file

@ -5,13 +5,14 @@ import { availableActions } from "../actions/availableActions";
import { AutomodTriggerMatchResult } from "../helpers";
import { CleanAction } from "../actions/clean";
import { checkAndUpdateCooldown } from "./checkAndUpdateCooldown";
import { TextChannel } from "eris";
export async function runAutomod(pluginData: GuildPluginData<AutomodPluginType>, context: AutomodContext) {
const userId = context.user?.id || context.member?.id || context.message?.user_id;
const user = context.user || (userId && pluginData.client.users.get(userId));
const member = context.member || (userId && pluginData.guild.members.get(userId));
const member = context.member || (userId && pluginData.guild.members.get(userId)) || null;
const channelId = context.message?.channel_id;
const channel = channelId && pluginData.guild.channels.get(channelId);
const channel = channelId ? (pluginData.guild.channels.get(channelId) as TextChannel) : null;
const categoryId = channel?.parentID;
const config = pluginData.config.getMatchingConfig({
@ -29,8 +30,8 @@ export async function runAutomod(pluginData: GuildPluginData<AutomodPluginType>,
return;
}
let matchResult: AutomodTriggerMatchResult<any>;
let contexts: AutomodContext[];
let matchResult: AutomodTriggerMatchResult<any> | null | undefined;
let contexts: AutomodContext[] = [];
triggerLoop: for (const triggerItem of rule.triggers) {
for (const [triggerName, triggerConfig] of Object.entries(triggerItem)) {

View file

@ -3,9 +3,8 @@ import { Awaitable } from "knub/dist/utils";
import * as t from "io-ts";
import { AutomodContext, AutomodPluginType } from "./types";
export interface AutomodTriggerMatchResult<TExtra extends any = unknown> {
interface BaseAutomodTriggerMatchResult {
extraContexts?: AutomodContext[];
extra?: TExtra;
silentClean?: boolean; // TODO: Maybe generalize to a "silent" value in general, which mutes alert/log
@ -13,12 +12,16 @@ export interface AutomodTriggerMatchResult<TExtra extends any = unknown> {
fullSummary?: string;
}
export type AutomodTriggerMatchResult<TExtra extends any = unknown> = unknown extends TExtra
? BaseAutomodTriggerMatchResult
: BaseAutomodTriggerMatchResult & { extra: TExtra };
type AutomodTriggerMatchFn<TConfigType, TMatchResultExtra> = (meta: {
ruleName: string;
pluginData: GuildPluginData<AutomodPluginType>;
context: AutomodContext;
triggerConfig: TConfigType;
}) => Awaitable<null | AutomodTriggerMatchResult<TMatchResultExtra>>;
}) => Awaitable<null | undefined | AutomodTriggerMatchResult<TMatchResultExtra>>;
type AutomodTriggerRenderMatchInformationFn<TConfigType, TMatchResultExtra> = (meta: {
ruleName: string;

View file

@ -73,15 +73,15 @@ export const MatchAttachmentTypeTrigger = automodTrigger<MatchResultType>()({
},
renderMatchInformation({ pluginData, contexts, matchResult }) {
const channel = pluginData.guild.channels.get(contexts[0].message.channel_id);
const channel = pluginData.guild.channels.get(contexts[0].message!.channel_id)!;
const prettyChannel = verboseChannelMention(channel);
return (
asSingleLine(`
Matched attachment type \`${disableInlineCode(matchResult.extra.matchedType)}\`
(${matchResult.extra.mode === "blacklist" ? "(blacklisted)" : "(not in whitelist)"})
in message (\`${contexts[0].message.id}\`) in ${prettyChannel}:
`) + messageSummary(contexts[0].message)
in message (\`${contexts[0].message!.id}\`) in ${prettyChannel}:
`) + messageSummary(contexts[0].message!)
);
},
});

View file

@ -1,10 +1,10 @@
import * as t from "io-ts";
import { GuildInvite } from "eris";
import { automodTrigger } from "../helpers";
import {
disableCodeBlocks,
disableInlineCode,
getInviteCodesInString,
GuildInvite,
isGuildInvite,
resolveInvite,
tNullable,

View file

@ -19,7 +19,7 @@ export const MemberJoinTrigger = automodTrigger<unknown>()({
}
if (triggerConfig.only_new) {
const threshold = Date.now() - convertDelayStringToMS(triggerConfig.new_threshold);
const threshold = Date.now() - convertDelayStringToMS(triggerConfig.new_threshold)!;
return context.member.createdAt >= threshold ? {} : null;
}
@ -27,6 +27,6 @@ export const MemberJoinTrigger = automodTrigger<unknown>()({
},
renderMatchInformation({ pluginData, contexts, triggerConfig }) {
return null;
return "";
},
});

View file

@ -25,7 +25,7 @@ export const MemberJoinSpamTrigger = automodTrigger<unknown>()({
return {};
}
const since = Date.now() - convertDelayStringToMS(triggerConfig.within);
const since = Date.now() - convertDelayStringToMS(triggerConfig.within)!;
const matchingActions = getMatchingRecentActions(pluginData, RecentActionType.MemberJoin, null, since);
const totalCount = sumRecentActionCounts(matchingActions);
@ -46,6 +46,6 @@ export const MemberJoinSpamTrigger = automodTrigger<unknown>()({
},
renderMatchInformation({ pluginData, contexts, triggerConfig }) {
return null;
return "";
},
});

View file

@ -9,16 +9,16 @@ interface RoleAddedMatchResult {
export const RoleAddedTrigger = automodTrigger<RoleAddedMatchResult>()({
configType: t.union([t.string, t.array(t.string)]),
defaultConfig: null,
defaultConfig: [],
async match({ triggerConfig, context, pluginData }) {
if (!context.member || !context.rolesChanged || context.rolesChanged.added.length === 0) {
if (!context.member || !context.rolesChanged || context.rolesChanged.added!.length === 0) {
return;
}
const triggerRoles = Array.isArray(triggerConfig) ? triggerConfig : [triggerConfig];
for (const roleId of triggerRoles) {
if (context.rolesChanged.added.includes(roleId)) {
if (context.rolesChanged.added!.includes(roleId)) {
if (consumeIgnoredRoleChange(pluginData, context.member.id, roleId)) {
continue;
}

View file

@ -9,10 +9,10 @@ interface RoleAddedMatchResult {
export const RoleRemovedTrigger = automodTrigger<RoleAddedMatchResult>()({
configType: t.union([t.string, t.array(t.string)]),
defaultConfig: null,
defaultConfig: [],
async match({ triggerConfig, context, pluginData }) {
if (!context.member || !context.rolesChanged || context.rolesChanged.removed.length === 0) {
if (!context.member || !context.rolesChanged || context.rolesChanged.removed!.length === 0) {
return;
}
@ -22,7 +22,7 @@ export const RoleRemovedTrigger = automodTrigger<RoleAddedMatchResult>()({
continue;
}
if (context.rolesChanged.removed.includes(roleId)) {
if (context.rolesChanged.removed!.includes(roleId)) {
return {
extra: {
matchedRoleId: roleId,

View file

@ -105,13 +105,13 @@ export interface AutomodContext {
export interface RecentAction {
type: RecentActionType;
identifier: string;
identifier: string | null;
count: number;
context: AutomodContext;
}
export interface RecentSpam {
archiveId: string;
archiveId: string | null;
type: RecentActionType;
identifiers: string[];
timestamp: number;