Disable mentions in logs, allowing mods to be mentioned (#142)
Optionally you can return to old behavior by setting allow_user_mentions to true
This commit is contained in:
parent
dea3c2516c
commit
f762a238de
5 changed files with 21 additions and 8 deletions
|
@ -31,7 +31,8 @@ const defaultOptions: PluginOptions<LogsPluginType> = {
|
|||
timestamp: FORMAT_NO_TIMESTAMP, // Legacy/deprecated, use timestamp_format below instead
|
||||
...DefaultLogMessages,
|
||||
},
|
||||
ping_user: true,
|
||||
ping_user: true, // Legacy/deprecated, if below is false mentions wont actually ping. In case you really want the old behavior, set below to true
|
||||
allow_user_mentions: false,
|
||||
timestamp_format: "YYYY-MM-DD HH:mm:ss z",
|
||||
include_embed_timestamp: true,
|
||||
},
|
||||
|
@ -40,7 +41,7 @@ const defaultOptions: PluginOptions<LogsPluginType> = {
|
|||
{
|
||||
level: ">=50",
|
||||
config: {
|
||||
ping_user: false,
|
||||
ping_user: false, // Legacy/deprecated, read comment on global ping_user option
|
||||
},
|
||||
},
|
||||
],
|
||||
|
|
|
@ -38,7 +38,8 @@ export const ConfigSchema = t.type({
|
|||
timestamp: t.string, // Legacy/deprecated
|
||||
}),
|
||||
]),
|
||||
ping_user: t.boolean,
|
||||
ping_user: t.boolean, // Legacy/deprecated, if below is false mentions wont actually ping
|
||||
allow_user_mentions: t.boolean,
|
||||
timestamp_format: t.string,
|
||||
include_embed_timestamp: t.boolean,
|
||||
});
|
||||
|
|
|
@ -61,7 +61,12 @@ export async function getLogMessage(
|
|||
|
||||
const memberConfig = pluginData.config.getMatchingConfig({ member, userId: user.id }) || ({} as any);
|
||||
|
||||
mentions.push(memberConfig.ping_user ? verboseUserMention(user) : verboseUserName(user));
|
||||
// Revert to old behavior (verbose name w/o ping if allow_user_mentions is enabled (for whatever reason))
|
||||
if (config.allow_user_mentions) {
|
||||
mentions.push(memberConfig.ping_user ? verboseUserMention(user) : verboseUserName(user));
|
||||
} else {
|
||||
mentions.push(verboseUserMention(user));
|
||||
}
|
||||
}
|
||||
|
||||
return mentions.join(", ");
|
||||
|
|
|
@ -103,6 +103,7 @@ export async function log(pluginData: GuildPluginData<LogsPluginType>, type: Log
|
|||
// Default to batched unless explicitly disabled
|
||||
const batched = opts.batched ?? true;
|
||||
const batchTime = opts.batch_time ?? 1000;
|
||||
const cfg = pluginData.config.get();
|
||||
|
||||
if (batched) {
|
||||
// If we're batching log messages, gather all log messages within the set batch_time into a single message
|
||||
|
@ -111,14 +112,14 @@ export async function log(pluginData: GuildPluginData<LogsPluginType>, type: Log
|
|||
setTimeout(async () => {
|
||||
const batchedMessage = pluginData.state.batches.get(channel.id)!.join("\n");
|
||||
pluginData.state.batches.delete(channel.id);
|
||||
createChunkedMessage(channel, batchedMessage).catch(noop);
|
||||
createChunkedMessage(channel, batchedMessage, { users: cfg.allow_user_mentions }).catch(noop);
|
||||
}, batchTime);
|
||||
}
|
||||
|
||||
pluginData.state.batches.get(channel.id)!.push(message);
|
||||
} else {
|
||||
// If we're not batching log messages, just send them immediately
|
||||
await createChunkedMessage(channel, message).catch(noop);
|
||||
await createChunkedMessage(channel, message, { users: cfg.allow_user_mentions }).catch(noop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import {
|
||||
AllowedMentions,
|
||||
Attachment,
|
||||
Client,
|
||||
Constants,
|
||||
|
@ -748,10 +749,14 @@ export function chunkMessageLines(str: string, maxChunkLength = 1990): string[]
|
|||
});
|
||||
}
|
||||
|
||||
export async function createChunkedMessage(channel: TextableChannel, messageText: string) {
|
||||
export async function createChunkedMessage(
|
||||
channel: TextableChannel,
|
||||
messageText: string,
|
||||
allowedMentions?: AllowedMentions,
|
||||
) {
|
||||
const chunks = chunkMessageLines(messageText);
|
||||
for (const chunk of chunks) {
|
||||
await channel.createMessage(chunk);
|
||||
await channel.createMessage({ content: chunk, allowedMentions });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue