mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 12:25:02 +00:00
feat: use webhooks for logs when possible
This commit is contained in:
parent
1081d1b361
commit
55a39e0758
12 changed files with 318 additions and 29 deletions
|
@ -112,6 +112,7 @@ import { logVoiceChannelLeave } from "./logFunctions/logVoiceChannelLeave";
|
|||
import { logVoiceChannelMove } from "./logFunctions/logVoiceChannelMove";
|
||||
import { logMemberTimedUnban } from "./logFunctions/logMemberTimedUnban";
|
||||
import { logDmFailed } from "./logFunctions/logDmFailed";
|
||||
import { InternalPosterPlugin } from "../InternalPoster/InternalPosterPlugin";
|
||||
|
||||
const defaultOptions: PluginOptions<LogsPluginType> = {
|
||||
config: {
|
||||
|
@ -145,6 +146,7 @@ export const LogsPlugin = zeppelinGuildPlugin<LogsPluginType>()({
|
|||
|
||||
dependencies: async () => [
|
||||
TimeAndDatePlugin,
|
||||
InternalPosterPlugin,
|
||||
// The `as any` cast here is to prevent TypeScript from locking up from the circular dependency
|
||||
((await import("../Cases/CasesPlugin")) as any).CasesPlugin,
|
||||
],
|
||||
|
|
|
@ -7,6 +7,7 @@ import { TypedTemplateSafeValueContainer } from "../../../templateFormatter";
|
|||
import { LogType } from "../../../data/LogType";
|
||||
import { MessageBuffer } from "../../../utils/MessageBuffer";
|
||||
import { createChunkedMessage, isDiscordAPIError, MINUTES } from "../../../utils";
|
||||
import { InternalPosterPlugin } from "../../InternalPoster/InternalPosterPlugin";
|
||||
|
||||
const excludedUserProps = ["user", "member", "mod"];
|
||||
const excludedRoleProps = ["message.member.roles", "member.roles"];
|
||||
|
@ -98,6 +99,7 @@ export async function log<TLogType extends keyof ILogTypeData>(
|
|||
// Initialize message buffer for this channel
|
||||
if (!pluginData.state.buffers.has(channelId)) {
|
||||
const batchTime = Math.min(Math.max(opts.batch_time ?? DEFAULT_BATCH_TIME, MIN_BATCH_TIME), MAX_BATCH_TIME);
|
||||
const internalPosterPlugin = pluginData.getPlugin(InternalPosterPlugin);
|
||||
pluginData.state.buffers.set(
|
||||
channelId,
|
||||
new MessageBuffer({
|
||||
|
@ -105,26 +107,26 @@ export async function log<TLogType extends keyof ILogTypeData>(
|
|||
textSeparator: "\n",
|
||||
consume: (part) => {
|
||||
const parse: MessageMentionTypes[] = pluginData.config.get().allow_user_mentions ? ["users"] : [];
|
||||
const promise =
|
||||
part.content && !part.embeds?.length
|
||||
? createChunkedMessage(channel, part.content, { parse })
|
||||
: channel.send({
|
||||
...part,
|
||||
allowedMentions: { parse },
|
||||
});
|
||||
promise.catch((err) => {
|
||||
if (isDiscordAPIError(err)) {
|
||||
// Missing Access / Missing Permissions
|
||||
// TODO: Show/log this somewhere
|
||||
if (err.code === 50001 || err.code === 50013) {
|
||||
pluginData.state.channelCooldowns.setCooldown(channelId, 2 * MINUTES);
|
||||
return;
|
||||
internalPosterPlugin
|
||||
.sendMessage(channel, {
|
||||
...part,
|
||||
allowedMentions: { parse },
|
||||
})
|
||||
.catch((err) => {
|
||||
if (isDiscordAPIError(err)) {
|
||||
// Missing Access / Missing Permissions
|
||||
// TODO: Show/log this somewhere
|
||||
if (err.code === 50001 || err.code === 50013) {
|
||||
pluginData.state.channelCooldowns.setCooldown(channelId, 2 * MINUTES);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// tslint:disable-next-line:no-console
|
||||
console.warn(`Error while sending ${typeStr} log to ${pluginData.guild.id}/${channelId}: ${err.message}`);
|
||||
});
|
||||
// tslint:disable-next-line:no-console
|
||||
console.warn(
|
||||
`Error while sending ${typeStr} log to ${pluginData.guild.id}/${channelId}: ${err.message}`,
|
||||
);
|
||||
});
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue