Start move to configAccessibleObjects, exclude perm overrides from logs

configAccessibleObjects are used to guarantee backwards compatibility and consistency.
Perm overrides from our own plugins are ignored as to not spam logs through bot managed slowmode or companion channels
This commit is contained in:
Dark 2021-07-06 05:23:47 +02:00
parent dda19de6e6
commit d2dd103175
No known key found for this signature in database
GPG key ID: 384C4B4F5B1E25A8
28 changed files with 259 additions and 75 deletions

View file

@ -14,7 +14,7 @@
"cors": "^2.8.5",
"cross-env": "^5.2.0",
"deep-diff": "^1.0.2",
"discord.js": "^13.0.0-dev.a7c6678.1625427504",
"discord.js": "^13.0.0-dev.2e078e4.1625529824",
"dotenv": "^4.0.0",
"emoji-regex": "^8.0.0",
"erlpack": "github:discord/erlpack",
@ -82,7 +82,7 @@
"license": "MIT",
"dependencies": {
"discord-api-types": "^0.18.1",
"discord.js": "^13.0.0-dev.a7c6678.1625427504",
"discord.js": "^13.0.0-dev.2e078e4.1625529824",
"knub-command-manager": "^9.1.0",
"ts-essentials": "^6.0.7"
},
@ -2159,9 +2159,9 @@
}
},
"node_modules/discord.js": {
"version": "13.0.0-dev.a7c6678.1625427504",
"resolved": "https://registry.npmjs.org/discord.js/-/discord.js-13.0.0-dev.a7c6678.1625427504.tgz",
"integrity": "sha512-S4ntnGVUCRyyOtz8YvoWNpSZyZEFwXTkTjXbU0shveD/QVT+0cBCcMX6vp0zPt3lCkMUgdW+crrOfEYKMGwKoQ==",
"version": "13.0.0-dev.2e078e4.1625529824",
"resolved": "https://registry.npmjs.org/discord.js/-/discord.js-13.0.0-dev.2e078e4.1625529824.tgz",
"integrity": "sha512-NKNnoEmh3+4eCG44BOIBjlJS0bKQEH8OgWoEjdJ9K53MYa5lfqbSho4NKXe5+hVpMr+U43wJ8ByUvw96ogqu8w==",
"dependencies": {
"@discordjs/builders": "^0.2.0",
"@discordjs/collection": "^0.1.6",
@ -8034,9 +8034,9 @@
"integrity": "sha512-hNC38R9ZF4uaujaZQtQfm5CdQO58uhdkoHQAVvMfIL0LgOSZeW575W8H6upngQOuoxWd8tiRII3LLJm9zuQKYg=="
},
"discord.js": {
"version": "13.0.0-dev.a7c6678.1625427504",
"resolved": "https://registry.npmjs.org/discord.js/-/discord.js-13.0.0-dev.a7c6678.1625427504.tgz",
"integrity": "sha512-S4ntnGVUCRyyOtz8YvoWNpSZyZEFwXTkTjXbU0shveD/QVT+0cBCcMX6vp0zPt3lCkMUgdW+crrOfEYKMGwKoQ==",
"version": "13.0.0-dev.2e078e4.1625529824",
"resolved": "https://registry.npmjs.org/discord.js/-/discord.js-13.0.0-dev.2e078e4.1625529824.tgz",
"integrity": "sha512-NKNnoEmh3+4eCG44BOIBjlJS0bKQEH8OgWoEjdJ9K53MYa5lfqbSho4NKXe5+hVpMr+U43wJ8ByUvw96ogqu8w==",
"requires": {
"@discordjs/builders": "^0.2.0",
"@discordjs/collection": "^0.1.6",
@ -8878,7 +8878,7 @@
"@typescript-eslint/parser": "^4.23.0",
"chai": "^4.3.4",
"discord-api-types": "^0.18.1",
"discord.js": "^13.0.0-dev.a7c6678.1625427504",
"discord.js": "^13.0.0-dev.2e078e4.1625529824",
"eslint": "^7.2.0",
"husky": "^4.3.8",
"knub-command-manager": "^9.1.0",

View file

@ -29,7 +29,7 @@
"cors": "^2.8.5",
"cross-env": "^5.2.0",
"deep-diff": "^1.0.2",
"discord.js": "^13.0.0-dev.a7c6678.1625427504",
"discord.js": "^13.0.0-dev.2e078e4.1625529824",
"dotenv": "^4.0.0",
"emoji-regex": "^8.0.0",
"erlpack": "github:discord/erlpack",

View file

@ -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}`;
}
}

View file

@ -52,7 +52,7 @@ export async function* matchMultipleTextTypesOnMessage(
yield ["nickname", member.nickname];
}
for (const activity of member.presence.activities) {
for (const activity of member.presence?.activities ?? []) {
if (activity.type === Constants.ActivityTypes[4]) {
yield ["customstatus", `${activity.emoji} ${activity.name}`];
break;

View file

@ -1,4 +1,5 @@
import { CooldownManager } from "knub";
import { GuildLogs } from "../../../data/GuildLogs";
import { trimPluginDescription } from "../../utils";
import { LogsPlugin } from "../Logs/LogsPlugin";
import { zeppelinGuildPlugin } from "../ZeppelinPluginBlueprint";
@ -32,4 +33,8 @@ export const CompanionChannelsPlugin = zeppelinGuildPlugin<CompanionChannelsPlug
beforeLoad(pluginData) {
pluginData.state.errorCooldownManager = new CooldownManager();
},
afterLoad(pluginData) {
pluginData.state.serverLogs = new GuildLogs(pluginData.guild.id);
},
});

View file

@ -53,6 +53,7 @@ export async function handleCompanionPermissions(
for (const channelId of permsToDelete) {
const channel = pluginData.guild.channels.cache.get(channelId as Snowflake);
if (!channel || !(channel instanceof TextChannel)) continue;
pluginData.state.serverLogs.ignoreLog(LogType.CHANNEL_UPDATE, channelId, 3 * 1000);
await channel.permissionOverwrites
.resolve(userId as Snowflake)
?.delete(`Companion Channel for ${oldChannel!.id} | User Left`);
@ -61,6 +62,7 @@ export async function handleCompanionPermissions(
for (const [channelId, permissions] of permsToSet) {
const channel = pluginData.guild.channels.cache.get(channelId as Snowflake);
if (!channel || !(channel instanceof TextChannel)) continue;
pluginData.state.serverLogs.ignoreLog(LogType.CHANNEL_UPDATE, channelId, 3 * 1000);
await channel.permissionOverwrites.create(userId as Snowflake, new Permissions(BigInt(permissions)).serialize(), {
reason: `Companion Channel for ${voiceChannel!.id} | User Joined`,
});

View file

@ -1,5 +1,6 @@
import * as t from "io-ts";
import { BasePluginType, CooldownManager, typedGuildEventListener } from "knub";
import { GuildLogs } from "../../data/GuildLogs";
import { tNullable } from "../../utils";
// Permissions using these numbers: https://abal.moe/Eris/docs/reference (add all allowed/denied ones up)
@ -24,6 +25,7 @@ export interface CompanionChannelsPluginType extends BasePluginType {
config: TConfigSchema;
state: {
errorCooldownManager: CooldownManager;
serverLogs: GuildLogs;
};
}

View file

@ -1,5 +1,6 @@
import { channelToConfigAccessibleChannel } from "../../../utils/configAccessibleObjects";
import { LogType } from "../../../data/LogType";
import { differenceToString, getScalarDifference, stripObjectToScalars } from "../../../utils";
import { differenceToString, getScalarDifference } from "../../../utils";
import { logsEvt } from "../types";
export const LogsChannelCreateEvt = logsEvt({
@ -7,7 +8,7 @@ export const LogsChannelCreateEvt = logsEvt({
async listener(meta) {
meta.pluginData.state.guildLogs.log(LogType.CHANNEL_CREATE, {
channel: stripObjectToScalars(meta.args.channel),
channel: channelToConfigAccessibleChannel(meta.args.channel),
});
},
});
@ -17,7 +18,7 @@ export const LogsChannelDeleteEvt = logsEvt({
async listener(meta) {
meta.pluginData.state.guildLogs.log(LogType.CHANNEL_DELETE, {
channel: stripObjectToScalars(meta.args.channel),
channel: channelToConfigAccessibleChannel(meta.args.channel),
});
},
});
@ -29,10 +30,14 @@ export const LogsChannelUpdateEvt = logsEvt({
const diff = getScalarDifference(meta.args.oldChannel, meta.args.newChannel);
const differenceString = differenceToString(diff);
meta.pluginData.state.guildLogs.log(LogType.CHANNEL_UPDATE, {
oldChannel: stripObjectToScalars(meta.args.oldChannel),
newChannel: stripObjectToScalars(meta.args.newChannel),
differenceString,
});
meta.pluginData.state.guildLogs.log(
LogType.CHANNEL_UPDATE,
{
oldChannel: channelToConfigAccessibleChannel(meta.args.oldChannel),
newChannel: channelToConfigAccessibleChannel(meta.args.newChannel),
differenceString,
},
meta.args.newChannel.id,
);
},
});

View file

@ -1,6 +1,6 @@
import { GuildAuditLogs } from "discord.js";
import { userToConfigAccessibleUser } from "../../../utils/configAccessibleObjects";
import { LogType } from "../../../data/LogType";
import { stripObjectToScalars, UnknownUser } from "../../../utils";
import { safeFindRelevantAuditLogEntry } from "../../../utils/safeFindRelevantAuditLogEntry";
import { logsEvt } from "../types";
@ -16,13 +16,13 @@ export const LogsGuildBanAddEvt = logsEvt({
GuildAuditLogs.Actions.MEMBER_BAN_ADD as number,
user.id,
);
const mod = relevantAuditLogEntry ? relevantAuditLogEntry.executor : new UnknownUser();
const mod = relevantAuditLogEntry ? relevantAuditLogEntry.executor : null;
pluginData.state.guildLogs.log(
LogType.MEMBER_BAN,
{
mod: stripObjectToScalars(mod),
user: stripObjectToScalars(user),
mod: mod ? userToConfigAccessibleUser(mod) : {},
user: userToConfigAccessibleUser(user),
},
user.id,
);
@ -41,12 +41,12 @@ export const LogsGuildBanRemoveEvt = logsEvt({
GuildAuditLogs.Actions.MEMBER_BAN_REMOVE as number,
user.id,
);
const mod = relevantAuditLogEntry ? relevantAuditLogEntry.executor : new UnknownUser();
const mod = relevantAuditLogEntry ? relevantAuditLogEntry.executor : null;
pluginData.state.guildLogs.log(
LogType.MEMBER_UNBAN,
{
mod: stripObjectToScalars(mod),
mod: mod ? userToConfigAccessibleUser(mod) : {},
userId: user.id,
},
user.id,

View file

@ -1,5 +1,6 @@
import humanizeDuration from "humanize-duration";
import moment from "moment-timezone";
import { memberToConfigAccessibleMember } from "../../../utils/configAccessibleObjects";
import { LogType } from "../../../data/LogType";
import { stripObjectToScalars } from "../../../utils";
import { CasesPlugin } from "../../Cases/CasesPlugin";
@ -46,7 +47,7 @@ export const LogsGuildMemberAddEvt = logsEvt({
}
pluginData.state.guildLogs.log(LogType.MEMBER_JOIN_WITH_PRIOR_RECORDS, {
member: stripObjectToScalars(member, ["user", "roles"]),
member: memberToConfigAccessibleMember(member),
recentCaseSummary,
});
}

View file

@ -1,5 +1,5 @@
import { memberToConfigAccessibleMember } from "../../../utils/configAccessibleObjects";
import { LogType } from "../../../data/LogType";
import { stripObjectToScalars } from "../../../utils";
import { logsEvt } from "../types";
export const LogsGuildMemberRemoveEvt = logsEvt({
@ -7,7 +7,7 @@ export const LogsGuildMemberRemoveEvt = logsEvt({
async listener(meta) {
meta.pluginData.state.guildLogs.log(LogType.MEMBER_LEAVE, {
member: stripObjectToScalars(meta.args.member, ["user", "roles"]),
member: memberToConfigAccessibleMember(meta.args.member),
});
},
});

View file

@ -1,5 +1,6 @@
import { roleToConfigAccessibleRole } from "../../../utils/configAccessibleObjects";
import { LogType } from "../../../data/LogType";
import { differenceToString, getScalarDifference, stripObjectToScalars } from "../../../utils";
import { differenceToString, getScalarDifference } from "../../../utils";
import { logsEvt } from "../types";
export const LogsRoleCreateEvt = logsEvt({
@ -7,7 +8,7 @@ export const LogsRoleCreateEvt = logsEvt({
async listener(meta) {
meta.pluginData.state.guildLogs.log(LogType.ROLE_CREATE, {
role: stripObjectToScalars(meta.args.role),
role: roleToConfigAccessibleRole(meta.args.role),
});
},
});
@ -17,7 +18,7 @@ export const LogsRoleDeleteEvt = logsEvt({
async listener(meta) {
meta.pluginData.state.guildLogs.log(LogType.ROLE_DELETE, {
role: stripObjectToScalars(meta.args.role),
role: roleToConfigAccessibleRole(meta.args.role),
});
},
});
@ -30,8 +31,8 @@ export const LogsRoleUpdateEvt = logsEvt({
const differenceString = differenceToString(diff);
meta.pluginData.state.guildLogs.log(LogType.ROLE_UPDATE, {
newRole: stripObjectToScalars(meta.args.newRole),
oldRole: stripObjectToScalars(meta.args.oldRole),
newRole: roleToConfigAccessibleRole(meta.args.newRole),
oldRole: roleToConfigAccessibleRole(meta.args.oldRole),
differenceString,
});
},

View file

@ -1,3 +1,4 @@
import { channelToConfigAccessibleChannel, stageToConfigAccessibleStage } from "../../../utils/configAccessibleObjects";
import { LogType } from "../../../data/LogType";
import { differenceToString, getScalarDifference, stripObjectToScalars } from "../../../utils";
import { logsEvt } from "../types";
@ -8,10 +9,11 @@ export const LogsStageInstanceCreateEvt = logsEvt({
async listener(meta) {
const stageChannel =
meta.args.stageInstance.channel ??
(await meta.pluginData.guild.channels.fetch(meta.args.stageInstance.channelId));
(await meta.pluginData.guild.channels.fetch(meta.args.stageInstance.channelId))!;
meta.pluginData.state.guildLogs.log(LogType.STAGE_INSTANCE_CREATE, {
stageInstance: stripObjectToScalars(meta.args.stageInstance),
stageChannel: stripObjectToScalars(stageChannel),
stageInstance: stageToConfigAccessibleStage(meta.args.stageInstance),
stageChannel: channelToConfigAccessibleChannel(stageChannel),
});
},
});
@ -22,10 +24,11 @@ export const LogsStageInstanceDeleteEvt = logsEvt({
async listener(meta) {
const stageChannel =
meta.args.stageInstance.channel ??
(await meta.pluginData.guild.channels.fetch(meta.args.stageInstance.channelId));
(await meta.pluginData.guild.channels.fetch(meta.args.stageInstance.channelId))!;
meta.pluginData.state.guildLogs.log(LogType.STAGE_INSTANCE_DELETE, {
stageInstance: stripObjectToScalars(meta.args.stageInstance),
stageChannel: stripObjectToScalars(stageChannel),
stageInstance: stageToConfigAccessibleStage(meta.args.stageInstance),
stageChannel: channelToConfigAccessibleChannel(stageChannel),
});
},
});
@ -36,15 +39,15 @@ export const LogsStageInstanceUpdateEvt = logsEvt({
async listener(meta) {
const stageChannel =
meta.args.newStageInstance.channel ??
(await meta.pluginData.guild.channels.fetch(meta.args.newStageInstance.channelId));
(await meta.pluginData.guild.channels.fetch(meta.args.newStageInstance.channelId))!;
const diff = getScalarDifference(meta.args.oldStageInstance, meta.args.newStageInstance);
const differenceString = differenceToString(diff);
meta.pluginData.state.guildLogs.log(LogType.STAGE_INSTANCE_UPDATE, {
oldStageInstance: stripObjectToScalars(meta.args.oldStageInstance),
newStageInstance: stripObjectToScalars(meta.args.newStageInstance),
stageChannel: stripObjectToScalars(stageChannel),
oldStageInstance: stageToConfigAccessibleStage(meta.args.oldStageInstance),
newStageInstance: stageToConfigAccessibleStage(meta.args.newStageInstance),
stageChannel: channelToConfigAccessibleChannel(stageChannel),
differenceString,
});
},

View file

@ -1,3 +1,4 @@
import { channelToConfigAccessibleChannel } from "../../../utils/configAccessibleObjects";
import { LogType } from "../../../data/LogType";
import { stripObjectToScalars, getScalarDifference, differenceToString } from "../../../utils";
import { logsEvt } from "../types";
@ -7,7 +8,7 @@ export const LogsThreadCreateEvt = logsEvt({
async listener(meta) {
meta.pluginData.state.guildLogs.log(LogType.THREAD_CREATE, {
thread: stripObjectToScalars(meta.args.thread),
thread: channelToConfigAccessibleChannel(meta.args.thread),
});
},
});
@ -17,7 +18,7 @@ export const LogsThreadDeleteEvt = logsEvt({
async listener(meta) {
meta.pluginData.state.guildLogs.log(LogType.THREAD_DELETE, {
thread: stripObjectToScalars(meta.args.thread),
thread: channelToConfigAccessibleChannel(meta.args.thread),
});
},
});
@ -29,10 +30,14 @@ export const LogsThreadUpdateEvt = logsEvt({
const diff = getScalarDifference(meta.args.oldThread, meta.args.newThread, ["messageCount", "archiveTimestamp"]);
const differenceString = differenceToString(diff);
meta.pluginData.state.guildLogs.log(LogType.THREAD_UPDATE, {
oldThread: stripObjectToScalars(meta.args.oldThread),
newThread: stripObjectToScalars(meta.args.newThread),
differenceString,
});
meta.pluginData.state.guildLogs.log(
LogType.THREAD_UPDATE,
{
oldThread: channelToConfigAccessibleChannel(meta.args.oldThread),
newThread: channelToConfigAccessibleChannel(meta.args.newThread),
differenceString,
},
meta.args.newThread.id,
);
},
});

View file

@ -1,8 +1,8 @@
import { GuildAuditLogs } from "discord.js";
import diff from "lodash.difference";
import isEqual from "lodash.isequal";
import { memberToConfigAccessibleMember, userToConfigAccessibleUser } from "src/utils/configAccessibleObjects";
import { LogType } from "../../../data/LogType";
import { stripObjectToScalars, UnknownUser } from "../../../utils";
import { safeFindRelevantAuditLogEntry } from "../../../utils/safeFindRelevantAuditLogEntry";
import { logsEvt } from "../types";
@ -16,7 +16,7 @@ export const LogsGuildMemberUpdateEvt = logsEvt({
if (!oldMember) return;
const logMember = stripObjectToScalars(member, ["user", "roles"]);
const logMember = memberToConfigAccessibleMember(member);
if (member.nickname !== oldMember.nickname) {
pluginData.state.guildLogs.log(LogType.MEMBER_NICK_CHANGE, {
@ -52,7 +52,7 @@ export const LogsGuildMemberUpdateEvt = logsEvt({
GuildAuditLogs.Actions.MEMBER_ROLE_UPDATE as number,
member.id,
);
const mod = relevantAuditLogEntry ? relevantAuditLogEntry.executor : new UnknownUser();
const mod = relevantAuditLogEntry ? relevantAuditLogEntry.executor : null;
if (addedRoles.length && removedRoles.length) {
// Roles added *and* removed
@ -68,7 +68,7 @@ export const LogsGuildMemberUpdateEvt = logsEvt({
.map(roleId => pluginData.guild.roles.cache.get(roleId) || { id: roleId, name: `Unknown (${roleId})` })
.map(r => r.name)
.join(", "),
mod: stripObjectToScalars(mod),
mod: mod ? userToConfigAccessibleUser(mod) : {},
},
member.id,
);
@ -82,7 +82,7 @@ export const LogsGuildMemberUpdateEvt = logsEvt({
.map(roleId => pluginData.guild.roles.cache.get(roleId) || { id: roleId, name: `Unknown (${roleId})` })
.map(r => r.name)
.join(", "),
mod: stripObjectToScalars(mod),
mod: mod ? userToConfigAccessibleUser(mod) : {},
},
member.id,
);
@ -96,7 +96,7 @@ export const LogsGuildMemberUpdateEvt = logsEvt({
.map(roleId => pluginData.guild.roles.cache.get(roleId) || { id: roleId, name: `Unknown (${roleId})` })
.map(r => r.name)
.join(", "),
mod: stripObjectToScalars(mod),
mod: mod ? userToConfigAccessibleUser(mod) : {},
},
member.id,
);

View file

@ -1,3 +1,4 @@
import { channelToConfigAccessibleChannel, memberToConfigAccessibleMember } from "src/utils/configAccessibleObjects";
import { LogType } from "../../../data/LogType";
import { stripObjectToScalars } from "../../../utils";
import { logsEvt } from "../types";
@ -10,25 +11,23 @@ export const LogsVoiceStateUpdateEvt = logsEvt({
const newChannel = meta.args.newState.channel;
const member = meta.args.newState.member ?? meta.args.oldState.member!;
if (!newChannel) {
if (!newChannel && oldChannel) {
// Leave evt
meta.pluginData.state.guildLogs.log(LogType.VOICE_CHANNEL_LEAVE, {
member: stripObjectToScalars(member, ["user", "roles"]),
oldChannel: stripObjectToScalars(oldChannel),
newChannel: stripObjectToScalars(newChannel),
member: memberToConfigAccessibleMember(member),
oldChannel: channelToConfigAccessibleChannel(oldChannel!),
});
} else if (!oldChannel) {
} else if (!oldChannel && newChannel) {
// Join Evt
meta.pluginData.state.guildLogs.log(LogType.VOICE_CHANNEL_JOIN, {
member: stripObjectToScalars(member, ["user", "roles"]),
oldChannel: stripObjectToScalars(oldChannel),
newChannel: stripObjectToScalars(newChannel),
member: memberToConfigAccessibleMember(member),
newChannel: channelToConfigAccessibleChannel(newChannel),
});
} else {
meta.pluginData.state.guildLogs.log(LogType.VOICE_CHANNEL_MOVE, {
member: stripObjectToScalars(member, ["user", "roles"]),
oldChannel: stripObjectToScalars(oldChannel),
newChannel: stripObjectToScalars(newChannel),
member: memberToConfigAccessibleMember(member),
oldChannel: channelToConfigAccessibleChannel(oldChannel!),
newChannel: channelToConfigAccessibleChannel(newChannel!),
});
}
},

View file

@ -66,6 +66,7 @@ export const SlowmodePlugin = zeppelinGuildPlugin<SlowmodePluginType>()({
afterLoad(pluginData) {
const { state } = pluginData;
state.serverLogs = new GuildLogs(pluginData.guild.id);
state.clearInterval = setInterval(() => clearExpiredSlowmodes(pluginData), BOT_SLOWMODE_CLEAR_INTERVAL);
state.onMessageCreateFn = msg => onMessageCreate(pluginData, msg);

View file

@ -19,6 +19,7 @@ export interface SlowmodePluginType extends BasePluginType {
savedMessages: GuildSavedMessages;
logs: GuildLogs;
clearInterval: NodeJS.Timeout;
serverLogs: GuildLogs;
onMessageCreateFn;
};

View file

@ -13,6 +13,7 @@ export async function applyBotSlowmodeToUserId(
// Deny sendMessage permission from the user. If there are existing permission overwrites, take those into account.
const existingOverride = channel.permissionOverwrites.resolve(userId as Snowflake);
try {
pluginData.state.serverLogs.ignoreLog(LogType.CHANNEL_UPDATE, channel.id, 5 * 1000);
if (existingOverride) {
await existingOverride.edit({ SEND_MESSAGES: false });
} else {

View file

@ -1,5 +1,6 @@
import { GuildChannel, Snowflake, TextChannel } from "discord.js";
import { GuildPluginData } from "knub";
import { LogType } from "../../../data/LogType";
import { SlowmodePluginType } from "../types";
export async function clearBotSlowmodeFromUserId(
@ -13,6 +14,7 @@ export async function clearBotSlowmodeFromUserId(
// Previously we diffed the overrides so we could clear the "send messages" override without touching other
// overrides. Unfortunately, it seems that was a bit buggy - we didn't always receive the event for the changed
// overrides and then we also couldn't diff against them. For consistency's sake, we just delete the override now.
pluginData.state.serverLogs.ignoreLog(LogType.CHANNEL_UPDATE, channel.id, 3 * 1000);
await channel.permissionOverwrites.resolve(userId as Snowflake)?.delete();
} catch (e) {
if (!force) {

View file

@ -1,5 +1,6 @@
import { GuildChannel, Snowflake, TextChannel } from "discord.js";
import { GuildPluginData } from "knub";
import { channelToConfigAccessibleChannel, userToConfigAccessibleUser } from "src/utils/configAccessibleObjects";
import { LogType } from "../../../data/LogType";
import { logger } from "../../../logger";
import { stripObjectToScalars, UnknownUser } from "../../../utils";
@ -22,10 +23,11 @@ export async function clearExpiredSlowmodes(pluginData: GuildPluginData<Slowmode
const realUser =
pluginData.client.users!.fetch(user.user_id as Snowflake) || new UnknownUser({ id: user.user_id });
pluginData.state.logs.log(LogType.BOT_ALERT, {
body: `Failed to clear slowmode permissions from {userMention(user)} in {channelMention(channel)}`,
user: stripObjectToScalars(realUser),
channel: stripObjectToScalars(channel),
user: userToConfigAccessibleUser(await realUser),
channel: channelToConfigAccessibleChannel(channel),
});
}
}

View file

@ -25,9 +25,6 @@ export const StarboardReactionAddEvt = starboardEvt({
}
}
// No self-votes!
if (msg.author.id === userId) return;
const member = await resolveMember(pluginData.client, pluginData.guild, userId);
if (!member || member.user.bot) return;
@ -61,7 +58,10 @@ export const StarboardReactionAddEvt = starboardEvt({
});
});
const selfStar = msg.author.id === userId;
for (const starboard of applicableStarboards) {
if (selfStar && !starboard.allow_selfstars) continue;
// Save reaction into the database
await pluginData.state.starboardReactions.createStarboardReaction(msg.id, userId).catch(noop);

View file

@ -9,6 +9,7 @@ const StarboardOpts = t.type({
channel_id: t.string,
stars_required: t.number,
star_emoji: tNullable(t.array(t.string)),
allow_selfstars: tNullable(t.boolean),
copy_full_embed: tNullable(t.boolean),
enabled: tNullable(t.boolean),
show_star_count: t.boolean,

View file

@ -35,7 +35,7 @@ import { SourceCmd } from "./commands/SourceCmd";
import { UserInfoCmd } from "./commands/UserInfoCmd";
import { VcdisconnectCmd } from "./commands/VcdisconnectCmd";
import { VcmoveAllCmd, VcmoveCmd } from "./commands/VcmoveCmd";
import { AutoJoinThreadEvt } from "./events/AutoJoinThreadEvt";
import { AutoJoinThreadEvt, AutoJoinThreadSyncEvt } from "./events/AutoJoinThreadEvt";
import { activeReloads } from "./guildReloads";
import { refreshMembersIfNeeded } from "./refreshMembers";
import { ConfigSchema, UtilityPluginType } from "./types";
@ -153,6 +153,7 @@ export const UtilityPlugin = zeppelinGuildPlugin<UtilityPluginType>()({
// prettier-ignore
events: [
AutoJoinThreadEvt,
AutoJoinThreadSyncEvt,
],
beforeLoad(pluginData) {

View file

@ -10,3 +10,18 @@ export const AutoJoinThreadEvt = utilityEvt({
}
},
});
export const AutoJoinThreadSyncEvt = utilityEvt({
event: "threadListSync",
async listener(meta) {
const config = meta.pluginData.config.get();
if (config.autojoin_threads) {
for (const thread of meta.args.threads.values()) {
if (!thread.joined && thread.joinable) {
await thread.join();
}
}
}
},
});

View file

@ -126,7 +126,7 @@ export async function getServerInfoEmbed(
}
if (!onlineMemberCount && thisServer) {
onlineMemberCount = thisServer.members.cache.filter(m => m.presence.status !== "offline").size; // Extremely inaccurate fallback
onlineMemberCount = thisServer.members.cache.filter(m => m.presence?.status !== "offline").size; // Extremely inaccurate fallback
}
const offlineMemberCount = totalMembers - onlineMemberCount;

View file

@ -36,6 +36,7 @@ import { sendDM } from "./utils/sendDM";
import { waitForButtonConfirm } from "./utils/waitForInteraction";
import { decodeAndValidateStrict, StrictValidationError } from "./validatorUtils";
import { isEqual } from "lodash";
import humanizeDuration from "humanize-duration";
const fsp = fs.promises;
@ -184,8 +185,28 @@ export function getScalarDifference<T>(
return diff;
}
// This is a stupid, messy solution that is not extendable at all.
// If anyone plans on adding anything to this, they should rewrite this first.
// I just want to get this done and this works for now :)
export function prettyDifference(diff: Map<string, { was: any; is: any }>): Map<string, { was: any; is: any }> {
const toReturn = new Map<string, { was: any; is: any }>();
for (let [key, difference] of diff) {
if (key === "rateLimitPerUser") {
difference.is = humanizeDuration(difference.is * 1000);
difference.was = humanizeDuration(difference.was * 1000);
key = "slowmode";
}
toReturn.set(key, { was: difference.was, is: difference.is });
}
return toReturn;
}
export function differenceToString(diff: Map<string, { was: any; is: any }>): string {
let toReturn = "";
diff = prettyDifference(diff);
for (const [key, difference] of diff) {
toReturn += `${key[0].toUpperCase() + key.slice(1)}: \`${difference.was}\`\`${difference.is}\`\n`;
}

View file

@ -0,0 +1,116 @@
import {
GuildChannel,
GuildMember,
PartialGuildMember,
Role,
Snowflake,
StageInstance,
ThreadChannel,
User,
} from "discord.js";
export interface IConfigAccessibleUser {
id: Snowflake;
username: string;
discriminator: string;
mention: string;
avatarURL: string;
bot: boolean;
createdAt: number;
}
export interface IConfigAccessibleRole {
id: Snowflake;
name: string;
createdAt: number;
hexColor: string;
hoist: boolean;
}
export interface IConfigAccessibleMember extends IConfigAccessibleUser {
user: IConfigAccessibleUser;
nick: string;
roles: IConfigAccessibleRole[];
joinedAt?: number;
// guildAvatarURL: string, Once DJS supports per-server avatars
guildName: string;
}
export function userToConfigAccessibleUser(user: User): IConfigAccessibleUser {
const toReturn: IConfigAccessibleUser = {
id: user.id,
username: user.username,
discriminator: user.discriminator,
mention: `<@${user.id}>`,
avatarURL: user.displayAvatarURL({ dynamic: true }),
bot: user.bot,
createdAt: user.createdTimestamp,
};
return toReturn;
}
export function roleToConfigAccessibleRole(role: Role): IConfigAccessibleRole {
const toReturn: IConfigAccessibleRole = {
id: role.id,
name: role.name,
createdAt: role.createdTimestamp,
hexColor: role.hexColor,
hoist: role.hoist,
};
return toReturn;
}
export function memberToConfigAccessibleMember(member: GuildMember | PartialGuildMember): IConfigAccessibleMember {
const user = userToConfigAccessibleUser(member.user!);
const toReturn: IConfigAccessibleMember = {
...user,
user,
nick: member.nickname ?? "*None*",
roles: member.roles.cache.mapValues(r => roleToConfigAccessibleRole(r)).array(),
joinedAt: member.joinedTimestamp ?? undefined,
guildName: member.guild.name,
};
return toReturn;
}
export interface IConfigAccessibleChannel {
id: Snowflake;
name: string;
mention: string;
parentId?: Snowflake;
}
export function channelToConfigAccessibleChannel(channel: GuildChannel | ThreadChannel): IConfigAccessibleChannel {
const toReturn: IConfigAccessibleChannel = {
id: channel.id,
name: channel.name,
mention: `<#${channel.id}>`,
parentId: channel.parentId ?? undefined,
};
return toReturn;
}
export interface IConfigAccessibleStage {
channelId: Snowflake;
channelMention: string;
createdAt: number;
discoverable: boolean;
topic: string;
}
export function stageToConfigAccessibleStage(stage: StageInstance): IConfigAccessibleStage {
const toReturn: IConfigAccessibleStage = {
channelId: stage.channelId,
channelMention: `<#${stage.channelId}>`,
createdAt: stage.createdTimestamp,
discoverable: !stage.discoverableDisabled,
topic: stage.topic,
};
return toReturn;
}