More rework progress, remove all eris imports
This commit is contained in:
parent
8f7a6510eb
commit
52839cc9f3
181 changed files with 352 additions and 343 deletions
|
@ -1,17 +1,16 @@
|
|||
import { Permissions } from "discord.js";
|
||||
import * as t from "io-ts";
|
||||
import { automodAction } from "../helpers";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { nonNullish, unique } from "../../../utils";
|
||||
import { Constants } from "eris";
|
||||
import { hasDiscordPermissions } from "../../../utils/hasDiscordPermissions";
|
||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||
import { getMissingPermissions } from "../../../utils/getMissingPermissions";
|
||||
import { canAssignRole } from "../../../utils/canAssignRole";
|
||||
import { missingPermissionError } from "../../../utils/missingPermissionError";
|
||||
import { ignoreRoleChange } from "../functions/ignoredRoleChanges";
|
||||
import { getMissingPermissions } from "../../../utils/getMissingPermissions";
|
||||
import { memberRolesLock } from "../../../utils/lockNameHelpers";
|
||||
import { missingPermissionError } from "../../../utils/missingPermissionError";
|
||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||
import { ignoreRoleChange } from "../functions/ignoredRoleChanges";
|
||||
import { automodAction } from "../helpers";
|
||||
|
||||
const p = Constants.Permissions;
|
||||
const p = Permissions.FLAGS;
|
||||
|
||||
export const AddRolesAction = automodAction({
|
||||
configType: t.array(t.string),
|
||||
|
@ -19,9 +18,9 @@ export const AddRolesAction = automodAction({
|
|||
|
||||
async apply({ pluginData, contexts, actionConfig, ruleName }) {
|
||||
const members = unique(contexts.map(c => c.member).filter(nonNullish));
|
||||
const me = pluginData.guild.members.get(pluginData.client.user.id)!;
|
||||
const me = pluginData.guild.members.cache.get(pluginData.client.user!.id)!;
|
||||
|
||||
const missingPermissions = getMissingPermissions(me.permission, p.manageRoles);
|
||||
const missingPermissions = getMissingPermissions(me.permissions, p.MANAGE_ROLES);
|
||||
if (missingPermissions) {
|
||||
const logs = pluginData.getPlugin(LogsPlugin);
|
||||
logs.log(LogType.BOT_ALERT, {
|
||||
|
@ -42,7 +41,7 @@ export const AddRolesAction = automodAction({
|
|||
|
||||
if (rolesWeCannotAssign.length) {
|
||||
const roleNamesWeCannotAssign = rolesWeCannotAssign.map(
|
||||
roleId => pluginData.guild.roles.get(roleId)?.name || roleId,
|
||||
roleId => pluginData.guild.roles.cache.get(roleId)?.name || roleId,
|
||||
);
|
||||
const logs = pluginData.getPlugin(LogsPlugin);
|
||||
logs.log(LogType.BOT_ALERT, {
|
||||
|
|
|
@ -2,22 +2,17 @@ import * as t from "io-ts";
|
|||
import { automodAction } from "../helpers";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import {
|
||||
asyncMap,
|
||||
createChunkedMessage,
|
||||
isDiscordRESTError,
|
||||
messageLink,
|
||||
resolveMember,
|
||||
stripObjectToScalars,
|
||||
tAllowedMentions,
|
||||
tNormalizedNullOptional,
|
||||
tNullable,
|
||||
verboseChannelMention,
|
||||
} from "../../../utils";
|
||||
import { resolveActionContactMethods } from "../functions/resolveActionContactMethods";
|
||||
import { ModActionsPlugin } from "../../ModActions/ModActionsPlugin";
|
||||
import { TextChannel } from "eris";
|
||||
import { renderTemplate, TemplateParseError } from "../../../templateFormatter";
|
||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||
import { TextChannel } from "discord.js";
|
||||
import { erisAllowedMentionsToDjsMentionOptions } from "src/utils/erisAllowedMentionsToDjsMentionOptions";
|
||||
|
||||
export const AlertAction = automodAction({
|
||||
configType: t.type({
|
||||
|
@ -29,7 +24,7 @@ export const AlertAction = automodAction({
|
|||
defaultConfig: {},
|
||||
|
||||
async apply({ pluginData, contexts, actionConfig, ruleName, matchResult }) {
|
||||
const channel = pluginData.guild.channels.get(actionConfig.channel);
|
||||
const channel = pluginData.guild.channels.cache.get(actionConfig.channel);
|
||||
const logs = pluginData.getPlugin(LogsPlugin);
|
||||
|
||||
if (channel && channel instanceof TextChannel) {
|
||||
|
@ -73,7 +68,11 @@ export const AlertAction = automodAction({
|
|||
}
|
||||
|
||||
try {
|
||||
await createChunkedMessage(channel, rendered, actionConfig.allowed_mentions);
|
||||
await createChunkedMessage(
|
||||
channel,
|
||||
rendered,
|
||||
erisAllowedMentionsToDjsMentionOptions(actionConfig.allowed_mentions),
|
||||
);
|
||||
} catch (err) {
|
||||
if (err.code === 50001) {
|
||||
logs.log(LogType.BOT_ALERT, {
|
||||
|
|
|
@ -37,7 +37,7 @@ export const BanAction = automodAction({
|
|||
const deleteMessageDays = actionConfig.deleteMessageDays || undefined;
|
||||
|
||||
const caseArgs: Partial<CaseArgs> = {
|
||||
modId: pluginData.client.user.id,
|
||||
modId: pluginData.client.user!.id,
|
||||
extraNotes: matchResult.fullSummary ? [matchResult.fullSummary] : [],
|
||||
automatic: true,
|
||||
postInCaseLogOverride: actionConfig.postInCaseLog ?? undefined,
|
||||
|
|
|
@ -2,6 +2,7 @@ import * as t from "io-ts";
|
|||
import { automodAction } from "../helpers";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { noop } from "../../../utils";
|
||||
import { TextChannel } from "discord.js";
|
||||
|
||||
export const CleanAction = automodAction({
|
||||
configType: t.boolean,
|
||||
|
@ -29,7 +30,8 @@ export const CleanAction = automodAction({
|
|||
pluginData.state.logs.ignoreLog(LogType.MESSAGE_DELETE, id);
|
||||
}
|
||||
|
||||
await pluginData.client.deleteMessages(channelId, messageIds).catch(noop);
|
||||
const channel = pluginData.guild.channels.cache.get(channelId) as TextChannel;
|
||||
await channel.bulkDelete(messageIds).catch(noop);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
|
|
@ -25,7 +25,7 @@ export const KickAction = automodAction({
|
|||
const contactMethods = actionConfig.notify ? resolveActionContactMethods(pluginData, actionConfig) : undefined;
|
||||
|
||||
const caseArgs: Partial<CaseArgs> = {
|
||||
modId: pluginData.client.user.id,
|
||||
modId: pluginData.client.user!.id,
|
||||
extraNotes: matchResult.fullSummary ? [matchResult.fullSummary] : [],
|
||||
automatic: true,
|
||||
postInCaseLogOverride: actionConfig.postInCaseLog ?? undefined,
|
||||
|
|
|
@ -42,7 +42,7 @@ export const MuteAction = automodAction({
|
|||
const rolesToRestore = actionConfig.restore_roles_on_mute;
|
||||
|
||||
const caseArgs: Partial<CaseArgs> = {
|
||||
modId: pluginData.client.user.id,
|
||||
modId: pluginData.client.user!.id,
|
||||
extraNotes: matchResult.fullSummary ? [matchResult.fullSummary] : [],
|
||||
automatic: true,
|
||||
postInCaseLogOverride: actionConfig.postInCaseLog ?? undefined,
|
||||
|
|
|
@ -8,11 +8,12 @@ import { getMissingPermissions } from "../../../utils/getMissingPermissions";
|
|||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||
import { missingPermissionError } from "../../../utils/missingPermissionError";
|
||||
import { canAssignRole } from "../../../utils/canAssignRole";
|
||||
import { Constants } from "eris";
|
||||
|
||||
import { ignoreRoleChange } from "../functions/ignoredRoleChanges";
|
||||
import { memberRolesLock } from "../../../utils/lockNameHelpers";
|
||||
import { Permissions } from "discord.js";
|
||||
|
||||
const p = Constants.Permissions;
|
||||
const p = Permissions.FLAGS;
|
||||
|
||||
export const RemoveRolesAction = automodAction({
|
||||
configType: t.array(t.string),
|
||||
|
@ -21,9 +22,9 @@ export const RemoveRolesAction = automodAction({
|
|||
|
||||
async apply({ pluginData, contexts, actionConfig, ruleName }) {
|
||||
const members = unique(contexts.map(c => c.member).filter(nonNullish));
|
||||
const me = pluginData.guild.members.get(pluginData.client.user.id)!;
|
||||
const me = pluginData.guild.members.cache.get(pluginData.client.user!.id)!;
|
||||
|
||||
const missingPermissions = getMissingPermissions(me.permission, p.manageRoles);
|
||||
const missingPermissions = getMissingPermissions(me.permissions, p.MANAGE_ROLES);
|
||||
if (missingPermissions) {
|
||||
const logs = pluginData.getPlugin(LogsPlugin);
|
||||
logs.log(LogType.BOT_ALERT, {
|
||||
|
@ -44,7 +45,7 @@ export const RemoveRolesAction = automodAction({
|
|||
|
||||
if (rolesWeCannotRemove.length) {
|
||||
const roleNamesWeCannotRemove = rolesWeCannotRemove.map(
|
||||
roleId => pluginData.guild.roles.get(roleId)?.name || roleId,
|
||||
roleId => pluginData.guild.roles.cache.get(roleId)?.name || roleId,
|
||||
);
|
||||
const logs = pluginData.getPlugin(LogsPlugin);
|
||||
logs.log(LogType.BOT_ALERT, {
|
||||
|
|
|
@ -12,11 +12,12 @@ import {
|
|||
unique,
|
||||
verboseChannelMention,
|
||||
} from "../../../utils";
|
||||
import { AdvancedMessageContent, Constants, MessageContent, TextChannel, User } from "eris";
|
||||
|
||||
import { AutomodContext } from "../types";
|
||||
import { renderTemplate } from "../../../templateFormatter";
|
||||
import { hasDiscordPermissions } from "../../../utils/hasDiscordPermissions";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { TextChannel, User, Constants, MessageOptions, Permissions } from "discord.js";
|
||||
|
||||
export const ReplyAction = automodAction({
|
||||
configType: t.union([
|
||||
|
@ -32,7 +33,7 @@ export const ReplyAction = automodAction({
|
|||
async apply({ pluginData, contexts, actionConfig, ruleName }) {
|
||||
const contextsWithTextChannels = contexts
|
||||
.filter(c => c.message?.channel_id)
|
||||
.filter(c => pluginData.guild.channels.get(c.message!.channel_id) instanceof TextChannel);
|
||||
.filter(c => pluginData.guild.channels.cache.get(c.message!.channel_id) instanceof TextChannel);
|
||||
|
||||
const contextsByChannelId = contextsWithTextChannels.reduce((map: Map<string, AutomodContext[]>, context) => {
|
||||
if (!map.has(context.message!.channel_id)) {
|
||||
|
@ -54,16 +55,16 @@ export const ReplyAction = automodAction({
|
|||
const formatted =
|
||||
typeof actionConfig === "string"
|
||||
? await renderReplyText(actionConfig)
|
||||
: ((await renderRecursively(actionConfig.text, renderReplyText)) as AdvancedMessageContent);
|
||||
: ((await renderRecursively(actionConfig.text, renderReplyText)) as MessageOptions);
|
||||
|
||||
if (formatted) {
|
||||
const channel = pluginData.guild.channels.get(channelId) as TextChannel;
|
||||
const channel = pluginData.guild.channels.cache.get(channelId) as TextChannel;
|
||||
|
||||
// Check for basic Send Messages and View Channel permissions
|
||||
if (
|
||||
!hasDiscordPermissions(
|
||||
channel.permissionsOf(pluginData.client.user.id),
|
||||
Constants.Permissions.sendMessages | Constants.Permissions.readMessages,
|
||||
channel.permissionsFor(pluginData.client.user!.id),
|
||||
Permissions.FLAGS.SEND_MESSAGES | Permissions.FLAGS.VIEW_CHANNEL,
|
||||
)
|
||||
) {
|
||||
pluginData.state.logs.log(LogType.BOT_ALERT, {
|
||||
|
@ -75,7 +76,7 @@ export const ReplyAction = automodAction({
|
|||
// If the message is an embed, check for embed permissions
|
||||
if (
|
||||
typeof formatted !== "string" &&
|
||||
!hasDiscordPermissions(channel.permissionsOf(pluginData.client.user.id), Constants.Permissions.embedLinks)
|
||||
!hasDiscordPermissions(channel.permissionsFor(pluginData.client.user!.id), Permissions.FLAGS.EMBED_LINKS)
|
||||
) {
|
||||
pluginData.state.logs.log(LogType.BOT_ALERT, {
|
||||
body: `Missing permissions to reply **with an embed** in ${verboseChannelMention(
|
||||
|
@ -85,12 +86,13 @@ export const ReplyAction = automodAction({
|
|||
continue;
|
||||
}
|
||||
|
||||
const messageContent: StrictMessageContent = typeof formatted === "string" ? { content: formatted } : formatted;
|
||||
const replyMsg = await channel.createMessage({
|
||||
const messageContent: MessageOptions = typeof formatted === "string" ? { content: formatted } : formatted;
|
||||
const replyMsg = await channel.send({
|
||||
...messageContent,
|
||||
allowedMentions: {
|
||||
users: [user.id],
|
||||
},
|
||||
split: false,
|
||||
});
|
||||
|
||||
if (typeof actionConfig === "object" && actionConfig.auto_delete) {
|
||||
|
|
|
@ -2,7 +2,8 @@ import * as t from "io-ts";
|
|||
import { automodAction } from "../helpers";
|
||||
import { convertDelayStringToMS, isDiscordRESTError, tDelayString, tNullable } from "../../../utils";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { Constants, TextChannel } from "eris";
|
||||
import { Constants, TextChannel } from "discord.js";
|
||||
import { ChannelTypeStrings } from "src/types";
|
||||
|
||||
export const SetSlowmodeAction = automodAction({
|
||||
configType: t.type({
|
||||
|
@ -18,24 +19,22 @@ export const SetSlowmodeAction = automodAction({
|
|||
const slowmodeMs = Math.max(actionConfig.duration ? convertDelayStringToMS(actionConfig.duration)! : 0, 0);
|
||||
|
||||
for (const channelId of actionConfig.channels) {
|
||||
const channel = pluginData.guild.channels.get(channelId);
|
||||
const channel = pluginData.guild.channels.cache.get(channelId);
|
||||
|
||||
// Only text channels and text channels within categories support slowmodes
|
||||
if (
|
||||
!channel ||
|
||||
!(channel.type === Constants.ChannelTypes.GUILD_TEXT || channel.type === Constants.ChannelTypes.GUILD_CATEGORY)
|
||||
) {
|
||||
if (!channel || !(channel.type === ChannelTypeStrings.TEXT || ChannelTypeStrings.CATEGORY)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let channelsToSlowmode: TextChannel[] = [];
|
||||
if (channel.type === Constants.ChannelTypes.GUILD_CATEGORY) {
|
||||
if (channel.type === ChannelTypeStrings.CATEGORY) {
|
||||
// Find all text channels within the category
|
||||
channelsToSlowmode = pluginData.guild.channels.filter(
|
||||
ch => ch.parentID === channel.id && ch.type === Constants.ChannelTypes.GUILD_TEXT,
|
||||
) as TextChannel[];
|
||||
for (const ch of pluginData.guild.channels.cache.values()) {
|
||||
if (ch.parentID === channel.id && ch.type === ChannelTypeStrings.TEXT)
|
||||
channelsToSlowmode.push(ch as TextChannel);
|
||||
}
|
||||
} else {
|
||||
channelsToSlowmode.push(channel);
|
||||
channelsToSlowmode.push(channel as TextChannel);
|
||||
}
|
||||
|
||||
const slowmodeSeconds = Math.ceil(slowmodeMs / 1000);
|
||||
|
|
|
@ -25,7 +25,7 @@ export const WarnAction = automodAction({
|
|||
const contactMethods = actionConfig.notify ? resolveActionContactMethods(pluginData, actionConfig) : undefined;
|
||||
|
||||
const caseArgs: Partial<CaseArgs> = {
|
||||
modId: pluginData.client.user.id,
|
||||
modId: pluginData.client.user!.id,
|
||||
extraNotes: matchResult.fullSummary ? [matchResult.fullSummary] : [],
|
||||
automatic: true,
|
||||
postInCaseLogOverride: actionConfig.postInCaseLog ?? undefined,
|
||||
|
|
|
@ -10,9 +10,9 @@ export const ViewAntiraidCmd = typedGuildCommand<AutomodPluginType>()({
|
|||
|
||||
async run({ pluginData, message }) {
|
||||
if (pluginData.state.cachedAntiraidLevel) {
|
||||
message.channel.createMessage(`Anti-raid is set to **${pluginData.state.cachedAntiraidLevel}**`);
|
||||
message.channel.send(`Anti-raid is set to **${pluginData.state.cachedAntiraidLevel}**`);
|
||||
} else {
|
||||
message.channel.createMessage(`Anti-raid is **off**`);
|
||||
message.channel.send(`Anti-raid is **off**`);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
|
|
@ -7,19 +7,19 @@ import diff from "lodash.difference";
|
|||
|
||||
export const RunAutomodOnMemberUpdate = typedGuildEventListener<AutomodPluginType>()({
|
||||
event: "guildMemberUpdate",
|
||||
listener({ pluginData, args: { member, oldMember } }) {
|
||||
listener({ pluginData, args: { oldMember, newMember } }) {
|
||||
if (!oldMember) return;
|
||||
|
||||
if (isEqual(oldMember.roles, member.roles)) return;
|
||||
if (isEqual(oldMember.roles, newMember.roles)) return;
|
||||
|
||||
const addedRoles = diff(member.roles, oldMember.roles);
|
||||
const removedRoles = diff(oldMember.roles, member.roles);
|
||||
const addedRoles = diff(newMember.roles, oldMember.roles);
|
||||
const removedRoles = diff(oldMember.roles, newMember.roles);
|
||||
|
||||
if (addedRoles.length || removedRoles.length) {
|
||||
const context: AutomodContext = {
|
||||
timestamp: Date.now(),
|
||||
user: member.user,
|
||||
member,
|
||||
user: newMember.user,
|
||||
member: newMember,
|
||||
rolesChanged: {
|
||||
added: addedRoles,
|
||||
removed: removedRoles,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { GuildPluginData } from "knub";
|
||||
import { AutomodContext, AutomodPluginType } from "../types";
|
||||
import { runAutomod } from "../functions/runAutomod";
|
||||
import { User } from "eris";
|
||||
import { User } from "discord.js";
|
||||
|
||||
export async function runAutomodOnAntiraidLevel(
|
||||
pluginData: GuildPluginData<AutomodPluginType>,
|
||||
|
|
|
@ -11,8 +11,8 @@ export function runAutomodOnMessage(
|
|||
message: SavedMessage,
|
||||
isEdit: boolean,
|
||||
) {
|
||||
const user = pluginData.client.users.get(message.user_id);
|
||||
const member = pluginData.guild.members.get(message.user_id);
|
||||
const user = pluginData.client.users.cache!.get(message.user_id);
|
||||
const member = pluginData.guild.members.cache.get(message.user_id);
|
||||
|
||||
const context: AutomodContext = {
|
||||
timestamp: moment.utc(message.posted_at).valueOf(),
|
||||
|
|
|
@ -2,7 +2,6 @@ import { MatchableTextType } from "./matchMultipleTextTypesOnMessage";
|
|||
import { AutomodContext, AutomodPluginType } from "../types";
|
||||
import { messageSummary, verboseChannelMention } from "../../../utils";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { User } from "eris";
|
||||
|
||||
export function getTextMatchPartialSummary(
|
||||
pluginData: GuildPluginData<AutomodPluginType>,
|
||||
|
@ -11,13 +10,13 @@ export function getTextMatchPartialSummary(
|
|||
) {
|
||||
if (type === "message") {
|
||||
const message = context.message!;
|
||||
const channel = pluginData.guild.channels.get(message.channel_id);
|
||||
const channel = pluginData.guild.channels.cache.get(message.channel_id);
|
||||
const channelMention = channel ? verboseChannelMention(channel) : `\`#${message.channel_id}\``;
|
||||
|
||||
return `message in ${channelMention}:\n${messageSummary(message)}`;
|
||||
} else if (type === "embed") {
|
||||
const message = context.message!;
|
||||
const channel = pluginData.guild.channels.get(message.channel_id);
|
||||
const channel = pluginData.guild.channels.cache.get(message.channel_id);
|
||||
const channelMention = channel ? verboseChannelMention(channel) : `\`#${message.channel_id}\``;
|
||||
|
||||
return `message embed in ${channelMention}:\n${messageSummary(message)}`;
|
||||
|
|
|
@ -2,6 +2,7 @@ import { SavedMessage } from "../../../data/entities/SavedMessage";
|
|||
import { resolveMember } from "../../../utils";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { AutomodPluginType } from "../types";
|
||||
import { Activity, Constants } from "discord.js";
|
||||
|
||||
type TextTriggerWithMultipleMatchTypes = {
|
||||
match_messages: boolean;
|
||||
|
@ -40,19 +41,21 @@ export async function* matchMultipleTextTypesOnMessage(
|
|||
}
|
||||
|
||||
if (trigger.match_visible_names) {
|
||||
yield ["visiblename", member.nick || msg.data.author.username];
|
||||
yield ["visiblename", member.nickname || msg.data.author.username];
|
||||
}
|
||||
|
||||
if (trigger.match_usernames) {
|
||||
yield ["username", `${msg.data.author.username}#${msg.data.author.discriminator}`];
|
||||
}
|
||||
|
||||
if (trigger.match_nicknames && member.nick) {
|
||||
yield ["nickname", member.nick];
|
||||
if (trigger.match_nicknames && member.nickname) {
|
||||
yield ["nickname", member.nickname];
|
||||
}
|
||||
|
||||
// type 4 = custom status
|
||||
if (trigger.match_custom_status && member.game?.type === 4 && member.game?.state) {
|
||||
yield ["customstatus", member.game.state];
|
||||
for (const activity of member.presence.activities) {
|
||||
if (activity.type === Constants.ActivityTypes[4]) {
|
||||
yield ["customstatus", `${activity.emoji} ${activity.name}`];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import { disableUserNotificationStrings, UserNotificationMethod } from "../../../utils";
|
||||
import { ERRORS, RecoverablePluginError } from "../../../RecoverablePluginError";
|
||||
import { TextChannel } from "eris";
|
||||
|
||||
import { GuildPluginData } from "knub";
|
||||
import { AutomodPluginType } from "../types";
|
||||
import { TextChannel } from "discord.js";
|
||||
|
||||
export function resolveActionContactMethods(
|
||||
pluginData: GuildPluginData<AutomodPluginType>,
|
||||
|
@ -18,7 +19,7 @@ export function resolveActionContactMethods(
|
|||
throw new RecoverablePluginError(ERRORS.NO_USER_NOTIFICATION_CHANNEL);
|
||||
}
|
||||
|
||||
const channel = pluginData.guild.channels.get(actionConfig.notifyChannel);
|
||||
const channel = pluginData.guild.channels.cache.get(actionConfig.notifyChannel);
|
||||
if (!(channel instanceof TextChannel)) {
|
||||
throw new RecoverablePluginError(ERRORS.INVALID_USER_NOTIFICATION_CHANNEL);
|
||||
}
|
||||
|
|
|
@ -5,14 +5,14 @@ import { availableActions } from "../actions/availableActions";
|
|||
import { AutomodTriggerMatchResult } from "../helpers";
|
||||
import { CleanAction } from "../actions/clean";
|
||||
import { checkAndUpdateCooldown } from "./checkAndUpdateCooldown";
|
||||
import { TextChannel } from "eris";
|
||||
import { TextChannel } from "discord.js";
|
||||
|
||||
export async function runAutomod(pluginData: GuildPluginData<AutomodPluginType>, context: AutomodContext) {
|
||||
const userId = context.user?.id || context.member?.id || context.message?.user_id;
|
||||
const user = context.user || (userId && pluginData.client.users.get(userId));
|
||||
const member = context.member || (userId && pluginData.guild.members.get(userId)) || null;
|
||||
const user = context.user || (userId && pluginData.client.users!.cache.get(userId));
|
||||
const member = context.member || (userId && pluginData.guild.members.cache.get(userId)) || null;
|
||||
const channelId = context.message?.channel_id;
|
||||
const channel = channelId ? (pluginData.guild.channels.get(channelId) as TextChannel) : null;
|
||||
const channel = channelId ? (pluginData.guild.channels.cache.get(channelId) as TextChannel) : null;
|
||||
const categoryId = channel?.parentID;
|
||||
|
||||
const config = await pluginData.config.getMatchingConfig({
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { User } from "eris";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { AutomodPluginType } from "../types";
|
||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { stripObjectToScalars } from "../../../utils";
|
||||
import { runAutomodOnAntiraidLevel } from "../events/runAutomodOnAntiraidLevel";
|
||||
import { User } from "discord.js";
|
||||
|
||||
export async function setAntiraidLevel(
|
||||
pluginData: GuildPluginData<AutomodPluginType>,
|
||||
|
|
|
@ -21,7 +21,7 @@ export const AnyMessageTrigger = automodTrigger<AnyMessageResultType>()({
|
|||
},
|
||||
|
||||
renderMatchInformation({ pluginData, contexts, matchResult }) {
|
||||
const channel = pluginData.guild.channels.get(contexts[0].message!.channel_id);
|
||||
const channel = pluginData.guild.channels.cache.get(contexts[0].message!.channel_id);
|
||||
return `Matched message (\`${contexts[0].message!.id}\`) in ${
|
||||
channel ? verboseChannelMention(channel) : "Unknown Channel"
|
||||
}`;
|
||||
|
|
|
@ -73,7 +73,7 @@ export const MatchAttachmentTypeTrigger = automodTrigger<MatchResultType>()({
|
|||
},
|
||||
|
||||
renderMatchInformation({ pluginData, contexts, matchResult }) {
|
||||
const channel = pluginData.guild.channels.get(contexts[0].message!.channel_id)!;
|
||||
const channel = pluginData.guild.channels.cache.get(contexts[0].message!.channel_id)!;
|
||||
const prettyChannel = verboseChannelMention(channel);
|
||||
|
||||
return (
|
||||
|
|
|
@ -33,7 +33,7 @@ export const RoleAddedTrigger = automodTrigger<RoleAddedMatchResult>()({
|
|||
},
|
||||
|
||||
renderMatchInformation({ matchResult, pluginData, contexts }) {
|
||||
const role = pluginData.guild.roles.get(matchResult.extra.matchedRoleId);
|
||||
const role = pluginData.guild.roles.cache.get(matchResult.extra.matchedRoleId);
|
||||
const roleName = role?.name || "Unknown";
|
||||
const member = contexts[0].member!;
|
||||
const memberName = `**${member.user.username}#${member.user.discriminator}** (\`${member.id}\`)`;
|
||||
|
|
|
@ -33,7 +33,7 @@ export const RoleRemovedTrigger = automodTrigger<RoleAddedMatchResult>()({
|
|||
},
|
||||
|
||||
renderMatchInformation({ matchResult, pluginData, contexts }) {
|
||||
const role = pluginData.guild.roles.get(matchResult.extra.matchedRoleId);
|
||||
const role = pluginData.guild.roles.cache.get(matchResult.extra.matchedRoleId);
|
||||
const roleName = role?.name || "Unknown";
|
||||
const member = contexts[0].member!;
|
||||
const memberName = `**${member.user.username}#${member.user.discriminator}** (\`${member.id}\`)`;
|
||||
|
|
|
@ -4,7 +4,7 @@ import { BasePluginType, CooldownManager } from "knub";
|
|||
import { GuildSavedMessages } from "../../data/GuildSavedMessages";
|
||||
import { GuildLogs } from "../../data/GuildLogs";
|
||||
import { SavedMessage } from "../../data/entities/SavedMessage";
|
||||
import { Member, User } from "eris";
|
||||
|
||||
import { AvailableTriggers } from "./triggers/availableTriggers";
|
||||
import { AvailableActions } from "./actions/availableActions";
|
||||
import { Queue } from "../../Queue";
|
||||
|
@ -16,6 +16,7 @@ import { RegExpRunner } from "../../RegExpRunner";
|
|||
import { CounterEvents } from "../Counters/types";
|
||||
import { ModActionsEvents, ModActionType } from "../ModActions/types";
|
||||
import { MutesEvents } from "../Mutes/types";
|
||||
import { GuildMember, User } from "discord.js";
|
||||
|
||||
export const Rule = t.type({
|
||||
enabled: t.boolean,
|
||||
|
@ -113,7 +114,7 @@ export interface AutomodContext {
|
|||
};
|
||||
user?: User;
|
||||
message?: SavedMessage;
|
||||
member?: Member;
|
||||
member?: GuildMember;
|
||||
joined?: boolean;
|
||||
rolesChanged?: {
|
||||
added?: string[];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue