mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-16 14:11:50 +00:00
Add a generic bot alert log type. Use this in several places.
This commit is contained in:
parent
e18193c1a2
commit
8a3097f63e
8 changed files with 110 additions and 27 deletions
|
@ -55,5 +55,7 @@
|
||||||
"MEMBER_MUTE_REJOIN": "⚠ Reapplied active mute for {userMention(member)} on rejoin",
|
"MEMBER_MUTE_REJOIN": "⚠ Reapplied active mute for {userMention(member)} on rejoin",
|
||||||
|
|
||||||
"SCHEDULED_MESSAGE": "⏰ {userMention(author)} scheduled a message to be posted to {channelMention(channel)} on {date} at {time} (UTC)",
|
"SCHEDULED_MESSAGE": "⏰ {userMention(author)} scheduled a message to be posted to {channelMention(channel)} on {date} at {time} (UTC)",
|
||||||
"POSTED_SCHEDULED_MESSAGE": "\uD83D\uDCE8 Posted scheduled message (`{messageId}`) to {channelMention(channel)} as scheduled by {userMention(author)}"
|
"POSTED_SCHEDULED_MESSAGE": "\uD83D\uDCE8 Posted scheduled message (`{messageId}`) to {channelMention(channel)} as scheduled by {userMention(author)}",
|
||||||
|
|
||||||
|
"BOT_ALERT": "⚠ {tmplEval(body)}"
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,4 +56,6 @@ export enum LogType {
|
||||||
|
|
||||||
SCHEDULED_MESSAGE,
|
SCHEDULED_MESSAGE,
|
||||||
POSTED_SCHEDULED_MESSAGE,
|
POSTED_SCHEDULED_MESSAGE,
|
||||||
|
|
||||||
|
BOT_ALERT,
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,8 @@ import { CaseTypeColors } from "../data/CaseTypeColors";
|
||||||
import { ZeppelinPlugin } from "./ZeppelinPlugin";
|
import { ZeppelinPlugin } from "./ZeppelinPlugin";
|
||||||
import { GuildArchives } from "../data/GuildArchives";
|
import { GuildArchives } from "../data/GuildArchives";
|
||||||
import { IPluginOptions } from "knub";
|
import { IPluginOptions } from "knub";
|
||||||
|
import { GuildLogs } from "../data/GuildLogs";
|
||||||
|
import { LogType } from "../data/LogType";
|
||||||
|
|
||||||
interface ICasesPluginConfig {
|
interface ICasesPluginConfig {
|
||||||
log_automatic_actions: boolean;
|
log_automatic_actions: boolean;
|
||||||
|
@ -43,6 +45,7 @@ export class CasesPlugin extends ZeppelinPlugin<ICasesPluginConfig> {
|
||||||
|
|
||||||
protected cases: GuildCases;
|
protected cases: GuildCases;
|
||||||
protected archives: GuildArchives;
|
protected archives: GuildArchives;
|
||||||
|
protected logs: GuildLogs;
|
||||||
|
|
||||||
getDefaultOptions(): IPluginOptions<ICasesPluginConfig> {
|
getDefaultOptions(): IPluginOptions<ICasesPluginConfig> {
|
||||||
return {
|
return {
|
||||||
|
@ -56,11 +59,7 @@ export class CasesPlugin extends ZeppelinPlugin<ICasesPluginConfig> {
|
||||||
onLoad() {
|
onLoad() {
|
||||||
this.cases = GuildCases.getInstance(this.guildId);
|
this.cases = GuildCases.getInstance(this.guildId);
|
||||||
this.archives = GuildArchives.getInstance(this.guildId);
|
this.archives = GuildArchives.getInstance(this.guildId);
|
||||||
|
this.logs = new GuildLogs(this.guildId);
|
||||||
// this.actions.register("postCase", async args => {
|
|
||||||
// const embed = await this.getCaseEmbed(args.caseId);
|
|
||||||
// return (args.channel as TextableChannel).createMessage(embed);
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected resolveCaseId(caseOrCaseId: Case | number): number {
|
protected resolveCaseId(caseOrCaseId: Case | number): number {
|
||||||
|
@ -124,9 +123,7 @@ export class CasesPlugin extends ZeppelinPlugin<ICasesPluginConfig> {
|
||||||
(!args.automatic || config.log_automatic_actions) &&
|
(!args.automatic || config.log_automatic_actions) &&
|
||||||
args.postInCaseLogOverride !== false
|
args.postInCaseLogOverride !== false
|
||||||
) {
|
) {
|
||||||
try {
|
await this.postCaseToCaseLogChannel(createdCase);
|
||||||
await this.postCaseToCaseLogChannel(createdCase);
|
|
||||||
} catch (e) {} // tslint:disable-line
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return createdCase;
|
return createdCase;
|
||||||
|
@ -173,9 +170,7 @@ export class CasesPlugin extends ZeppelinPlugin<ICasesPluginConfig> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((!args.automatic || this.getConfig().log_automatic_actions) && args.postInCaseLogOverride !== false) {
|
if ((!args.automatic || this.getConfig().log_automatic_actions) && args.postInCaseLogOverride !== false) {
|
||||||
try {
|
await this.postCaseToCaseLogChannel(theCase.id);
|
||||||
await this.postCaseToCaseLogChannel(theCase.id);
|
|
||||||
} catch (e) {} // tslint:disable-line
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,9 +251,19 @@ export class CasesPlugin extends ZeppelinPlugin<ICasesPluginConfig> {
|
||||||
* A helper to post a case embed to the case log channel
|
* A helper to post a case embed to the case log channel
|
||||||
*/
|
*/
|
||||||
public async postCaseToCaseLogChannel(caseOrCaseId: Case | number): Promise<Message> {
|
public async postCaseToCaseLogChannel(caseOrCaseId: Case | number): Promise<Message> {
|
||||||
|
const theCase = await this.cases.find(this.resolveCaseId(caseOrCaseId));
|
||||||
|
if (!theCase) return;
|
||||||
|
|
||||||
const caseEmbed = await this.getCaseEmbed(caseOrCaseId);
|
const caseEmbed = await this.getCaseEmbed(caseOrCaseId);
|
||||||
if (!caseEmbed) return;
|
if (!caseEmbed) return;
|
||||||
|
|
||||||
return this.postToCaseLogChannel(caseEmbed);
|
try {
|
||||||
|
return this.postToCaseLogChannel(caseEmbed);
|
||||||
|
} catch (e) {
|
||||||
|
this.logs.log(LogType.BOT_ALERT, {
|
||||||
|
body: `Failed to post case #${theCase.case_number} to the case log channel`,
|
||||||
|
});
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -169,7 +169,7 @@ export class LogsPlugin extends ZeppelinPlugin<ILogsPluginConfig> {
|
||||||
|
|
||||||
let formatted;
|
let formatted;
|
||||||
try {
|
try {
|
||||||
formatted = await renderTemplate(format, {
|
const values = {
|
||||||
...data,
|
...data,
|
||||||
userMention: async userOrMember => {
|
userMention: async userOrMember => {
|
||||||
if (!userOrMember) return "";
|
if (!userOrMember) return "";
|
||||||
|
@ -217,7 +217,16 @@ export class LogsPlugin extends ZeppelinPlugin<ILogsPluginConfig> {
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
});
|
};
|
||||||
|
|
||||||
|
if (type === LogType.BOT_ALERT) {
|
||||||
|
const valuesWithoutTmplEval = { ...values };
|
||||||
|
values.tmplEval = str => {
|
||||||
|
return renderTemplate(str, valuesWithoutTmplEval);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
formatted = await renderTemplate(format, values);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof TemplateParseError) {
|
if (e instanceof TemplateParseError) {
|
||||||
logger.error(`Error when parsing template:\nError: ${e.message}\nTemplate: ${format}`);
|
logger.error(`Error when parsing template:\nError: ${e.message}\nTemplate: ${format}`);
|
||||||
|
|
|
@ -571,7 +571,12 @@ export class MutesPlugin extends ZeppelinPlugin<IMutesPluginConfig> {
|
||||||
if (member) {
|
if (member) {
|
||||||
try {
|
try {
|
||||||
await member.removeRole(this.getConfig().mute_role);
|
await member.removeRole(this.getConfig().mute_role);
|
||||||
} catch (e) {} // tslint:disable-line
|
} catch (e) {
|
||||||
|
this.serverLogs.log(LogType.BOT_ALERT, {
|
||||||
|
body: `Failed to remove mute role from {userMention(member)}`,
|
||||||
|
member: stripObjectToScalars(member),
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.mutes.clear(mute.user_id);
|
await this.mutes.clear(mute.user_id);
|
||||||
|
|
|
@ -152,16 +152,26 @@ export class PostPlugin extends ZeppelinPlugin<IPostPluginConfig> {
|
||||||
for (const post of duePosts) {
|
for (const post of duePosts) {
|
||||||
const channel = this.guild.channels.get(post.channel_id);
|
const channel = this.guild.channels.get(post.channel_id);
|
||||||
if (channel instanceof TextChannel) {
|
if (channel instanceof TextChannel) {
|
||||||
|
const [username, discriminator] = post.author_name.split("#");
|
||||||
|
const author: Partial<User> = this.bot.users.get(post.author_id) || {
|
||||||
|
id: post.author_id,
|
||||||
|
username,
|
||||||
|
discriminator,
|
||||||
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const postedMessage = await this.postMessage(channel, post.content, post.attachments, post.enable_mentions);
|
const postedMessage = await this.postMessage(channel, post.content, post.attachments, post.enable_mentions);
|
||||||
|
|
||||||
const [username, discriminator] = post.author_name.split("#");
|
|
||||||
this.logs.log(LogType.POSTED_SCHEDULED_MESSAGE, {
|
this.logs.log(LogType.POSTED_SCHEDULED_MESSAGE, {
|
||||||
author: ({ id: post.author_id, username, discriminator } as any) as Partial<User>,
|
author: stripObjectToScalars(author),
|
||||||
channel: stripObjectToScalars(channel),
|
channel: stripObjectToScalars(channel),
|
||||||
messageId: postedMessage.id,
|
messageId: postedMessage.id,
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
this.logs.log(LogType.BOT_ALERT, {
|
||||||
|
body: `Failed to post scheduled message by {userMention(author)} to {channelMention(channel)}`,
|
||||||
|
channel: stripObjectToScalars(channel),
|
||||||
|
author: stripObjectToScalars(author),
|
||||||
|
});
|
||||||
logger.warn(
|
logger.warn(
|
||||||
`Failed to post scheduled message to #${channel.name} (${channel.id}) on ${this.guild.name} (${
|
`Failed to post scheduled message to #${channel.name} (${channel.id}) on ${this.guild.name} (${
|
||||||
this.guildId
|
this.guildId
|
||||||
|
|
|
@ -1,12 +1,22 @@
|
||||||
import { decorators as d, IPluginOptions, logger } from "knub";
|
import { decorators as d, IPluginOptions, logger } from "knub";
|
||||||
import { GuildChannel, Message, TextChannel, Constants as ErisConstants, User } from "eris";
|
import { GuildChannel, Message, TextChannel, Constants as ErisConstants, User } from "eris";
|
||||||
import { convertDelayStringToMS, createChunkedMessage, errorMessage, noop, successMessage } from "../utils";
|
import {
|
||||||
|
convertDelayStringToMS,
|
||||||
|
createChunkedMessage,
|
||||||
|
errorMessage,
|
||||||
|
noop,
|
||||||
|
stripObjectToScalars,
|
||||||
|
successMessage,
|
||||||
|
UnknownUser,
|
||||||
|
} from "../utils";
|
||||||
import { GuildSlowmodes } from "../data/GuildSlowmodes";
|
import { GuildSlowmodes } from "../data/GuildSlowmodes";
|
||||||
import humanizeDuration from "humanize-duration";
|
import humanizeDuration from "humanize-duration";
|
||||||
import { ZeppelinPlugin } from "./ZeppelinPlugin";
|
import { ZeppelinPlugin } from "./ZeppelinPlugin";
|
||||||
import { SavedMessage } from "../data/entities/SavedMessage";
|
import { SavedMessage } from "../data/entities/SavedMessage";
|
||||||
import { GuildSavedMessages } from "../data/GuildSavedMessages";
|
import { GuildSavedMessages } from "../data/GuildSavedMessages";
|
||||||
import DiscordRESTError from "eris/lib/errors/DiscordRESTError"; // tslint:disable-line
|
import DiscordRESTError from "eris/lib/errors/DiscordRESTError"; // tslint:disable-line
|
||||||
|
import { GuildLogs } from "../data/GuildLogs";
|
||||||
|
import { LogType } from "../data/LogType";
|
||||||
|
|
||||||
const NATIVE_SLOWMODE_LIMIT = 6 * 60 * 60; // 6 hours
|
const NATIVE_SLOWMODE_LIMIT = 6 * 60 * 60; // 6 hours
|
||||||
const MAX_SLOWMODE = 60 * 60 * 24 * 365 * 100; // 100 years
|
const MAX_SLOWMODE = 60 * 60 * 24 * 365 * 100; // 100 years
|
||||||
|
@ -24,6 +34,7 @@ export class SlowmodePlugin extends ZeppelinPlugin<ISlowmodePluginConfig> {
|
||||||
|
|
||||||
protected slowmodes: GuildSlowmodes;
|
protected slowmodes: GuildSlowmodes;
|
||||||
protected savedMessages: GuildSavedMessages;
|
protected savedMessages: GuildSavedMessages;
|
||||||
|
protected logs: GuildLogs;
|
||||||
protected clearInterval;
|
protected clearInterval;
|
||||||
|
|
||||||
private onMessageCreateFn;
|
private onMessageCreateFn;
|
||||||
|
@ -52,6 +63,7 @@ export class SlowmodePlugin extends ZeppelinPlugin<ISlowmodePluginConfig> {
|
||||||
onLoad() {
|
onLoad() {
|
||||||
this.slowmodes = GuildSlowmodes.getInstance(this.guildId);
|
this.slowmodes = GuildSlowmodes.getInstance(this.guildId);
|
||||||
this.savedMessages = GuildSavedMessages.getInstance(this.guildId);
|
this.savedMessages = GuildSavedMessages.getInstance(this.guildId);
|
||||||
|
this.logs = new GuildLogs(this.guildId);
|
||||||
this.clearInterval = setInterval(() => this.clearExpiredSlowmodes(), BOT_SLOWMODE_CLEAR_INTERVAL);
|
this.clearInterval = setInterval(() => this.clearExpiredSlowmodes(), BOT_SLOWMODE_CLEAR_INTERVAL);
|
||||||
|
|
||||||
this.onMessageCreateFn = this.onMessageCreate.bind(this);
|
this.onMessageCreateFn = this.onMessageCreate.bind(this);
|
||||||
|
@ -78,13 +90,25 @@ export class SlowmodePlugin extends ZeppelinPlugin<ISlowmodePluginConfig> {
|
||||||
try {
|
try {
|
||||||
await channel.editPermission(userId, newAllowedPermissions, newDeniedPermissions, "member");
|
await channel.editPermission(userId, newAllowedPermissions, newDeniedPermissions, "member");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
const user = this.bot.users.get(userId) || new UnknownUser({ id: userId });
|
||||||
|
|
||||||
if (e instanceof DiscordRESTError && e.code === 50013) {
|
if (e instanceof DiscordRESTError && e.code === 50013) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
`Missing permissions to apply bot slowmode to user ${userId} on channel ${channel.name} (${
|
`Missing permissions to apply bot slowmode to user ${userId} on channel ${channel.name} (${
|
||||||
channel.id
|
channel.id
|
||||||
}) on server ${this.guild.name} (${this.guildId})`,
|
}) on server ${this.guild.name} (${this.guildId})`,
|
||||||
);
|
);
|
||||||
|
this.logs.log(LogType.BOT_ALERT, {
|
||||||
|
body: `Missing permissions to apply bot slowmode to {userMention(user)} in {channelMention(channel)}`,
|
||||||
|
user: stripObjectToScalars(user),
|
||||||
|
channel: stripObjectToScalars(channel),
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
|
this.logs.log(LogType.BOT_ALERT, {
|
||||||
|
body: `Failed to apply bot slowmode to {userMention(user)} in {channelMention(channel)}`,
|
||||||
|
user: stripObjectToScalars(user),
|
||||||
|
channel: stripObjectToScalars(channel),
|
||||||
|
});
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -190,11 +214,18 @@ export class SlowmodePlugin extends ZeppelinPlugin<ISlowmodePluginConfig> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.clearBotSlowmodeFromUserId(args.channel, args.user.id);
|
try {
|
||||||
msg.channel.createMessage(
|
await this.clearBotSlowmodeFromUserId(args.channel, args.user.id);
|
||||||
successMessage(
|
} catch (e) {
|
||||||
`Slowmode cleared from **${args.user.username}#${args.user.discriminator}** in <#${args.channel.id}>`,
|
return this.sendErrorMessage(
|
||||||
),
|
msg.channel,
|
||||||
|
`Failed to clear slowmode from **${args.user.username}#${args.user.discriminator}** in <#${args.channel.id}>`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.sendSuccessMessage(
|
||||||
|
msg.channel,
|
||||||
|
`Slowmode cleared from **${args.user.username}#${args.user.discriminator}** in <#${args.channel.id}>`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,8 @@ import { decorators as d, IPluginOptions } from "knub";
|
||||||
import { Member, TextChannel } from "eris";
|
import { Member, TextChannel } from "eris";
|
||||||
import { renderTemplate } from "../templateFormatter";
|
import { renderTemplate } from "../templateFormatter";
|
||||||
import { createChunkedMessage, stripObjectToScalars } from "../utils";
|
import { createChunkedMessage, stripObjectToScalars } from "../utils";
|
||||||
|
import { LogType } from "../data/LogType";
|
||||||
|
import { GuildLogs } from "../data/GuildLogs";
|
||||||
|
|
||||||
interface IWelcomeMessageConfig {
|
interface IWelcomeMessageConfig {
|
||||||
send_dm: boolean;
|
send_dm: boolean;
|
||||||
|
@ -13,6 +15,8 @@ interface IWelcomeMessageConfig {
|
||||||
export class WelcomeMessagePlugin extends ZeppelinPlugin<IWelcomeMessageConfig> {
|
export class WelcomeMessagePlugin extends ZeppelinPlugin<IWelcomeMessageConfig> {
|
||||||
public static pluginName = "welcome_message";
|
public static pluginName = "welcome_message";
|
||||||
|
|
||||||
|
protected logs: GuildLogs;
|
||||||
|
|
||||||
protected getDefaultOptions(): IPluginOptions<IWelcomeMessageConfig> {
|
protected getDefaultOptions(): IPluginOptions<IWelcomeMessageConfig> {
|
||||||
return {
|
return {
|
||||||
config: {
|
config: {
|
||||||
|
@ -23,6 +27,10 @@ export class WelcomeMessagePlugin extends ZeppelinPlugin<IWelcomeMessageConfig>
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected onLoad() {
|
||||||
|
this.logs = new GuildLogs(this.guildId);
|
||||||
|
}
|
||||||
|
|
||||||
@d.event("guildMemberAdd")
|
@d.event("guildMemberAdd")
|
||||||
async onGuildMemberAdd(_, member: Member) {
|
async onGuildMemberAdd(_, member: Member) {
|
||||||
const config = this.getConfig();
|
const config = this.getConfig();
|
||||||
|
@ -39,7 +47,12 @@ export class WelcomeMessagePlugin extends ZeppelinPlugin<IWelcomeMessageConfig>
|
||||||
|
|
||||||
try {
|
try {
|
||||||
createChunkedMessage(dmChannel, formatted);
|
createChunkedMessage(dmChannel, formatted);
|
||||||
} catch (e) {} // tslint:disable-line
|
} catch (e) {
|
||||||
|
this.logs.log(LogType.BOT_ALERT, {
|
||||||
|
body: `Failed send a welcome DM to {userMention(member)}`,
|
||||||
|
member: stripObjectToScalars(member),
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.send_to_channel) {
|
if (config.send_to_channel) {
|
||||||
|
@ -48,7 +61,13 @@ export class WelcomeMessagePlugin extends ZeppelinPlugin<IWelcomeMessageConfig>
|
||||||
|
|
||||||
try {
|
try {
|
||||||
createChunkedMessage(channel, formatted);
|
createChunkedMessage(channel, formatted);
|
||||||
} catch (e) {} // tslint:disable-line
|
} catch (e) {
|
||||||
|
this.logs.log(LogType.BOT_ALERT, {
|
||||||
|
body: `Failed send a welcome message for {userMention(member)} to {channelMention(channel)}`,
|
||||||
|
member: stripObjectToScalars(member),
|
||||||
|
channel: stripObjectToScalars(channel),
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue