3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-11 04:45:02 +00:00

More Automod updates

This commit is contained in:
Dragory 2020-07-28 21:51:58 +03:00
parent e359fc46b2
commit 07da88b7cb
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
13 changed files with 88 additions and 28 deletions

View file

@ -6,6 +6,7 @@ import { resolveActionContactMethods } from "../functions/resolveActionContactMe
import { ModActionsPlugin } from "../../ModActions/ModActionsPlugin";
import { TextChannel } from "eris";
import { renderTemplate } from "../../../templateFormatter";
import { LogsPlugin } from "../../Logs/LogsPlugin";
export const AlertAction = automodAction({
configType: t.type({
@ -15,6 +16,7 @@ export const AlertAction = automodAction({
async apply({ pluginData, contexts, actionConfig, ruleName, matchResult }) {
const channel = pluginData.guild.channels.get(actionConfig.channel);
const logs = pluginData.getPlugin(LogsPlugin);
if (channel && channel instanceof TextChannel) {
const text = actionConfig.text;
@ -23,26 +25,31 @@ export const AlertAction = automodAction({
const safeUsers = contexts.map(c => c.user && stripObjectToScalars(c.user)).filter(Boolean);
const safeUser = safeUsers[0];
const actionsTaken = Object.keys(pluginData.config.get().rules[ruleName].actions);
const takenActions = Object.keys(pluginData.config.get().rules[ruleName].actions);
// TODO: Generate logMessage
const logMessage = "";
const logMessage = logs.getLogMessage(LogType.AUTOMOD_ACTION, {
rule: ruleName,
user: safeUser,
users: safeUsers,
actionsTaken,
matchSummary: matchResult.summary,
});
const rendered = await renderTemplate(actionConfig.text, {
rule: ruleName,
user: safeUser,
users: safeUsers,
text,
actionsTaken,
matchSummary: matchResult.summary,
messageLink: theMessageLink,
logMessage,
});
channel.createMessage(rendered);
} else {
// TODO: Post BOT_ALERT log
/*this.getLogs().log(LogType.BOT_ALERT, {
body: `Invalid channel id \`${actionConfig.channel}\` for alert action in automod rule **${rule.name}**`,
});*/
logs.log(LogType.BOT_ALERT, {
body: `Invalid channel id \`${actionConfig.channel}\` for alert action in automod rule **${ruleName}**`,
});
}
},
});

View file

@ -13,7 +13,7 @@ export const BanAction = automodAction({
deleteMessageDays: tNullable(t.number),
}),
async apply({ pluginData, contexts, actionConfig }) {
async apply({ pluginData, contexts, actionConfig, matchResult }) {
const reason = actionConfig.reason || "Kicked automatically";
const contactMethods = resolveActionContactMethods(pluginData, actionConfig);
const deleteMessageDays = actionConfig.deleteMessageDays;
@ -21,7 +21,7 @@ export const BanAction = automodAction({
const caseArgs = {
modId: pluginData.client.user.id,
extraNotes: [
/* TODO */
matchResult.summary, // TODO
],
};

View file

@ -1,9 +1,7 @@
import * as t from "io-ts";
import { automodAction } from "../helpers";
import { LogType } from "../../../data/LogType";
import { asyncMap, resolveMember, tNullable } from "../../../utils";
import { resolveActionContactMethods } from "../functions/resolveActionContactMethods";
import { ModActionsPlugin } from "../../ModActions/ModActionsPlugin";
import { LogsPlugin } from "../../Logs/LogsPlugin";
export const ChangeNicknameAction = automodAction({
configType: t.type({
@ -18,7 +16,9 @@ export const ChangeNicknameAction = automodAction({
if (pluginData.state.recentNicknameChanges.has(member.id)) continue;
member.edit({ nick: actionConfig.name }).catch(err => {
/* TODO: Log this error */
pluginData.getPlugin(LogsPlugin).log(LogType.BOT_ALERT, {
body: `Failed to change the nickname of \`${member.id}\``,
});
});
pluginData.state.recentNicknameChanges.set(member.id, { timestamp: Date.now() });

View file

@ -12,14 +12,14 @@ export const KickAction = automodAction({
notifyChannel: tNullable(t.string),
}),
async apply({ pluginData, contexts, actionConfig }) {
async apply({ pluginData, contexts, actionConfig, matchResult }) {
const reason = actionConfig.reason || "Kicked automatically";
const contactMethods = resolveActionContactMethods(pluginData, actionConfig);
const caseArgs = {
modId: pluginData.client.user.id,
extraNotes: [
/* TODO */
matchResult.summary, // TODO
],
};

View file

@ -1,10 +1,23 @@
import * as t from "io-ts";
import { automodAction } from "../helpers";
import { LogsPlugin } from "../../Logs/LogsPlugin";
import { LogType } from "../../../data/LogType";
import { stripObjectToScalars } from "../../../utils";
export const LogAction = automodAction({
configType: t.boolean,
async apply({ pluginData, contexts, actionConfig }) {
// TODO: Everything
async apply({ pluginData, contexts, ruleName, matchResult }) {
const safeUsers = contexts.map(c => c.user && stripObjectToScalars(c.user)).filter(Boolean);
const safeUser = safeUsers[0];
const actionsTaken = Object.keys(pluginData.config.get().rules[ruleName].actions);
pluginData.getPlugin(LogsPlugin).log(LogType.AUTOMOD_ACTION, {
rule: ruleName,
user: safeUser,
users: safeUsers,
actionsTaken,
matchSummary: matchResult.summary,
});
},
});

View file

@ -14,7 +14,7 @@ export const MuteAction = automodAction({
notifyChannel: tNullable(t.string),
}),
async apply({ pluginData, contexts, actionConfig }) {
async apply({ pluginData, contexts, actionConfig, matchResult }) {
const duration = actionConfig.duration ? convertDelayStringToMS(actionConfig.duration) : null;
const reason = actionConfig.reason || "Muted automatically";
const contactMethods = resolveActionContactMethods(pluginData, actionConfig);
@ -22,7 +22,7 @@ export const MuteAction = automodAction({
const caseArgs = {
modId: pluginData.client.user.id,
extraNotes: [
/* TODO */
matchResult.summary, // TODO
],
};

View file

@ -12,14 +12,14 @@ export const WarnAction = automodAction({
notifyChannel: tNullable(t.string),
}),
async apply({ pluginData, contexts, actionConfig }) {
async apply({ pluginData, contexts, actionConfig, matchResult }) {
const reason = actionConfig.reason || "Warned automatically";
const contactMethods = resolveActionContactMethods(pluginData, actionConfig);
const caseArgs = {
modId: pluginData.client.user.id,
extraNotes: [
/* TODO */
matchResult.summary, // TODO
],
};