mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 12:25:02 +00:00
Reformat all files with Prettier
This commit is contained in:
parent
0cde0d46d2
commit
ac79eb09f5
206 changed files with 727 additions and 888 deletions
|
@ -45,13 +45,13 @@ export const AutoDeletePlugin = zeppelinGuildPlugin<AutoDeletePluginType>()({
|
|||
afterLoad(pluginData) {
|
||||
const { state, guild } = pluginData;
|
||||
|
||||
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);
|
||||
},
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ export async function deleteNextItem(pluginData: GuildPluginData<AutoDeletePlugi
|
|||
const timeAndDate = pluginData.getPlugin(TimeAndDatePlugin);
|
||||
|
||||
pluginData.state.guildLogs.ignoreLog(LogType.MESSAGE_DELETE, itemToDelete.message.id);
|
||||
(channel as TextChannel).messages.delete(itemToDelete.message.id as Snowflake).catch(err => {
|
||||
(channel as TextChannel).messages.delete(itemToDelete.message.id as Snowflake).catch((err) => {
|
||||
if (err.code === 10008) {
|
||||
// "Unknown Message", probably already deleted by automod or another bot, ignore
|
||||
return;
|
||||
|
|
|
@ -4,7 +4,7 @@ import { AutoDeletePluginType } from "../types";
|
|||
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);
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -35,7 +35,7 @@ export const AddDashboardUserCmd = botControlCmd({
|
|||
await pluginData.state.apiPermissionAssignments.addUser(args.guildId, user.id, [ApiPermissions.EditConfig]);
|
||||
}
|
||||
|
||||
const userNameList = args.users.map(user => `<@!${user.id}> (**${user.tag}**, \`${user.id}\`)`);
|
||||
const userNameList = args.users.map((user) => `<@!${user.id}> (**${user.tag}**, \`${user.id}\`)`);
|
||||
sendSuccessMessage(
|
||||
pluginData,
|
||||
msg.channel as TextChannel,
|
||||
|
|
|
@ -52,10 +52,7 @@ export const AddServerFromInviteCmd = botControlCmd({
|
|||
invite.guild.id,
|
||||
msg.author.id,
|
||||
[ApiPermissions.ManageAccess],
|
||||
moment
|
||||
.utc()
|
||||
.add(1, "hour")
|
||||
.format(DBDateFormat),
|
||||
moment.utc().add(1, "hour").format(DBDateFormat),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -48,10 +48,7 @@ export const AllowServerCmd = botControlCmd({
|
|||
args.guildId,
|
||||
msg.author.id,
|
||||
[ApiPermissions.ManageAccess],
|
||||
moment
|
||||
.utc()
|
||||
.add(1, "hour")
|
||||
.format(DBDateFormat),
|
||||
moment.utc().add(1, "hour").format(DBDateFormat),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ export const ListDashboardUsersCmd = botControlCmd({
|
|||
|
||||
const dashboardUsers = await pluginData.state.apiPermissionAssignments.getByGuildId(guild.id);
|
||||
const users = await Promise.all(
|
||||
dashboardUsers.map(async perm => ({
|
||||
dashboardUsers.map(async (perm) => ({
|
||||
user: await resolveUser(pluginData.client, perm.target_id),
|
||||
permission: perm,
|
||||
})),
|
||||
|
|
|
@ -13,7 +13,7 @@ export const PerformanceCmd = botControlCmd({
|
|||
async run({ pluginData, message: msg, args }) {
|
||||
const stats = pluginData.getKnubInstance().getPluginPerformanceStats();
|
||||
const averageLoadTimeEntries = Object.entries(stats.averageLoadTimes);
|
||||
averageLoadTimeEntries.sort(sorter(v => v[1].time, "DESC"));
|
||||
averageLoadTimeEntries.sort(sorter((v) => v[1].time, "DESC"));
|
||||
const lines = averageLoadTimeEntries.map(
|
||||
([pluginName, { time }]) => `${pluginName}: **${formatNumber(Math.round(time))}ms**`,
|
||||
);
|
||||
|
|
|
@ -34,7 +34,7 @@ export const RemoveDashboardUserCmd = botControlCmd({
|
|||
await pluginData.state.apiPermissionAssignments.removeUser(args.guildId, user.id);
|
||||
}
|
||||
|
||||
const userNameList = args.users.map(user => `<@!${user.id}> (**${user.tag}**, \`${user.id}\`)`);
|
||||
const userNameList = args.users.map((user) => `<@!${user.id}> (**${user.tag}**, \`${user.id}\`)`);
|
||||
sendSuccessMessage(
|
||||
pluginData,
|
||||
msg.channel as TextChannel,
|
||||
|
|
|
@ -22,7 +22,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.cache.values());
|
||||
const loadedGuilds = pluginData.getKnubInstance().getLoadedGuilds();
|
||||
|
@ -32,21 +32,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.tag}** \`${owner.id}\`)`;
|
||||
|
@ -57,7 +57,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.send(
|
||||
|
|
|
@ -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++;
|
||||
}
|
||||
|
|
|
@ -71,10 +71,10 @@ export const CensorPlugin = zeppelinGuildPlugin<CensorPluginType>()({
|
|||
afterLoad(pluginData) {
|
||||
const { state, guild } = pluginData;
|
||||
|
||||
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);
|
||||
},
|
||||
|
||||
|
|
|
@ -19,7 +19,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 MessageEmbed[]).map(e => cloneDeep(e));
|
||||
const embeds = (savedMessage.data.embeds as MessageEmbed[]).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
|
||||
|
@ -52,7 +52,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) {
|
||||
|
|
|
@ -14,5 +14,5 @@ export const ChannelArchiverPlugin = zeppelinGuildPlugin<ChannelArchiverPluginTy
|
|||
// prettier-ignore
|
||||
commands: [
|
||||
ArchiveChannelCmd,
|
||||
]
|
||||
],
|
||||
});
|
||||
|
|
|
@ -68,9 +68,9 @@ export const ArchiveChannelCmd = channelArchiverCmd({
|
|||
|
||||
for (const message of messages.values()) {
|
||||
const ts = moment.utc(message.createdTimestamp).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.size) {
|
||||
if (args["attachment-channel"]) {
|
||||
|
|
|
@ -14,9 +14,9 @@ export async function getCompanionChannelOptsForVoiceChannelId(
|
|||
const config = await 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));
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ export async function handleCompanionPermissions(
|
|||
if (!channel || !(channel instanceof TextChannel)) continue;
|
||||
pluginData.state.serverLogs.ignoreLog(LogType.CHANNEL_UPDATE, channelId, 3 * 1000);
|
||||
const fullSerialized = new Permissions(BigInt(permissions)).serialize();
|
||||
const onlyAllowed = filterObject(fullSerialized, v => v === true);
|
||||
const onlyAllowed = filterObject(fullSerialized, (v) => v === true);
|
||||
await channel.permissionOverwrites.create(userId, onlyAllowed, {
|
||||
reason: `Companion Channel for ${voiceChannel!.id} | User Joined`,
|
||||
});
|
||||
|
|
|
@ -48,8 +48,9 @@ export async function muteAction(
|
|||
|
||||
const muteMessage = `Muted **${result.case.user_name}** ${
|
||||
durationMs ? `for ${humanizeDuration(durationMs)}` : "indefinitely"
|
||||
} (Case #${result.case.case_number}) (user notified via ${result.notifyResult.method ??
|
||||
"dm"})\nPlease update the new case with the \`update\` command`;
|
||||
} (Case #${result.case.case_number}) (user notified via ${
|
||||
result.notifyResult.method ?? "dm"
|
||||
})\nPlease update the new case with the \`update\` command`;
|
||||
|
||||
interaction.followUp({ ephemeral: true, content: muteMessage });
|
||||
} catch (e) {
|
||||
|
|
|
@ -26,7 +26,7 @@ export async function loadAllCommands(pluginData: GuildPluginData<ContextMenuPlu
|
|||
newCommands.push(data);
|
||||
}
|
||||
|
||||
const setCommands = await comms.set(newCommands, pluginData.guild.id).catch(e => {
|
||||
const setCommands = await comms.set(newCommands, pluginData.guild.id).catch((e) => {
|
||||
pluginData.getPlugin(LogsPlugin).logBotAlert({ body: `Unable to overwrite context menus: ${e}` });
|
||||
return undefined;
|
||||
});
|
||||
|
|
|
@ -55,7 +55,7 @@ const defaultOptions: PluginOptions<CountersPluginType> = {
|
|||
],
|
||||
};
|
||||
|
||||
const configPreprocessor: ConfigPreprocessorFn<CountersPluginType> = options => {
|
||||
const configPreprocessor: ConfigPreprocessorFn<CountersPluginType> = (options) => {
|
||||
for (const [counterName, counter] of Object.entries(options.config?.counters || {})) {
|
||||
counter.name = counterName;
|
||||
counter.per_user = counter.per_user ?? false;
|
||||
|
|
|
@ -13,13 +13,13 @@ export const CountersListCmd = typedGuildCommand<CountersPluginType>()({
|
|||
async run({ pluginData, message, args }) {
|
||||
const config = await pluginData.config.getForMessage(message);
|
||||
|
||||
const countersToShow = Array.from(Object.values(config.counters)).filter(c => c.can_view !== false);
|
||||
const countersToShow = Array.from(Object.values(config.counters)).filter((c) => c.can_view !== false);
|
||||
if (!countersToShow.length) {
|
||||
sendErrorMessage(pluginData, message.channel, "No counters are configured for this server");
|
||||
return;
|
||||
}
|
||||
|
||||
const counterLines = countersToShow.map(counter => {
|
||||
const counterLines = countersToShow.map((counter) => {
|
||||
const title = counter.pretty_name ? `**${counter.pretty_name}** (\`${counter.name}\`)` : `\`${counter.name}\``;
|
||||
|
||||
const types: string[] = [];
|
||||
|
|
|
@ -38,10 +38,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)),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,8 +25,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();
|
||||
|
|
|
@ -35,10 +35,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)),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ export async function addRoleAction(
|
|||
throw new ActionError("Missing permissions");
|
||||
}
|
||||
const rolesToAdd = (Array.isArray(action.role) ? action.role : [action.role]).filter(
|
||||
id => !target.roles.cache.has(id),
|
||||
(id) => !target.roles.cache.has(id),
|
||||
);
|
||||
if (rolesToAdd.length === 0) {
|
||||
throw new ActionError("Target already has the role(s) specified");
|
||||
|
|
|
@ -5,7 +5,7 @@ export const GuildBanRemoveAlertsEvt = locateUserEvt({
|
|||
|
||||
async listener(meta) {
|
||||
const alerts = await meta.pluginData.state.alerts.getAlertsByUserId(meta.args.ban.user.id);
|
||||
alerts.forEach(alert => {
|
||||
alerts.forEach((alert) => {
|
||||
meta.pluginData.state.alerts.delete(alert.id);
|
||||
});
|
||||
},
|
||||
|
|
|
@ -19,7 +19,7 @@ export const VoiceStateUpdateAlertEvt = locateUserEvt({
|
|||
const triggeredAlerts = await meta.pluginData.state.alerts.getAlertsByUserId(memberId);
|
||||
const voiceChannel = meta.args.oldState.channel!;
|
||||
|
||||
triggeredAlerts.forEach(alert => {
|
||||
triggeredAlerts.forEach((alert) => {
|
||||
const txtChannel = meta.pluginData.guild.channels.resolve(alert.channel_id as Snowflake) as TextChannel;
|
||||
txtChannel.send({
|
||||
content: `🔴 <@!${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.guild.channels.resolve(alert.channel_id as Snowflake) as TextChannel;
|
||||
sendWhere(pluginData, member, txtChannel, prepend);
|
||||
|
|
|
@ -177,7 +177,7 @@ export const LogsPlugin = zeppelinGuildPlugin<LogsPluginType>()({
|
|||
],
|
||||
|
||||
public: {
|
||||
getLogMessage: pluginData => {
|
||||
getLogMessage: (pluginData) => {
|
||||
return <TLogType extends keyof ILogTypeData>(
|
||||
type: TLogType,
|
||||
data: TypedTemplateSafeValueContainer<ILogTypeData[TLogType]>,
|
||||
|
@ -277,10 +277,10 @@ export const LogsPlugin = zeppelinGuildPlugin<LogsPluginType>()({
|
|||
state.logListener = ({ type, data }) => log(pluginData, type, data);
|
||||
state.guildLogs.on("log", state.logListener);
|
||||
|
||||
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);
|
||||
|
|
|
@ -58,10 +58,10 @@ export const LogsGuildMemberUpdateEvt = logsEvt({
|
|||
logMemberRoleChanges(pluginData, {
|
||||
member,
|
||||
addedRoles: addedRoles.map(
|
||||
roleId => pluginData.guild.roles.cache.get(roleId) ?? { id: roleId, name: `Unknown (${roleId})` },
|
||||
(roleId) => pluginData.guild.roles.cache.get(roleId) ?? { id: roleId, name: `Unknown (${roleId})` },
|
||||
),
|
||||
removedRoles: removedRoles.map(
|
||||
roleId => pluginData.guild.roles.cache.get(roleId) ?? { id: roleId, name: `Unknown (${roleId})` },
|
||||
(roleId) => pluginData.guild.roles.cache.get(roleId) ?? { id: roleId, name: `Unknown (${roleId})` },
|
||||
),
|
||||
mod: null,
|
||||
});
|
||||
|
@ -70,7 +70,7 @@ export const LogsGuildMemberUpdateEvt = logsEvt({
|
|||
logMemberRoleAdd(pluginData, {
|
||||
member,
|
||||
roles: addedRoles.map(
|
||||
roleId => pluginData.guild.roles.cache.get(roleId) ?? { id: roleId, name: `Unknown (${roleId})` },
|
||||
(roleId) => pluginData.guild.roles.cache.get(roleId) ?? { id: roleId, name: `Unknown (${roleId})` },
|
||||
),
|
||||
mod: null,
|
||||
});
|
||||
|
@ -79,7 +79,7 @@ export const LogsGuildMemberUpdateEvt = logsEvt({
|
|||
logMemberRoleRemove(pluginData, {
|
||||
member,
|
||||
roles: removedRoles.map(
|
||||
roleId => pluginData.guild.roles.cache.get(roleId) ?? { id: roleId, name: `Unknown (${roleId})` },
|
||||
(roleId) => pluginData.guild.roles.cache.get(roleId) ?? { id: roleId, name: `Unknown (${roleId})` },
|
||||
),
|
||||
mod: null,
|
||||
});
|
||||
|
|
|
@ -21,7 +21,7 @@ export function logAutomodAction(pluginData: GuildPluginData<LogsPluginType>, da
|
|||
createTypedTemplateSafeValueContainer({
|
||||
rule: data.rule,
|
||||
user: data.user ? userToTemplateSafeUser(data.user) : null,
|
||||
users: data.users.map(user => userToTemplateSafeUser(user)),
|
||||
users: data.users.map((user) => userToTemplateSafeUser(user)),
|
||||
actionsTaken: data.actionsTaken,
|
||||
matchSummary: data.matchSummary ?? "",
|
||||
}),
|
||||
|
|
|
@ -19,7 +19,7 @@ export function logMemberRoleAdd(pluginData: GuildPluginData<LogsPluginType>, da
|
|||
createTypedTemplateSafeValueContainer({
|
||||
mod: data.mod ? userToTemplateSafeUser(data.mod) : null,
|
||||
member: memberToTemplateSafeMember(data.member),
|
||||
roles: data.roles.map(r => r.name).join(", "),
|
||||
roles: data.roles.map((r) => r.name).join(", "),
|
||||
}),
|
||||
{
|
||||
userId: data.member.id,
|
||||
|
|
|
@ -21,8 +21,8 @@ export function logMemberRoleChanges(pluginData: GuildPluginData<LogsPluginType>
|
|||
createTypedTemplateSafeValueContainer({
|
||||
mod: data.mod ? userToTemplateSafeUser(data.mod) : null,
|
||||
member: memberToTemplateSafeMember(data.member),
|
||||
addedRoles: data.addedRoles.map(r => r.name).join(", "),
|
||||
removedRoles: data.removedRoles.map(r => r.name).join(", "),
|
||||
addedRoles: data.addedRoles.map((r) => r.name).join(", "),
|
||||
removedRoles: data.removedRoles.map((r) => r.name).join(", "),
|
||||
}),
|
||||
{
|
||||
userId: data.member.id,
|
||||
|
|
|
@ -19,7 +19,7 @@ export function logMemberRoleRemove(pluginData: GuildPluginData<LogsPluginType>,
|
|||
createTypedTemplateSafeValueContainer({
|
||||
mod: data.mod ? userToTemplateSafeUser(data.mod) : null,
|
||||
member: memberToTemplateSafeMember(data.member),
|
||||
roles: data.roles.map(r => r.name).join(", "),
|
||||
roles: data.roles.map((r) => r.name).join(", "),
|
||||
}),
|
||||
{
|
||||
userId: data.member.id,
|
||||
|
|
|
@ -406,10 +406,7 @@ export const LogTypeData = z.object({
|
|||
}),
|
||||
|
||||
[LogType.MEMBER_ROLE_CHANGES]: z.object({
|
||||
mod: z
|
||||
.instanceof(TemplateSafeUser)
|
||||
.or(z.instanceof(TemplateSafeUnknownUser))
|
||||
.or(z.null()),
|
||||
mod: z.instanceof(TemplateSafeUser).or(z.instanceof(TemplateSafeUnknownUser)).or(z.null()),
|
||||
member: z.instanceof(TemplateSafeMember),
|
||||
addedRoles: z.string(),
|
||||
removedRoles: z.string(),
|
||||
|
|
|
@ -60,7 +60,7 @@ export async function getLogMessage<TLogType extends keyof ILogTypeData>(
|
|||
const inputArray = Array.isArray(inputUserOrMember) ? inputUserOrMember : [inputUserOrMember];
|
||||
// TODO: Resolve IDs to users/members
|
||||
const usersOrMembers = inputArray.filter(
|
||||
v => v instanceof TemplateSafeUser || v instanceof TemplateSafeMember,
|
||||
(v) => v instanceof TemplateSafeUser || v instanceof TemplateSafeMember,
|
||||
) as Array<TemplateSafeUser | TemplateSafeMember>;
|
||||
|
||||
const mentions: string[] = [];
|
||||
|
@ -83,7 +83,7 @@ export async function getLogMessage<TLogType extends keyof ILogTypeData>(
|
|||
const memberConfig =
|
||||
(await pluginData.config.getMatchingConfig({
|
||||
level,
|
||||
memberRoles: member ? member.roles.map(r => r.id) : [],
|
||||
memberRoles: member ? member.roles.map((r) => r.id) : [],
|
||||
userId: user.id,
|
||||
})) || ({} as any);
|
||||
|
||||
|
@ -97,7 +97,7 @@ export async function getLogMessage<TLogType extends keyof ILogTypeData>(
|
|||
|
||||
return mentions.join(", ");
|
||||
},
|
||||
channelMention: channel => {
|
||||
channelMention: (channel) => {
|
||||
if (!channel) return "";
|
||||
return verboseChannelMention(channel);
|
||||
},
|
||||
|
@ -109,12 +109,12 @@ export async function getLogMessage<TLogType extends keyof ILogTypeData>(
|
|||
|
||||
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 {
|
||||
|
|
|
@ -100,14 +100,14 @@ export async function log<TLogType extends keyof ILogTypeData>(
|
|||
channelId,
|
||||
new MessageBuffer({
|
||||
timeout: batchTime,
|
||||
consume: part => {
|
||||
consume: (part) => {
|
||||
const parse: MessageMentionTypes[] = pluginData.config.get().allow_user_mentions ? ["users"] : [];
|
||||
channel
|
||||
.send({
|
||||
...part,
|
||||
allowedMentions: { parse },
|
||||
})
|
||||
.catch(err => {
|
||||
.catch((err) => {
|
||||
// tslint:disable-next-line:no-console
|
||||
console.warn(
|
||||
`Error while sending ${typeStr} log to ${pluginData.guild.id}/${channelId}: ${err.message}`,
|
||||
|
|
|
@ -17,7 +17,7 @@ export async function onMessageDeleteBulk(pluginData: GuildPluginData<LogsPlugin
|
|||
| ThreadChannel;
|
||||
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}\``)));
|
||||
const authorIds = Array.from(new Set(savedMessages.map((item) => `\`${item.user_id}\``)));
|
||||
|
||||
logMessageDeleteBulk(pluginData, {
|
||||
count: savedMessages.length,
|
||||
|
|
|
@ -17,12 +17,12 @@ export async function onMessageUpdate(
|
|||
let logUpdate = false;
|
||||
|
||||
const oldEmbedsToCompare = ((oldSavedMessage.data.embeds || []) as MessageEmbed[])
|
||||
.map(e => cloneDeep(e))
|
||||
.filter(e => (e as MessageEmbed).type === "rich");
|
||||
.map((e) => cloneDeep(e))
|
||||
.filter((e) => (e as MessageEmbed).type === "rich");
|
||||
|
||||
const newEmbedsToCompare = ((savedMessage.data.embeds || []) as MessageEmbed[])
|
||||
.map(e => cloneDeep(e))
|
||||
.filter(e => (e as MessageEmbed).type === "rich");
|
||||
.map((e) => cloneDeep(e))
|
||||
.filter((e) => (e as MessageEmbed).type === "rich");
|
||||
|
||||
for (const embed of [...oldEmbedsToCompare, ...newEmbedsToCompare]) {
|
||||
if (embed.thumbnail) {
|
||||
|
|
|
@ -52,7 +52,11 @@ export const MessageCreateEvt = messageSaverEvt({
|
|||
console.warn(`Tried to save duplicate message from messageCreate event: ${context} / saved at: ${timestamp}`);
|
||||
return;
|
||||
}
|
||||
recentlyCreatedMessages.set(meta.args.message.id, [meta.pluginData.state.debugId, Date.now(), meta.pluginData.guild.id]);
|
||||
recentlyCreatedMessages.set(meta.args.message.id, [
|
||||
meta.pluginData.state.debugId,
|
||||
Date.now(),
|
||||
meta.pluginData.guild.id,
|
||||
]);
|
||||
|
||||
await meta.pluginData.state.savedMessages.createFromMsg(meta.args.message);
|
||||
},
|
||||
|
@ -97,7 +101,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);
|
||||
},
|
||||
});
|
||||
|
|
|
@ -46,9 +46,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;
|
||||
|
|
|
@ -53,13 +53,13 @@ export const CasesUserCmd = modActionsCmd({
|
|||
|
||||
if (typesToShow.length > 0) {
|
||||
// Reversed: Hide specified types
|
||||
if (args.reverseFilters) cases = cases.filter(c => !typesToShow.includes(c.type));
|
||||
if (args.reverseFilters) cases = cases.filter((c) => !typesToShow.includes(c.type));
|
||||
// Normal: Show only specified types
|
||||
else cases = cases.filter(c => typesToShow.includes(c.type));
|
||||
else cases = cases.filter((c) => typesToShow.includes(c.type));
|
||||
}
|
||||
|
||||
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 ? cases[cases.length - 1].user_name : user.tag;
|
||||
|
||||
|
@ -83,7 +83,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;
|
||||
|
|
|
@ -42,7 +42,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);
|
||||
|
@ -91,19 +91,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;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -53,7 +53,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 { MessageAttachment } from "discord.js";
|
||||
|
||||
export function formatReasonWithAttachments(reason: string, attachments: MessageAttachment[]) {
|
||||
const attachmentUrls = attachments.map(a => a.url);
|
||||
const attachmentUrls = attachments.map((a) => a.url);
|
||||
return ((reason || "") + " " + attachmentUrls.join(" ")).trim();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ export const ClearBannedMutesCmd = mutesCmd({
|
|||
const activeMutes = await pluginData.state.mutes.getActiveMutes();
|
||||
|
||||
const bans = await pluginData.guild.bans.fetch({ cache: true });
|
||||
const bannedIds = bans.map(b => b.user.id);
|
||||
const bannedIds = bans.map((b) => b.user.id);
|
||||
|
||||
await msg.channel.send(`Found ${activeMutes.length} mutes and ${bannedIds.length} bans, cross-referencing...`);
|
||||
|
||||
|
|
|
@ -53,12 +53,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: GuildMember[] = [];
|
||||
const muteRole = pluginData.config.get().mute_role;
|
||||
|
||||
if (muteRole) {
|
||||
pluginData.guild.members.cache.forEach(member => {
|
||||
pluginData.guild.members.cache.forEach((member) => {
|
||||
if (muteUserIds.has(member.id)) return;
|
||||
if (member.roles.cache.has(muteRole as Snowflake)) manuallyMutedMembers.push(member);
|
||||
});
|
||||
|
@ -66,7 +66,7 @@ export const MutesCmd = mutesCmd({
|
|||
|
||||
totalMutes = manuallyMutedMembers.length;
|
||||
|
||||
lines = manuallyMutedMembers.map(member => {
|
||||
lines = manuallyMutedMembers.map((member) => {
|
||||
return `<@!${member.id}> (**${member.user.tag}**, \`${member.id}\`) 🔧 Manual mute`;
|
||||
});
|
||||
} else {
|
||||
|
@ -76,11 +76,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;
|
||||
}
|
||||
|
||||
|
@ -93,7 +90,7 @@ export const MutesCmd = mutesCmd({
|
|||
if (!member) {
|
||||
if (!bannedIds) {
|
||||
const bans = await pluginData.guild.bans.fetch({ cache: true });
|
||||
bannedIds = bans.map(u => u.user.id);
|
||||
bannedIds = bans.map((u) => u.user.id);
|
||||
}
|
||||
|
||||
muteWithDetails.banned = bannedIds.includes(mute.user_id);
|
||||
|
@ -106,18 +103,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.resolve(mute.user_id as Snowflake);
|
||||
const username = user ? user.tag : "Unknown#0000";
|
||||
const theCase = muteCasesById.get(mute.case_id);
|
||||
|
@ -152,7 +149,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;
|
||||
|
||||
|
@ -197,19 +194,9 @@ export const MutesCmd = mutesCmd({
|
|||
const idMod = `${listMessage.id}:muteList`;
|
||||
const buttons: MessageButton[] = [];
|
||||
|
||||
buttons.push(
|
||||
new MessageButton()
|
||||
.setStyle("SECONDARY")
|
||||
.setEmoji("⬅")
|
||||
.setCustomId(`previousButton:${idMod}`),
|
||||
);
|
||||
buttons.push(new MessageButton().setStyle("SECONDARY").setEmoji("⬅").setCustomId(`previousButton:${idMod}`));
|
||||
|
||||
buttons.push(
|
||||
new MessageButton()
|
||||
.setStyle("SECONDARY")
|
||||
.setEmoji("➡")
|
||||
.setCustomId(`nextButton:${idMod}`),
|
||||
);
|
||||
buttons.push(new MessageButton().setStyle("SECONDARY").setEmoji("➡").setCustomId(`nextButton:${idMod}`));
|
||||
|
||||
const row = new MessageActionRow().addComponents(buttons);
|
||||
await listMessage.edit({ components: [row] });
|
||||
|
|
|
@ -22,7 +22,7 @@ export async function clearExpiredMutes(pluginData: GuildPluginData<MutesPluginT
|
|||
}
|
||||
if (mute.roles_to_restore) {
|
||||
const guildRoles = pluginData.guild.roles.cache;
|
||||
const newRoles = [...member.roles.cache.keys()].filter(roleId => roleId !== muteRole);
|
||||
const newRoles = [...member.roles.cache.keys()].filter((roleId) => roleId !== muteRole);
|
||||
for (const toRestore of mute.roles_to_restore) {
|
||||
if (guildRoles.has(toRestore) && toRestore !== muteRole && !newRoles.includes(toRestore)) {
|
||||
newRoles.push(toRestore);
|
||||
|
|
|
@ -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.cache.filter(x => x.managed).map(y => y.id);
|
||||
newRoles = currentUserRoles.filter(r => !managedRoles.includes(r));
|
||||
const managedRoles = pluginData.guild.roles.cache.filter((x) => x.managed).map((y) => y.id);
|
||||
newRoles = currentUserRoles.filter((r) => !managedRoles.includes(r));
|
||||
await member.roles.set(newRoles as Snowflake[]);
|
||||
}
|
||||
} else {
|
||||
newRoles = currentUserRoles.filter(x => !(<string[]>removeRoles).includes(x));
|
||||
newRoles = currentUserRoles.filter((x) => !(<string[]>removeRoles).includes(x));
|
||||
await member.roles.set(newRoles as Snowflake[]);
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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.cache.filter(x => zep!.roles.cache.has(x.id));
|
||||
const zepRoles = pluginData.guild.roles.cache.filter((x) => zep!.roles.cache.has(x.id));
|
||||
// If we have roles and one of them is above the muted role, throw generic error
|
||||
if (zepRoles.size >= 0 && zepRoles.some(zepRole => zepRole.position > actualMuteRole.position)) {
|
||||
if (zepRoles.size >= 0 && zepRoles.some((zepRole) => zepRole.position > actualMuteRole.position)) {
|
||||
lock.unlock();
|
||||
logs.logBotAlert({
|
||||
body: `Cannot mute user ${member.id}: ${e}`,
|
||||
|
|
|
@ -43,7 +43,7 @@ export async function unmuteUser(
|
|||
}
|
||||
if (existingMute?.roles_to_restore) {
|
||||
const guildRoles = pluginData.guild.roles.cache;
|
||||
const newRoles = [...member.roles.cache.keys()].filter(roleId => roleId !== muteRole);
|
||||
const newRoles = [...member.roles.cache.keys()].filter((roleId) => roleId !== muteRole);
|
||||
for (const toRestore of existingMute.roles_to_restore) {
|
||||
if (guildRoles.has(toRestore) && toRestore !== muteRole && !newRoles.includes(toRestore)) {
|
||||
newRoles.push(toRestore);
|
||||
|
|
|
@ -26,9 +26,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 = await pluginData.client.users.fetch(args.userId as Snowflake).catch(() => null);
|
||||
const currentUsername = user ? user.tag : args.userId;
|
||||
|
|
|
@ -21,7 +21,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.embeds?.[0]?.description || p.content.embeds?.[0]?.title || "";
|
||||
|
||||
const isTruncated = previewText.length > SCHEDULED_POST_PREVIEW_TEXT_LENGTH;
|
||||
|
|
|
@ -147,18 +147,10 @@ export async function actualPostCmd(
|
|||
channel_id: targetChannel.id,
|
||||
content,
|
||||
attachments: [...msg.attachments.values()],
|
||||
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,
|
||||
});
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ const defaultOptions: PluginOptions<ReactionRolesPluginType> = {
|
|||
|
||||
const MAXIMUM_COMPONENT_ROWS = 5;
|
||||
|
||||
const configPreprocessor: ConfigPreprocessorFn<ReactionRolesPluginType> = options => {
|
||||
const configPreprocessor: ConfigPreprocessorFn<ReactionRolesPluginType> = (options) => {
|
||||
if (options.config.button_groups) {
|
||||
for (const [groupName, group] of Object.entries(options.config.button_groups)) {
|
||||
const defaultButtonNames = Object.keys(group.default_buttons);
|
||||
|
|
|
@ -58,17 +58,15 @@ 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(
|
||||
(pair): TReactionRolePair => {
|
||||
const customEmojiMatch = pair[0].match(/^<a?:(.*?):(\d+)>$/);
|
||||
if (customEmojiMatch) {
|
||||
return [customEmojiMatch[2], pair[1], customEmojiMatch[1]];
|
||||
} else {
|
||||
return pair as TReactionRolePair;
|
||||
}
|
||||
},
|
||||
);
|
||||
.map((v) => v.split(/[\s=,]+/).map((v) => v.trim())) // tslint:disable-line
|
||||
.map((pair): TReactionRolePair => {
|
||||
const customEmojiMatch = pair[0].match(/^<a?:(.*?):(\d+)>$/);
|
||||
if (customEmojiMatch) {
|
||||
return [customEmojiMatch[2], pair[1], customEmojiMatch[1]];
|
||||
} else {
|
||||
return pair as TReactionRolePair;
|
||||
}
|
||||
});
|
||||
|
||||
// Verify the specified emojis and roles are valid and usable
|
||||
for (const pair of emojiRolePairs) {
|
||||
|
|
|
@ -31,9 +31,7 @@ export const PostButtonRolesCmd = reactionRolesCmd({
|
|||
const buttons: MessageButton[] = [];
|
||||
const toInsert: Array<{ customId; buttonGroup; buttonName }> = [];
|
||||
for (const [buttonName, button] of Object.entries(group.default_buttons)) {
|
||||
const customId = createHash("md5")
|
||||
.update(`${buttonName}${moment.utc().valueOf()}`)
|
||||
.digest("hex");
|
||||
const customId = createHash("md5").update(`${buttonName}${moment.utc().valueOf()}`).digest("hex");
|
||||
|
||||
const btn = new MessageButton()
|
||||
.setLabel(button.label ?? "")
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -65,7 +65,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"),
|
||||
);
|
||||
|
|
|
@ -60,7 +60,7 @@ export const MassAddRoleCmd = rolesCmd({
|
|||
return;
|
||||
}
|
||||
|
||||
const membersWithoutTheRole = members.filter(m => !m.roles.cache.has(roleId));
|
||||
const membersWithoutTheRole = members.filter((m) => !m.roles.cache.has(roleId));
|
||||
let assigned = 0;
|
||||
const failed: string[] = [];
|
||||
const alreadyHadRole = members.length - membersWithoutTheRole.length;
|
||||
|
|
|
@ -60,7 +60,7 @@ export const MassRemoveRoleCmd = rolesCmd({
|
|||
return;
|
||||
}
|
||||
|
||||
const membersWithTheRole = members.filter(m => m.roles.cache.has(roleId));
|
||||
const membersWithTheRole = members.filter((m) => m.roles.cache.has(roleId));
|
||||
let assigned = 0;
|
||||
const failed: string[] = [];
|
||||
const didNotHaveRole = members.length - membersWithTheRole.length;
|
||||
|
|
|
@ -70,7 +70,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
|
||||
|
@ -79,7 +79,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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,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.cache.get(id as Snowflake)!)
|
||||
.map((id) => pluginData.guild.roles.cache.get(id as Snowflake)!)
|
||||
.filter(Boolean)
|
||||
.reduce((map, role) => {
|
||||
map.set(role.id, role);
|
||||
|
@ -94,7 +94,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[] = [];
|
||||
|
@ -104,11 +104,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 ");
|
||||
|
|
|
@ -29,20 +29,20 @@ export const RoleRemoveCmd = selfGrantableRolesCmd({
|
|||
const matchedRoleIds = findMatchingRoles(roleNames, applyingEntries);
|
||||
|
||||
const rolesToRemove = Array.from(matchedRoleIds.values()).map(
|
||||
id => pluginData.guild.roles.cache.get(id as Snowflake)!,
|
||||
(id) => pluginData.guild.roles.cache.get(id as Snowflake)!,
|
||||
);
|
||||
const roleIdsToRemove = rolesToRemove.map(r => r.id);
|
||||
const roleIdsToRemove = rolesToRemove.map((r) => r.id);
|
||||
|
||||
// Remove the roles
|
||||
if (rolesToRemove.length) {
|
||||
const newRoleIds = msg.member.roles.cache.filter(role => !roleIdsToRemove.includes(role.id));
|
||||
const newRoleIds = msg.member.roles.cache.filter((role) => !roleIdsToRemove.includes(role.id));
|
||||
|
||||
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 async 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);
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ export const SlowmodePlugin = zeppelinGuildPlugin<SlowmodePluginType>()({
|
|||
state.serverLogs = new GuildLogs(pluginData.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";
|
||||
|
|
|
@ -82,7 +82,7 @@ export const SpamPlugin = zeppelinGuildPlugin<SpamPluginType>()({
|
|||
const { state } = pluginData;
|
||||
|
||||
state.expiryInterval = setInterval(() => clearOldRecentActions(pluginData), 1000 * 60);
|
||||
state.onMessageCreateFn = msg => onMessageCreate(pluginData, msg);
|
||||
state.onMessageCreateFn = (msg) => onMessageCreate(pluginData, msg);
|
||||
state.savedMessages.events.on("create", state.onMessageCreateFn);
|
||||
},
|
||||
|
||||
|
|
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