mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-22 01:05:02 +00:00
format: Prettier
This commit is contained in:
parent
70be2a2055
commit
517ce4f52f
161 changed files with 534 additions and 659 deletions
|
@ -1,5 +1,5 @@
|
|||
import { PluginOptions } from "knub";
|
||||
import { AFKPluginType, ConfigSchema } from './types';
|
||||
import { AFKPluginType, ConfigSchema } from "./types";
|
||||
import { zeppelinGuildPlugin } from "../ZeppelinPluginBlueprint";
|
||||
import { AFK } from "src/data/AFK";
|
||||
|
||||
|
@ -7,40 +7,39 @@ import { AfkSetCmd } from "./commands/AFKCmd";
|
|||
import { AFKNotificationEvt } from "./events/AFKNotificationEvt";
|
||||
|
||||
const defaultOptions: PluginOptions<AFKPluginType> = {
|
||||
config: {
|
||||
can_afk: false,
|
||||
allow_links: false,
|
||||
allow_invites: false,
|
||||
config: {
|
||||
can_afk: false,
|
||||
allow_links: false,
|
||||
allow_invites: false,
|
||||
},
|
||||
overrides: [
|
||||
{
|
||||
level: ">=50",
|
||||
config: {
|
||||
can_afk: true,
|
||||
allow_links: true,
|
||||
allow_invites: true,
|
||||
},
|
||||
},
|
||||
overrides: [
|
||||
{
|
||||
level: '>=50',
|
||||
config: {
|
||||
can_afk: true,
|
||||
allow_links: true,
|
||||
allow_invites: true,
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
};
|
||||
|
||||
export const AFKPlugin = zeppelinGuildPlugin<AFKPluginType>()("afk", {
|
||||
showInDocs: true,
|
||||
info: {
|
||||
prettyName: "AFK",
|
||||
description: "Allows you to set your AFK Status.",
|
||||
},
|
||||
showInDocs: true,
|
||||
info: {
|
||||
prettyName: "AFK",
|
||||
description: "Allows you to set your AFK Status.",
|
||||
},
|
||||
|
||||
configSchema: ConfigSchema,
|
||||
defaultOptions,
|
||||
configSchema: ConfigSchema,
|
||||
defaultOptions,
|
||||
|
||||
commands: [AfkSetCmd],
|
||||
events: [AFKNotificationEvt],
|
||||
commands: [AfkSetCmd],
|
||||
events: [AFKNotificationEvt],
|
||||
|
||||
onLoad(pluginData) {
|
||||
const { state } = pluginData;
|
||||
|
||||
state.afkUsers = new AFK();
|
||||
}
|
||||
})
|
||||
onLoad(pluginData) {
|
||||
const { state } = pluginData;
|
||||
|
||||
state.afkUsers = new AFK();
|
||||
},
|
||||
});
|
||||
|
|
|
@ -4,43 +4,40 @@ import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
|||
import { parseStatusMessage } from "../functions/parseStatusMessage";
|
||||
|
||||
export const AfkSetCmd = afkCmd({
|
||||
trigger: ['afk', 'afk set'],
|
||||
permission: 'can_afk',
|
||||
trigger: ["afk", "afk set"],
|
||||
permission: "can_afk",
|
||||
|
||||
signature: {
|
||||
status: ct.string({ rest: true, required: true }),
|
||||
},
|
||||
signature: {
|
||||
status: ct.string({ rest: true, required: true }),
|
||||
},
|
||||
|
||||
async run({ message: msg, args, pluginData }) {
|
||||
// Checks if the user is AFK, if so, return.
|
||||
const isAfk = await pluginData.state.afkUsers.getUserAFKStatus(msg.author.id);
|
||||
if (isAfk) return;
|
||||
|
||||
const status = args.status.join(" ");
|
||||
async run({ message: msg, args, pluginData }) {
|
||||
// Checks if the user is AFK, if so, return.
|
||||
const isAfk = await pluginData.state.afkUsers.getUserAFKStatus(msg.author.id);
|
||||
if (isAfk) return;
|
||||
|
||||
// Check status length
|
||||
if (status.length > 124) {
|
||||
sendErrorMessage(pluginData, msg.channel, "Status length is above **124** characters.");
|
||||
return;
|
||||
}
|
||||
const status = args.status.join(" ");
|
||||
|
||||
// Checks status based on configuration options
|
||||
const parsed = parseStatusMessage(pluginData, msg.member, status);
|
||||
if (typeof parsed === 'string') {
|
||||
sendErrorMessage(pluginData, msg.channel, parsed);
|
||||
return;
|
||||
}
|
||||
|
||||
// Set user status
|
||||
const afk = await pluginData.state.afkUsers.setAfkStatus(
|
||||
msg.author.id,
|
||||
status,
|
||||
);
|
||||
|
||||
sendSuccessMessage(pluginData, msg.channel, `AFK Status set to: **${afk.status}**`, {
|
||||
roles: false,
|
||||
everyone: false,
|
||||
users: false,
|
||||
});
|
||||
// Check status length
|
||||
if (status.length > 124) {
|
||||
sendErrorMessage(pluginData, msg.channel, "Status length is above **124** characters.");
|
||||
return;
|
||||
}
|
||||
})
|
||||
|
||||
// Checks status based on configuration options
|
||||
const parsed = parseStatusMessage(pluginData, msg.member, status);
|
||||
if (typeof parsed === "string") {
|
||||
sendErrorMessage(pluginData, msg.channel, parsed);
|
||||
return;
|
||||
}
|
||||
|
||||
// Set user status
|
||||
const afk = await pluginData.state.afkUsers.setAfkStatus(msg.author.id, status);
|
||||
|
||||
sendSuccessMessage(pluginData, msg.channel, `AFK Status set to: **${afk.status}**`, {
|
||||
roles: false,
|
||||
everyone: false,
|
||||
users: false,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
|
|
@ -2,27 +2,27 @@ import { sendUserMentionMessage, sendWelcomeBackMessage } from "../functions/bui
|
|||
import { afkEvt } from "../types";
|
||||
|
||||
export const AFKNotificationEvt = afkEvt({
|
||||
event: 'messageCreate',
|
||||
event: "messageCreate",
|
||||
|
||||
listener: async ({ pluginData, args: { message } }) => {
|
||||
// Mention Check (if someone mentions the AFK user)
|
||||
if (message.mentions.length) {
|
||||
const afk = await pluginData.state.afkUsers.getUserAFKStatus(message.mentions[0].id);
|
||||
if (!afk) return;
|
||||
|
||||
sendUserMentionMessage(message, afk.status);
|
||||
listener: async ({ pluginData, args: { message } }) => {
|
||||
// Mention Check (if someone mentions the AFK user)
|
||||
if (message.mentions.length) {
|
||||
const afk = await pluginData.state.afkUsers.getUserAFKStatus(message.mentions[0].id);
|
||||
if (!afk) return;
|
||||
|
||||
return;
|
||||
}
|
||||
sendUserMentionMessage(message, afk.status);
|
||||
|
||||
// Self AFK Check (if user is the one that's AFK)
|
||||
const afk = await pluginData.state.afkUsers.getUserAFKStatus(message.author.id);
|
||||
if (!afk) return;
|
||||
|
||||
try {
|
||||
await pluginData.state.afkUsers.clearAFKStatus(message.author.id);
|
||||
} catch (err) {}
|
||||
|
||||
sendWelcomeBackMessage(message);
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
// Self AFK Check (if user is the one that's AFK)
|
||||
const afk = await pluginData.state.afkUsers.getUserAFKStatus(message.author.id);
|
||||
if (!afk) return;
|
||||
|
||||
try {
|
||||
await pluginData.state.afkUsers.clearAFKStatus(message.author.id);
|
||||
} catch (err) {}
|
||||
|
||||
sendWelcomeBackMessage(message);
|
||||
},
|
||||
});
|
||||
|
|
|
@ -1,23 +1,23 @@
|
|||
import { Message } from "eris";
|
||||
|
||||
export function sendUserMentionMessage(message: Message, status: string) {
|
||||
return message.channel.createMessage({
|
||||
allowedMentions: {
|
||||
users: [message.author.id],
|
||||
everyone: false,
|
||||
roles: false,
|
||||
},
|
||||
content: `<@!${message.author.id}>, the user mentioned is currently AFK: **${status}**`,
|
||||
});
|
||||
return message.channel.createMessage({
|
||||
allowedMentions: {
|
||||
users: [message.author.id],
|
||||
everyone: false,
|
||||
roles: false,
|
||||
},
|
||||
content: `<@!${message.author.id}>, the user mentioned is currently AFK: **${status}**`,
|
||||
});
|
||||
}
|
||||
|
||||
export function sendWelcomeBackMessage(message: Message) {
|
||||
return message.channel.createMessage({
|
||||
allowedMentions: {
|
||||
users: [message.author.id],
|
||||
everyone: false,
|
||||
roles: false,
|
||||
},
|
||||
content: `<@!${message.author.id}>, welcome back!`,
|
||||
});
|
||||
}
|
||||
return message.channel.createMessage({
|
||||
allowedMentions: {
|
||||
users: [message.author.id],
|
||||
everyone: false,
|
||||
roles: false,
|
||||
},
|
||||
content: `<@!${message.author.id}>, welcome back!`,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -10,9 +10,9 @@ const HttpUrlRegex = /^(https?):\/\/[^\s$.?#].[^\s]*$/;
|
|||
const DiscordInviteLinkRegex = /^(?:https?:\/\/)?(?:www\.)?(?:discord\.gg\/|discord(?:app)?\.com\/invite\/)?(?<code>[\w\d-]{2,})$/i;
|
||||
|
||||
export function parseStatusMessage(pluginData: GuildPluginData<AFKPluginType>, member: Member, status: string) {
|
||||
const allow_links = hasPermission(pluginData, "allow_links", { member });
|
||||
const allow_invites = hasPermission(pluginData, "allow_invites", { member });
|
||||
const allow_links = hasPermission(pluginData, "allow_links", { member });
|
||||
const allow_invites = hasPermission(pluginData, "allow_invites", { member });
|
||||
|
||||
if (!allow_links && HttpUrlRegex.test(status)) return "Links are not allowed in an AFK status!";
|
||||
if (!allow_invites && DiscordInviteLinkRegex.test(status)) return "Invites are not allowed in an AFK status!";
|
||||
}
|
||||
if (!allow_links && HttpUrlRegex.test(status)) return "Links are not allowed in an AFK status!";
|
||||
if (!allow_invites && DiscordInviteLinkRegex.test(status)) return "Invites are not allowed in an AFK status!";
|
||||
}
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
import * as t from 'io-ts';
|
||||
import { BasePluginType, guildCommand, guildEventListener } from 'knub';
|
||||
import { AFK } from '../../data/AFK';
|
||||
import * as t from "io-ts";
|
||||
import { BasePluginType, guildCommand, guildEventListener } from "knub";
|
||||
import { AFK } from "../../data/AFK";
|
||||
|
||||
export const ConfigSchema = t.type({
|
||||
can_afk: t.boolean,
|
||||
allow_links: t.boolean,
|
||||
allow_invites: t.boolean,
|
||||
can_afk: t.boolean,
|
||||
allow_links: t.boolean,
|
||||
allow_invites: t.boolean,
|
||||
});
|
||||
export type TConfigSchema = t.TypeOf<typeof ConfigSchema>;
|
||||
|
||||
export interface AFKPluginType extends BasePluginType {
|
||||
config: TConfigSchema;
|
||||
state: {
|
||||
afkUsers: AFK;
|
||||
}
|
||||
config: TConfigSchema;
|
||||
state: {
|
||||
afkUsers: AFK;
|
||||
};
|
||||
}
|
||||
|
||||
export const afkCmd = guildCommand<AFKPluginType>();
|
||||
export const afkEvt = guildEventListener<AFKPluginType>();
|
||||
export const afkEvt = guildEventListener<AFKPluginType>();
|
||||
|
|
|
@ -39,13 +39,13 @@ export const AutoDeletePlugin = zeppelinGuildPlugin<AutoDeletePluginType>()("aut
|
|||
|
||||
state.maxDelayWarningSent = false;
|
||||
|
||||
state.onMessageCreateFn = msg => onMessageCreate(pluginData, msg);
|
||||
state.onMessageCreateFn = (msg) => onMessageCreate(pluginData, msg);
|
||||
state.guildSavedMessages.events.on("create", state.onMessageCreateFn);
|
||||
|
||||
state.onMessageDeleteFn = msg => onMessageDelete(pluginData, msg);
|
||||
state.onMessageDeleteFn = (msg) => onMessageDelete(pluginData, msg);
|
||||
state.guildSavedMessages.events.on("delete", state.onMessageDeleteFn);
|
||||
|
||||
state.onMessageDeleteBulkFn = msgs => onMessageDeleteBulk(pluginData, msgs);
|
||||
state.onMessageDeleteBulkFn = (msgs) => onMessageDeleteBulk(pluginData, msgs);
|
||||
state.guildSavedMessages.events.on("deleteBulk", state.onMessageDeleteBulkFn);
|
||||
},
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import { SavedMessage } from "../../../data/entities/SavedMessage";
|
|||
import { scheduleNextDeletion } from "./scheduleNextDeletion";
|
||||
|
||||
export function onMessageDelete(pluginData: GuildPluginData<AutoDeletePluginType>, msg: SavedMessage) {
|
||||
const indexToDelete = pluginData.state.deletionQueue.findIndex(item => item.message.id === msg.id);
|
||||
const indexToDelete = pluginData.state.deletionQueue.findIndex((item) => item.message.id === msg.id);
|
||||
if (indexToDelete > -1) {
|
||||
pluginData.state.deletionQueue.splice(indexToDelete, 1);
|
||||
scheduleNextDeletion(pluginData);
|
||||
|
|
|
@ -61,7 +61,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)) {
|
||||
|
@ -217,10 +217,10 @@ export const AutomodPlugin = zeppelinGuildPlugin<AutomodPluginType>()("automod",
|
|||
pluginData.state.antiraidLevels = GuildAntiraidLevels.getGuildInstance(pluginData.guild.id);
|
||||
pluginData.state.archives = GuildArchives.getGuildInstance(pluginData.guild.id);
|
||||
|
||||
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);
|
||||
|
||||
pluginData.state.cachedAntiraidLevel = await pluginData.state.antiraidLevels.get();
|
||||
|
|
|
@ -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.get(pluginData.client.user.id)!;
|
||||
|
||||
const missingPermissions = getMissingPermissions(me.permission, p.manageRoles);
|
||||
|
@ -41,7 +41,7 @@ export const AddRolesAction = automodAction({
|
|||
|
||||
if (rolesWeCannotAssign.length) {
|
||||
const roleNamesWeCannotAssign = rolesWeCannotAssign.map(
|
||||
roleId => pluginData.guild.roles.get(roleId)?.name || roleId,
|
||||
(roleId) => pluginData.guild.roles.get(roleId)?.name || roleId,
|
||||
);
|
||||
const logs = pluginData.getPlugin(LogsPlugin);
|
||||
logs.log(LogType.BOT_ALERT, {
|
||||
|
@ -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);
|
||||
for (const roleId of rolesToAssign) {
|
||||
memberRoles.add(roleId);
|
||||
|
|
|
@ -33,7 +33,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 && stripObjectToScalars(c.user)).filter(Boolean);
|
||||
const safeUsers = contexts.map((c) => c.user && stripObjectToScalars(c.user)).filter(Boolean);
|
||||
const safeUser = safeUsers[0];
|
||||
const actionsTaken = Object.keys(pluginData.config.get().rules[ruleName].actions).join(", ");
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ export const BanAction = automodAction({
|
|||
extraNotes: matchResult.fullSummary ? [matchResult.fullSummary] : [],
|
||||
};
|
||||
|
||||
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).log(LogType.BOT_ALERT, {
|
||||
body: `Failed to change the nickname of \`${member.id}\``,
|
||||
});
|
||||
|
|
|
@ -25,8 +25,8 @@ export const KickAction = automodAction({
|
|||
extraNotes: matchResult.fullSummary ? [matchResult.fullSummary] : [],
|
||||
};
|
||||
|
||||
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) {
|
||||
|
|
|
@ -9,9 +9,9 @@ export const LogAction = automodAction({
|
|||
defaultConfig: true,
|
||||
|
||||
async apply({ pluginData, contexts, ruleName, matchResult }) {
|
||||
const safeUsers = unique(contexts.map(c => c.user))
|
||||
const safeUsers = unique(contexts.map((c) => c.user))
|
||||
.filter(Boolean)
|
||||
.map(user => stripObjectToScalars(user));
|
||||
.map((user) => stripObjectToScalars(user));
|
||||
const safeUser = safeUsers[0];
|
||||
const actionsTaken = Object.keys(pluginData.config.get().rules[ruleName].actions).join(", ");
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ export const MuteAction = automodAction({
|
|||
extraNotes: matchResult.fullSummary ? [matchResult.fullSummary] : [],
|
||||
};
|
||||
|
||||
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) {
|
||||
|
|
|
@ -19,7 +19,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.get(pluginData.client.user.id)!;
|
||||
|
||||
const missingPermissions = getMissingPermissions(me.permission, p.manageRoles);
|
||||
|
@ -43,7 +43,7 @@ export const RemoveRolesAction = automodAction({
|
|||
|
||||
if (rolesWeCannotRemove.length) {
|
||||
const roleNamesWeCannotRemove = rolesWeCannotRemove.map(
|
||||
roleId => pluginData.guild.roles.get(roleId)?.name || roleId,
|
||||
(roleId) => pluginData.guild.roles.get(roleId)?.name || roleId,
|
||||
);
|
||||
const logs = pluginData.getPlugin(LogsPlugin);
|
||||
logs.log(LogType.BOT_ALERT, {
|
||||
|
@ -54,7 +54,7 @@ export const RemoveRolesAction = automodAction({
|
|||
}
|
||||
|
||||
await Promise.all(
|
||||
members.map(async member => {
|
||||
members.map(async (member) => {
|
||||
const memberRoles = new Set(member.roles);
|
||||
for (const roleId of rolesToRemove) {
|
||||
memberRoles.delete(roleId);
|
||||
|
|
|
@ -27,8 +27,8 @@ 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) => c.message?.channel_id)
|
||||
.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)) {
|
||||
|
@ -40,10 +40,10 @@ 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))));
|
||||
const users = unique(Array.from(new Set(_contexts.map((c) => c.user).filter(Boolean))));
|
||||
const user = users[0];
|
||||
|
||||
const renderReplyText = async str =>
|
||||
const renderReplyText = async (str) =>
|
||||
renderTemplate(str, {
|
||||
user: stripObjectToScalars(user),
|
||||
});
|
||||
|
|
|
@ -25,8 +25,8 @@ export const WarnAction = automodAction({
|
|||
extraNotes: matchResult.fullSummary ? [matchResult.fullSummary] : [],
|
||||
};
|
||||
|
||||
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 { RECENT_ACTION_EXPIRY_TIME } from "../constants";
|
|||
|
||||
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 { RECENT_SPAM_EXPIRY_TIME } from "../constants";
|
|||
|
||||
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;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -8,7 +8,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) &&
|
||||
|
|
|
@ -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: {
|
||||
|
|
|
@ -37,13 +37,10 @@ export const MatchAttachmentTypeTrigger = automodTrigger<MatchResultType>()({
|
|||
const attachments: any[] = context.message.data.attachments;
|
||||
|
||||
for (const attachment of attachments) {
|
||||
const attachmentType = attachment.filename
|
||||
.split(".")
|
||||
.pop()
|
||||
.toLowerCase();
|
||||
const attachmentType = attachment.filename.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)) {
|
||||
|
@ -56,7 +53,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)) {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -35,7 +35,7 @@ export const AddDashboardUserCmd = botControlCmd({
|
|||
}
|
||||
|
||||
const userNameList = args.users.map(
|
||||
user => `<@!${user.id}> (**${user.username}#${user.discriminator}**, \`${user.id}\`)`,
|
||||
(user) => `<@!${user.id}> (**${user.username}#${user.discriminator}**, \`${user.id}\`)`,
|
||||
);
|
||||
sendSuccessMessage(
|
||||
pluginData,
|
||||
|
|
|
@ -23,9 +23,9 @@ export const ListDashboardUsersCmd = botControlCmd({
|
|||
}
|
||||
|
||||
const dashboardUsers = await pluginData.state.apiPermissionAssignments.getByGuildId(guild.id);
|
||||
const users = await Promise.all(dashboardUsers.map(perm => resolveUser(pluginData.client, perm.target_id)));
|
||||
const users = await Promise.all(dashboardUsers.map((perm) => resolveUser(pluginData.client, perm.target_id)));
|
||||
const userNameList = users.map(
|
||||
user => `<@!${user.id}> (**${user.username}#${user.discriminator}**, \`${user.id}\`)`,
|
||||
(user) => `<@!${user.id}> (**${user.username}#${user.discriminator}**, \`${user.id}\`)`,
|
||||
);
|
||||
|
||||
sendSuccessMessage(
|
||||
|
|
|
@ -35,7 +35,7 @@ export const RemoveDashboardUserCmd = botControlCmd({
|
|||
}
|
||||
|
||||
const userNameList = args.users.map(
|
||||
user => `<@!${user.id}> (**${user.username}#${user.discriminator}**, \`${user.id}\`)`,
|
||||
(user) => `<@!${user.id}> (**${user.username}#${user.discriminator}**, \`${user.id}\`)`,
|
||||
);
|
||||
sendSuccessMessage(
|
||||
pluginData,
|
||||
|
|
|
@ -21,7 +21,7 @@ export const ServersCmd = botControlCmd({
|
|||
|
||||
async run({ pluginData, message: msg, args }) {
|
||||
const showList = Boolean(args.all || args.initialized || args.uninitialized || args.search);
|
||||
const search = args.search ? new RegExp([...args.search].map(s => escapeStringRegexp(s)).join(".*"), "i") : null;
|
||||
const search = args.search ? new RegExp([...args.search].map((s) => escapeStringRegexp(s)).join(".*"), "i") : null;
|
||||
|
||||
const joinedGuilds = Array.from(pluginData.client.guilds.values());
|
||||
const loadedGuilds = pluginData.getKnubInstance().getLoadedGuilds();
|
||||
|
@ -31,21 +31,21 @@ export const ServersCmd = botControlCmd({
|
|||
let filteredGuilds = Array.from(joinedGuilds);
|
||||
|
||||
if (args.initialized) {
|
||||
filteredGuilds = filteredGuilds.filter(g => loadedGuildsMap.has(g.id));
|
||||
filteredGuilds = filteredGuilds.filter((g) => loadedGuildsMap.has(g.id));
|
||||
}
|
||||
|
||||
if (args.uninitialized) {
|
||||
filteredGuilds = filteredGuilds.filter(g => !loadedGuildsMap.has(g.id));
|
||||
filteredGuilds = filteredGuilds.filter((g) => !loadedGuildsMap.has(g.id));
|
||||
}
|
||||
|
||||
if (args.search) {
|
||||
filteredGuilds = filteredGuilds.filter(g => search!.test(`${g.id} ${g.name}`));
|
||||
filteredGuilds = filteredGuilds.filter((g) => search!.test(`${g.id} ${g.name}`));
|
||||
}
|
||||
|
||||
if (filteredGuilds.length) {
|
||||
filteredGuilds.sort(sorter(g => g.name.toLowerCase()));
|
||||
filteredGuilds.sort(sorter((g) => g.name.toLowerCase()));
|
||||
const longestId = filteredGuilds.reduce((longest, guild) => Math.max(longest, guild.id.length), 0);
|
||||
const lines = filteredGuilds.map(g => {
|
||||
const lines = filteredGuilds.map((g) => {
|
||||
const paddedId = g.id.padEnd(longestId, " ");
|
||||
const owner = getUser(pluginData.client, g.ownerID);
|
||||
return `\`${paddedId}\` **${g.name}** (${g.memberCount} members) (owner **${owner.username}#${owner.discriminator}** \`${owner.id}\`)`;
|
||||
|
@ -56,7 +56,7 @@ export const ServersCmd = botControlCmd({
|
|||
}
|
||||
} else {
|
||||
const total = joinedGuilds.length;
|
||||
const initialized = joinedGuilds.filter(g => loadedGuildsMap.has(g.id)).length;
|
||||
const initialized = joinedGuilds.filter((g) => loadedGuildsMap.has(g.id)).length;
|
||||
const unInitialized = total - initialized;
|
||||
|
||||
msg.channel.createMessage(
|
||||
|
|
|
@ -22,7 +22,7 @@ export async function createCaseNote(pluginData: GuildPluginData<CasesPluginType
|
|||
|
||||
// Add note details to the beginning of the note
|
||||
if (args.noteDetails && args.noteDetails.length) {
|
||||
body = args.noteDetails.map(d => `__[${d}]__`).join(" ") + " " + body;
|
||||
body = args.noteDetails.map((d) => `__[${d}]__`).join(" ") + " " + body;
|
||||
}
|
||||
|
||||
await pluginData.state.cases.createNote(theCase.id, {
|
||||
|
|
|
@ -7,11 +7,11 @@ export async function getCaseTypeAmountForUserId(
|
|||
userID: string,
|
||||
type: CaseTypes,
|
||||
): Promise<number> {
|
||||
const cases = (await pluginData.state.cases.getByUserId(userID)).filter(c => !c.is_hidden);
|
||||
const cases = (await pluginData.state.cases.getByUserId(userID)).filter((c) => !c.is_hidden);
|
||||
let typeAmount = 0;
|
||||
|
||||
if (cases.length > 0) {
|
||||
cases.forEach(singleCase => {
|
||||
cases.forEach((singleCase) => {
|
||||
if (singleCase.type === type.valueOf()) {
|
||||
typeAmount++;
|
||||
}
|
||||
|
|
|
@ -65,10 +65,10 @@ export const CensorPlugin = zeppelinGuildPlugin<CensorPluginType>()("censor", {
|
|||
|
||||
state.regexRunner = getRegExpRunner(`guild-${pluginData.guild.id}`);
|
||||
|
||||
state.onMessageCreateFn = msg => onMessageCreate(pluginData, msg);
|
||||
state.onMessageCreateFn = (msg) => onMessageCreate(pluginData, msg);
|
||||
state.savedMessages.events.on("create", state.onMessageCreateFn);
|
||||
|
||||
state.onMessageUpdateFn = msg => onMessageUpdate(pluginData, msg);
|
||||
state.onMessageUpdateFn = (msg) => onMessageUpdate(pluginData, msg);
|
||||
state.savedMessages.events.on("update", state.onMessageUpdateFn);
|
||||
},
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ export async function applyFiltersToMsg(
|
|||
let messageContent = savedMessage.data.content || "";
|
||||
if (savedMessage.data.attachments) messageContent += " " + JSON.stringify(savedMessage.data.attachments);
|
||||
if (savedMessage.data.embeds) {
|
||||
const embeds = (savedMessage.data.embeds as Embed[]).map(e => cloneDeep(e));
|
||||
const embeds = (savedMessage.data.embeds as Embed[]).map((e) => cloneDeep(e));
|
||||
for (const embed of embeds) {
|
||||
if (embed.type === "video") {
|
||||
// Ignore video descriptions as they're not actually shown on the embed
|
||||
|
@ -53,7 +53,7 @@ export async function applyFiltersToMsg(
|
|||
const inviteCodes = getInviteCodesInString(messageContent);
|
||||
|
||||
const invites: Array<Invite | null> = await Promise.all(
|
||||
inviteCodes.map(code => resolveInvite(pluginData.client, code)),
|
||||
inviteCodes.map((code) => resolveInvite(pluginData.client, code)),
|
||||
);
|
||||
|
||||
for (const invite of invites) {
|
||||
|
|
|
@ -66,9 +66,9 @@ export const ArchiveChannelCmd = channelArchiverCmd({
|
|||
|
||||
for (const message of messages) {
|
||||
const ts = moment.utc(message.timestamp).format("YYYY-MM-DD HH:mm:ss");
|
||||
let content = `[${ts}] [${message.author.id}] [${message.author.username}#${
|
||||
message.author.discriminator
|
||||
}]: ${message.content || "<no text content>"}`;
|
||||
let content = `[${ts}] [${message.author.id}] [${message.author.username}#${message.author.discriminator}]: ${
|
||||
message.content || "<no text content>"
|
||||
}`;
|
||||
|
||||
if (message.attachments.length) {
|
||||
if (args["attachment-channel"]) {
|
||||
|
|
|
@ -14,9 +14,9 @@ export function getCompanionChannelOptsForVoiceChannelId(
|
|||
const config = pluginData.config.getMatchingConfig({ userId, channelId: voiceChannel.id });
|
||||
return Object.values(config.entries)
|
||||
.filter(
|
||||
opts =>
|
||||
(opts) =>
|
||||
opts.voice_channel_ids.includes(voiceChannel.id) ||
|
||||
(voiceChannel.parentID && opts.voice_channel_ids.includes(voiceChannel.parentID)),
|
||||
)
|
||||
.map(opts => Object.assign({}, defaultCompanionChannelOpts, opts));
|
||||
.map((opts) => Object.assign({}, defaultCompanionChannelOpts, opts));
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ const defaultOptions: PluginOptions<CountersPluginType> = {
|
|||
],
|
||||
};
|
||||
|
||||
const configPreprocessor: ConfigPreprocessorFn<CountersPluginType> = options => {
|
||||
const configPreprocessor: ConfigPreprocessorFn<CountersPluginType> = (options) => {
|
||||
for (const counter of Object.values(options.config?.counters || {})) {
|
||||
counter.per_user = counter.per_user ?? false;
|
||||
counter.per_channel = counter.per_channel ?? false;
|
||||
|
|
|
@ -37,10 +37,10 @@ export async function changeCounterValue(
|
|||
if (triggers) {
|
||||
const triggersArr = Array.from(triggers.values());
|
||||
await Promise.all(
|
||||
triggersArr.map(trigger => checkCounterTrigger(pluginData, counterName, trigger, channelId, userId)),
|
||||
triggersArr.map((trigger) => checkCounterTrigger(pluginData, counterName, trigger, channelId, userId)),
|
||||
);
|
||||
await Promise.all(
|
||||
triggersArr.map(trigger => checkReverseCounterTrigger(pluginData, counterName, trigger, channelId, userId)),
|
||||
triggersArr.map((trigger) => checkReverseCounterTrigger(pluginData, counterName, trigger, channelId, userId)),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,8 +24,8 @@ export async function decayCounter(
|
|||
const triggers = pluginData.state.counterTriggersByCounterId.get(counterId);
|
||||
if (triggers) {
|
||||
const triggersArr = Array.from(triggers.values());
|
||||
await Promise.all(triggersArr.map(trigger => checkAllValuesForTrigger(pluginData, counterName, trigger)));
|
||||
await Promise.all(triggersArr.map(trigger => checkAllValuesForReverseTrigger(pluginData, counterName, trigger)));
|
||||
await Promise.all(triggersArr.map((trigger) => checkAllValuesForTrigger(pluginData, counterName, trigger)));
|
||||
await Promise.all(triggersArr.map((trigger) => checkAllValuesForReverseTrigger(pluginData, counterName, trigger)));
|
||||
}
|
||||
|
||||
lock.unlock();
|
||||
|
|
|
@ -34,10 +34,10 @@ export async function setCounterValue(
|
|||
if (triggers) {
|
||||
const triggersArr = Array.from(triggers.values());
|
||||
await Promise.all(
|
||||
triggersArr.map(trigger => checkCounterTrigger(pluginData, counterName, trigger, channelId, userId)),
|
||||
triggersArr.map((trigger) => checkCounterTrigger(pluginData, counterName, trigger, channelId, userId)),
|
||||
);
|
||||
await Promise.all(
|
||||
triggersArr.map(trigger => checkReverseCounterTrigger(pluginData, counterName, trigger, channelId, userId)),
|
||||
triggersArr.map((trigger) => checkReverseCounterTrigger(pluginData, counterName, trigger, channelId, userId)),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ export const GuildBanRemoveAlertsEvt = locateUserEvt({
|
|||
|
||||
async listener(meta) {
|
||||
const alerts = await meta.pluginData.state.alerts.getAlertsByUserId(meta.args.user.id);
|
||||
alerts.forEach(alert => {
|
||||
alerts.forEach((alert) => {
|
||||
meta.pluginData.state.alerts.delete(alert.id);
|
||||
});
|
||||
},
|
||||
|
|
|
@ -29,7 +29,7 @@ export const ChannelLeaveAlertsEvt = locateUserEvt({
|
|||
const triggeredAlerts = await meta.pluginData.state.alerts.getAlertsByUserId(meta.args.member.id);
|
||||
const voiceChannel = meta.args.oldChannel as VoiceChannel;
|
||||
|
||||
triggeredAlerts.forEach(alert => {
|
||||
triggeredAlerts.forEach((alert) => {
|
||||
const txtChannel = meta.pluginData.client.getChannel(alert.channel_id) as TextableChannel;
|
||||
txtChannel.createMessage(
|
||||
`🔴 <@!${alert.requestor_id}> the user <@!${alert.user_id}> disconnected out of \`${voiceChannel.name}\``,
|
||||
|
|
|
@ -4,7 +4,7 @@ import { LocateUserPluginType } from "../types";
|
|||
export async function fillActiveAlertsList(pluginData: GuildPluginData<LocateUserPluginType>) {
|
||||
const allAlerts = await pluginData.state.alerts.getAllGuildAlerts();
|
||||
|
||||
allAlerts.forEach(alert => {
|
||||
allAlerts.forEach((alert) => {
|
||||
if (!pluginData.state.usersWithAlerts.includes(alert.user_id)) {
|
||||
pluginData.state.usersWithAlerts.push(alert.user_id);
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ export async function sendAlerts(pluginData: GuildPluginData<LocateUserPluginTyp
|
|||
const member = await resolveMember(pluginData.client, pluginData.guild, userId);
|
||||
if (!member) return;
|
||||
|
||||
triggeredAlerts.forEach(alert => {
|
||||
triggeredAlerts.forEach((alert) => {
|
||||
const prepend = `<@!${alert.requestor_id}>, an alert requested by you has triggered!\nReminder: \`${alert.body}\`\n`;
|
||||
const txtChannel = pluginData.client.getChannel(alert.channel_id) as TextableChannel;
|
||||
sendWhere(pluginData, member, txtChannel, prepend);
|
||||
|
|
|
@ -97,10 +97,10 @@ export const LogsPlugin = zeppelinGuildPlugin<LogsPluginType>()("logs", {
|
|||
|
||||
state.batches = new Map();
|
||||
|
||||
state.onMessageDeleteFn = msg => onMessageDelete(pluginData, msg);
|
||||
state.onMessageDeleteFn = (msg) => onMessageDelete(pluginData, msg);
|
||||
state.savedMessages.events.on("delete", state.onMessageDeleteFn);
|
||||
|
||||
state.onMessageDeleteBulkFn = msg => onMessageDeleteBulk(pluginData, msg);
|
||||
state.onMessageDeleteBulkFn = (msg) => onMessageDeleteBulk(pluginData, msg);
|
||||
state.savedMessages.events.on("deleteBulk", state.onMessageDeleteBulkFn);
|
||||
|
||||
state.onMessageUpdateFn = (newMsg, oldMsg) => onMessageUpdate(pluginData, newMsg, oldMsg);
|
||||
|
|
|
@ -24,7 +24,7 @@ export const LogsGuildMemberAddEvt = logsEvt({
|
|||
account_age: accountAge,
|
||||
});
|
||||
|
||||
const cases = (await pluginData.state.cases.with("notes").getByUserId(member.id)).filter(c => !c.is_hidden);
|
||||
const cases = (await pluginData.state.cases.with("notes").getByUserId(member.id)).filter((c) => !c.is_hidden);
|
||||
cases.sort((a, b) => (a.created_at > b.created_at ? -1 : 1));
|
||||
|
||||
if (cases.length) {
|
||||
|
|
|
@ -61,12 +61,12 @@ export const LogsGuildMemberUpdateEvt = logsEvt({
|
|||
{
|
||||
member: logMember,
|
||||
addedRoles: addedRoles
|
||||
.map(roleId => pluginData.guild.roles.get(roleId) || { id: roleId, name: `Unknown (${roleId})` })
|
||||
.map(r => r.name)
|
||||
.map((roleId) => pluginData.guild.roles.get(roleId) || { id: roleId, name: `Unknown (${roleId})` })
|
||||
.map((r) => r.name)
|
||||
.join(", "),
|
||||
removedRoles: removedRoles
|
||||
.map(roleId => pluginData.guild.roles.get(roleId) || { id: roleId, name: `Unknown (${roleId})` })
|
||||
.map(r => r.name)
|
||||
.map((roleId) => pluginData.guild.roles.get(roleId) || { id: roleId, name: `Unknown (${roleId})` })
|
||||
.map((r) => r.name)
|
||||
.join(", "),
|
||||
mod: stripObjectToScalars(mod),
|
||||
},
|
||||
|
@ -79,8 +79,8 @@ export const LogsGuildMemberUpdateEvt = logsEvt({
|
|||
{
|
||||
member: logMember,
|
||||
roles: addedRoles
|
||||
.map(roleId => pluginData.guild.roles.get(roleId) || { id: roleId, name: `Unknown (${roleId})` })
|
||||
.map(r => r.name)
|
||||
.map((roleId) => pluginData.guild.roles.get(roleId) || { id: roleId, name: `Unknown (${roleId})` })
|
||||
.map((r) => r.name)
|
||||
.join(", "),
|
||||
mod: stripObjectToScalars(mod),
|
||||
},
|
||||
|
@ -93,8 +93,8 @@ export const LogsGuildMemberUpdateEvt = logsEvt({
|
|||
{
|
||||
member: logMember,
|
||||
roles: removedRoles
|
||||
.map(roleId => pluginData.guild.roles.get(roleId) || { id: roleId, name: `Unknown (${roleId})` })
|
||||
.map(r => r.name)
|
||||
.map((roleId) => pluginData.guild.roles.get(roleId) || { id: roleId, name: `Unknown (${roleId})` })
|
||||
.map((r) => r.name)
|
||||
.join(", "),
|
||||
mod: stripObjectToScalars(mod),
|
||||
},
|
||||
|
|
|
@ -41,7 +41,7 @@ export async function getLogMessage(
|
|||
const values = {
|
||||
...data,
|
||||
timestamp,
|
||||
userMention: async inputUserOrMember => {
|
||||
userMention: async (inputUserOrMember) => {
|
||||
if (!inputUserOrMember) return "";
|
||||
|
||||
const usersOrMembers = Array.isArray(inputUserOrMember) ? inputUserOrMember : [inputUserOrMember];
|
||||
|
@ -71,7 +71,7 @@ export async function getLogMessage(
|
|||
|
||||
return mentions.join(", ");
|
||||
},
|
||||
channelMention: channel => {
|
||||
channelMention: (channel) => {
|
||||
if (!channel) return "";
|
||||
return verboseChannelMention(channel);
|
||||
},
|
||||
|
@ -83,12 +83,12 @@ export async function getLogMessage(
|
|||
|
||||
if (type === LogType.BOT_ALERT) {
|
||||
const valuesWithoutTmplEval = { ...values };
|
||||
values.tmplEval = str => {
|
||||
values.tmplEval = (str) => {
|
||||
return renderTemplate(str, valuesWithoutTmplEval);
|
||||
};
|
||||
}
|
||||
|
||||
const renderLogString = str => renderTemplate(str, values);
|
||||
const renderLogString = (str) => renderTemplate(str, values);
|
||||
|
||||
let formatted;
|
||||
try {
|
||||
|
|
|
@ -8,7 +8,7 @@ export async function onMessageDeleteBulk(pluginData: GuildPluginData<LogsPlugin
|
|||
const channel = pluginData.guild.channels.get(savedMessages[0].channel_id);
|
||||
const archiveId = await pluginData.state.archives.createFromSavedMessages(savedMessages, pluginData.guild);
|
||||
const archiveUrl = pluginData.state.archives.getUrl(getBaseUrl(pluginData), archiveId);
|
||||
const authorIds = Array.from(new Set(savedMessages.map(item => `\`${item.user_id}\``))).join(", ");
|
||||
const authorIds = Array.from(new Set(savedMessages.map((item) => `\`${item.user_id}\``))).join(", ");
|
||||
|
||||
pluginData.state.guildLogs.log(
|
||||
LogType.MESSAGE_DELETE_BULK,
|
||||
|
|
|
@ -15,12 +15,12 @@ export async function onMessageUpdate(
|
|||
let logUpdate = false;
|
||||
|
||||
const oldEmbedsToCompare = ((oldSavedMessage.data.embeds || []) as Embed[])
|
||||
.map(e => cloneDeep(e))
|
||||
.filter(e => (e as Embed).type === "rich");
|
||||
.map((e) => cloneDeep(e))
|
||||
.filter((e) => (e as Embed).type === "rich");
|
||||
|
||||
const newEmbedsToCompare = ((savedMessage.data.embeds || []) as Embed[])
|
||||
.map(e => cloneDeep(e))
|
||||
.filter(e => (e as Embed).type === "rich");
|
||||
.map((e) => cloneDeep(e))
|
||||
.filter((e) => (e as Embed).type === "rich");
|
||||
|
||||
for (const embed of [...oldEmbedsToCompare, ...newEmbedsToCompare]) {
|
||||
if (embed.thumbnail) {
|
||||
|
|
|
@ -19,7 +19,7 @@ export const SavePinsToDBCmd = messageSaverCmd({
|
|||
const { savedCount, failed } = await saveMessagesToDB(
|
||||
pluginData,
|
||||
args.channel,
|
||||
pins.map(m => m.id),
|
||||
pins.map((m) => m.id),
|
||||
);
|
||||
|
||||
if (failed.length) {
|
||||
|
|
|
@ -51,7 +51,7 @@ export const MessageDeleteBulkEvt = messageSaverEvt({
|
|||
allowSelf: true,
|
||||
|
||||
async listener(meta) {
|
||||
const ids = meta.args.messages.map(m => m.id);
|
||||
const ids = meta.args.messages.map((m) => m.id);
|
||||
await meta.pluginData.state.savedMessages.markBulkAsDeleted(ids);
|
||||
},
|
||||
});
|
||||
|
|
|
@ -47,9 +47,9 @@ export const CasesModCmd = modActionsCmd({
|
|||
pluginData.client,
|
||||
msg.channel,
|
||||
totalPages,
|
||||
async page => {
|
||||
async (page) => {
|
||||
const cases = await casesPlugin.getRecentCasesByMod(modId, casesPerPage, (page - 1) * casesPerPage);
|
||||
const lines = await asyncMap(cases, c => casesPlugin.getCaseSummary(c, true, msg.author.id));
|
||||
const lines = await asyncMap(cases, (c) => casesPlugin.getCaseSummary(c, true, msg.author.id));
|
||||
|
||||
const firstCaseNum = (page - 1) * casesPerPage + 1;
|
||||
const lastCaseNum = page * casesPerPage;
|
||||
|
|
|
@ -42,8 +42,8 @@ export const CasesUserCmd = modActionsCmd({
|
|||
}
|
||||
|
||||
const cases = await pluginData.state.cases.with("notes").getByUserId(user.id);
|
||||
const normalCases = cases.filter(c => !c.is_hidden);
|
||||
const hiddenCases = cases.filter(c => c.is_hidden);
|
||||
const normalCases = cases.filter((c) => !c.is_hidden);
|
||||
const hiddenCases = cases.filter((c) => c.is_hidden);
|
||||
|
||||
const userName =
|
||||
user instanceof UnknownUser && cases.length
|
||||
|
@ -70,7 +70,7 @@ export const CasesUserCmd = modActionsCmd({
|
|||
} else {
|
||||
// Compact view (= regular message with a preview of each case)
|
||||
const casesPlugin = pluginData.getPlugin(CasesPlugin);
|
||||
const lines = await asyncMap(casesToDisplay, c => casesPlugin.getCaseSummary(c, true, msg.author.id));
|
||||
const lines = await asyncMap(casesToDisplay, (c) => casesPlugin.getCaseSummary(c, true, msg.author.id));
|
||||
|
||||
const prefix = getGuildPrefix(pluginData);
|
||||
const linesPerChunk = 10;
|
||||
|
|
|
@ -52,7 +52,7 @@ export const MassbanCmd = modActionsCmd({
|
|||
|
||||
// Ignore automatic ban cases and logs for these users
|
||||
// We'll create our own cases below and post a single "mass banned" log instead
|
||||
args.userIds.forEach(userId => {
|
||||
args.userIds.forEach((userId) => {
|
||||
// Use longer timeouts since this can take a while
|
||||
ignoreEvent(pluginData, IgnoredEventType.Ban, userId, 120 * 1000);
|
||||
pluginData.state.serverLogs.ignoreLog(LogType.MEMBER_BAN, userId, 120 * 1000);
|
||||
|
|
|
@ -41,7 +41,7 @@ export const MassunbanCmd = modActionsCmd({
|
|||
|
||||
// Ignore automatic unban cases and logs for these users
|
||||
// We'll create our own cases below and post a single "mass unbanned" log instead
|
||||
args.userIds.forEach(userId => {
|
||||
args.userIds.forEach((userId) => {
|
||||
// Use longer timeouts since this can take a while
|
||||
ignoreEvent(pluginData, IgnoredEventType.Unban, userId, 120 * 1000);
|
||||
pluginData.state.serverLogs.ignoreLog(LogType.MEMBER_UNBAN, userId, 120 * 1000);
|
||||
|
@ -90,19 +90,19 @@ export const MassunbanCmd = modActionsCmd({
|
|||
});
|
||||
|
||||
if (failedUnbans.length) {
|
||||
const notBanned = failedUnbans.filter(x => x.reason === UnbanFailReasons.NOT_BANNED);
|
||||
const unbanFailed = failedUnbans.filter(x => x.reason === UnbanFailReasons.UNBAN_FAILED);
|
||||
const notBanned = failedUnbans.filter((x) => x.reason === UnbanFailReasons.NOT_BANNED);
|
||||
const unbanFailed = failedUnbans.filter((x) => x.reason === UnbanFailReasons.UNBAN_FAILED);
|
||||
|
||||
let failedMsg = "";
|
||||
if (notBanned.length > 0) {
|
||||
failedMsg += `${notBanned.length}x ${UnbanFailReasons.NOT_BANNED}:`;
|
||||
notBanned.forEach(fail => {
|
||||
notBanned.forEach((fail) => {
|
||||
failedMsg += " " + fail.userId;
|
||||
});
|
||||
}
|
||||
if (unbanFailed.length > 0) {
|
||||
failedMsg += `\n${unbanFailed.length}x ${UnbanFailReasons.UNBAN_FAILED}:`;
|
||||
unbanFailed.forEach(fail => {
|
||||
unbanFailed.forEach((fail) => {
|
||||
failedMsg += " " + fail.userId;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ export const MassmuteCmd = modActionsCmd({
|
|||
|
||||
// Ignore automatic mute cases and logs for these users
|
||||
// We'll create our own cases below and post a single "mass muted" log instead
|
||||
args.userIds.forEach(userId => {
|
||||
args.userIds.forEach((userId) => {
|
||||
// Use longer timeouts since this can take a while
|
||||
pluginData.state.serverLogs.ignoreLog(LogType.MEMBER_MUTE, userId, 120 * 1000);
|
||||
});
|
||||
|
|
|
@ -7,7 +7,7 @@ export function clearIgnoredEvents(
|
|||
userId: string,
|
||||
) {
|
||||
pluginData.state.ignoredEvents.splice(
|
||||
pluginData.state.ignoredEvents.findIndex(info => type === info.type && userId === info.userId),
|
||||
pluginData.state.ignoredEvents.findIndex((info) => type === info.type && userId === info.userId),
|
||||
1,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Attachment } from "eris";
|
||||
|
||||
export function formatReasonWithAttachments(reason: string, attachments: Attachment[]) {
|
||||
const attachmentUrls = attachments.map(a => a.url);
|
||||
const attachmentUrls = attachments.map((a) => a.url);
|
||||
return ((reason || "") + " " + attachmentUrls.join(" ")).trim();
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import { isDiscordHTTPError } from "../../../utils";
|
|||
export async function isBanned(pluginData: GuildPluginData<ModActionsPluginType>, userId: string): Promise<boolean> {
|
||||
try {
|
||||
const bans = await pluginData.guild.getBans();
|
||||
return bans.some(b => b.user.id === userId);
|
||||
return bans.some((b) => b.user.id === userId);
|
||||
} catch (e) {
|
||||
if (isDiscordHTTPError(e) && e.code === 500) {
|
||||
return false;
|
||||
|
|
|
@ -6,5 +6,5 @@ export function isEventIgnored(
|
|||
type: IgnoredEventType,
|
||||
userId: string,
|
||||
) {
|
||||
return pluginData.state.ignoredEvents.some(info => type === info.type && userId === info.userId);
|
||||
return pluginData.state.ignoredEvents.some((info) => type === info.type && userId === info.userId);
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ export const ClearBannedMutesCmd = mutesCmd({
|
|||
|
||||
// Mismatch in Eris docs and actual result here, based on Eris's code comments anyway
|
||||
const bans: Array<{ reason: string; user: User }> = (await pluginData.guild.getBans()) as any;
|
||||
const bannedIds = bans.map(b => b.user.id);
|
||||
const bannedIds = bans.map((b) => b.user.id);
|
||||
|
||||
await msg.channel.createMessage(
|
||||
`Found ${activeMutes.length} mutes and ${bannedIds.length} bans, cross-referencing...`,
|
||||
|
|
|
@ -47,12 +47,12 @@ export const MutesCmd = mutesCmd({
|
|||
|
||||
if (args.manual) {
|
||||
// Show only manual mutes (i.e. "Muted" role added without a logged mute)
|
||||
const muteUserIds = new Set(activeMutes.map(m => m.user_id));
|
||||
const muteUserIds = new Set(activeMutes.map((m) => m.user_id));
|
||||
const manuallyMutedMembers: Member[] = [];
|
||||
const muteRole = pluginData.config.get().mute_role;
|
||||
|
||||
if (muteRole) {
|
||||
pluginData.guild.members.forEach(member => {
|
||||
pluginData.guild.members.forEach((member) => {
|
||||
if (muteUserIds.has(member.id)) return;
|
||||
if (member.roles.includes(muteRole)) manuallyMutedMembers.push(member);
|
||||
});
|
||||
|
@ -60,7 +60,7 @@ export const MutesCmd = mutesCmd({
|
|||
|
||||
totalMutes = manuallyMutedMembers.length;
|
||||
|
||||
lines = manuallyMutedMembers.map(member => {
|
||||
lines = manuallyMutedMembers.map((member) => {
|
||||
return `<@!${member.id}> (**${member.user.username}#${member.user.discriminator}**, \`${member.id}\`) 🔧 Manual mute`;
|
||||
});
|
||||
} else {
|
||||
|
@ -70,11 +70,8 @@ export const MutesCmd = mutesCmd({
|
|||
|
||||
// Filter: mute age
|
||||
if (args.age) {
|
||||
const cutoff = moment
|
||||
.utc()
|
||||
.subtract(args.age, "ms")
|
||||
.format(DBDateFormat);
|
||||
filteredMutes = filteredMutes.filter(m => m.created_at <= cutoff);
|
||||
const cutoff = moment.utc().subtract(args.age, "ms").format(DBDateFormat);
|
||||
filteredMutes = filteredMutes.filter((m) => m.created_at <= cutoff);
|
||||
hasFilters = true;
|
||||
}
|
||||
|
||||
|
@ -87,7 +84,7 @@ export const MutesCmd = mutesCmd({
|
|||
if (!member) {
|
||||
if (!bannedIds) {
|
||||
const bans = await pluginData.guild.getBans();
|
||||
bannedIds = bans.map(u => u.user.id);
|
||||
bannedIds = bans.map((u) => u.user.id);
|
||||
}
|
||||
|
||||
muteWithDetails.banned = bannedIds.includes(mute.user_id);
|
||||
|
@ -100,18 +97,18 @@ export const MutesCmd = mutesCmd({
|
|||
|
||||
// Filter: left the server
|
||||
if (args.left != null) {
|
||||
filteredMutes = filteredMutes.filter(m => (args.left && !m.member) || (!args.left && m.member));
|
||||
filteredMutes = filteredMutes.filter((m) => (args.left && !m.member) || (!args.left && m.member));
|
||||
hasFilters = true;
|
||||
}
|
||||
|
||||
totalMutes = filteredMutes.length;
|
||||
|
||||
// Create a message line for each mute
|
||||
const caseIds = filteredMutes.map(m => m.case_id).filter(v => !!v);
|
||||
const caseIds = filteredMutes.map((m) => m.case_id).filter((v) => !!v);
|
||||
const muteCases = caseIds.length ? await pluginData.state.cases.get(caseIds) : [];
|
||||
const muteCasesById = muteCases.reduce((map, c) => map.set(c.id, c), new Map());
|
||||
|
||||
lines = filteredMutes.map(mute => {
|
||||
lines = filteredMutes.map((mute) => {
|
||||
const user = pluginData.client.users.get(mute.user_id);
|
||||
const username = user ? `${user.username}#${user.discriminator}` : "Unknown#0000";
|
||||
const theCase = muteCasesById.get(mute.case_id);
|
||||
|
@ -146,7 +143,7 @@ export const MutesCmd = mutesCmd({
|
|||
let currentPage = 1;
|
||||
const totalPages = Math.ceil(lines.length / mutesPerPage);
|
||||
|
||||
const drawListPage = async page => {
|
||||
const drawListPage = async (page) => {
|
||||
page = Math.max(1, Math.min(totalPages, page));
|
||||
currentPage = page;
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ export async function clearExpiredMutes(pluginData: GuildPluginData<MutesPluginT
|
|||
const memberOptions: MemberOptions = {};
|
||||
const guildRoles = pluginData.guild.roles;
|
||||
memberOptions.roles = Array.from(
|
||||
new Set([...mute.roles_to_restore, ...member.roles.filter(x => x !== muteRole && guildRoles.has(x))]),
|
||||
new Set([...mute.roles_to_restore, ...member.roles.filter((x) => x !== muteRole && guildRoles.has(x))]),
|
||||
);
|
||||
member.edit(memberOptions);
|
||||
}
|
||||
|
|
|
@ -67,12 +67,12 @@ export async function muteUser(
|
|||
if (!Array.isArray(removeRoles)) {
|
||||
if (removeRoles) {
|
||||
// exclude managed roles from being removed
|
||||
const managedRoles = pluginData.guild.roles.filter(x => x.managed).map(y => y.id);
|
||||
memberOptions.roles = managedRoles.filter(x => member.roles.includes(x));
|
||||
const managedRoles = pluginData.guild.roles.filter((x) => x.managed).map((y) => y.id);
|
||||
memberOptions.roles = managedRoles.filter((x) => member.roles.includes(x));
|
||||
await member.edit(memberOptions);
|
||||
}
|
||||
} else {
|
||||
memberOptions.roles = currentUserRoles.filter(x => !(<string[]>removeRoles).includes(x));
|
||||
memberOptions.roles = currentUserRoles.filter((x) => !(<string[]>removeRoles).includes(x));
|
||||
await member.edit(memberOptions);
|
||||
}
|
||||
|
||||
|
@ -82,7 +82,7 @@ export async function muteUser(
|
|||
rolesToRestore = currentUserRoles;
|
||||
}
|
||||
} else {
|
||||
rolesToRestore = currentUserRoles.filter(x => (<string[]>restoreRoles).includes(x));
|
||||
rolesToRestore = currentUserRoles.filter((x) => (<string[]>restoreRoles).includes(x));
|
||||
}
|
||||
|
||||
// Apply mute role if it's missing
|
||||
|
@ -90,7 +90,7 @@ export async function muteUser(
|
|||
try {
|
||||
await member.addRole(muteRole);
|
||||
} catch (e) {
|
||||
const actualMuteRole = pluginData.guild.roles.find(x => x.id === muteRole);
|
||||
const actualMuteRole = pluginData.guild.roles.find((x) => x.id === muteRole);
|
||||
if (!actualMuteRole) {
|
||||
lock.unlock();
|
||||
logs.log(LogType.BOT_ALERT, {
|
||||
|
@ -100,9 +100,9 @@ export async function muteUser(
|
|||
}
|
||||
|
||||
const zep = await resolveMember(pluginData.client, pluginData.guild, pluginData.client.user.id);
|
||||
const zepRoles = pluginData.guild.roles.filter(x => zep!.roles.includes(x.id));
|
||||
const zepRoles = pluginData.guild.roles.filter((x) => zep!.roles.includes(x.id));
|
||||
// If we have roles and one of them is above the muted role, throw generic error
|
||||
if (zepRoles.length >= 0 && zepRoles.some(zepRole => zepRole.position > actualMuteRole.position)) {
|
||||
if (zepRoles.length >= 0 && zepRoles.some((zepRole) => zepRole.position > actualMuteRole.position)) {
|
||||
lock.unlock();
|
||||
logs.log(LogType.BOT_ALERT, {
|
||||
body: `Cannot mute user ${member.id}: ${e}`,
|
||||
|
|
|
@ -40,7 +40,10 @@ export async function unmuteUser(
|
|||
const memberOptions: MemberOptions = {};
|
||||
const guildRoles = pluginData.guild.roles;
|
||||
memberOptions.roles = Array.from(
|
||||
new Set([...existingMute.roles_to_restore, ...member.roles.filter(x => x !== muteRole && guildRoles.has(x))]),
|
||||
new Set([
|
||||
...existingMute.roles_to_restore,
|
||||
...member.roles.filter((x) => x !== muteRole && guildRoles.has(x)),
|
||||
]),
|
||||
);
|
||||
member.edit(memberOptions);
|
||||
}
|
||||
|
|
|
@ -25,9 +25,9 @@ export const NamesCmd = nameHistoryCmd({
|
|||
}
|
||||
|
||||
const nicknameRows = nicknames.map(
|
||||
r => `\`[${r.timestamp}]\` ${r.nickname ? `**${disableCodeBlocks(r.nickname)}**` : "*None*"}`,
|
||||
(r) => `\`[${r.timestamp}]\` ${r.nickname ? `**${disableCodeBlocks(r.nickname)}**` : "*None*"}`,
|
||||
);
|
||||
const usernameRows = usernames.map(r => `\`[${r.timestamp}]\` **${disableCodeBlocks(r.username)}**`);
|
||||
const usernameRows = usernames.map((r) => `\`[${r.timestamp}]\` **${disableCodeBlocks(r.username)}**`);
|
||||
|
||||
const user = pluginData.client.users.get(args.userId);
|
||||
const currentUsername = user ? `${user.username}#${user.discriminator}` : args.userId;
|
||||
|
|
|
@ -27,7 +27,7 @@ export const ScheduledPostsListCmd = postCmd({
|
|||
scheduledPosts.sort(sorter("post_at"));
|
||||
|
||||
let i = 1;
|
||||
const postLines = scheduledPosts.map(p => {
|
||||
const postLines = scheduledPosts.map((p) => {
|
||||
let previewText =
|
||||
p.content.content || (p.content.embed && (p.content.embed.description || p.content.embed.title)) || "";
|
||||
|
||||
|
|
|
@ -125,18 +125,10 @@ export async function actualPostCmd(
|
|||
channel_id: targetChannel.id,
|
||||
content,
|
||||
attachments: msg.attachments,
|
||||
post_at: postAt
|
||||
.clone()
|
||||
.tz("Etc/UTC")
|
||||
.format(DBDateFormat),
|
||||
post_at: postAt.clone().tz("Etc/UTC").format(DBDateFormat),
|
||||
enable_mentions: opts["enable-mentions"],
|
||||
repeat_interval: opts.repeat,
|
||||
repeat_until: repeatUntil
|
||||
? repeatUntil
|
||||
.clone()
|
||||
.tz("Etc/UTC")
|
||||
.format(DBDateFormat)
|
||||
: null,
|
||||
repeat_until: repeatUntil ? repeatUntil.clone().tz("Etc/UTC").format(DBDateFormat) : null,
|
||||
repeat_times: repeatTimes ?? null,
|
||||
});
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ export const InitReactionRolesCmd = reactionRolesCmd({
|
|||
const emojiRolePairs: TReactionRolePair[] = args.reactionRolePairs
|
||||
.trim()
|
||||
.split("\n")
|
||||
.map(v => v.split(/[\s=,]+/).map(v => v.trim())) // tslint:disable-line
|
||||
.map((v) => v.split(/[\s=,]+/).map((v) => v.trim())) // tslint:disable-line
|
||||
.map(
|
||||
(pair): TReactionRolePair => {
|
||||
const customEmojiMatch = pair[0].match(/^<a?:(.*?):(\d+)>$/);
|
||||
|
|
|
@ -29,7 +29,7 @@ export const AddReactionRoleEvt = reactionRolesEvt({
|
|||
|
||||
if (emoji.name === CLEAR_ROLES_EMOJI) {
|
||||
// User reacted with "clear roles" emoji -> clear their roles
|
||||
const reactionRoleRoleIds = reactionRoles.map(rr => rr.role_id);
|
||||
const reactionRoleRoleIds = reactionRoles.map((rr) => rr.role_id);
|
||||
for (const roleId of reactionRoleRoleIds) {
|
||||
addMemberPendingRoleChange(pluginData, userId, "-", roleId);
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ export async function applyReactionRoleReactionsToMessage(
|
|||
await sleep(1500);
|
||||
|
||||
// Add reaction role reactions
|
||||
const emojisToAdd = reactionRoles.map(rr => rr.emoji);
|
||||
const emojisToAdd = reactionRoles.map((rr) => rr.emoji);
|
||||
emojisToAdd.push(CLEAR_ROLES_EMOJI);
|
||||
|
||||
for (const rawEmoji of emojisToAdd) {
|
||||
|
|
|
@ -5,7 +5,7 @@ import { refreshReactionRoles } from "./refreshReactionRoles";
|
|||
export async function runAutoRefresh(pluginData: GuildPluginData<ReactionRolesPluginType>) {
|
||||
// Refresh reaction roles on all reaction role messages
|
||||
const reactionRoles = await pluginData.state.reactionRoles.all();
|
||||
const idPairs = new Set(reactionRoles.map(r => `${r.channel_id}-${r.message_id}`));
|
||||
const idPairs = new Set(reactionRoles.map((r) => `${r.channel_id}-${r.message_id}`));
|
||||
for (const pair of idPairs) {
|
||||
const [channelId, messageId] = pair.split("-");
|
||||
await refreshReactionRoles(pluginData, channelId, messageId);
|
||||
|
|
|
@ -53,10 +53,7 @@ export const RemindCmd = remindersCmd({
|
|||
await pluginData.state.reminders.add(
|
||||
msg.author.id,
|
||||
msg.channel.id,
|
||||
reminderTime
|
||||
.clone()
|
||||
.tz("Etc/UTC")
|
||||
.format("YYYY-MM-DD HH:mm:ss"),
|
||||
reminderTime.clone().tz("Etc/UTC").format("YYYY-MM-DD HH:mm:ss"),
|
||||
reminderBody,
|
||||
moment.utc().format("YYYY-MM-DD HH:mm:ss"),
|
||||
);
|
||||
|
|
|
@ -58,7 +58,7 @@ export const MassAddRoleCmd = rolesCmd({
|
|||
return;
|
||||
}
|
||||
|
||||
const membersWithoutTheRole = members.filter(m => !m.roles.includes(roleId));
|
||||
const membersWithoutTheRole = members.filter((m) => !m.roles.includes(roleId));
|
||||
let assigned = 0;
|
||||
const failed: string[] = [];
|
||||
const alreadyHadRole = members.length - membersWithoutTheRole.length;
|
||||
|
|
|
@ -58,7 +58,7 @@ export const MassRemoveRoleCmd = rolesCmd({
|
|||
return;
|
||||
}
|
||||
|
||||
const membersWithTheRole = members.filter(m => m.roles.includes(roleId));
|
||||
const membersWithTheRole = members.filter((m) => m.roles.includes(roleId));
|
||||
let assigned = 0;
|
||||
const failed: string[] = [];
|
||||
const didNotHaveRole = members.length - membersWithTheRole.length;
|
||||
|
|
|
@ -69,7 +69,7 @@ export const SelfGrantableRolesPlugin = zeppelinGuildPlugin<SelfGrantableRolesPl
|
|||
`),
|
||||
},
|
||||
|
||||
configPreprocessor: options => {
|
||||
configPreprocessor: (options) => {
|
||||
const config = options.config;
|
||||
for (const [key, entry] of Object.entries(config.entries)) {
|
||||
// Apply default entry config
|
||||
|
@ -78,7 +78,7 @@ export const SelfGrantableRolesPlugin = zeppelinGuildPlugin<SelfGrantableRolesPl
|
|||
// Normalize alias names
|
||||
if (entry.roles) {
|
||||
for (const [roleId, aliases] of Object.entries(entry.roles)) {
|
||||
entry.roles[roleId] = aliases.map(a => a.toLowerCase());
|
||||
entry.roles[roleId] = aliases.map((a) => a.toLowerCase());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ export const RoleAddCmd = selfGrantableRolesCmd({
|
|||
const hasUnknownRoles = matchedRoleIds.length !== roleNames.length;
|
||||
|
||||
const rolesToAdd: Map<string, Role> = Array.from(matchedRoleIds.values())
|
||||
.map(id => pluginData.guild.roles.get(id)!)
|
||||
.map((id) => pluginData.guild.roles.get(id)!)
|
||||
.filter(Boolean)
|
||||
.reduce((map, role) => {
|
||||
map.set(role.id, role);
|
||||
|
@ -91,7 +91,7 @@ export const RoleAddCmd = selfGrantableRolesCmd({
|
|||
}
|
||||
|
||||
const mentionRoles = pluginData.config.get().mention_roles;
|
||||
const addedRolesStr = Array.from(rolesToAdd.values()).map(r => (mentionRoles ? `<@&${r.id}>` : `**${r.name}**`));
|
||||
const addedRolesStr = Array.from(rolesToAdd.values()).map((r) => (mentionRoles ? `<@&${r.id}>` : `**${r.name}**`));
|
||||
const addedRolesWord = rolesToAdd.size === 1 ? "role" : "roles";
|
||||
|
||||
const messageParts: string[] = [];
|
||||
|
@ -101,11 +101,11 @@ export const RoleAddCmd = selfGrantableRolesCmd({
|
|||
const skippedRolesStr = skipped.size
|
||||
? "skipped " +
|
||||
Array.from(skipped.values())
|
||||
.map(r => (mentionRoles ? `<@&${r.id}>` : `**${r.name}**`))
|
||||
.map((r) => (mentionRoles ? `<@&${r.id}>` : `**${r.name}**`))
|
||||
.join(",")
|
||||
: null;
|
||||
const removedRolesStr = removed.size
|
||||
? "removed " + Array.from(removed.values()).map(r => (mentionRoles ? `<@&${r.id}>` : `**${r.name}**`))
|
||||
? "removed " + Array.from(removed.values()).map((r) => (mentionRoles ? `<@&${r.id}>` : `**${r.name}**`))
|
||||
: null;
|
||||
|
||||
const skippedRemovedStr = [skippedRolesStr, removedRolesStr].filter(Boolean).join(" and ");
|
||||
|
|
|
@ -26,19 +26,19 @@ export const RoleRemoveCmd = selfGrantableRolesCmd({
|
|||
const roleNames = normalizeRoleNames(splitRoleNames(args.roleNames));
|
||||
const matchedRoleIds = findMatchingRoles(roleNames, applyingEntries);
|
||||
|
||||
const rolesToRemove = Array.from(matchedRoleIds.values()).map(id => pluginData.guild.roles.get(id)!);
|
||||
const roleIdsToRemove = rolesToRemove.map(r => r.id);
|
||||
const rolesToRemove = Array.from(matchedRoleIds.values()).map((id) => pluginData.guild.roles.get(id)!);
|
||||
const roleIdsToRemove = rolesToRemove.map((r) => r.id);
|
||||
|
||||
// Remove the roles
|
||||
if (rolesToRemove.length) {
|
||||
const newRoleIds = msg.member.roles.filter(roleId => !roleIdsToRemove.includes(roleId));
|
||||
const newRoleIds = msg.member.roles.filter((roleId) => !roleIdsToRemove.includes(roleId));
|
||||
|
||||
try {
|
||||
await msg.member.edit({
|
||||
roles: newRoleIds,
|
||||
});
|
||||
|
||||
const removedRolesStr = rolesToRemove.map(r => `**${r.name}**`);
|
||||
const removedRolesStr = rolesToRemove.map((r) => `**${r.name}**`);
|
||||
const removedRolesWord = rolesToRemove.length === 1 ? "role" : "roles";
|
||||
|
||||
if (rolesToRemove.length !== roleNames.length) {
|
||||
|
|
|
@ -11,5 +11,5 @@ export function findMatchingRoles(roleNames: string[], entries: TSelfGrantableRo
|
|||
return map;
|
||||
}, new Map());
|
||||
|
||||
return roleNames.map(roleName => aliasToRoleId.get(roleName)).filter(Boolean);
|
||||
return roleNames.map((roleName) => aliasToRoleId.get(roleName)).filter(Boolean);
|
||||
}
|
||||
|
|
|
@ -11,5 +11,5 @@ export function getApplyingEntries(
|
|||
([k, e]) =>
|
||||
e.can_use && !(!e.can_ignore_cooldown && pluginData.state.cooldowns.isOnCooldown(`${k}:${msg.author.id}`)),
|
||||
)
|
||||
.map(pair => pair[1]);
|
||||
.map((pair) => pair[1]);
|
||||
}
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
export function normalizeRoleNames(roleNames: string[]) {
|
||||
return roleNames.map(v => v.toLowerCase());
|
||||
return roleNames.map((v) => v.toLowerCase());
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
export function splitRoleNames(roleNames: string[]) {
|
||||
return roleNames
|
||||
.map(v => v.split(/[\s,]+/))
|
||||
.map((v) => v.split(/[\s,]+/))
|
||||
.flat()
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ export const SlowmodePlugin = zeppelinGuildPlugin<SlowmodePluginType>()("slowmod
|
|||
state.logs = new GuildLogs(guild.id);
|
||||
state.clearInterval = setInterval(() => clearExpiredSlowmodes(pluginData), BOT_SLOWMODE_CLEAR_INTERVAL);
|
||||
|
||||
state.onMessageCreateFn = msg => onMessageCreate(pluginData, msg);
|
||||
state.onMessageCreateFn = (msg) => onMessageCreate(pluginData, msg);
|
||||
state.savedMessages.events.on("create", state.onMessageCreateFn);
|
||||
},
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ export const SlowmodeListCmd = slowmodeCmd({
|
|||
}
|
||||
|
||||
if (slowmodes.length) {
|
||||
const lines = slowmodes.map(slowmode => {
|
||||
const lines = slowmodes.map((slowmode) => {
|
||||
const humanized = humanizeDuration(slowmode.seconds * 1000);
|
||||
|
||||
const type = slowmode.native ? "native slowmode" : "bot slowmode";
|
||||
|
|
|
@ -77,7 +77,7 @@ export const SpamPlugin = zeppelinGuildPlugin<SpamPluginType>()("spam", {
|
|||
|
||||
state.spamDetectionQueue = Promise.resolve();
|
||||
|
||||
state.onMessageCreateFn = msg => onMessageCreate(pluginData, msg);
|
||||
state.onMessageCreateFn = (msg) => onMessageCreate(pluginData, msg);
|
||||
state.savedMessages.events.on("create", state.onMessageCreateFn);
|
||||
},
|
||||
|
||||
|
|
|
@ -6,5 +6,7 @@ const MAX_INTERVAL = 300;
|
|||
export function clearOldRecentActions(pluginData: GuildPluginData<SpamPluginType>) {
|
||||
// TODO: Figure out expiry time from longest interval in the config?
|
||||
const expiryTimestamp = Date.now() - 1000 * MAX_INTERVAL;
|
||||
pluginData.state.recentActions = pluginData.state.recentActions.filter(action => action.timestamp >= expiryTimestamp);
|
||||
pluginData.state.recentActions = pluginData.state.recentActions.filter(
|
||||
(action) => action.timestamp >= expiryTimestamp,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ export function clearRecentUserActions(
|
|||
userId: string,
|
||||
actionGroupId: string,
|
||||
) {
|
||||
pluginData.state.recentActions = pluginData.state.recentActions.filter(action => {
|
||||
pluginData.state.recentActions = pluginData.state.recentActions.filter((action) => {
|
||||
return action.type !== type || action.userId !== userId || action.actionGroupId !== actionGroupId;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ export function getRecentActions(
|
|||
actionGroupId: string,
|
||||
since: number,
|
||||
) {
|
||||
return pluginData.state.recentActions.filter(action => {
|
||||
return pluginData.state.recentActions.filter((action) => {
|
||||
if (action.timestamp < since) return false;
|
||||
if (action.type !== type) return false;
|
||||
if (action.actionGroupId !== actionGroupId) return false;
|
||||
|
|
|
@ -108,8 +108,8 @@ export async function logAndDetectMessageSpam(
|
|||
|
||||
// Get the offending message IDs
|
||||
// We also get the IDs of any messages after the last offending message, to account for lag before detection
|
||||
const savedMessages = recentActions.map(a => a.extraData as SavedMessage);
|
||||
const msgIds = savedMessages.map(m => m.id);
|
||||
const savedMessages = recentActions.map((a) => a.extraData as SavedMessage);
|
||||
const msgIds = savedMessages.map((m) => m.id);
|
||||
const lastDetectedMsgId = msgIds[msgIds.length - 1];
|
||||
|
||||
const additionalMessages = await pluginData.state.savedMessages.getUserMessagesByChannelAfterId(
|
||||
|
@ -117,11 +117,11 @@ export async function logAndDetectMessageSpam(
|
|||
savedMessage.channel_id,
|
||||
lastDetectedMsgId,
|
||||
);
|
||||
additionalMessages.forEach(m => msgIds.push(m.id));
|
||||
additionalMessages.forEach((m) => msgIds.push(m.id));
|
||||
|
||||
// Then, if enabled, remove the spam messages
|
||||
if (spamConfig.clean !== false) {
|
||||
msgIds.forEach(id => pluginData.state.logs.ignoreLog(LogType.MESSAGE_DELETE, id));
|
||||
msgIds.forEach((id) => pluginData.state.logs.ignoreLog(LogType.MESSAGE_DELETE, id));
|
||||
pluginData.client.deleteMessages(savedMessage.channel_id, msgIds).catch(noop);
|
||||
}
|
||||
|
||||
|
@ -129,7 +129,7 @@ export async function logAndDetectMessageSpam(
|
|||
const uniqueMessages = Array.from(new Set([...savedMessages, ...additionalMessages]));
|
||||
uniqueMessages.sort((a, b) => (a.id > b.id ? 1 : -1));
|
||||
const lastHandledMsgId = uniqueMessages
|
||||
.map(m => m.id)
|
||||
.map((m) => m.id)
|
||||
.reduce((last, id): string => {
|
||||
return id > last ? id : last;
|
||||
});
|
||||
|
@ -191,7 +191,7 @@ export async function logAndDetectMessageSpam(
|
|||
});
|
||||
}
|
||||
},
|
||||
err => {
|
||||
(err) => {
|
||||
logger.error(`Error while detecting spam:\n${err}`);
|
||||
},
|
||||
);
|
||||
|
|
|
@ -139,7 +139,7 @@ export const StarboardPlugin = zeppelinGuildPlugin<StarboardPluginType>()("starb
|
|||
state.starboardMessages = GuildStarboardMessages.getGuildInstance(guild.id);
|
||||
state.starboardReactions = GuildStarboardReactions.getGuildInstance(guild.id);
|
||||
|
||||
state.onMessageDeleteFn = msg => onMessageDelete(pluginData, msg);
|
||||
state.onMessageDeleteFn = (msg) => onMessageDelete(pluginData, msg);
|
||||
state.savedMessages.events.on("delete", state.onMessageDeleteFn);
|
||||
},
|
||||
|
||||
|
|
|
@ -39,11 +39,11 @@ export const StarboardReactionAddEvt = starboardEvt({
|
|||
const boardLock = await pluginData.locks.acquire(`starboards`);
|
||||
|
||||
const applicableStarboards = Object.values(config.boards)
|
||||
.filter(board => board.enabled)
|
||||
.filter((board) => board.enabled)
|
||||
// Can't star messages in the starboard channel itself
|
||||
.filter(board => board.channel_id !== msg.channel.id)
|
||||
.filter((board) => board.channel_id !== msg.channel.id)
|
||||
// Matching emoji
|
||||
.filter(board => {
|
||||
.filter((board) => {
|
||||
return board.star_emoji!.some((boardEmoji: string) => {
|
||||
if (emoji.id) {
|
||||
// Custom emoji
|
||||
|
|
|
@ -53,10 +53,7 @@ export function createStarboardEmbedFromMessage(msg: Message, copyFullEmbed: boo
|
|||
// If there are no embeds, add the first image attachment explicitly
|
||||
else if (msg.attachments.length) {
|
||||
for (const attachment of msg.attachments) {
|
||||
const ext = path
|
||||
.extname(attachment.filename)
|
||||
.slice(1)
|
||||
.toLowerCase();
|
||||
const ext = path.extname(attachment.filename).slice(1).toLowerCase();
|
||||
|
||||
if (imageAttachmentExtensions.includes(ext)) {
|
||||
embed.image = { url: attachment.url };
|
||||
|
|
|
@ -103,10 +103,10 @@ export const TagsPlugin = zeppelinGuildPlugin<TagsPluginType>()("tags", {
|
|||
state.savedMessages = GuildSavedMessages.getGuildInstance(guild.id);
|
||||
state.logs = new GuildLogs(guild.id);
|
||||
|
||||
state.onMessageCreateFn = msg => onMessageCreate(pluginData, msg);
|
||||
state.onMessageCreateFn = (msg) => onMessageCreate(pluginData, msg);
|
||||
state.savedMessages.events.on("create", state.onMessageCreateFn);
|
||||
|
||||
state.onMessageDeleteFn = msg => onMessageDelete(pluginData, msg);
|
||||
state.onMessageDeleteFn = (msg) => onMessageDelete(pluginData, msg);
|
||||
state.savedMessages.events.on("delete", state.onMessageDeleteFn);
|
||||
|
||||
const timeAndDate = pluginData.getPlugin(TimeAndDatePlugin);
|
||||
|
@ -155,10 +155,7 @@ export const TagsPlugin = zeppelinGuildPlugin<TagsPluginType>()("tags", {
|
|||
}
|
||||
|
||||
const delayMS = convertDelayStringToMS(delay) ?? 0;
|
||||
return moment
|
||||
.utc(reference, "x")
|
||||
.add(delayMS)
|
||||
.valueOf();
|
||||
return moment.utc(reference, "x").add(delayMS).valueOf();
|
||||
},
|
||||
|
||||
timeSub(...args) {
|
||||
|
@ -176,10 +173,7 @@ export const TagsPlugin = zeppelinGuildPlugin<TagsPluginType>()("tags", {
|
|||
}
|
||||
|
||||
const delayMS = convertDelayStringToMS(delay) ?? 0;
|
||||
return moment
|
||||
.utc(reference, "x")
|
||||
.subtract(delayMS)
|
||||
.valueOf();
|
||||
return moment.utc(reference, "x").subtract(delayMS).valueOf();
|
||||
},
|
||||
|
||||
timeAgo(delay) {
|
||||
|
@ -197,7 +191,7 @@ export const TagsPlugin = zeppelinGuildPlugin<TagsPluginType>()("tags", {
|
|||
return timeAndDate.inGuildTz(parsed).format("YYYY-MM-DD");
|
||||
},
|
||||
|
||||
mention: input => {
|
||||
mention: (input) => {
|
||||
if (typeof input !== "string") {
|
||||
return "";
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ export const TagListCmd = tagsCmd({
|
|||
}
|
||||
|
||||
const prefix = pluginData.config.getForMessage(msg).prefix;
|
||||
const tagNames = tags.map(tag => tag.tag).sort();
|
||||
const tagNames = tags.map((tag) => tag.tag).sort();
|
||||
|
||||
createChunkedMessage(msg.channel, `Available tags (use with ${prefix}tag): \`\`\`${tagNames.join(", ")}\`\`\``);
|
||||
},
|
||||
|
|
|
@ -77,7 +77,7 @@ export async function onMessageCreate(pluginData: GuildPluginData<TagsPluginType
|
|||
}
|
||||
}
|
||||
|
||||
const isOnCooldown = cooldowns.some(cd => pluginData.cooldowns.isOnCooldown(cd[0]));
|
||||
const isOnCooldown = cooldowns.some((cd) => pluginData.cooldowns.isOnCooldown(cd[0]));
|
||||
if (isOnCooldown) return;
|
||||
|
||||
for (const cd of cooldowns) {
|
||||
|
|
|
@ -53,6 +53,6 @@ export async function renderTagBody(
|
|||
return { content: await renderTemplate(body, data) };
|
||||
} else {
|
||||
// Embed
|
||||
return renderRecursively(body, str => renderTemplate(str, data));
|
||||
return renderRecursively(body, (str) => renderTemplate(str, data));
|
||||
}
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue