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:
parent
dda19de6e6
commit
d2dd103175
28 changed files with 259 additions and 75 deletions
18
backend/package-lock.json
generated
18
backend/package-lock.json
generated
|
@ -14,7 +14,7 @@
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"cross-env": "^5.2.0",
|
"cross-env": "^5.2.0",
|
||||||
"deep-diff": "^1.0.2",
|
"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",
|
"dotenv": "^4.0.0",
|
||||||
"emoji-regex": "^8.0.0",
|
"emoji-regex": "^8.0.0",
|
||||||
"erlpack": "github:discord/erlpack",
|
"erlpack": "github:discord/erlpack",
|
||||||
|
@ -82,7 +82,7 @@
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"discord-api-types": "^0.18.1",
|
"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",
|
"knub-command-manager": "^9.1.0",
|
||||||
"ts-essentials": "^6.0.7"
|
"ts-essentials": "^6.0.7"
|
||||||
},
|
},
|
||||||
|
@ -2159,9 +2159,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/discord.js": {
|
"node_modules/discord.js": {
|
||||||
"version": "13.0.0-dev.a7c6678.1625427504",
|
"version": "13.0.0-dev.2e078e4.1625529824",
|
||||||
"resolved": "https://registry.npmjs.org/discord.js/-/discord.js-13.0.0-dev.a7c6678.1625427504.tgz",
|
"resolved": "https://registry.npmjs.org/discord.js/-/discord.js-13.0.0-dev.2e078e4.1625529824.tgz",
|
||||||
"integrity": "sha512-S4ntnGVUCRyyOtz8YvoWNpSZyZEFwXTkTjXbU0shveD/QVT+0cBCcMX6vp0zPt3lCkMUgdW+crrOfEYKMGwKoQ==",
|
"integrity": "sha512-NKNnoEmh3+4eCG44BOIBjlJS0bKQEH8OgWoEjdJ9K53MYa5lfqbSho4NKXe5+hVpMr+U43wJ8ByUvw96ogqu8w==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@discordjs/builders": "^0.2.0",
|
"@discordjs/builders": "^0.2.0",
|
||||||
"@discordjs/collection": "^0.1.6",
|
"@discordjs/collection": "^0.1.6",
|
||||||
|
@ -8034,9 +8034,9 @@
|
||||||
"integrity": "sha512-hNC38R9ZF4uaujaZQtQfm5CdQO58uhdkoHQAVvMfIL0LgOSZeW575W8H6upngQOuoxWd8tiRII3LLJm9zuQKYg=="
|
"integrity": "sha512-hNC38R9ZF4uaujaZQtQfm5CdQO58uhdkoHQAVvMfIL0LgOSZeW575W8H6upngQOuoxWd8tiRII3LLJm9zuQKYg=="
|
||||||
},
|
},
|
||||||
"discord.js": {
|
"discord.js": {
|
||||||
"version": "13.0.0-dev.a7c6678.1625427504",
|
"version": "13.0.0-dev.2e078e4.1625529824",
|
||||||
"resolved": "https://registry.npmjs.org/discord.js/-/discord.js-13.0.0-dev.a7c6678.1625427504.tgz",
|
"resolved": "https://registry.npmjs.org/discord.js/-/discord.js-13.0.0-dev.2e078e4.1625529824.tgz",
|
||||||
"integrity": "sha512-S4ntnGVUCRyyOtz8YvoWNpSZyZEFwXTkTjXbU0shveD/QVT+0cBCcMX6vp0zPt3lCkMUgdW+crrOfEYKMGwKoQ==",
|
"integrity": "sha512-NKNnoEmh3+4eCG44BOIBjlJS0bKQEH8OgWoEjdJ9K53MYa5lfqbSho4NKXe5+hVpMr+U43wJ8ByUvw96ogqu8w==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@discordjs/builders": "^0.2.0",
|
"@discordjs/builders": "^0.2.0",
|
||||||
"@discordjs/collection": "^0.1.6",
|
"@discordjs/collection": "^0.1.6",
|
||||||
|
@ -8878,7 +8878,7 @@
|
||||||
"@typescript-eslint/parser": "^4.23.0",
|
"@typescript-eslint/parser": "^4.23.0",
|
||||||
"chai": "^4.3.4",
|
"chai": "^4.3.4",
|
||||||
"discord-api-types": "^0.18.1",
|
"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",
|
"eslint": "^7.2.0",
|
||||||
"husky": "^4.3.8",
|
"husky": "^4.3.8",
|
||||||
"knub-command-manager": "^9.1.0",
|
"knub-command-manager": "^9.1.0",
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"cross-env": "^5.2.0",
|
"cross-env": "^5.2.0",
|
||||||
"deep-diff": "^1.0.2",
|
"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",
|
"dotenv": "^4.0.0",
|
||||||
"emoji-regex": "^8.0.0",
|
"emoji-regex": "^8.0.0",
|
||||||
"erlpack": "github:discord/erlpack",
|
"erlpack": "github:discord/erlpack",
|
||||||
|
|
|
@ -29,6 +29,6 @@ export function getTextMatchPartialSummary(
|
||||||
const visibleName = context.member?.nickname || context.user!.username;
|
const visibleName = context.member?.nickname || context.user!.username;
|
||||||
return `visible name: ${visibleName}`;
|
return `visible name: ${visibleName}`;
|
||||||
} else if (type === "customstatus") {
|
} 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}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ export async function* matchMultipleTextTypesOnMessage(
|
||||||
yield ["nickname", member.nickname];
|
yield ["nickname", member.nickname];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const activity of member.presence.activities) {
|
for (const activity of member.presence?.activities ?? []) {
|
||||||
if (activity.type === Constants.ActivityTypes[4]) {
|
if (activity.type === Constants.ActivityTypes[4]) {
|
||||||
yield ["customstatus", `${activity.emoji} ${activity.name}`];
|
yield ["customstatus", `${activity.emoji} ${activity.name}`];
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { CooldownManager } from "knub";
|
import { CooldownManager } from "knub";
|
||||||
|
import { GuildLogs } from "../../../data/GuildLogs";
|
||||||
import { trimPluginDescription } from "../../utils";
|
import { trimPluginDescription } from "../../utils";
|
||||||
import { LogsPlugin } from "../Logs/LogsPlugin";
|
import { LogsPlugin } from "../Logs/LogsPlugin";
|
||||||
import { zeppelinGuildPlugin } from "../ZeppelinPluginBlueprint";
|
import { zeppelinGuildPlugin } from "../ZeppelinPluginBlueprint";
|
||||||
|
@ -32,4 +33,8 @@ export const CompanionChannelsPlugin = zeppelinGuildPlugin<CompanionChannelsPlug
|
||||||
beforeLoad(pluginData) {
|
beforeLoad(pluginData) {
|
||||||
pluginData.state.errorCooldownManager = new CooldownManager();
|
pluginData.state.errorCooldownManager = new CooldownManager();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
afterLoad(pluginData) {
|
||||||
|
pluginData.state.serverLogs = new GuildLogs(pluginData.guild.id);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -53,6 +53,7 @@ export async function handleCompanionPermissions(
|
||||||
for (const channelId of permsToDelete) {
|
for (const channelId of permsToDelete) {
|
||||||
const channel = pluginData.guild.channels.cache.get(channelId as Snowflake);
|
const channel = pluginData.guild.channels.cache.get(channelId as Snowflake);
|
||||||
if (!channel || !(channel instanceof TextChannel)) continue;
|
if (!channel || !(channel instanceof TextChannel)) continue;
|
||||||
|
pluginData.state.serverLogs.ignoreLog(LogType.CHANNEL_UPDATE, channelId, 3 * 1000);
|
||||||
await channel.permissionOverwrites
|
await channel.permissionOverwrites
|
||||||
.resolve(userId as Snowflake)
|
.resolve(userId as Snowflake)
|
||||||
?.delete(`Companion Channel for ${oldChannel!.id} | User Left`);
|
?.delete(`Companion Channel for ${oldChannel!.id} | User Left`);
|
||||||
|
@ -61,6 +62,7 @@ export async function handleCompanionPermissions(
|
||||||
for (const [channelId, permissions] of permsToSet) {
|
for (const [channelId, permissions] of permsToSet) {
|
||||||
const channel = pluginData.guild.channels.cache.get(channelId as Snowflake);
|
const channel = pluginData.guild.channels.cache.get(channelId as Snowflake);
|
||||||
if (!channel || !(channel instanceof TextChannel)) continue;
|
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(), {
|
await channel.permissionOverwrites.create(userId as Snowflake, new Permissions(BigInt(permissions)).serialize(), {
|
||||||
reason: `Companion Channel for ${voiceChannel!.id} | User Joined`,
|
reason: `Companion Channel for ${voiceChannel!.id} | User Joined`,
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import * as t from "io-ts";
|
import * as t from "io-ts";
|
||||||
import { BasePluginType, CooldownManager, typedGuildEventListener } from "knub";
|
import { BasePluginType, CooldownManager, typedGuildEventListener } from "knub";
|
||||||
|
import { GuildLogs } from "../../data/GuildLogs";
|
||||||
import { tNullable } from "../../utils";
|
import { tNullable } from "../../utils";
|
||||||
|
|
||||||
// Permissions using these numbers: https://abal.moe/Eris/docs/reference (add all allowed/denied ones up)
|
// 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;
|
config: TConfigSchema;
|
||||||
state: {
|
state: {
|
||||||
errorCooldownManager: CooldownManager;
|
errorCooldownManager: CooldownManager;
|
||||||
|
serverLogs: GuildLogs;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
import { channelToConfigAccessibleChannel } from "../../../utils/configAccessibleObjects";
|
||||||
import { LogType } from "../../../data/LogType";
|
import { LogType } from "../../../data/LogType";
|
||||||
import { differenceToString, getScalarDifference, stripObjectToScalars } from "../../../utils";
|
import { differenceToString, getScalarDifference } from "../../../utils";
|
||||||
import { logsEvt } from "../types";
|
import { logsEvt } from "../types";
|
||||||
|
|
||||||
export const LogsChannelCreateEvt = logsEvt({
|
export const LogsChannelCreateEvt = logsEvt({
|
||||||
|
@ -7,7 +8,7 @@ export const LogsChannelCreateEvt = logsEvt({
|
||||||
|
|
||||||
async listener(meta) {
|
async listener(meta) {
|
||||||
meta.pluginData.state.guildLogs.log(LogType.CHANNEL_CREATE, {
|
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) {
|
async listener(meta) {
|
||||||
meta.pluginData.state.guildLogs.log(LogType.CHANNEL_DELETE, {
|
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 diff = getScalarDifference(meta.args.oldChannel, meta.args.newChannel);
|
||||||
const differenceString = differenceToString(diff);
|
const differenceString = differenceToString(diff);
|
||||||
|
|
||||||
meta.pluginData.state.guildLogs.log(LogType.CHANNEL_UPDATE, {
|
meta.pluginData.state.guildLogs.log(
|
||||||
oldChannel: stripObjectToScalars(meta.args.oldChannel),
|
LogType.CHANNEL_UPDATE,
|
||||||
newChannel: stripObjectToScalars(meta.args.newChannel),
|
{
|
||||||
differenceString,
|
oldChannel: channelToConfigAccessibleChannel(meta.args.oldChannel),
|
||||||
});
|
newChannel: channelToConfigAccessibleChannel(meta.args.newChannel),
|
||||||
|
differenceString,
|
||||||
|
},
|
||||||
|
meta.args.newChannel.id,
|
||||||
|
);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { GuildAuditLogs } from "discord.js";
|
import { GuildAuditLogs } from "discord.js";
|
||||||
|
import { userToConfigAccessibleUser } from "../../../utils/configAccessibleObjects";
|
||||||
import { LogType } from "../../../data/LogType";
|
import { LogType } from "../../../data/LogType";
|
||||||
import { stripObjectToScalars, UnknownUser } from "../../../utils";
|
|
||||||
import { safeFindRelevantAuditLogEntry } from "../../../utils/safeFindRelevantAuditLogEntry";
|
import { safeFindRelevantAuditLogEntry } from "../../../utils/safeFindRelevantAuditLogEntry";
|
||||||
import { logsEvt } from "../types";
|
import { logsEvt } from "../types";
|
||||||
|
|
||||||
|
@ -16,13 +16,13 @@ export const LogsGuildBanAddEvt = logsEvt({
|
||||||
GuildAuditLogs.Actions.MEMBER_BAN_ADD as number,
|
GuildAuditLogs.Actions.MEMBER_BAN_ADD as number,
|
||||||
user.id,
|
user.id,
|
||||||
);
|
);
|
||||||
const mod = relevantAuditLogEntry ? relevantAuditLogEntry.executor : new UnknownUser();
|
const mod = relevantAuditLogEntry ? relevantAuditLogEntry.executor : null;
|
||||||
|
|
||||||
pluginData.state.guildLogs.log(
|
pluginData.state.guildLogs.log(
|
||||||
LogType.MEMBER_BAN,
|
LogType.MEMBER_BAN,
|
||||||
{
|
{
|
||||||
mod: stripObjectToScalars(mod),
|
mod: mod ? userToConfigAccessibleUser(mod) : {},
|
||||||
user: stripObjectToScalars(user),
|
user: userToConfigAccessibleUser(user),
|
||||||
},
|
},
|
||||||
user.id,
|
user.id,
|
||||||
);
|
);
|
||||||
|
@ -41,12 +41,12 @@ export const LogsGuildBanRemoveEvt = logsEvt({
|
||||||
GuildAuditLogs.Actions.MEMBER_BAN_REMOVE as number,
|
GuildAuditLogs.Actions.MEMBER_BAN_REMOVE as number,
|
||||||
user.id,
|
user.id,
|
||||||
);
|
);
|
||||||
const mod = relevantAuditLogEntry ? relevantAuditLogEntry.executor : new UnknownUser();
|
const mod = relevantAuditLogEntry ? relevantAuditLogEntry.executor : null;
|
||||||
|
|
||||||
pluginData.state.guildLogs.log(
|
pluginData.state.guildLogs.log(
|
||||||
LogType.MEMBER_UNBAN,
|
LogType.MEMBER_UNBAN,
|
||||||
{
|
{
|
||||||
mod: stripObjectToScalars(mod),
|
mod: mod ? userToConfigAccessibleUser(mod) : {},
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
},
|
},
|
||||||
user.id,
|
user.id,
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import humanizeDuration from "humanize-duration";
|
import humanizeDuration from "humanize-duration";
|
||||||
import moment from "moment-timezone";
|
import moment from "moment-timezone";
|
||||||
|
import { memberToConfigAccessibleMember } from "../../../utils/configAccessibleObjects";
|
||||||
import { LogType } from "../../../data/LogType";
|
import { LogType } from "../../../data/LogType";
|
||||||
import { stripObjectToScalars } from "../../../utils";
|
import { stripObjectToScalars } from "../../../utils";
|
||||||
import { CasesPlugin } from "../../Cases/CasesPlugin";
|
import { CasesPlugin } from "../../Cases/CasesPlugin";
|
||||||
|
@ -46,7 +47,7 @@ export const LogsGuildMemberAddEvt = logsEvt({
|
||||||
}
|
}
|
||||||
|
|
||||||
pluginData.state.guildLogs.log(LogType.MEMBER_JOIN_WITH_PRIOR_RECORDS, {
|
pluginData.state.guildLogs.log(LogType.MEMBER_JOIN_WITH_PRIOR_RECORDS, {
|
||||||
member: stripObjectToScalars(member, ["user", "roles"]),
|
member: memberToConfigAccessibleMember(member),
|
||||||
recentCaseSummary,
|
recentCaseSummary,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
import { memberToConfigAccessibleMember } from "../../../utils/configAccessibleObjects";
|
||||||
import { LogType } from "../../../data/LogType";
|
import { LogType } from "../../../data/LogType";
|
||||||
import { stripObjectToScalars } from "../../../utils";
|
|
||||||
import { logsEvt } from "../types";
|
import { logsEvt } from "../types";
|
||||||
|
|
||||||
export const LogsGuildMemberRemoveEvt = logsEvt({
|
export const LogsGuildMemberRemoveEvt = logsEvt({
|
||||||
|
@ -7,7 +7,7 @@ export const LogsGuildMemberRemoveEvt = logsEvt({
|
||||||
|
|
||||||
async listener(meta) {
|
async listener(meta) {
|
||||||
meta.pluginData.state.guildLogs.log(LogType.MEMBER_LEAVE, {
|
meta.pluginData.state.guildLogs.log(LogType.MEMBER_LEAVE, {
|
||||||
member: stripObjectToScalars(meta.args.member, ["user", "roles"]),
|
member: memberToConfigAccessibleMember(meta.args.member),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
import { roleToConfigAccessibleRole } from "../../../utils/configAccessibleObjects";
|
||||||
import { LogType } from "../../../data/LogType";
|
import { LogType } from "../../../data/LogType";
|
||||||
import { differenceToString, getScalarDifference, stripObjectToScalars } from "../../../utils";
|
import { differenceToString, getScalarDifference } from "../../../utils";
|
||||||
import { logsEvt } from "../types";
|
import { logsEvt } from "../types";
|
||||||
|
|
||||||
export const LogsRoleCreateEvt = logsEvt({
|
export const LogsRoleCreateEvt = logsEvt({
|
||||||
|
@ -7,7 +8,7 @@ export const LogsRoleCreateEvt = logsEvt({
|
||||||
|
|
||||||
async listener(meta) {
|
async listener(meta) {
|
||||||
meta.pluginData.state.guildLogs.log(LogType.ROLE_CREATE, {
|
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) {
|
async listener(meta) {
|
||||||
meta.pluginData.state.guildLogs.log(LogType.ROLE_DELETE, {
|
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);
|
const differenceString = differenceToString(diff);
|
||||||
|
|
||||||
meta.pluginData.state.guildLogs.log(LogType.ROLE_UPDATE, {
|
meta.pluginData.state.guildLogs.log(LogType.ROLE_UPDATE, {
|
||||||
newRole: stripObjectToScalars(meta.args.newRole),
|
newRole: roleToConfigAccessibleRole(meta.args.newRole),
|
||||||
oldRole: stripObjectToScalars(meta.args.oldRole),
|
oldRole: roleToConfigAccessibleRole(meta.args.oldRole),
|
||||||
differenceString,
|
differenceString,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { channelToConfigAccessibleChannel, stageToConfigAccessibleStage } from "../../../utils/configAccessibleObjects";
|
||||||
import { LogType } from "../../../data/LogType";
|
import { LogType } from "../../../data/LogType";
|
||||||
import { differenceToString, getScalarDifference, stripObjectToScalars } from "../../../utils";
|
import { differenceToString, getScalarDifference, stripObjectToScalars } from "../../../utils";
|
||||||
import { logsEvt } from "../types";
|
import { logsEvt } from "../types";
|
||||||
|
@ -8,10 +9,11 @@ export const LogsStageInstanceCreateEvt = logsEvt({
|
||||||
async listener(meta) {
|
async listener(meta) {
|
||||||
const stageChannel =
|
const stageChannel =
|
||||||
meta.args.stageInstance.channel ??
|
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, {
|
meta.pluginData.state.guildLogs.log(LogType.STAGE_INSTANCE_CREATE, {
|
||||||
stageInstance: stripObjectToScalars(meta.args.stageInstance),
|
stageInstance: stageToConfigAccessibleStage(meta.args.stageInstance),
|
||||||
stageChannel: stripObjectToScalars(stageChannel),
|
stageChannel: channelToConfigAccessibleChannel(stageChannel),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -22,10 +24,11 @@ export const LogsStageInstanceDeleteEvt = logsEvt({
|
||||||
async listener(meta) {
|
async listener(meta) {
|
||||||
const stageChannel =
|
const stageChannel =
|
||||||
meta.args.stageInstance.channel ??
|
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, {
|
meta.pluginData.state.guildLogs.log(LogType.STAGE_INSTANCE_DELETE, {
|
||||||
stageInstance: stripObjectToScalars(meta.args.stageInstance),
|
stageInstance: stageToConfigAccessibleStage(meta.args.stageInstance),
|
||||||
stageChannel: stripObjectToScalars(stageChannel),
|
stageChannel: channelToConfigAccessibleChannel(stageChannel),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -36,15 +39,15 @@ export const LogsStageInstanceUpdateEvt = logsEvt({
|
||||||
async listener(meta) {
|
async listener(meta) {
|
||||||
const stageChannel =
|
const stageChannel =
|
||||||
meta.args.newStageInstance.channel ??
|
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 diff = getScalarDifference(meta.args.oldStageInstance, meta.args.newStageInstance);
|
||||||
const differenceString = differenceToString(diff);
|
const differenceString = differenceToString(diff);
|
||||||
|
|
||||||
meta.pluginData.state.guildLogs.log(LogType.STAGE_INSTANCE_UPDATE, {
|
meta.pluginData.state.guildLogs.log(LogType.STAGE_INSTANCE_UPDATE, {
|
||||||
oldStageInstance: stripObjectToScalars(meta.args.oldStageInstance),
|
oldStageInstance: stageToConfigAccessibleStage(meta.args.oldStageInstance),
|
||||||
newStageInstance: stripObjectToScalars(meta.args.newStageInstance),
|
newStageInstance: stageToConfigAccessibleStage(meta.args.newStageInstance),
|
||||||
stageChannel: stripObjectToScalars(stageChannel),
|
stageChannel: channelToConfigAccessibleChannel(stageChannel),
|
||||||
differenceString,
|
differenceString,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { channelToConfigAccessibleChannel } from "../../../utils/configAccessibleObjects";
|
||||||
import { LogType } from "../../../data/LogType";
|
import { LogType } from "../../../data/LogType";
|
||||||
import { stripObjectToScalars, getScalarDifference, differenceToString } from "../../../utils";
|
import { stripObjectToScalars, getScalarDifference, differenceToString } from "../../../utils";
|
||||||
import { logsEvt } from "../types";
|
import { logsEvt } from "../types";
|
||||||
|
@ -7,7 +8,7 @@ export const LogsThreadCreateEvt = logsEvt({
|
||||||
|
|
||||||
async listener(meta) {
|
async listener(meta) {
|
||||||
meta.pluginData.state.guildLogs.log(LogType.THREAD_CREATE, {
|
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) {
|
async listener(meta) {
|
||||||
meta.pluginData.state.guildLogs.log(LogType.THREAD_DELETE, {
|
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 diff = getScalarDifference(meta.args.oldThread, meta.args.newThread, ["messageCount", "archiveTimestamp"]);
|
||||||
const differenceString = differenceToString(diff);
|
const differenceString = differenceToString(diff);
|
||||||
|
|
||||||
meta.pluginData.state.guildLogs.log(LogType.THREAD_UPDATE, {
|
meta.pluginData.state.guildLogs.log(
|
||||||
oldThread: stripObjectToScalars(meta.args.oldThread),
|
LogType.THREAD_UPDATE,
|
||||||
newThread: stripObjectToScalars(meta.args.newThread),
|
{
|
||||||
differenceString,
|
oldThread: channelToConfigAccessibleChannel(meta.args.oldThread),
|
||||||
});
|
newThread: channelToConfigAccessibleChannel(meta.args.newThread),
|
||||||
|
differenceString,
|
||||||
|
},
|
||||||
|
meta.args.newThread.id,
|
||||||
|
);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import { GuildAuditLogs } from "discord.js";
|
import { GuildAuditLogs } from "discord.js";
|
||||||
import diff from "lodash.difference";
|
import diff from "lodash.difference";
|
||||||
import isEqual from "lodash.isequal";
|
import isEqual from "lodash.isequal";
|
||||||
|
import { memberToConfigAccessibleMember, userToConfigAccessibleUser } from "src/utils/configAccessibleObjects";
|
||||||
import { LogType } from "../../../data/LogType";
|
import { LogType } from "../../../data/LogType";
|
||||||
import { stripObjectToScalars, UnknownUser } from "../../../utils";
|
|
||||||
import { safeFindRelevantAuditLogEntry } from "../../../utils/safeFindRelevantAuditLogEntry";
|
import { safeFindRelevantAuditLogEntry } from "../../../utils/safeFindRelevantAuditLogEntry";
|
||||||
import { logsEvt } from "../types";
|
import { logsEvt } from "../types";
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ export const LogsGuildMemberUpdateEvt = logsEvt({
|
||||||
|
|
||||||
if (!oldMember) return;
|
if (!oldMember) return;
|
||||||
|
|
||||||
const logMember = stripObjectToScalars(member, ["user", "roles"]);
|
const logMember = memberToConfigAccessibleMember(member);
|
||||||
|
|
||||||
if (member.nickname !== oldMember.nickname) {
|
if (member.nickname !== oldMember.nickname) {
|
||||||
pluginData.state.guildLogs.log(LogType.MEMBER_NICK_CHANGE, {
|
pluginData.state.guildLogs.log(LogType.MEMBER_NICK_CHANGE, {
|
||||||
|
@ -52,7 +52,7 @@ export const LogsGuildMemberUpdateEvt = logsEvt({
|
||||||
GuildAuditLogs.Actions.MEMBER_ROLE_UPDATE as number,
|
GuildAuditLogs.Actions.MEMBER_ROLE_UPDATE as number,
|
||||||
member.id,
|
member.id,
|
||||||
);
|
);
|
||||||
const mod = relevantAuditLogEntry ? relevantAuditLogEntry.executor : new UnknownUser();
|
const mod = relevantAuditLogEntry ? relevantAuditLogEntry.executor : null;
|
||||||
|
|
||||||
if (addedRoles.length && removedRoles.length) {
|
if (addedRoles.length && removedRoles.length) {
|
||||||
// Roles added *and* removed
|
// 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(roleId => pluginData.guild.roles.cache.get(roleId) || { id: roleId, name: `Unknown (${roleId})` })
|
||||||
.map(r => r.name)
|
.map(r => r.name)
|
||||||
.join(", "),
|
.join(", "),
|
||||||
mod: stripObjectToScalars(mod),
|
mod: mod ? userToConfigAccessibleUser(mod) : {},
|
||||||
},
|
},
|
||||||
member.id,
|
member.id,
|
||||||
);
|
);
|
||||||
|
@ -82,7 +82,7 @@ export const LogsGuildMemberUpdateEvt = logsEvt({
|
||||||
.map(roleId => pluginData.guild.roles.cache.get(roleId) || { id: roleId, name: `Unknown (${roleId})` })
|
.map(roleId => pluginData.guild.roles.cache.get(roleId) || { id: roleId, name: `Unknown (${roleId})` })
|
||||||
.map(r => r.name)
|
.map(r => r.name)
|
||||||
.join(", "),
|
.join(", "),
|
||||||
mod: stripObjectToScalars(mod),
|
mod: mod ? userToConfigAccessibleUser(mod) : {},
|
||||||
},
|
},
|
||||||
member.id,
|
member.id,
|
||||||
);
|
);
|
||||||
|
@ -96,7 +96,7 @@ export const LogsGuildMemberUpdateEvt = logsEvt({
|
||||||
.map(roleId => pluginData.guild.roles.cache.get(roleId) || { id: roleId, name: `Unknown (${roleId})` })
|
.map(roleId => pluginData.guild.roles.cache.get(roleId) || { id: roleId, name: `Unknown (${roleId})` })
|
||||||
.map(r => r.name)
|
.map(r => r.name)
|
||||||
.join(", "),
|
.join(", "),
|
||||||
mod: stripObjectToScalars(mod),
|
mod: mod ? userToConfigAccessibleUser(mod) : {},
|
||||||
},
|
},
|
||||||
member.id,
|
member.id,
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { channelToConfigAccessibleChannel, memberToConfigAccessibleMember } from "src/utils/configAccessibleObjects";
|
||||||
import { LogType } from "../../../data/LogType";
|
import { LogType } from "../../../data/LogType";
|
||||||
import { stripObjectToScalars } from "../../../utils";
|
import { stripObjectToScalars } from "../../../utils";
|
||||||
import { logsEvt } from "../types";
|
import { logsEvt } from "../types";
|
||||||
|
@ -10,25 +11,23 @@ export const LogsVoiceStateUpdateEvt = logsEvt({
|
||||||
const newChannel = meta.args.newState.channel;
|
const newChannel = meta.args.newState.channel;
|
||||||
const member = meta.args.newState.member ?? meta.args.oldState.member!;
|
const member = meta.args.newState.member ?? meta.args.oldState.member!;
|
||||||
|
|
||||||
if (!newChannel) {
|
if (!newChannel && oldChannel) {
|
||||||
// Leave evt
|
// Leave evt
|
||||||
meta.pluginData.state.guildLogs.log(LogType.VOICE_CHANNEL_LEAVE, {
|
meta.pluginData.state.guildLogs.log(LogType.VOICE_CHANNEL_LEAVE, {
|
||||||
member: stripObjectToScalars(member, ["user", "roles"]),
|
member: memberToConfigAccessibleMember(member),
|
||||||
oldChannel: stripObjectToScalars(oldChannel),
|
oldChannel: channelToConfigAccessibleChannel(oldChannel!),
|
||||||
newChannel: stripObjectToScalars(newChannel),
|
|
||||||
});
|
});
|
||||||
} else if (!oldChannel) {
|
} else if (!oldChannel && newChannel) {
|
||||||
// Join Evt
|
// Join Evt
|
||||||
meta.pluginData.state.guildLogs.log(LogType.VOICE_CHANNEL_JOIN, {
|
meta.pluginData.state.guildLogs.log(LogType.VOICE_CHANNEL_JOIN, {
|
||||||
member: stripObjectToScalars(member, ["user", "roles"]),
|
member: memberToConfigAccessibleMember(member),
|
||||||
oldChannel: stripObjectToScalars(oldChannel),
|
newChannel: channelToConfigAccessibleChannel(newChannel),
|
||||||
newChannel: stripObjectToScalars(newChannel),
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
meta.pluginData.state.guildLogs.log(LogType.VOICE_CHANNEL_MOVE, {
|
meta.pluginData.state.guildLogs.log(LogType.VOICE_CHANNEL_MOVE, {
|
||||||
member: stripObjectToScalars(member, ["user", "roles"]),
|
member: memberToConfigAccessibleMember(member),
|
||||||
oldChannel: stripObjectToScalars(oldChannel),
|
oldChannel: channelToConfigAccessibleChannel(oldChannel!),
|
||||||
newChannel: stripObjectToScalars(newChannel),
|
newChannel: channelToConfigAccessibleChannel(newChannel!),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -66,6 +66,7 @@ export const SlowmodePlugin = zeppelinGuildPlugin<SlowmodePluginType>()({
|
||||||
afterLoad(pluginData) {
|
afterLoad(pluginData) {
|
||||||
const { state } = pluginData;
|
const { state } = pluginData;
|
||||||
|
|
||||||
|
state.serverLogs = new GuildLogs(pluginData.guild.id);
|
||||||
state.clearInterval = setInterval(() => clearExpiredSlowmodes(pluginData), BOT_SLOWMODE_CLEAR_INTERVAL);
|
state.clearInterval = setInterval(() => clearExpiredSlowmodes(pluginData), BOT_SLOWMODE_CLEAR_INTERVAL);
|
||||||
|
|
||||||
state.onMessageCreateFn = msg => onMessageCreate(pluginData, msg);
|
state.onMessageCreateFn = msg => onMessageCreate(pluginData, msg);
|
||||||
|
|
|
@ -19,6 +19,7 @@ export interface SlowmodePluginType extends BasePluginType {
|
||||||
savedMessages: GuildSavedMessages;
|
savedMessages: GuildSavedMessages;
|
||||||
logs: GuildLogs;
|
logs: GuildLogs;
|
||||||
clearInterval: NodeJS.Timeout;
|
clearInterval: NodeJS.Timeout;
|
||||||
|
serverLogs: GuildLogs;
|
||||||
|
|
||||||
onMessageCreateFn;
|
onMessageCreateFn;
|
||||||
};
|
};
|
||||||
|
|
|
@ -13,6 +13,7 @@ export async function applyBotSlowmodeToUserId(
|
||||||
// Deny sendMessage permission from the user. If there are existing permission overwrites, take those into account.
|
// Deny sendMessage permission from the user. If there are existing permission overwrites, take those into account.
|
||||||
const existingOverride = channel.permissionOverwrites.resolve(userId as Snowflake);
|
const existingOverride = channel.permissionOverwrites.resolve(userId as Snowflake);
|
||||||
try {
|
try {
|
||||||
|
pluginData.state.serverLogs.ignoreLog(LogType.CHANNEL_UPDATE, channel.id, 5 * 1000);
|
||||||
if (existingOverride) {
|
if (existingOverride) {
|
||||||
await existingOverride.edit({ SEND_MESSAGES: false });
|
await existingOverride.edit({ SEND_MESSAGES: false });
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { GuildChannel, Snowflake, TextChannel } from "discord.js";
|
import { GuildChannel, Snowflake, TextChannel } from "discord.js";
|
||||||
import { GuildPluginData } from "knub";
|
import { GuildPluginData } from "knub";
|
||||||
|
import { LogType } from "../../../data/LogType";
|
||||||
import { SlowmodePluginType } from "../types";
|
import { SlowmodePluginType } from "../types";
|
||||||
|
|
||||||
export async function clearBotSlowmodeFromUserId(
|
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
|
// 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. 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.
|
// 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();
|
await channel.permissionOverwrites.resolve(userId as Snowflake)?.delete();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (!force) {
|
if (!force) {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { GuildChannel, Snowflake, TextChannel } from "discord.js";
|
import { GuildChannel, Snowflake, TextChannel } from "discord.js";
|
||||||
import { GuildPluginData } from "knub";
|
import { GuildPluginData } from "knub";
|
||||||
|
import { channelToConfigAccessibleChannel, userToConfigAccessibleUser } from "src/utils/configAccessibleObjects";
|
||||||
import { LogType } from "../../../data/LogType";
|
import { LogType } from "../../../data/LogType";
|
||||||
import { logger } from "../../../logger";
|
import { logger } from "../../../logger";
|
||||||
import { stripObjectToScalars, UnknownUser } from "../../../utils";
|
import { stripObjectToScalars, UnknownUser } from "../../../utils";
|
||||||
|
@ -22,10 +23,11 @@ export async function clearExpiredSlowmodes(pluginData: GuildPluginData<Slowmode
|
||||||
|
|
||||||
const realUser =
|
const realUser =
|
||||||
pluginData.client.users!.fetch(user.user_id as Snowflake) || new UnknownUser({ id: user.user_id });
|
pluginData.client.users!.fetch(user.user_id as Snowflake) || new UnknownUser({ id: user.user_id });
|
||||||
|
|
||||||
pluginData.state.logs.log(LogType.BOT_ALERT, {
|
pluginData.state.logs.log(LogType.BOT_ALERT, {
|
||||||
body: `Failed to clear slowmode permissions from {userMention(user)} in {channelMention(channel)}`,
|
body: `Failed to clear slowmode permissions from {userMention(user)} in {channelMention(channel)}`,
|
||||||
user: stripObjectToScalars(realUser),
|
user: userToConfigAccessibleUser(await realUser),
|
||||||
channel: stripObjectToScalars(channel),
|
channel: channelToConfigAccessibleChannel(channel),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
const member = await resolveMember(pluginData.client, pluginData.guild, userId);
|
||||||
if (!member || member.user.bot) return;
|
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) {
|
for (const starboard of applicableStarboards) {
|
||||||
|
if (selfStar && !starboard.allow_selfstars) continue;
|
||||||
|
|
||||||
// Save reaction into the database
|
// Save reaction into the database
|
||||||
await pluginData.state.starboardReactions.createStarboardReaction(msg.id, userId).catch(noop);
|
await pluginData.state.starboardReactions.createStarboardReaction(msg.id, userId).catch(noop);
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ const StarboardOpts = t.type({
|
||||||
channel_id: t.string,
|
channel_id: t.string,
|
||||||
stars_required: t.number,
|
stars_required: t.number,
|
||||||
star_emoji: tNullable(t.array(t.string)),
|
star_emoji: tNullable(t.array(t.string)),
|
||||||
|
allow_selfstars: tNullable(t.boolean),
|
||||||
copy_full_embed: tNullable(t.boolean),
|
copy_full_embed: tNullable(t.boolean),
|
||||||
enabled: tNullable(t.boolean),
|
enabled: tNullable(t.boolean),
|
||||||
show_star_count: t.boolean,
|
show_star_count: t.boolean,
|
||||||
|
|
|
@ -35,7 +35,7 @@ import { SourceCmd } from "./commands/SourceCmd";
|
||||||
import { UserInfoCmd } from "./commands/UserInfoCmd";
|
import { UserInfoCmd } from "./commands/UserInfoCmd";
|
||||||
import { VcdisconnectCmd } from "./commands/VcdisconnectCmd";
|
import { VcdisconnectCmd } from "./commands/VcdisconnectCmd";
|
||||||
import { VcmoveAllCmd, VcmoveCmd } from "./commands/VcmoveCmd";
|
import { VcmoveAllCmd, VcmoveCmd } from "./commands/VcmoveCmd";
|
||||||
import { AutoJoinThreadEvt } from "./events/AutoJoinThreadEvt";
|
import { AutoJoinThreadEvt, AutoJoinThreadSyncEvt } from "./events/AutoJoinThreadEvt";
|
||||||
import { activeReloads } from "./guildReloads";
|
import { activeReloads } from "./guildReloads";
|
||||||
import { refreshMembersIfNeeded } from "./refreshMembers";
|
import { refreshMembersIfNeeded } from "./refreshMembers";
|
||||||
import { ConfigSchema, UtilityPluginType } from "./types";
|
import { ConfigSchema, UtilityPluginType } from "./types";
|
||||||
|
@ -153,6 +153,7 @@ export const UtilityPlugin = zeppelinGuildPlugin<UtilityPluginType>()({
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
events: [
|
events: [
|
||||||
AutoJoinThreadEvt,
|
AutoJoinThreadEvt,
|
||||||
|
AutoJoinThreadSyncEvt,
|
||||||
],
|
],
|
||||||
|
|
||||||
beforeLoad(pluginData) {
|
beforeLoad(pluginData) {
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
|
@ -126,7 +126,7 @@ export async function getServerInfoEmbed(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!onlineMemberCount && thisServer) {
|
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;
|
const offlineMemberCount = totalMembers - onlineMemberCount;
|
||||||
|
|
|
@ -36,6 +36,7 @@ import { sendDM } from "./utils/sendDM";
|
||||||
import { waitForButtonConfirm } from "./utils/waitForInteraction";
|
import { waitForButtonConfirm } from "./utils/waitForInteraction";
|
||||||
import { decodeAndValidateStrict, StrictValidationError } from "./validatorUtils";
|
import { decodeAndValidateStrict, StrictValidationError } from "./validatorUtils";
|
||||||
import { isEqual } from "lodash";
|
import { isEqual } from "lodash";
|
||||||
|
import humanizeDuration from "humanize-duration";
|
||||||
|
|
||||||
const fsp = fs.promises;
|
const fsp = fs.promises;
|
||||||
|
|
||||||
|
@ -184,8 +185,28 @@ export function getScalarDifference<T>(
|
||||||
return diff;
|
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 {
|
export function differenceToString(diff: Map<string, { was: any; is: any }>): string {
|
||||||
let toReturn = "";
|
let toReturn = "";
|
||||||
|
diff = prettyDifference(diff);
|
||||||
for (const [key, difference] of diff) {
|
for (const [key, difference] of diff) {
|
||||||
toReturn += `${key[0].toUpperCase() + key.slice(1)}: \`${difference.was}\` ➜ \`${difference.is}\`\n`;
|
toReturn += `${key[0].toUpperCase() + key.slice(1)}: \`${difference.was}\` ➜ \`${difference.is}\`\n`;
|
||||||
}
|
}
|
||||||
|
|
116
backend/src/utils/configAccessibleObjects.ts
Normal file
116
backend/src/utils/configAccessibleObjects.ts
Normal 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;
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue