Reformat all files with Prettier
This commit is contained in:
parent
0cde0d46d2
commit
ac79eb09f5
206 changed files with 727 additions and 888 deletions
|
@ -57,7 +57,7 @@ const defaultOptions = {
|
|||
/**
|
||||
* Config preprocessor to set default values for triggers and perform extra validation
|
||||
*/
|
||||
const configPreprocessor: ConfigPreprocessorFn<AutomodPluginType> = options => {
|
||||
const configPreprocessor: ConfigPreprocessorFn<AutomodPluginType> = (options) => {
|
||||
if (options.config?.rules) {
|
||||
// Loop through each rule
|
||||
for (const [name, rule] of Object.entries(options.config.rules)) {
|
||||
|
@ -232,10 +232,10 @@ export const AutomodPlugin = zeppelinGuildPlugin<AutomodPluginType>()({
|
|||
30 * SECONDS,
|
||||
);
|
||||
|
||||
pluginData.state.onMessageCreateFn = message => runAutomodOnMessage(pluginData, message, false);
|
||||
pluginData.state.onMessageCreateFn = (message) => runAutomodOnMessage(pluginData, message, false);
|
||||
pluginData.state.savedMessages.events.on("create", pluginData.state.onMessageCreateFn);
|
||||
|
||||
pluginData.state.onMessageUpdateFn = message => runAutomodOnMessage(pluginData, message, true);
|
||||
pluginData.state.onMessageUpdateFn = (message) => runAutomodOnMessage(pluginData, message, true);
|
||||
pluginData.state.savedMessages.events.on("update", pluginData.state.onMessageUpdateFn);
|
||||
|
||||
const countersPlugin = pluginData.getPlugin(CountersPlugin);
|
||||
|
|
|
@ -17,7 +17,7 @@ export const AddRolesAction = automodAction({
|
|||
defaultConfig: [],
|
||||
|
||||
async apply({ pluginData, contexts, actionConfig, ruleName }) {
|
||||
const members = unique(contexts.map(c => c.member).filter(nonNullish));
|
||||
const members = unique(contexts.map((c) => c.member).filter(nonNullish));
|
||||
const me = pluginData.guild.members.cache.get(pluginData.client.user!.id)!;
|
||||
|
||||
const missingPermissions = getMissingPermissions(me.permissions, p.MANAGE_ROLES);
|
||||
|
@ -41,7 +41,7 @@ export const AddRolesAction = automodAction({
|
|||
|
||||
if (rolesWeCannotAssign.length) {
|
||||
const roleNamesWeCannotAssign = rolesWeCannotAssign.map(
|
||||
roleId => pluginData.guild.roles.cache.get(roleId as Snowflake)?.name || roleId,
|
||||
(roleId) => pluginData.guild.roles.cache.get(roleId as Snowflake)?.name || roleId,
|
||||
);
|
||||
const logs = pluginData.getPlugin(LogsPlugin);
|
||||
logs.logBotAlert({
|
||||
|
@ -52,7 +52,7 @@ export const AddRolesAction = automodAction({
|
|||
}
|
||||
|
||||
await Promise.all(
|
||||
members.map(async member => {
|
||||
members.map(async (member) => {
|
||||
const memberRoles = new Set(member.roles.cache.keys());
|
||||
for (const roleId of rolesToAssign) {
|
||||
memberRoles.add(roleId as Snowflake);
|
||||
|
|
|
@ -41,7 +41,7 @@ export const AlertAction = automodAction({
|
|||
const theMessageLink =
|
||||
contexts[0].message && messageLink(pluginData.guild.id, contexts[0].message.channel_id, contexts[0].message.id);
|
||||
|
||||
const safeUsers = contexts.map(c => (c.user ? userToTemplateSafeUser(c.user) : null)).filter(isTruthy);
|
||||
const safeUsers = contexts.map((c) => (c.user ? userToTemplateSafeUser(c.user) : null)).filter(isTruthy);
|
||||
const safeUser = safeUsers[0];
|
||||
const actionsTaken = Object.keys(pluginData.config.get().rules[ruleName].actions).join(", ");
|
||||
|
||||
|
|
|
@ -9,8 +9,8 @@ export const ArchiveThreadAction = automodAction({
|
|||
|
||||
async apply({ pluginData, contexts }) {
|
||||
const threads = contexts
|
||||
.filter(c => c.message?.channel_id)
|
||||
.map(c => pluginData.guild.channels.cache.get(c.message!.channel_id))
|
||||
.filter((c) => c.message?.channel_id)
|
||||
.map((c) => pluginData.guild.channels.cache.get(c.message!.channel_id))
|
||||
.filter((c): c is ThreadChannel => c?.isThread() ?? false);
|
||||
|
||||
for (const thread of threads) {
|
||||
|
|
|
@ -35,7 +35,7 @@ export const BanAction = automodAction({
|
|||
hide: Boolean(actionConfig.hide_case),
|
||||
};
|
||||
|
||||
const userIdsToBan = unique(contexts.map(c => c.user?.id).filter(nonNullish));
|
||||
const userIdsToBan = unique(contexts.map((c) => c.user?.id).filter(nonNullish));
|
||||
|
||||
const modActions = pluginData.getPlugin(ModActionsPlugin);
|
||||
for (const userId of userIdsToBan) {
|
||||
|
|
|
@ -15,13 +15,13 @@ export const ChangeNicknameAction = automodAction({
|
|||
defaultConfig: {},
|
||||
|
||||
async apply({ pluginData, contexts, actionConfig }) {
|
||||
const members = unique(contexts.map(c => c.member).filter(nonNullish));
|
||||
const members = unique(contexts.map((c) => c.member).filter(nonNullish));
|
||||
|
||||
for (const member of members) {
|
||||
if (pluginData.state.recentNicknameChanges.has(member.id)) continue;
|
||||
const newName = typeof actionConfig === "string" ? actionConfig : actionConfig.name;
|
||||
|
||||
member.edit({ nick: newName }).catch(err => {
|
||||
member.edit({ nick: newName }).catch((err) => {
|
||||
pluginData.getPlugin(LogsPlugin).logBotAlert({
|
||||
body: `Failed to change the nickname of \`${member.id}\``,
|
||||
});
|
||||
|
|
|
@ -31,8 +31,8 @@ export const KickAction = automodAction({
|
|||
hide: Boolean(actionConfig.hide_case),
|
||||
};
|
||||
|
||||
const userIdsToKick = unique(contexts.map(c => c.user?.id).filter(nonNullish));
|
||||
const membersToKick = await asyncMap(userIdsToKick, id => resolveMember(pluginData.client, pluginData.guild, id));
|
||||
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) {
|
||||
|
|
|
@ -10,7 +10,7 @@ export const LogAction = automodAction({
|
|||
defaultConfig: true,
|
||||
|
||||
async apply({ pluginData, contexts, ruleName, matchResult }) {
|
||||
const users = unique(contexts.map(c => c.user)).filter(isTruthy);
|
||||
const users = unique(contexts.map((c) => c.user)).filter(isTruthy);
|
||||
const user = users[0];
|
||||
const actionsTaken = Object.keys(pluginData.config.get().rules[ruleName].actions).join(", ");
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ export const MuteAction = automodAction({
|
|||
hide: Boolean(actionConfig.hide_case),
|
||||
};
|
||||
|
||||
const userIdsToMute = unique(contexts.map(c => c.user?.id).filter(nonNullish));
|
||||
const userIdsToMute = unique(contexts.map((c) => c.user?.id).filter(nonNullish));
|
||||
|
||||
const mutes = pluginData.getPlugin(MutesPlugin);
|
||||
for (const userId of userIdsToMute) {
|
||||
|
|
|
@ -18,7 +18,7 @@ export const RemoveRolesAction = automodAction({
|
|||
defaultConfig: [],
|
||||
|
||||
async apply({ pluginData, contexts, actionConfig, ruleName }) {
|
||||
const members = unique(contexts.map(c => c.member).filter(nonNullish));
|
||||
const members = unique(contexts.map((c) => c.member).filter(nonNullish));
|
||||
const me = pluginData.guild.members.cache.get(pluginData.client.user!.id)!;
|
||||
|
||||
const missingPermissions = getMissingPermissions(me.permissions, p.MANAGE_ROLES);
|
||||
|
@ -42,7 +42,7 @@ export const RemoveRolesAction = automodAction({
|
|||
|
||||
if (rolesWeCannotRemove.length) {
|
||||
const roleNamesWeCannotRemove = rolesWeCannotRemove.map(
|
||||
roleId => pluginData.guild.roles.cache.get(roleId as Snowflake)?.name || roleId,
|
||||
(roleId) => pluginData.guild.roles.cache.get(roleId as Snowflake)?.name || roleId,
|
||||
);
|
||||
const logs = pluginData.getPlugin(LogsPlugin);
|
||||
logs.logBotAlert({
|
||||
|
@ -53,7 +53,7 @@ export const RemoveRolesAction = automodAction({
|
|||
}
|
||||
|
||||
await Promise.all(
|
||||
members.map(async member => {
|
||||
members.map(async (member) => {
|
||||
const memberRoles = new Set(member.roles.cache.keys());
|
||||
for (const roleId of rolesToRemove) {
|
||||
memberRoles.delete(roleId as Snowflake);
|
||||
|
|
|
@ -32,8 +32,8 @@ export const ReplyAction = automodAction({
|
|||
|
||||
async apply({ pluginData, contexts, actionConfig, ruleName }) {
|
||||
const contextsWithTextChannels = contexts
|
||||
.filter(c => c.message?.channel_id)
|
||||
.filter(c => {
|
||||
.filter((c) => c.message?.channel_id)
|
||||
.filter((c) => {
|
||||
const channel = pluginData.guild.channels.cache.get(c.message!.channel_id as Snowflake);
|
||||
return channel instanceof TextChannel || channel instanceof ThreadChannel;
|
||||
});
|
||||
|
@ -48,7 +48,7 @@ export const ReplyAction = automodAction({
|
|||
}, new Map());
|
||||
|
||||
for (const [channelId, _contexts] of contextsByChannelId.entries()) {
|
||||
const users = unique(Array.from(new Set(_contexts.map(c => c.user).filter(Boolean)))) as User[];
|
||||
const users = unique(Array.from(new Set(_contexts.map((c) => c.user).filter(Boolean)))) as User[];
|
||||
const user = users[0];
|
||||
|
||||
const renderReplyText = async (str: string) =>
|
||||
|
|
|
@ -31,8 +31,8 @@ export const WarnAction = automodAction({
|
|||
hide: Boolean(actionConfig.hide_case),
|
||||
};
|
||||
|
||||
const userIdsToWarn = unique(contexts.map(c => c.user?.id).filter(nonNullish));
|
||||
const membersToWarn = await asyncMap(userIdsToWarn, id => resolveMember(pluginData.client, pluginData.guild, id));
|
||||
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) {
|
||||
|
|
|
@ -4,7 +4,7 @@ import { AutomodPluginType } from "../types";
|
|||
|
||||
export function clearOldRecentActions(pluginData: GuildPluginData<AutomodPluginType>) {
|
||||
const now = Date.now();
|
||||
pluginData.state.recentActions = pluginData.state.recentActions.filter(info => {
|
||||
pluginData.state.recentActions = pluginData.state.recentActions.filter((info) => {
|
||||
return info.context.timestamp + RECENT_ACTION_EXPIRY_TIME > now;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import { AutomodPluginType } from "../types";
|
|||
|
||||
export function clearOldRecentSpam(pluginData: GuildPluginData<AutomodPluginType>) {
|
||||
const now = Date.now();
|
||||
pluginData.state.recentSpam = pluginData.state.recentSpam.filter(spam => {
|
||||
pluginData.state.recentSpam = pluginData.state.recentSpam.filter((spam) => {
|
||||
return spam.timestamp + RECENT_SPAM_EXPIRY_TIME > now;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ export function clearRecentActionsForMessage(pluginData: GuildPluginData<Automod
|
|||
const globalIdentifier = message.user_id;
|
||||
const perChannelIdentifier = `${message.channel_id}-${message.user_id}`;
|
||||
|
||||
pluginData.state.recentActions = pluginData.state.recentActions.filter(act => {
|
||||
pluginData.state.recentActions = pluginData.state.recentActions.filter((act) => {
|
||||
return act.identifier !== globalIdentifier && act.identifier !== perChannelIdentifier;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ export function createMessageSpamTrigger(spamType: RecentActionType, prettyName:
|
|||
|
||||
if (matchedSpam) {
|
||||
const messages = matchedSpam.recentActions
|
||||
.map(action => action.context.message)
|
||||
.map((action) => action.context.message)
|
||||
.filter(Boolean)
|
||||
.sort(sorter("posted_at")) as SavedMessage[];
|
||||
|
||||
|
@ -75,8 +75,8 @@ export function createMessageSpamTrigger(spamType: RecentActionType, prettyName:
|
|||
|
||||
return {
|
||||
extraContexts: matchedSpam.recentActions
|
||||
.map(action => action.context)
|
||||
.filter(_context => _context !== context),
|
||||
.map((action) => action.context)
|
||||
.filter((_context) => _context !== context),
|
||||
|
||||
extra: {
|
||||
archiveId,
|
||||
|
|
|
@ -7,7 +7,7 @@ export function findRecentSpam(
|
|||
type: RecentActionType,
|
||||
identifier?: string,
|
||||
) {
|
||||
return pluginData.state.recentSpam.find(spam => {
|
||||
return pluginData.state.recentSpam.find((spam) => {
|
||||
return spam.type === type && (!identifier || spam.identifiers.includes(identifier));
|
||||
});
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ export function getMatchingRecentActions(
|
|||
) {
|
||||
to = to || Date.now();
|
||||
|
||||
return pluginData.state.recentActions.filter(action => {
|
||||
return pluginData.state.recentActions.filter((action) => {
|
||||
return (
|
||||
action.type === type &&
|
||||
(!identifier || action.identifier === identifier) &&
|
||||
|
|
|
@ -29,6 +29,6 @@ export function getTextMatchPartialSummary(
|
|||
const visibleName = context.member?.nickname || context.user!.username;
|
||||
return `visible name: ${visibleName}`;
|
||||
} else if (type === "customstatus") {
|
||||
return `custom status: ${context.member!.presence?.activities.find(a => a.type === "CUSTOM")?.name}`;
|
||||
return `custom status: ${context.member!.presence?.activities.find((a) => a.type === "CUSTOM")?.name}`;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ export const ExampleTrigger = automodTrigger<ExampleMatchResultType>()({
|
|||
},
|
||||
|
||||
async match({ triggerConfig, context }) {
|
||||
const foundFruit = triggerConfig.allowedFruits.find(fruit => context.message?.data.content === fruit);
|
||||
const foundFruit = triggerConfig.allowedFruits.find((fruit) => context.message?.data.content === fruit);
|
||||
if (foundFruit) {
|
||||
return {
|
||||
extra: {
|
||||
|
|
|
@ -33,13 +33,10 @@ export const MatchAttachmentTypeTrigger = automodTrigger<MatchResultType>()({
|
|||
}
|
||||
|
||||
for (const attachment of context.message.data.attachments) {
|
||||
const attachmentType = attachment.url
|
||||
.split(".")
|
||||
.pop()!
|
||||
.toLowerCase();
|
||||
const attachmentType = attachment.url.split(".").pop()!.toLowerCase();
|
||||
|
||||
const blacklist = trigger.blacklist_enabled
|
||||
? (trigger.filetype_blacklist || []).map(_t => _t.toLowerCase())
|
||||
? (trigger.filetype_blacklist || []).map((_t) => _t.toLowerCase())
|
||||
: null;
|
||||
|
||||
if (blacklist && blacklist.includes(attachmentType)) {
|
||||
|
@ -52,7 +49,7 @@ export const MatchAttachmentTypeTrigger = automodTrigger<MatchResultType>()({
|
|||
}
|
||||
|
||||
const whitelist = trigger.whitelist_enabled
|
||||
? (trigger.filetype_whitelist || []).map(_t => _t.toLowerCase())
|
||||
? (trigger.filetype_whitelist || []).map((_t) => _t.toLowerCase())
|
||||
: null;
|
||||
|
||||
if (whitelist && !whitelist.includes(attachmentType)) {
|
||||
|
|
|
@ -34,7 +34,7 @@ export const MatchMimeTypeTrigger = automodTrigger<MatchResultType>()({
|
|||
const contentType = (rawContentType || "").split(";")[0]; // Remove "; charset=utf8" and similar from the end
|
||||
|
||||
const blacklist = trigger.blacklist_enabled
|
||||
? (trigger.mime_type_blacklist ?? []).map(_t => _t.toLowerCase())
|
||||
? (trigger.mime_type_blacklist ?? []).map((_t) => _t.toLowerCase())
|
||||
: null;
|
||||
|
||||
if (contentType && blacklist?.includes(contentType)) {
|
||||
|
@ -47,7 +47,7 @@ export const MatchMimeTypeTrigger = automodTrigger<MatchResultType>()({
|
|||
}
|
||||
|
||||
const whitelist = trigger.whitelist_enabled
|
||||
? (trigger.mime_type_whitelist ?? []).map(_t => _t.toLowerCase())
|
||||
? (trigger.mime_type_whitelist ?? []).map((_t) => _t.toLowerCase())
|
||||
: null;
|
||||
|
||||
if (whitelist && (!contentType || !whitelist.includes(contentType))) {
|
||||
|
|
|
@ -64,7 +64,7 @@ export const MatchWordsTrigger = automodTrigger<MatchResultType>()({
|
|||
// When performing loose matching, allow any amount of whitespace or up to looseMatchingThreshold number of other
|
||||
// characters between the matched characters. E.g. if we're matching banana, a loose match could also match b a n a n a
|
||||
let pattern = trigger.loose_matching
|
||||
? [...word].map(c => escapeStringRegexp(c)).join(`(?:\\s*|.{0,${looseMatchingThreshold})`)
|
||||
? [...word].map((c) => escapeStringRegexp(c)).join(`(?:\\s*|.{0,${looseMatchingThreshold})`)
|
||||
: escapeStringRegexp(word);
|
||||
|
||||
if (trigger.only_full_words) {
|
||||
|
|
|
@ -30,7 +30,7 @@ export const MemberJoinSpamTrigger = automodTrigger<unknown>()({
|
|||
const totalCount = sumRecentActionCounts(matchingActions);
|
||||
|
||||
if (totalCount >= triggerConfig.amount) {
|
||||
const extraContexts = matchingActions.map(a => a.context).filter(c => c !== context);
|
||||
const extraContexts = matchingActions.map((a) => a.context).filter((c) => c !== context);
|
||||
|
||||
pluginData.state.recentSpam.push({
|
||||
type: RecentActionType.MemberJoin,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue