3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-16 14:11:50 +00:00

Support excluding users from being logged

This commit is contained in:
Dragory 2019-04-21 18:11:49 +03:00
parent f45e745d54
commit 38b11775e5

View file

@ -30,22 +30,16 @@ interface ILogChannel {
exclude?: string[]; exclude?: string[];
batched?: boolean; batched?: boolean;
batch_time?: number; batch_time?: number;
excluded_users?: string[];
} }
interface ILogChannelMap { interface ILogChannelMap {
[channelId: string]: ILogChannel; [channelId: string]: ILogChannel;
} }
interface IChannelConfig {
include?: string[];
exclude?: string[];
batched?: boolean;
batch_time?: number;
}
interface ILogsPluginConfig { interface ILogsPluginConfig {
channels: { channels: {
[key: string]: IChannelConfig; [key: string]: ILogChannel;
}; };
format: { format: {
[key: string]: string; [key: string]: string;
@ -71,6 +65,8 @@ export class LogsPlugin extends ZeppelinPlugin<ILogsPluginConfig> {
private onMessageDeleteBulkFn; private onMessageDeleteBulkFn;
private onMessageUpdateFn; private onMessageUpdateFn;
private excludedUserProps = ["user", "member", "mod"];
getDefaultOptions(): IPluginOptions<ILogsPluginConfig> { getDefaultOptions(): IPluginOptions<ILogsPluginConfig> {
return { return {
config: { config: {
@ -126,11 +122,21 @@ export class LogsPlugin extends ZeppelinPlugin<ILogsPluginConfig> {
const logChannels: ILogChannelMap = this.getConfig().channels; const logChannels: ILogChannelMap = this.getConfig().channels;
const typeStr = LogType[type]; const typeStr = LogType[type];
for (const [channelId, opts] of Object.entries(logChannels)) { logChannelLoop: for (const [channelId, opts] of Object.entries(logChannels)) {
const channel = this.guild.channels.get(channelId); const channel = this.guild.channels.get(channelId);
if (!channel || !(channel instanceof TextChannel)) continue; if (!channel || !(channel instanceof TextChannel)) continue;
if ((opts.include && opts.include.includes(typeStr)) || (opts.exclude && !opts.exclude.includes(typeStr))) { if ((opts.include && opts.include.includes(typeStr)) || (opts.exclude && !opts.exclude.includes(typeStr))) {
// If this log entry is about an excluded user, skip it
// TODO: Quick and dirty solution, look into changing at some point
if (opts.excluded_users) {
for (const prop of this.excludedUserProps) {
if (data && data[prop] && opts.excluded_users.includes(data[prop].id)) {
continue logChannelLoop;
}
}
}
const message = await this.getLogMessage(type, data); const message = await this.getLogMessage(type, data);
if (message) { if (message) {
if (opts.batched) { if (opts.batched) {