3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-18 15:00:00 +00:00

More rework progress, remove all eris imports

This commit is contained in:
Dark 2021-06-01 02:05:55 +02:00
parent 8f7a6510eb
commit 52839cc9f3
No known key found for this signature in database
GPG key ID: 2CD6ACB6B0A87B8A
181 changed files with 352 additions and 343 deletions

View file

@ -7,8 +7,8 @@ import { logger } from "../../../logger";
import { scheduleNextDeletion } from "./scheduleNextDeletion"; import { scheduleNextDeletion } from "./scheduleNextDeletion";
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin"; import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
import { hasDiscordPermissions } from "../../../utils/hasDiscordPermissions"; import { hasDiscordPermissions } from "../../../utils/hasDiscordPermissions";
import { Constants } from "eris";
import { LogsPlugin } from "../../Logs/LogsPlugin"; import { LogsPlugin } from "../../Logs/LogsPlugin";
import { Permissions, TextChannel } from "discord.js";
export async function deleteNextItem(pluginData: GuildPluginData<AutoDeletePluginType>) { export async function deleteNextItem(pluginData: GuildPluginData<AutoDeletePluginType>) {
const [itemToDelete] = pluginData.state.deletionQueue.splice(0, 1); const [itemToDelete] = pluginData.state.deletionQueue.splice(0, 1);
@ -16,16 +16,16 @@ export async function deleteNextItem(pluginData: GuildPluginData<AutoDeletePlugi
scheduleNextDeletion(pluginData); scheduleNextDeletion(pluginData);
const channel = pluginData.guild.channels.get(itemToDelete.message.channel_id); const channel = pluginData.guild.channels.cache.get(itemToDelete.message.channel_id);
if (!channel) { if (!channel) {
// Channel was deleted, ignore // Channel was deleted, ignore
return; return;
} }
const logs = pluginData.getPlugin(LogsPlugin); const logs = pluginData.getPlugin(LogsPlugin);
const perms = channel.permissionsOf(pluginData.client.user.id); const perms = channel.permissionsFor(pluginData.client.user!.id);
if (!hasDiscordPermissions(perms, Constants.Permissions.readMessages | Constants.Permissions.readMessageHistory)) { if (!hasDiscordPermissions(perms, Permissions.FLAGS.VIEW_CHANNEL | Permissions.FLAGS.READ_MESSAGE_HISTORY)) {
logs.log(LogType.BOT_ALERT, { logs.log(LogType.BOT_ALERT, {
body: `Missing permissions to read messages or message history in auto-delete channel ${verboseChannelMention( body: `Missing permissions to read messages or message history in auto-delete channel ${verboseChannelMention(
channel, channel,
@ -34,7 +34,7 @@ export async function deleteNextItem(pluginData: GuildPluginData<AutoDeletePlugi
return; return;
} }
if (!hasDiscordPermissions(perms, Constants.Permissions.manageMessages)) { if (!hasDiscordPermissions(perms, Permissions.FLAGS.MANAGE_MESSAGES)) {
logs.log(LogType.BOT_ALERT, { logs.log(LogType.BOT_ALERT, {
body: `Missing permissions to delete messages in auto-delete channel ${verboseChannelMention(channel)}`, body: `Missing permissions to delete messages in auto-delete channel ${verboseChannelMention(channel)}`,
}); });
@ -44,7 +44,7 @@ export async function deleteNextItem(pluginData: GuildPluginData<AutoDeletePlugi
const timeAndDate = pluginData.getPlugin(TimeAndDatePlugin); const timeAndDate = pluginData.getPlugin(TimeAndDatePlugin);
pluginData.state.guildLogs.ignoreLog(LogType.MESSAGE_DELETE, itemToDelete.message.id); pluginData.state.guildLogs.ignoreLog(LogType.MESSAGE_DELETE, itemToDelete.message.id);
pluginData.client.deleteMessage(itemToDelete.message.channel_id, itemToDelete.message.id).catch(err => { (channel as TextChannel).messages.delete(itemToDelete.message.id).catch(err => {
if (err.code === 10008) { if (err.code === 10008) {
// "Unknown Message", probably already deleted by automod or another bot, ignore // "Unknown Message", probably already deleted by automod or another bot, ignore
return; return;

View file

@ -3,11 +3,12 @@ import { commandTypeHelpers as ct } from "../../../commandTypes";
import { canUseEmoji, customEmojiRegex, isEmoji } from "../../../utils"; import { canUseEmoji, customEmojiRegex, isEmoji } from "../../../utils";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { getMissingChannelPermissions } from "../../../utils/getMissingChannelPermissions"; import { getMissingChannelPermissions } from "../../../utils/getMissingChannelPermissions";
import { Constants, GuildChannel } from "eris";
import { readChannelPermissions } from "../../../utils/readChannelPermissions"; import { readChannelPermissions } from "../../../utils/readChannelPermissions";
import { missingPermissionError } from "../../../utils/missingPermissionError"; import { missingPermissionError } from "../../../utils/missingPermissionError";
import { GuildChannel, Permissions } from "discord.js";
const requiredPermissions = readChannelPermissions | Constants.Permissions.addReactions; const requiredPermissions = readChannelPermissions | Permissions.FLAGS.ADD_REACTIONS;
export const NewAutoReactionsCmd = autoReactionsCmd({ export const NewAutoReactionsCmd = autoReactionsCmd({
trigger: "auto_reactions", trigger: "auto_reactions",
@ -22,7 +23,7 @@ export const NewAutoReactionsCmd = autoReactionsCmd({
async run({ message: msg, args, pluginData }) { async run({ message: msg, args, pluginData }) {
const finalReactions: string[] = []; const finalReactions: string[] = [];
const me = pluginData.guild.members.get(pluginData.client.user.id)!; const me = pluginData.guild.members.cache.get(pluginData.client.user!.id)!;
const missingPermissions = getMissingChannelPermissions(me, args.channel as GuildChannel, requiredPermissions); const missingPermissions = getMissingChannelPermissions(me, args.channel as GuildChannel, requiredPermissions);
if (missingPermissions) { if (missingPermissions) {
sendErrorMessage( sendErrorMessage(

View file

@ -1,17 +1,17 @@
import { autoReactionsEvt } from "../types"; import { autoReactionsEvt } from "../types";
import { isDiscordRESTError } from "../../../utils"; import { isDiscordRESTError } from "../../../utils";
import { LogType } from "../../../data/LogType"; import { LogType } from "../../../data/LogType";
import { logger } from "../../../logger";
import { LogsPlugin } from "../../Logs/LogsPlugin"; import { LogsPlugin } from "../../Logs/LogsPlugin";
import { Constants, GuildChannel } from "eris";
import { getMissingChannelPermissions } from "../../../utils/getMissingChannelPermissions"; import { getMissingChannelPermissions } from "../../../utils/getMissingChannelPermissions";
import { readChannelPermissions } from "../../../utils/readChannelPermissions"; import { readChannelPermissions } from "../../../utils/readChannelPermissions";
import { missingPermissionError } from "../../../utils/missingPermissionError"; import { missingPermissionError } from "../../../utils/missingPermissionError";
import { GuildChannel, Permissions } from "discord.js";
const p = Constants.Permissions; const p = Permissions.FLAGS;
export const AddReactionsEvt = autoReactionsEvt({ export const AddReactionsEvt = autoReactionsEvt({
event: "messageCreate", event: "message",
allowBots: true, allowBots: true,
allowSelf: true, allowSelf: true,
@ -19,11 +19,11 @@ export const AddReactionsEvt = autoReactionsEvt({
const autoReaction = await pluginData.state.autoReactions.getForChannel(message.channel.id); const autoReaction = await pluginData.state.autoReactions.getForChannel(message.channel.id);
if (!autoReaction) return; if (!autoReaction) return;
const me = pluginData.guild.members.get(pluginData.client.user.id)!; const me = pluginData.guild.members.cache.get(pluginData.client.user!.id)!;
const missingPermissions = getMissingChannelPermissions( const missingPermissions = getMissingChannelPermissions(
me, me,
message.channel as GuildChannel, message.channel as GuildChannel,
readChannelPermissions | p.addReactions, readChannelPermissions | p.ADD_REACTIONS,
); );
if (missingPermissions) { if (missingPermissions) {
const logs = pluginData.getPlugin(LogsPlugin); const logs = pluginData.getPlugin(LogsPlugin);
@ -35,7 +35,7 @@ export const AddReactionsEvt = autoReactionsEvt({
for (const reaction of autoReaction.reactions) { for (const reaction of autoReaction.reactions) {
try { try {
await message.addReaction(reaction); await message.react(reaction);
} catch (e) { } catch (e) {
if (isDiscordRESTError(e)) { if (isDiscordRESTError(e)) {
const logs = pluginData.getPlugin(LogsPlugin); const logs = pluginData.getPlugin(LogsPlugin);

View file

@ -1,17 +1,16 @@
import { Permissions } from "discord.js";
import * as t from "io-ts"; import * as t from "io-ts";
import { automodAction } from "../helpers";
import { LogType } from "../../../data/LogType"; import { LogType } from "../../../data/LogType";
import { nonNullish, unique } from "../../../utils"; 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 { canAssignRole } from "../../../utils/canAssignRole";
import { missingPermissionError } from "../../../utils/missingPermissionError"; import { getMissingPermissions } from "../../../utils/getMissingPermissions";
import { ignoreRoleChange } from "../functions/ignoredRoleChanges";
import { memberRolesLock } from "../../../utils/lockNameHelpers"; 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({ export const AddRolesAction = automodAction({
configType: t.array(t.string), configType: t.array(t.string),
@ -19,9 +18,9 @@ export const AddRolesAction = automodAction({
async apply({ pluginData, contexts, actionConfig, ruleName }) { async apply({ pluginData, contexts, actionConfig, ruleName }) {
const members = unique(contexts.map(c => c.member).filter(nonNullish)); 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) { if (missingPermissions) {
const logs = pluginData.getPlugin(LogsPlugin); const logs = pluginData.getPlugin(LogsPlugin);
logs.log(LogType.BOT_ALERT, { logs.log(LogType.BOT_ALERT, {
@ -42,7 +41,7 @@ export const AddRolesAction = automodAction({
if (rolesWeCannotAssign.length) { if (rolesWeCannotAssign.length) {
const roleNamesWeCannotAssign = rolesWeCannotAssign.map( 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); const logs = pluginData.getPlugin(LogsPlugin);
logs.log(LogType.BOT_ALERT, { logs.log(LogType.BOT_ALERT, {

View file

@ -2,22 +2,17 @@ import * as t from "io-ts";
import { automodAction } from "../helpers"; import { automodAction } from "../helpers";
import { LogType } from "../../../data/LogType"; import { LogType } from "../../../data/LogType";
import { import {
asyncMap,
createChunkedMessage, createChunkedMessage,
isDiscordRESTError,
messageLink, messageLink,
resolveMember,
stripObjectToScalars, stripObjectToScalars,
tAllowedMentions, tAllowedMentions,
tNormalizedNullOptional, tNormalizedNullOptional,
tNullable,
verboseChannelMention, verboseChannelMention,
} from "../../../utils"; } from "../../../utils";
import { resolveActionContactMethods } from "../functions/resolveActionContactMethods";
import { ModActionsPlugin } from "../../ModActions/ModActionsPlugin";
import { TextChannel } from "eris";
import { renderTemplate, TemplateParseError } from "../../../templateFormatter"; import { renderTemplate, TemplateParseError } from "../../../templateFormatter";
import { LogsPlugin } from "../../Logs/LogsPlugin"; import { LogsPlugin } from "../../Logs/LogsPlugin";
import { TextChannel } from "discord.js";
import { erisAllowedMentionsToDjsMentionOptions } from "src/utils/erisAllowedMentionsToDjsMentionOptions";
export const AlertAction = automodAction({ export const AlertAction = automodAction({
configType: t.type({ configType: t.type({
@ -29,7 +24,7 @@ export const AlertAction = automodAction({
defaultConfig: {}, defaultConfig: {},
async apply({ pluginData, contexts, actionConfig, ruleName, matchResult }) { 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); const logs = pluginData.getPlugin(LogsPlugin);
if (channel && channel instanceof TextChannel) { if (channel && channel instanceof TextChannel) {
@ -73,7 +68,11 @@ export const AlertAction = automodAction({
} }
try { try {
await createChunkedMessage(channel, rendered, actionConfig.allowed_mentions); await createChunkedMessage(
channel,
rendered,
erisAllowedMentionsToDjsMentionOptions(actionConfig.allowed_mentions),
);
} catch (err) { } catch (err) {
if (err.code === 50001) { if (err.code === 50001) {
logs.log(LogType.BOT_ALERT, { logs.log(LogType.BOT_ALERT, {

View file

@ -37,7 +37,7 @@ export const BanAction = automodAction({
const deleteMessageDays = actionConfig.deleteMessageDays || undefined; const deleteMessageDays = actionConfig.deleteMessageDays || undefined;
const caseArgs: Partial<CaseArgs> = { const caseArgs: Partial<CaseArgs> = {
modId: pluginData.client.user.id, modId: pluginData.client.user!.id,
extraNotes: matchResult.fullSummary ? [matchResult.fullSummary] : [], extraNotes: matchResult.fullSummary ? [matchResult.fullSummary] : [],
automatic: true, automatic: true,
postInCaseLogOverride: actionConfig.postInCaseLog ?? undefined, postInCaseLogOverride: actionConfig.postInCaseLog ?? undefined,

View file

@ -2,6 +2,7 @@ import * as t from "io-ts";
import { automodAction } from "../helpers"; import { automodAction } from "../helpers";
import { LogType } from "../../../data/LogType"; import { LogType } from "../../../data/LogType";
import { noop } from "../../../utils"; import { noop } from "../../../utils";
import { TextChannel } from "discord.js";
export const CleanAction = automodAction({ export const CleanAction = automodAction({
configType: t.boolean, configType: t.boolean,
@ -29,7 +30,8 @@ export const CleanAction = automodAction({
pluginData.state.logs.ignoreLog(LogType.MESSAGE_DELETE, id); 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);
} }
}, },
}); });

View file

@ -25,7 +25,7 @@ export const KickAction = automodAction({
const contactMethods = actionConfig.notify ? resolveActionContactMethods(pluginData, actionConfig) : undefined; const contactMethods = actionConfig.notify ? resolveActionContactMethods(pluginData, actionConfig) : undefined;
const caseArgs: Partial<CaseArgs> = { const caseArgs: Partial<CaseArgs> = {
modId: pluginData.client.user.id, modId: pluginData.client.user!.id,
extraNotes: matchResult.fullSummary ? [matchResult.fullSummary] : [], extraNotes: matchResult.fullSummary ? [matchResult.fullSummary] : [],
automatic: true, automatic: true,
postInCaseLogOverride: actionConfig.postInCaseLog ?? undefined, postInCaseLogOverride: actionConfig.postInCaseLog ?? undefined,

View file

@ -42,7 +42,7 @@ export const MuteAction = automodAction({
const rolesToRestore = actionConfig.restore_roles_on_mute; const rolesToRestore = actionConfig.restore_roles_on_mute;
const caseArgs: Partial<CaseArgs> = { const caseArgs: Partial<CaseArgs> = {
modId: pluginData.client.user.id, modId: pluginData.client.user!.id,
extraNotes: matchResult.fullSummary ? [matchResult.fullSummary] : [], extraNotes: matchResult.fullSummary ? [matchResult.fullSummary] : [],
automatic: true, automatic: true,
postInCaseLogOverride: actionConfig.postInCaseLog ?? undefined, postInCaseLogOverride: actionConfig.postInCaseLog ?? undefined,

View file

@ -8,11 +8,12 @@ import { getMissingPermissions } from "../../../utils/getMissingPermissions";
import { LogsPlugin } from "../../Logs/LogsPlugin"; import { LogsPlugin } from "../../Logs/LogsPlugin";
import { missingPermissionError } from "../../../utils/missingPermissionError"; import { missingPermissionError } from "../../../utils/missingPermissionError";
import { canAssignRole } from "../../../utils/canAssignRole"; import { canAssignRole } from "../../../utils/canAssignRole";
import { Constants } from "eris";
import { ignoreRoleChange } from "../functions/ignoredRoleChanges"; import { ignoreRoleChange } from "../functions/ignoredRoleChanges";
import { memberRolesLock } from "../../../utils/lockNameHelpers"; import { memberRolesLock } from "../../../utils/lockNameHelpers";
import { Permissions } from "discord.js";
const p = Constants.Permissions; const p = Permissions.FLAGS;
export const RemoveRolesAction = automodAction({ export const RemoveRolesAction = automodAction({
configType: t.array(t.string), configType: t.array(t.string),
@ -21,9 +22,9 @@ export const RemoveRolesAction = automodAction({
async apply({ pluginData, contexts, actionConfig, ruleName }) { async apply({ pluginData, contexts, actionConfig, ruleName }) {
const members = unique(contexts.map(c => c.member).filter(nonNullish)); 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) { if (missingPermissions) {
const logs = pluginData.getPlugin(LogsPlugin); const logs = pluginData.getPlugin(LogsPlugin);
logs.log(LogType.BOT_ALERT, { logs.log(LogType.BOT_ALERT, {
@ -44,7 +45,7 @@ export const RemoveRolesAction = automodAction({
if (rolesWeCannotRemove.length) { if (rolesWeCannotRemove.length) {
const roleNamesWeCannotRemove = rolesWeCannotRemove.map( 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); const logs = pluginData.getPlugin(LogsPlugin);
logs.log(LogType.BOT_ALERT, { logs.log(LogType.BOT_ALERT, {

View file

@ -12,11 +12,12 @@ import {
unique, unique,
verboseChannelMention, verboseChannelMention,
} from "../../../utils"; } from "../../../utils";
import { AdvancedMessageContent, Constants, MessageContent, TextChannel, User } from "eris";
import { AutomodContext } from "../types"; import { AutomodContext } from "../types";
import { renderTemplate } from "../../../templateFormatter"; import { renderTemplate } from "../../../templateFormatter";
import { hasDiscordPermissions } from "../../../utils/hasDiscordPermissions"; import { hasDiscordPermissions } from "../../../utils/hasDiscordPermissions";
import { LogType } from "../../../data/LogType"; import { LogType } from "../../../data/LogType";
import { TextChannel, User, Constants, MessageOptions, Permissions } from "discord.js";
export const ReplyAction = automodAction({ export const ReplyAction = automodAction({
configType: t.union([ configType: t.union([
@ -32,7 +33,7 @@ export const ReplyAction = automodAction({
async apply({ pluginData, contexts, actionConfig, ruleName }) { async apply({ pluginData, contexts, actionConfig, ruleName }) {
const contextsWithTextChannels = contexts const contextsWithTextChannels = contexts
.filter(c => c.message?.channel_id) .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) => { const contextsByChannelId = contextsWithTextChannels.reduce((map: Map<string, AutomodContext[]>, context) => {
if (!map.has(context.message!.channel_id)) { if (!map.has(context.message!.channel_id)) {
@ -54,16 +55,16 @@ export const ReplyAction = automodAction({
const formatted = const formatted =
typeof actionConfig === "string" typeof actionConfig === "string"
? await renderReplyText(actionConfig) ? await renderReplyText(actionConfig)
: ((await renderRecursively(actionConfig.text, renderReplyText)) as AdvancedMessageContent); : ((await renderRecursively(actionConfig.text, renderReplyText)) as MessageOptions);
if (formatted) { 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 // Check for basic Send Messages and View Channel permissions
if ( if (
!hasDiscordPermissions( !hasDiscordPermissions(
channel.permissionsOf(pluginData.client.user.id), channel.permissionsFor(pluginData.client.user!.id),
Constants.Permissions.sendMessages | Constants.Permissions.readMessages, Permissions.FLAGS.SEND_MESSAGES | Permissions.FLAGS.VIEW_CHANNEL,
) )
) { ) {
pluginData.state.logs.log(LogType.BOT_ALERT, { 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 the message is an embed, check for embed permissions
if ( if (
typeof formatted !== "string" && 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, { pluginData.state.logs.log(LogType.BOT_ALERT, {
body: `Missing permissions to reply **with an embed** in ${verboseChannelMention( body: `Missing permissions to reply **with an embed** in ${verboseChannelMention(
@ -85,12 +86,13 @@ export const ReplyAction = automodAction({
continue; continue;
} }
const messageContent: StrictMessageContent = typeof formatted === "string" ? { content: formatted } : formatted; const messageContent: MessageOptions = typeof formatted === "string" ? { content: formatted } : formatted;
const replyMsg = await channel.createMessage({ const replyMsg = await channel.send({
...messageContent, ...messageContent,
allowedMentions: { allowedMentions: {
users: [user.id], users: [user.id],
}, },
split: false,
}); });
if (typeof actionConfig === "object" && actionConfig.auto_delete) { if (typeof actionConfig === "object" && actionConfig.auto_delete) {

View file

@ -2,7 +2,8 @@ import * as t from "io-ts";
import { automodAction } from "../helpers"; import { automodAction } from "../helpers";
import { convertDelayStringToMS, isDiscordRESTError, tDelayString, tNullable } from "../../../utils"; import { convertDelayStringToMS, isDiscordRESTError, tDelayString, tNullable } from "../../../utils";
import { LogType } from "../../../data/LogType"; 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({ export const SetSlowmodeAction = automodAction({
configType: t.type({ configType: t.type({
@ -18,24 +19,22 @@ export const SetSlowmodeAction = automodAction({
const slowmodeMs = Math.max(actionConfig.duration ? convertDelayStringToMS(actionConfig.duration)! : 0, 0); const slowmodeMs = Math.max(actionConfig.duration ? convertDelayStringToMS(actionConfig.duration)! : 0, 0);
for (const channelId of actionConfig.channels) { 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 // Only text channels and text channels within categories support slowmodes
if ( if (!channel || !(channel.type === ChannelTypeStrings.TEXT || ChannelTypeStrings.CATEGORY)) {
!channel ||
!(channel.type === Constants.ChannelTypes.GUILD_TEXT || channel.type === Constants.ChannelTypes.GUILD_CATEGORY)
) {
continue; continue;
} }
let channelsToSlowmode: TextChannel[] = []; let channelsToSlowmode: TextChannel[] = [];
if (channel.type === Constants.ChannelTypes.GUILD_CATEGORY) { if (channel.type === ChannelTypeStrings.CATEGORY) {
// Find all text channels within the category // Find all text channels within the category
channelsToSlowmode = pluginData.guild.channels.filter( for (const ch of pluginData.guild.channels.cache.values()) {
ch => ch.parentID === channel.id && ch.type === Constants.ChannelTypes.GUILD_TEXT, if (ch.parentID === channel.id && ch.type === ChannelTypeStrings.TEXT)
) as TextChannel[]; channelsToSlowmode.push(ch as TextChannel);
}
} else { } else {
channelsToSlowmode.push(channel); channelsToSlowmode.push(channel as TextChannel);
} }
const slowmodeSeconds = Math.ceil(slowmodeMs / 1000); const slowmodeSeconds = Math.ceil(slowmodeMs / 1000);

View file

@ -25,7 +25,7 @@ export const WarnAction = automodAction({
const contactMethods = actionConfig.notify ? resolveActionContactMethods(pluginData, actionConfig) : undefined; const contactMethods = actionConfig.notify ? resolveActionContactMethods(pluginData, actionConfig) : undefined;
const caseArgs: Partial<CaseArgs> = { const caseArgs: Partial<CaseArgs> = {
modId: pluginData.client.user.id, modId: pluginData.client.user!.id,
extraNotes: matchResult.fullSummary ? [matchResult.fullSummary] : [], extraNotes: matchResult.fullSummary ? [matchResult.fullSummary] : [],
automatic: true, automatic: true,
postInCaseLogOverride: actionConfig.postInCaseLog ?? undefined, postInCaseLogOverride: actionConfig.postInCaseLog ?? undefined,

View file

@ -10,9 +10,9 @@ export const ViewAntiraidCmd = typedGuildCommand<AutomodPluginType>()({
async run({ pluginData, message }) { async run({ pluginData, message }) {
if (pluginData.state.cachedAntiraidLevel) { 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 { } else {
message.channel.createMessage(`Anti-raid is **off**`); message.channel.send(`Anti-raid is **off**`);
} }
}, },
}); });

View file

@ -7,19 +7,19 @@ import diff from "lodash.difference";
export const RunAutomodOnMemberUpdate = typedGuildEventListener<AutomodPluginType>()({ export const RunAutomodOnMemberUpdate = typedGuildEventListener<AutomodPluginType>()({
event: "guildMemberUpdate", event: "guildMemberUpdate",
listener({ pluginData, args: { member, oldMember } }) { listener({ pluginData, args: { oldMember, newMember } }) {
if (!oldMember) return; 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 addedRoles = diff(newMember.roles, oldMember.roles);
const removedRoles = diff(oldMember.roles, member.roles); const removedRoles = diff(oldMember.roles, newMember.roles);
if (addedRoles.length || removedRoles.length) { if (addedRoles.length || removedRoles.length) {
const context: AutomodContext = { const context: AutomodContext = {
timestamp: Date.now(), timestamp: Date.now(),
user: member.user, user: newMember.user,
member, member: newMember,
rolesChanged: { rolesChanged: {
added: addedRoles, added: addedRoles,
removed: removedRoles, removed: removedRoles,

View file

@ -1,7 +1,7 @@
import { GuildPluginData } from "knub"; import { GuildPluginData } from "knub";
import { AutomodContext, AutomodPluginType } from "../types"; import { AutomodContext, AutomodPluginType } from "../types";
import { runAutomod } from "../functions/runAutomod"; import { runAutomod } from "../functions/runAutomod";
import { User } from "eris"; import { User } from "discord.js";
export async function runAutomodOnAntiraidLevel( export async function runAutomodOnAntiraidLevel(
pluginData: GuildPluginData<AutomodPluginType>, pluginData: GuildPluginData<AutomodPluginType>,

View file

@ -11,8 +11,8 @@ export function runAutomodOnMessage(
message: SavedMessage, message: SavedMessage,
isEdit: boolean, isEdit: boolean,
) { ) {
const user = pluginData.client.users.get(message.user_id); const user = pluginData.client.users.cache!.get(message.user_id);
const member = pluginData.guild.members.get(message.user_id); const member = pluginData.guild.members.cache.get(message.user_id);
const context: AutomodContext = { const context: AutomodContext = {
timestamp: moment.utc(message.posted_at).valueOf(), timestamp: moment.utc(message.posted_at).valueOf(),

View file

@ -2,7 +2,6 @@ import { MatchableTextType } from "./matchMultipleTextTypesOnMessage";
import { AutomodContext, AutomodPluginType } from "../types"; import { AutomodContext, AutomodPluginType } from "../types";
import { messageSummary, verboseChannelMention } from "../../../utils"; import { messageSummary, verboseChannelMention } from "../../../utils";
import { GuildPluginData } from "knub"; import { GuildPluginData } from "knub";
import { User } from "eris";
export function getTextMatchPartialSummary( export function getTextMatchPartialSummary(
pluginData: GuildPluginData<AutomodPluginType>, pluginData: GuildPluginData<AutomodPluginType>,
@ -11,13 +10,13 @@ export function getTextMatchPartialSummary(
) { ) {
if (type === "message") { if (type === "message") {
const message = context.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}\``; const channelMention = channel ? verboseChannelMention(channel) : `\`#${message.channel_id}\``;
return `message in ${channelMention}:\n${messageSummary(message)}`; return `message in ${channelMention}:\n${messageSummary(message)}`;
} else if (type === "embed") { } else if (type === "embed") {
const message = context.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}\``; const channelMention = channel ? verboseChannelMention(channel) : `\`#${message.channel_id}\``;
return `message embed in ${channelMention}:\n${messageSummary(message)}`; return `message embed in ${channelMention}:\n${messageSummary(message)}`;

View file

@ -2,6 +2,7 @@ import { SavedMessage } from "../../../data/entities/SavedMessage";
import { resolveMember } from "../../../utils"; import { resolveMember } from "../../../utils";
import { GuildPluginData } from "knub"; import { GuildPluginData } from "knub";
import { AutomodPluginType } from "../types"; import { AutomodPluginType } from "../types";
import { Activity, Constants } from "discord.js";
type TextTriggerWithMultipleMatchTypes = { type TextTriggerWithMultipleMatchTypes = {
match_messages: boolean; match_messages: boolean;
@ -40,19 +41,21 @@ export async function* matchMultipleTextTypesOnMessage(
} }
if (trigger.match_visible_names) { 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) { if (trigger.match_usernames) {
yield ["username", `${msg.data.author.username}#${msg.data.author.discriminator}`]; yield ["username", `${msg.data.author.username}#${msg.data.author.discriminator}`];
} }
if (trigger.match_nicknames && member.nick) { if (trigger.match_nicknames && member.nickname) {
yield ["nickname", member.nick]; yield ["nickname", member.nickname];
} }
// type 4 = custom status for (const activity of member.presence.activities) {
if (trigger.match_custom_status && member.game?.type === 4 && member.game?.state) { if (activity.type === Constants.ActivityTypes[4]) {
yield ["customstatus", member.game.state]; yield ["customstatus", `${activity.emoji} ${activity.name}`];
break;
}
} }
} }

View file

@ -1,8 +1,9 @@
import { disableUserNotificationStrings, UserNotificationMethod } from "../../../utils"; import { disableUserNotificationStrings, UserNotificationMethod } from "../../../utils";
import { ERRORS, RecoverablePluginError } from "../../../RecoverablePluginError"; import { ERRORS, RecoverablePluginError } from "../../../RecoverablePluginError";
import { TextChannel } from "eris";
import { GuildPluginData } from "knub"; import { GuildPluginData } from "knub";
import { AutomodPluginType } from "../types"; import { AutomodPluginType } from "../types";
import { TextChannel } from "discord.js";
export function resolveActionContactMethods( export function resolveActionContactMethods(
pluginData: GuildPluginData<AutomodPluginType>, pluginData: GuildPluginData<AutomodPluginType>,
@ -18,7 +19,7 @@ export function resolveActionContactMethods(
throw new RecoverablePluginError(ERRORS.NO_USER_NOTIFICATION_CHANNEL); 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)) { if (!(channel instanceof TextChannel)) {
throw new RecoverablePluginError(ERRORS.INVALID_USER_NOTIFICATION_CHANNEL); throw new RecoverablePluginError(ERRORS.INVALID_USER_NOTIFICATION_CHANNEL);
} }

View file

@ -5,14 +5,14 @@ import { availableActions } from "../actions/availableActions";
import { AutomodTriggerMatchResult } from "../helpers"; import { AutomodTriggerMatchResult } from "../helpers";
import { CleanAction } from "../actions/clean"; import { CleanAction } from "../actions/clean";
import { checkAndUpdateCooldown } from "./checkAndUpdateCooldown"; import { checkAndUpdateCooldown } from "./checkAndUpdateCooldown";
import { TextChannel } from "eris"; import { TextChannel } from "discord.js";
export async function runAutomod(pluginData: GuildPluginData<AutomodPluginType>, context: AutomodContext) { export async function runAutomod(pluginData: GuildPluginData<AutomodPluginType>, context: AutomodContext) {
const userId = context.user?.id || context.member?.id || context.message?.user_id; const userId = context.user?.id || context.member?.id || context.message?.user_id;
const user = context.user || (userId && pluginData.client.users.get(userId)); const user = context.user || (userId && pluginData.client.users!.cache.get(userId));
const member = context.member || (userId && pluginData.guild.members.get(userId)) || null; const member = context.member || (userId && pluginData.guild.members.cache.get(userId)) || null;
const channelId = context.message?.channel_id; 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 categoryId = channel?.parentID;
const config = await pluginData.config.getMatchingConfig({ const config = await pluginData.config.getMatchingConfig({

View file

@ -1,10 +1,10 @@
import { User } from "eris";
import { GuildPluginData } from "knub"; import { GuildPluginData } from "knub";
import { AutomodPluginType } from "../types"; import { AutomodPluginType } from "../types";
import { LogsPlugin } from "../../Logs/LogsPlugin"; import { LogsPlugin } from "../../Logs/LogsPlugin";
import { LogType } from "../../../data/LogType"; import { LogType } from "../../../data/LogType";
import { stripObjectToScalars } from "../../../utils"; import { stripObjectToScalars } from "../../../utils";
import { runAutomodOnAntiraidLevel } from "../events/runAutomodOnAntiraidLevel"; import { runAutomodOnAntiraidLevel } from "../events/runAutomodOnAntiraidLevel";
import { User } from "discord.js";
export async function setAntiraidLevel( export async function setAntiraidLevel(
pluginData: GuildPluginData<AutomodPluginType>, pluginData: GuildPluginData<AutomodPluginType>,

View file

@ -21,7 +21,7 @@ export const AnyMessageTrigger = automodTrigger<AnyMessageResultType>()({
}, },
renderMatchInformation({ pluginData, contexts, matchResult }) { 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 ${ return `Matched message (\`${contexts[0].message!.id}\`) in ${
channel ? verboseChannelMention(channel) : "Unknown Channel" channel ? verboseChannelMention(channel) : "Unknown Channel"
}`; }`;

View file

@ -73,7 +73,7 @@ export const MatchAttachmentTypeTrigger = automodTrigger<MatchResultType>()({
}, },
renderMatchInformation({ pluginData, contexts, matchResult }) { 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); const prettyChannel = verboseChannelMention(channel);
return ( return (

View file

@ -33,7 +33,7 @@ export const RoleAddedTrigger = automodTrigger<RoleAddedMatchResult>()({
}, },
renderMatchInformation({ matchResult, pluginData, contexts }) { 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 roleName = role?.name || "Unknown";
const member = contexts[0].member!; const member = contexts[0].member!;
const memberName = `**${member.user.username}#${member.user.discriminator}** (\`${member.id}\`)`; const memberName = `**${member.user.username}#${member.user.discriminator}** (\`${member.id}\`)`;

View file

@ -33,7 +33,7 @@ export const RoleRemovedTrigger = automodTrigger<RoleAddedMatchResult>()({
}, },
renderMatchInformation({ matchResult, pluginData, contexts }) { 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 roleName = role?.name || "Unknown";
const member = contexts[0].member!; const member = contexts[0].member!;
const memberName = `**${member.user.username}#${member.user.discriminator}** (\`${member.id}\`)`; const memberName = `**${member.user.username}#${member.user.discriminator}** (\`${member.id}\`)`;

View file

@ -4,7 +4,7 @@ import { BasePluginType, CooldownManager } from "knub";
import { GuildSavedMessages } from "../../data/GuildSavedMessages"; import { GuildSavedMessages } from "../../data/GuildSavedMessages";
import { GuildLogs } from "../../data/GuildLogs"; import { GuildLogs } from "../../data/GuildLogs";
import { SavedMessage } from "../../data/entities/SavedMessage"; import { SavedMessage } from "../../data/entities/SavedMessage";
import { Member, User } from "eris";
import { AvailableTriggers } from "./triggers/availableTriggers"; import { AvailableTriggers } from "./triggers/availableTriggers";
import { AvailableActions } from "./actions/availableActions"; import { AvailableActions } from "./actions/availableActions";
import { Queue } from "../../Queue"; import { Queue } from "../../Queue";
@ -16,6 +16,7 @@ import { RegExpRunner } from "../../RegExpRunner";
import { CounterEvents } from "../Counters/types"; import { CounterEvents } from "../Counters/types";
import { ModActionsEvents, ModActionType } from "../ModActions/types"; import { ModActionsEvents, ModActionType } from "../ModActions/types";
import { MutesEvents } from "../Mutes/types"; import { MutesEvents } from "../Mutes/types";
import { GuildMember, User } from "discord.js";
export const Rule = t.type({ export const Rule = t.type({
enabled: t.boolean, enabled: t.boolean,
@ -113,7 +114,7 @@ export interface AutomodContext {
}; };
user?: User; user?: User;
message?: SavedMessage; message?: SavedMessage;
member?: Member; member?: GuildMember;
joined?: boolean; joined?: boolean;
rolesChanged?: { rolesChanged?: {
added?: string[]; added?: string[];

View file

@ -1,7 +1,7 @@
import { zeppelinGlobalPlugin } from "../ZeppelinPluginBlueprint"; import { zeppelinGlobalPlugin } from "../ZeppelinPluginBlueprint";
import { BotControlPluginType, ConfigSchema } from "./types"; import { BotControlPluginType, ConfigSchema } from "./types";
import { GuildArchives } from "../../data/GuildArchives"; import { GuildArchives } from "../../data/GuildArchives";
import { TextChannel } from "eris";
import { sendSuccessMessage } from "../../pluginUtils"; import { sendSuccessMessage } from "../../pluginUtils";
import { getActiveReload, resetActiveReload } from "./activeReload"; import { getActiveReload, resetActiveReload } from "./activeReload";
import { ReloadGlobalPluginsCmd } from "./commands/ReloadGlobalPluginsCmd"; import { ReloadGlobalPluginsCmd } from "./commands/ReloadGlobalPluginsCmd";
@ -18,6 +18,7 @@ import { ApiPermissionAssignments } from "../../data/ApiPermissionAssignments";
import { ListDashboardUsersCmd } from "./commands/ListDashboardUsersCmd"; import { ListDashboardUsersCmd } from "./commands/ListDashboardUsersCmd";
import { ListDashboardPermsCmd } from "./commands/ListDashboardPermsCmd"; import { ListDashboardPermsCmd } from "./commands/ListDashboardPermsCmd";
import { EligibleCmd } from "./commands/EligibleCmd"; import { EligibleCmd } from "./commands/EligibleCmd";
import { TextChannel } from "discord.js";
const defaultOptions = { const defaultOptions = {
config: { config: {
@ -47,7 +48,7 @@ export const BotControlPlugin = zeppelinGlobalPlugin<BotControlPluginType>()({
EligibleCmd, EligibleCmd,
], ],
afterLoad(pluginData) { async afterLoad(pluginData) {
pluginData.state.archives = new GuildArchives(0); pluginData.state.archives = new GuildArchives(0);
pluginData.state.allowedGuilds = new AllowedGuilds(); pluginData.state.allowedGuilds = new AllowedGuilds();
pluginData.state.configs = new Configs(); pluginData.state.configs = new Configs();
@ -58,9 +59,9 @@ export const BotControlPlugin = zeppelinGlobalPlugin<BotControlPluginType>()({
const [guildId, channelId] = activeReload; const [guildId, channelId] = activeReload;
resetActiveReload(); resetActiveReload();
const guild = pluginData.client.guilds.get(guildId); const guild = await pluginData.client.guilds.fetch(guildId);
if (guild) { if (guild) {
const channel = guild.channels.get(channelId); const channel = guild.channels.cache.get(channelId);
if (channel instanceof TextChannel) { if (channel instanceof TextChannel) {
sendSuccessMessage(pluginData, channel, "Global plugins reloaded!"); sendSuccessMessage(pluginData, channel, "Global plugins reloaded!");
} }

View file

@ -3,7 +3,6 @@ import { isOwnerPreFilter, sendErrorMessage, sendSuccessMessage } from "../../..
import { commandTypeHelpers as ct } from "../../../commandTypes"; import { commandTypeHelpers as ct } from "../../../commandTypes";
import { ApiPermissions } from "@shared/apiPermissions"; import { ApiPermissions } from "@shared/apiPermissions";
import { resolveUser, UnknownUser } from "../../../utils"; import { resolveUser, UnknownUser } from "../../../utils";
import { User } from "eris";
export const ListDashboardUsersCmd = botControlCmd({ export const ListDashboardUsersCmd = botControlCmd({
trigger: ["list_dashboard_users"], trigger: ["list_dashboard_users"],

View file

@ -1,7 +1,6 @@
import { botControlCmd } from "../types"; import { botControlCmd } from "../types";
import { isOwnerPreFilter } from "../../../pluginUtils"; import { isOwnerPreFilter } from "../../../pluginUtils";
import { getActiveReload, setActiveReload } from "../activeReload"; import { getActiveReload, setActiveReload } from "../activeReload";
import { TextChannel } from "eris";
export const ReloadGlobalPluginsCmd = botControlCmd({ export const ReloadGlobalPluginsCmd = botControlCmd({
trigger: "bot_reload_global_plugins", trigger: "bot_reload_global_plugins",

View file

@ -1,5 +1,5 @@
import { Case } from "../../../data/entities/Case"; import { Case } from "../../../data/entities/Case";
import { AdvancedMessageContent, MessageContent } from "eris";
import moment from "moment-timezone"; import moment from "moment-timezone";
import { CaseTypes } from "../../../data/CaseTypes"; import { CaseTypes } from "../../../data/CaseTypes";
import { GuildPluginData, helpers } from "knub"; import { GuildPluginData, helpers } from "knub";
@ -8,13 +8,14 @@ import { resolveCaseId } from "./resolveCaseId";
import { chunkLines, chunkMessageLines, emptyEmbedValue, messageLink } from "../../../utils"; import { chunkLines, chunkMessageLines, emptyEmbedValue, messageLink } from "../../../utils";
import { getCaseColor } from "./getCaseColor"; import { getCaseColor } from "./getCaseColor";
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin"; import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
import { MessageOptions } from "discord.js";
export async function getCaseEmbed( export async function getCaseEmbed(
pluginData: GuildPluginData<CasesPluginType>, pluginData: GuildPluginData<CasesPluginType>,
caseOrCaseId: Case | number, caseOrCaseId: Case | number,
requestMemberId?: string, requestMemberId?: string,
noOriginalCaseLink?: boolean, noOriginalCaseLink?: boolean,
): Promise<AdvancedMessageContent> { ): Promise<MessageOptions> {
const theCase = await pluginData.state.cases.with("notes").find(resolveCaseId(caseOrCaseId)); const theCase = await pluginData.state.cases.with("notes").find(resolveCaseId(caseOrCaseId));
if (!theCase) { if (!theCase) {
throw new Error("Unknown case"); throw new Error("Unknown case");

View file

@ -1,27 +1,30 @@
import { GuildPluginData } from "knub"; import { GuildPluginData } from "knub";
import { CasesPluginType } from "../types"; import { CasesPluginType } from "../types";
import { Message, MessageContent, MessageFile, TextChannel } from "eris";
import { isDiscordRESTError } from "../../../utils"; import { isDiscordRESTError } from "../../../utils";
import { LogType } from "../../../data/LogType"; import { LogType } from "../../../data/LogType";
import { Case } from "../../../data/entities/Case"; import { Case } from "../../../data/entities/Case";
import { getCaseEmbed } from "./getCaseEmbed"; import { getCaseEmbed } from "./getCaseEmbed";
import { resolveCaseId } from "./resolveCaseId"; import { resolveCaseId } from "./resolveCaseId";
import { logger } from "../../../logger"; import { FileOptions, Message, MessageOptions, TextChannel } from "discord.js";
export async function postToCaseLogChannel( export async function postToCaseLogChannel(
pluginData: GuildPluginData<CasesPluginType>, pluginData: GuildPluginData<CasesPluginType>,
content: MessageContent, content: MessageOptions,
file?: MessageFile, file?: FileOptions[],
): Promise<Message | null> { ): Promise<Message | null> {
const caseLogChannelId = pluginData.config.get().case_log_channel; const caseLogChannelId = pluginData.config.get().case_log_channel;
if (!caseLogChannelId) return null; if (!caseLogChannelId) return null;
const caseLogChannel = pluginData.guild.channels.get(caseLogChannelId); const caseLogChannel = pluginData.guild.channels.cache.get(caseLogChannelId);
if (!caseLogChannel || !(caseLogChannel instanceof TextChannel)) return null; if (!caseLogChannel || !(caseLogChannel instanceof TextChannel)) return null;
let result; let result;
try { try {
result = await caseLogChannel.createMessage(content, file); if (file != undefined) {
content.files = file;
}
result = await caseLogChannel.send({ ...content, split: false });
} catch (e) { } catch (e) {
if (isDiscordRESTError(e) && (e.code === 50013 || e.code === 50001)) { if (isDiscordRESTError(e) && (e.code === 50013 || e.code === 50001)) {
pluginData.state.logs.log(LogType.BOT_ALERT, { pluginData.state.logs.log(LogType.BOT_ALERT, {
@ -50,7 +53,8 @@ export async function postCaseToCaseLogChannel(
const [channelId, messageId] = theCase.log_message_id.split("-"); const [channelId, messageId] = theCase.log_message_id.split("-");
try { try {
await pluginData.client.editMessage(channelId, messageId, caseEmbed); const channel = pluginData.guild.channels.resolve(channelId) as TextChannel;
await channel.messages.edit(messageId, caseEmbed);
return null; return null;
} catch {} // tslint:disable-line:no-empty } catch {} // tslint:disable-line:no-empty
} }

View file

@ -1,7 +1,7 @@
import { GuildPluginData } from "knub"; import { GuildPluginData } from "knub";
import { CensorPluginType } from "../types"; import { CensorPluginType } from "../types";
import { SavedMessage } from "../../../data/entities/SavedMessage"; import { SavedMessage } from "../../../data/entities/SavedMessage";
import { Embed, Invite } from "eris";
import { ZalgoRegex } from "../../../data/Zalgo"; import { ZalgoRegex } from "../../../data/Zalgo";
import { getInviteCodesInString, getUrlsInString, resolveMember, resolveInvite, isGuildInvite } from "../../../utils"; import { getInviteCodesInString, getUrlsInString, resolveMember, resolveInvite, isGuildInvite } from "../../../utils";
import cloneDeep from "lodash.clonedeep"; import cloneDeep from "lodash.clonedeep";

View file

@ -19,7 +19,7 @@ export async function censorMessage(
} }
const user = await resolveUser(pluginData.client, savedMessage.user_id); const user = await resolveUser(pluginData.client, savedMessage.user_id);
const channel = pluginData.guild.channels.get(savedMessage.channel_id); const channel = pluginData.guild.channels.cache.get(savedMessage.channel_id);
pluginData.state.serverLogs.log(LogType.CENSOR, { pluginData.state.serverLogs.log(LogType.CENSOR, {
user: stripObjectToScalars(user), user: stripObjectToScalars(user),

View file

@ -1,4 +1,3 @@
import { Attachment, TextChannel } from "eris";
import { downloadFile } from "../../utils"; import { downloadFile } from "../../utils";
import fs from "fs"; import fs from "fs";
const fsp = fs.promises; const fsp = fs.promises;

View file

@ -1,4 +1,3 @@
import { VoiceChannel } from "eris";
import { GuildPluginData } from "knub"; import { GuildPluginData } from "knub";
import { CompanionChannelsPluginType, TCompanionChannelOpts } from "../types"; import { CompanionChannelsPluginType, TCompanionChannelOpts } from "../types";

View file

@ -1,7 +1,7 @@
import { CompanionChannelsPluginType, TCompanionChannelOpts } from "../types"; import { CompanionChannelsPluginType, TCompanionChannelOpts } from "../types";
import { getCompanionChannelOptsForVoiceChannelId } from "./getCompanionChannelOptsForVoiceChannelId"; import { getCompanionChannelOptsForVoiceChannelId } from "./getCompanionChannelOptsForVoiceChannelId";
import { GuildPluginData } from "knub"; import { GuildPluginData } from "knub";
import { TextChannel, VoiceChannel } from "eris";
import { isDiscordRESTError, MINUTES } from "../../../utils"; import { isDiscordRESTError, MINUTES } from "../../../utils";
import { LogsPlugin } from "../../Logs/LogsPlugin"; import { LogsPlugin } from "../../Logs/LogsPlugin";
import { LogType } from "../../../data/LogType"; import { LogType } from "../../../data/LogType";
@ -63,13 +63,13 @@ export async function handleCompanionPermissions(
try { try {
for (const channelId of permsToDelete) { for (const channelId of permsToDelete) {
const channel = pluginData.guild.channels.get(channelId); const channel = pluginData.guild.channels.cache.get(channelId);
if (!channel || !(channel instanceof TextChannel)) continue; if (!channel || !(channel instanceof TextChannel)) continue;
await channel.deletePermission(userId, `Companion Channel for ${oldChannel!.id} | User Left`); await channel.deletePermission(userId, `Companion Channel for ${oldChannel!.id} | User Left`);
} }
for (const [channelId, permissions] of permsToSet) { for (const [channelId, permissions] of permsToSet) {
const channel = pluginData.guild.channels.get(channelId); const channel = pluginData.guild.channels.cache.get(channelId);
if (!channel || !(channel instanceof TextChannel)) continue; if (!channel || !(channel instanceof TextChannel)) continue;
await channel.editPermission( await channel.editPermission(
userId, userId,

View file

@ -3,7 +3,7 @@ import { CountersPluginType } from "../types";
import { commandTypeHelpers as ct } from "../../../commandTypes"; import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage } from "../../../pluginUtils"; import { sendErrorMessage } from "../../../pluginUtils";
import { resolveChannel, waitForReply } from "knub/dist/helpers"; import { resolveChannel, waitForReply } from "knub/dist/helpers";
import { TextChannel, User } from "eris";
import { resolveUser, UnknownUser } from "../../../utils"; import { resolveUser, UnknownUser } from "../../../utils";
import { changeCounterValue } from "../functions/changeCounterValue"; import { changeCounterValue } from "../functions/changeCounterValue";

View file

@ -3,7 +3,7 @@ import { CountersPluginType } from "../types";
import { commandTypeHelpers as ct } from "../../../commandTypes"; import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { resolveChannel, waitForReply } from "knub/dist/helpers"; import { resolveChannel, waitForReply } from "knub/dist/helpers";
import { TextChannel, User } from "eris";
import { confirm, MINUTES, noop, resolveUser, trimMultilineString, UnknownUser } from "../../../utils"; import { confirm, MINUTES, noop, resolveUser, trimMultilineString, UnknownUser } from "../../../utils";
import { changeCounterValue } from "../functions/changeCounterValue"; import { changeCounterValue } from "../functions/changeCounterValue";
import { setCounterValue } from "../functions/setCounterValue"; import { setCounterValue } from "../functions/setCounterValue";

View file

@ -3,7 +3,7 @@ import { CountersPluginType } from "../types";
import { commandTypeHelpers as ct } from "../../../commandTypes"; import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage } from "../../../pluginUtils"; import { sendErrorMessage } from "../../../pluginUtils";
import { resolveChannel, waitForReply } from "knub/dist/helpers"; import { resolveChannel, waitForReply } from "knub/dist/helpers";
import { TextChannel } from "eris";
import { resolveUser, UnknownUser } from "../../../utils"; import { resolveUser, UnknownUser } from "../../../utils";
import { setCounterValue } from "../functions/setCounterValue"; import { setCounterValue } from "../functions/setCounterValue";

View file

@ -3,7 +3,7 @@ import { CountersPluginType } from "../types";
import { commandTypeHelpers as ct } from "../../../commandTypes"; import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage } from "../../../pluginUtils"; import { sendErrorMessage } from "../../../pluginUtils";
import { resolveChannel, waitForReply } from "knub/dist/helpers"; import { resolveChannel, waitForReply } from "knub/dist/helpers";
import { TextChannel, User } from "eris";
import { resolveUser, UnknownUser } from "../../../utils"; import { resolveUser, UnknownUser } from "../../../utils";
import { changeCounterValue } from "../functions/changeCounterValue"; import { changeCounterValue } from "../functions/changeCounterValue";
import { setCounterValue } from "../functions/setCounterValue"; import { setCounterValue } from "../functions/setCounterValue";

View file

@ -3,7 +3,7 @@ import { CountersPluginType } from "../types";
import { commandTypeHelpers as ct } from "../../../commandTypes"; import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage } from "../../../pluginUtils"; import { sendErrorMessage } from "../../../pluginUtils";
import { resolveChannel, waitForReply } from "knub/dist/helpers"; import { resolveChannel, waitForReply } from "knub/dist/helpers";
import { TextChannel, User } from "eris";
import { resolveUser, UnknownUser } from "../../../utils"; import { resolveUser, UnknownUser } from "../../../utils";
export const ViewCounterCmd = typedGuildCommand<CountersPluginType>()({ export const ViewCounterCmd = typedGuildCommand<CountersPluginType>()({

View file

@ -5,7 +5,6 @@ import { renderTemplate } from "../../../templateFormatter";
import { resolveMember } from "../../../utils"; import { resolveMember } from "../../../utils";
import { ActionError } from "../ActionError"; import { ActionError } from "../ActionError";
import { canActOn } from "../../../pluginUtils"; import { canActOn } from "../../../pluginUtils";
import { Message } from "eris";
export const AddRoleAction = t.type({ export const AddRoleAction = t.type({
type: t.literal("add_role"), type: t.literal("add_role"),

View file

@ -18,7 +18,7 @@ export async function makeRoleMentionableAction(
event: TCustomEvent, event: TCustomEvent,
eventData: any, eventData: any,
) { ) {
const role = pluginData.guild.roles.get(action.role); const role = pluginData.guild.roles.cache.get(action.role);
if (!role) { if (!role) {
throw new ActionError(`Unknown role: ${role}`); throw new ActionError(`Unknown role: ${role}`);
} }

View file

@ -16,7 +16,7 @@ export async function makeRoleUnmentionableAction(
event: TCustomEvent, event: TCustomEvent,
eventData: any, eventData: any,
) { ) {
const role = pluginData.guild.roles.get(action.role); const role = pluginData.guild.roles.cache.get(action.role);
if (!role) { if (!role) {
throw new ActionError(`Unknown role: ${role}`); throw new ActionError(`Unknown role: ${role}`);
} }

View file

@ -3,7 +3,6 @@ import { CustomEventsPluginType } from "../types";
import * as t from "io-ts"; import * as t from "io-ts";
import { renderTemplate } from "../../../templateFormatter"; import { renderTemplate } from "../../../templateFormatter";
import { ActionError } from "../ActionError"; import { ActionError } from "../ActionError";
import { TextChannel } from "eris";
export const MessageAction = t.type({ export const MessageAction = t.type({
type: t.literal("message"), type: t.literal("message"),
@ -18,7 +17,7 @@ export async function messageAction(
values: any, values: any,
) { ) {
const targetChannelId = await renderTemplate(action.channel, values, false); const targetChannelId = await renderTemplate(action.channel, values, false);
const targetChannel = pluginData.guild.channels.get(targetChannelId); const targetChannel = pluginData.guild.channels.cache.get(targetChannelId);
if (!targetChannel) throw new ActionError("Unknown target channel"); if (!targetChannel) throw new ActionError("Unknown target channel");
if (!(targetChannel instanceof TextChannel)) throw new ActionError("Target channel is not a text channel"); if (!(targetChannel instanceof TextChannel)) throw new ActionError("Target channel is not a text channel");

View file

@ -5,7 +5,6 @@ import { renderTemplate } from "../../../templateFormatter";
import { resolveMember } from "../../../utils"; import { resolveMember } from "../../../utils";
import { ActionError } from "../ActionError"; import { ActionError } from "../ActionError";
import { canActOn } from "../../../pluginUtils"; import { canActOn } from "../../../pluginUtils";
import { Message, VoiceChannel } from "eris";
export const MoveToVoiceChannelAction = t.type({ export const MoveToVoiceChannelAction = t.type({
type: t.literal("move_to_vc"), type: t.literal("move_to_vc"),
@ -30,7 +29,7 @@ export async function moveToVoiceChannelAction(
} }
const targetChannelId = await renderTemplate(action.channel, values, false); const targetChannelId = await renderTemplate(action.channel, values, false);
const targetChannel = pluginData.guild.channels.get(targetChannelId); const targetChannel = pluginData.guild.channels.cache.get(targetChannelId);
if (!targetChannel) throw new ActionError("Unknown target channel"); if (!targetChannel) throw new ActionError("Unknown target channel");
if (!(targetChannel instanceof VoiceChannel)) throw new ActionError("Target channel is not a voice channel"); if (!(targetChannel instanceof VoiceChannel)) throw new ActionError("Target channel is not a voice channel");

View file

@ -24,7 +24,7 @@ export async function setChannelPermissionOverridesAction(
event: TCustomEvent, event: TCustomEvent,
eventData: any, eventData: any,
) { ) {
const channel = pluginData.guild.channels.get(action.channel); const channel = pluginData.guild.channels.cache.get(action.channel);
if (!channel) { if (!channel) {
throw new ActionError(`Unknown channel: ${action.channel}`); throw new ActionError(`Unknown channel: ${action.channel}`);
} }

View file

@ -2,7 +2,7 @@ import { GuildPluginData } from "knub";
import { CustomEventsPluginType, TCustomEvent } from "../types"; import { CustomEventsPluginType, TCustomEvent } from "../types";
import { sendErrorMessage } from "../../../pluginUtils"; import { sendErrorMessage } from "../../../pluginUtils";
import { ActionError } from "../ActionError"; import { ActionError } from "../ActionError";
import { Message } from "eris";
import { addRoleAction } from "../actions/addRoleAction"; import { addRoleAction } from "../actions/addRoleAction";
import { createCaseAction } from "../actions/createCaseAction"; import { createCaseAction } from "../actions/createCaseAction";
import { moveToVoiceChannelAction } from "../actions/moveToVoiceChannelAction"; import { moveToVoiceChannelAction } from "../actions/moveToVoiceChannelAction";

View file

@ -2,7 +2,6 @@ import { zeppelinGlobalPlugin } from "../ZeppelinPluginBlueprint";
import { BasePluginType, typedGlobalEventListener, GlobalPluginData } from "knub"; import { BasePluginType, typedGlobalEventListener, GlobalPluginData } from "knub";
import * as t from "io-ts"; import * as t from "io-ts";
import { AllowedGuilds } from "../../data/AllowedGuilds"; import { AllowedGuilds } from "../../data/AllowedGuilds";
import { Guild } from "eris";
interface GuildAccessMonitorPluginType extends BasePluginType { interface GuildAccessMonitorPluginType extends BasePluginType {
config: {}; config: {};

View file

@ -1,6 +1,5 @@
import { locateUserEvt } from "../types"; import { locateUserEvt } from "../types";
import { sendAlerts } from "../utils/sendAlerts"; import { sendAlerts } from "../utils/sendAlerts";
import { TextableChannel, VoiceChannel } from "eris";
export const ChannelJoinAlertsEvt = locateUserEvt({ export const ChannelJoinAlertsEvt = locateUserEvt({
event: "voiceChannelJoin", event: "voiceChannelJoin",

View file

@ -1,5 +1,3 @@
import { VoiceChannel } from "eris";
export async function createOrReuseInvite(vc: VoiceChannel) { export async function createOrReuseInvite(vc: VoiceChannel) {
const existingInvites = await vc.getInvites(); const existingInvites = await vc.getInvites();

View file

@ -1,4 +1,3 @@
import { Member, TextableChannel } from "eris";
import { GuildPluginData } from "knub"; import { GuildPluginData } from "knub";
import { LocateUserPluginType } from "../types"; import { LocateUserPluginType } from "../types";
import { sendErrorMessage } from "../../../pluginUtils"; import { sendErrorMessage } from "../../../pluginUtils";

View file

@ -2,7 +2,7 @@ import { GuildPluginData } from "knub";
import { LocateUserPluginType } from "../types"; import { LocateUserPluginType } from "../types";
import { resolveMember } from "../../../utils"; import { resolveMember } from "../../../utils";
import { sendWhere } from "./sendWhere"; import { sendWhere } from "./sendWhere";
import { TextableChannel } from "eris";
import { moveMember } from "./moveMember"; import { moveMember } from "./moveMember";
export async function sendAlerts(pluginData: GuildPluginData<LocateUserPluginType>, userId: string) { export async function sendAlerts(pluginData: GuildPluginData<LocateUserPluginType>, userId: string) {

View file

@ -1,4 +1,3 @@
import { Invite, Member, TextableChannel, VoiceChannel } from "eris";
import { getInviteLink } from "knub/dist/helpers"; import { getInviteLink } from "knub/dist/helpers";
import { createOrReuseInvite } from "./createOrReuseInvite"; import { createOrReuseInvite } from "./createOrReuseInvite";
import { GuildPluginData } from "knub"; import { GuildPluginData } from "knub";
@ -12,7 +11,7 @@ export async function sendWhere(
prepend: string, prepend: string,
) { ) {
const voice = member.voiceState.channelID const voice = member.voiceState.channelID
? (pluginData.guild.channels.get(member.voiceState.channelID) as VoiceChannel) ? (pluginData.guild.channels.cache.get(member.voiceState.channelID) as VoiceChannel)
: null; : null;
if (voice == null) { if (voice == null) {

View file

@ -14,7 +14,6 @@ import { LogsGuildMemberRemoveEvt } from "./events/LogsGuildMemberRemoveEvt";
import { LogsGuildMemberUpdateEvt } from "./events/LogsUserUpdateEvts"; import { LogsGuildMemberUpdateEvt } from "./events/LogsUserUpdateEvts";
import { LogsChannelCreateEvt, LogsChannelDeleteEvt } from "./events/LogsChannelModifyEvts"; import { LogsChannelCreateEvt, LogsChannelDeleteEvt } from "./events/LogsChannelModifyEvts";
import { LogsRoleCreateEvt, LogsRoleDeleteEvt } from "./events/LogsRoleModifyEvts"; import { LogsRoleCreateEvt, LogsRoleDeleteEvt } from "./events/LogsRoleModifyEvts";
import { LogsVoiceJoinEvt, LogsVoiceLeaveEvt, LogsVoiceSwitchEvt } from "./events/LogsVoiceChannelEvts";
import { log } from "./util/log"; import { log } from "./util/log";
import { LogType } from "../../data/LogType"; import { LogType } from "../../data/LogType";
import { getLogMessage } from "./util/getLogMessage"; import { getLogMessage } from "./util/getLogMessage";
@ -23,6 +22,7 @@ import { disableCodeBlocks } from "../../utils";
import { logger } from "../../logger"; import { logger } from "../../logger";
import { CasesPlugin } from "../Cases/CasesPlugin"; import { CasesPlugin } from "../Cases/CasesPlugin";
import { TimeAndDatePlugin } from "../TimeAndDate/TimeAndDatePlugin"; import { TimeAndDatePlugin } from "../TimeAndDate/TimeAndDatePlugin";
import { LogsVoiceStateUpdateEvt } from "./events/LogsVoiceChannelEvts";
const defaultOptions: PluginOptions<LogsPluginType> = { const defaultOptions: PluginOptions<LogsPluginType> = {
config: { config: {
@ -66,9 +66,7 @@ export const LogsPlugin = zeppelinGuildPlugin<LogsPluginType>()({
LogsChannelDeleteEvt, LogsChannelDeleteEvt,
LogsRoleCreateEvt, LogsRoleCreateEvt,
LogsRoleDeleteEvt, LogsRoleDeleteEvt,
LogsVoiceJoinEvt, LogsVoiceStateUpdateEvt,
LogsVoiceLeaveEvt,
LogsVoiceSwitchEvt,
], ],
public: { public: {

View file

@ -1,7 +1,7 @@
import { logsEvt } from "../types"; import { logsEvt } from "../types";
import { stripObjectToScalars, UnknownUser } from "../../../utils"; import { stripObjectToScalars, UnknownUser } from "../../../utils";
import { LogType } from "../../../data/LogType"; import { LogType } from "../../../data/LogType";
import { Constants as ErisConstants } from "eris";
import { safeFindRelevantAuditLogEntry } from "../../../utils/safeFindRelevantAuditLogEntry"; import { safeFindRelevantAuditLogEntry } from "../../../utils/safeFindRelevantAuditLogEntry";
export const LogsGuildBanAddEvt = logsEvt({ export const LogsGuildBanAddEvt = logsEvt({

View file

@ -3,7 +3,7 @@ import { stripObjectToScalars } from "../../../utils";
import { LogType } from "../../../data/LogType"; import { LogType } from "../../../data/LogType";
export const LogsRoleCreateEvt = logsEvt({ export const LogsRoleCreateEvt = logsEvt({
event: "guildRoleCreate", event: "roleCreate",
async listener(meta) { async listener(meta) {
meta.pluginData.state.guildLogs.log(LogType.ROLE_CREATE, { meta.pluginData.state.guildLogs.log(LogType.ROLE_CREATE, {
@ -13,7 +13,7 @@ export const LogsRoleCreateEvt = logsEvt({
}); });
export const LogsRoleDeleteEvt = logsEvt({ export const LogsRoleDeleteEvt = logsEvt({
event: "guildRoleDelete", event: "roleDelete",
async listener(meta) { async listener(meta) {
meta.pluginData.state.guildLogs.log(LogType.ROLE_DELETE, { meta.pluginData.state.guildLogs.log(LogType.ROLE_DELETE, {

View file

@ -1,6 +1,6 @@
import { logsEvt } from "../types"; import { logsEvt } from "../types";
import { stripObjectToScalars, UnknownUser } from "../../../utils"; import { stripObjectToScalars, UnknownUser } from "../../../utils";
import { Constants as ErisConstants } from "eris";
import { LogType } from "../../../data/LogType"; import { LogType } from "../../../data/LogType";
import isEqual from "lodash.isequal"; import isEqual from "lodash.isequal";
import diff from "lodash.difference"; import diff from "lodash.difference";
@ -61,11 +61,11 @@ export const LogsGuildMemberUpdateEvt = logsEvt({
{ {
member: logMember, member: logMember,
addedRoles: addedRoles addedRoles: addedRoles
.map(roleId => pluginData.guild.roles.get(roleId) || { id: roleId, name: `Unknown (${roleId})` }) .map(roleId => pluginData.guild.roles.cache.get(roleId) || { id: roleId, name: `Unknown (${roleId})` })
.map(r => r.name) .map(r => r.name)
.join(", "), .join(", "),
removedRoles: removedRoles removedRoles: removedRoles
.map(roleId => pluginData.guild.roles.get(roleId) || { id: roleId, name: `Unknown (${roleId})` }) .map(roleId => pluginData.guild.roles.cache.get(roleId) || { id: roleId, name: `Unknown (${roleId})` })
.map(r => r.name) .map(r => r.name)
.join(", "), .join(", "),
mod: stripObjectToScalars(mod), mod: stripObjectToScalars(mod),
@ -79,7 +79,7 @@ export const LogsGuildMemberUpdateEvt = logsEvt({
{ {
member: logMember, member: logMember,
roles: addedRoles roles: addedRoles
.map(roleId => pluginData.guild.roles.get(roleId) || { id: roleId, name: `Unknown (${roleId})` }) .map(roleId => pluginData.guild.roles.cache.get(roleId) || { id: roleId, name: `Unknown (${roleId})` })
.map(r => r.name) .map(r => r.name)
.join(", "), .join(", "),
mod: stripObjectToScalars(mod), mod: stripObjectToScalars(mod),
@ -93,7 +93,7 @@ export const LogsGuildMemberUpdateEvt = logsEvt({
{ {
member: logMember, member: logMember,
roles: removedRoles roles: removedRoles
.map(roleId => pluginData.guild.roles.get(roleId) || { id: roleId, name: `Unknown (${roleId})` }) .map(roleId => pluginData.guild.roles.cache.get(roleId) || { id: roleId, name: `Unknown (${roleId})` })
.map(r => r.name) .map(r => r.name)
.join(", "), .join(", "),
mod: stripObjectToScalars(mod), mod: stripObjectToScalars(mod),

View file

@ -1,7 +1,7 @@
import { logsEvt } from "../types"; import { logsEvt } from "../types";
import { stripObjectToScalars } from "../../../utils"; import { stripObjectToScalars } from "../../../utils";
import { LogType } from "../../../data/LogType"; import { LogType } from "../../../data/LogType";
/** Merge into single event
export const LogsVoiceJoinEvt = logsEvt({ export const LogsVoiceJoinEvt = logsEvt({
event: "voiceChannelJoin", event: "voiceChannelJoin",
@ -35,3 +35,12 @@ export const LogsVoiceSwitchEvt = logsEvt({
}); });
}, },
}); });
**/
export const LogsVoiceStateUpdateEvt = logsEvt({
event: "voiceStateUpdate",
async listener(meta) {
console.error(`Fixme @LogsVoiceChannelEvts.ts`);
},
});

View file

@ -14,7 +14,6 @@ import { renderTemplate, TemplateParseError } from "../../../templateFormatter";
import { logger } from "../../../logger"; import { logger } from "../../../logger";
import moment from "moment-timezone"; import moment from "moment-timezone";
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin"; import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
import { MessageContent } from "eris";
export async function getLogMessage( export async function getLogMessage(
pluginData: GuildPluginData<LogsPluginType>, pluginData: GuildPluginData<LogsPluginType>,

View file

@ -1,7 +1,7 @@
import { GuildPluginData } from "knub"; import { GuildPluginData } from "knub";
import { LogsPluginType, TLogChannelMap } from "../types"; import { LogsPluginType, TLogChannelMap } from "../types";
import { LogType } from "../../../data/LogType"; import { LogType } from "../../../data/LogType";
import { TextChannel } from "eris";
import { createChunkedMessage, get, noop } from "../../../utils"; import { createChunkedMessage, get, noop } from "../../../utils";
import { getLogMessage } from "./getLogMessage"; import { getLogMessage } from "./getLogMessage";
import { allowTimeout } from "../../../RegExpRunner"; import { allowTimeout } from "../../../RegExpRunner";
@ -19,7 +19,7 @@ export async function log(pluginData: GuildPluginData<LogsPluginType>, type: Log
const typeStr = LogType[type]; const typeStr = LogType[type];
logChannelLoop: for (const [channelId, opts] of Object.entries(logChannels)) { logChannelLoop: for (const [channelId, opts] of Object.entries(logChannels)) {
const channel = pluginData.guild.channels.get(channelId); const channel = pluginData.guild.channels.cache.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))) {
@ -45,7 +45,7 @@ export async function log(pluginData: GuildPluginData<LogsPluginType>, type: Log
if (opts.excluded_roles) { if (opts.excluded_roles) {
for (const value of Object.values(data || {})) { for (const value of Object.values(data || {})) {
if (value instanceof SavedMessage) { if (value instanceof SavedMessage) {
const member = pluginData.guild.members.get(value.user_id); const member = pluginData.guild.members.cache.get(value.user_id);
for (const role of member?.roles || []) { for (const role of member?.roles || []) {
if (opts.excluded_roles.includes(role)) { if (opts.excluded_roles.includes(role)) {
continue logChannelLoop; continue logChannelLoop;

View file

@ -1,5 +1,5 @@
import { SavedMessage } from "../../../data/entities/SavedMessage"; import { SavedMessage } from "../../../data/entities/SavedMessage";
import { Attachment } from "eris";
import { useMediaUrls, stripObjectToScalars, resolveUser } from "../../../utils"; import { useMediaUrls, stripObjectToScalars, resolveUser } from "../../../utils";
import { LogType } from "../../../data/LogType"; import { LogType } from "../../../data/LogType";
import moment from "moment-timezone"; import moment from "moment-timezone";
@ -9,7 +9,7 @@ import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
export async function onMessageDelete(pluginData: GuildPluginData<LogsPluginType>, savedMessage: SavedMessage) { export async function onMessageDelete(pluginData: GuildPluginData<LogsPluginType>, savedMessage: SavedMessage) {
const user = await resolveUser(pluginData.client, savedMessage.user_id); const user = await resolveUser(pluginData.client, savedMessage.user_id);
const channel = pluginData.guild.channels.get(savedMessage.channel_id); const channel = pluginData.guild.channels.cache.get(savedMessage.channel_id);
if (user) { if (user) {
// Replace attachment URLs with media URLs // Replace attachment URLs with media URLs

View file

@ -5,7 +5,7 @@ import { LogType } from "../../../data/LogType";
import { getBaseUrl } from "../../../pluginUtils"; import { getBaseUrl } from "../../../pluginUtils";
export async function onMessageDeleteBulk(pluginData: GuildPluginData<LogsPluginType>, savedMessages: SavedMessage[]) { export async function onMessageDeleteBulk(pluginData: GuildPluginData<LogsPluginType>, savedMessages: SavedMessage[]) {
const channel = pluginData.guild.channels.get(savedMessages[0].channel_id); const channel = pluginData.guild.channels.cache.get(savedMessages[0].channel_id);
const archiveId = await pluginData.state.archives.createFromSavedMessages(savedMessages, pluginData.guild); const archiveId = await pluginData.state.archives.createFromSavedMessages(savedMessages, pluginData.guild);
const archiveUrl = pluginData.state.archives.getUrl(getBaseUrl(pluginData), archiveId); const archiveUrl = pluginData.state.archives.getUrl(getBaseUrl(pluginData), archiveId);
const authorIds = Array.from(new Set(savedMessages.map(item => `\`${item.user_id}\``))).join(", "); const authorIds = Array.from(new Set(savedMessages.map(item => `\`${item.user_id}\``))).join(", ");

View file

@ -1,7 +1,7 @@
import { GuildPluginData } from "knub"; import { GuildPluginData } from "knub";
import { LogsPluginType } from "../types"; import { LogsPluginType } from "../types";
import { SavedMessage } from "../../../data/entities/SavedMessage"; import { SavedMessage } from "../../../data/entities/SavedMessage";
import { Embed } from "eris";
import { LogType } from "../../../data/LogType"; import { LogType } from "../../../data/LogType";
import { stripObjectToScalars, resolveUser } from "../../../utils"; import { stripObjectToScalars, resolveUser } from "../../../utils";
import cloneDeep from "lodash.clonedeep"; import cloneDeep from "lodash.clonedeep";
@ -47,7 +47,7 @@ export async function onMessageUpdate(
} }
const user = await resolveUser(pluginData.client, savedMessage.user_id); const user = await resolveUser(pluginData.client, savedMessage.user_id);
const channel = pluginData.guild.channels.get(savedMessage.channel_id); const channel = pluginData.guild.channels.cache.get(savedMessage.channel_id);
pluginData.state.guildLogs.log(LogType.MESSAGE_EDIT, { pluginData.state.guildLogs.log(LogType.MESSAGE_EDIT, {
user: stripObjectToScalars(user), user: stripObjectToScalars(user),

View file

@ -1,8 +1,7 @@
import { messageSaverEvt } from "../types"; import { messageSaverEvt } from "../types";
import { Message } from "eris";
export const MessageCreateEvt = messageSaverEvt({ export const MessageCreateEvt = messageSaverEvt({
event: "messageCreate", event: "message",
allowBots: true, allowBots: true,
allowSelf: true, allowSelf: true,

View file

@ -1,6 +1,5 @@
import { MessageSaverPluginType } from "./types"; import { MessageSaverPluginType } from "./types";
import { GuildPluginData } from "knub"; import { GuildPluginData } from "knub";
import { Message, TextChannel } from "eris";
export async function saveMessagesToDB( export async function saveMessagesToDB(
pluginData: GuildPluginData<MessageSaverPluginType>, pluginData: GuildPluginData<MessageSaverPluginType>,

View file

@ -30,7 +30,7 @@ import { GuildCases } from "../../data/GuildCases";
import { GuildLogs } from "../../data/GuildLogs"; import { GuildLogs } from "../../data/GuildLogs";
import { ForceUnmuteCmd } from "./commands/ForceunmuteCmd"; import { ForceUnmuteCmd } from "./commands/ForceunmuteCmd";
import { warnMember } from "./functions/warnMember"; import { warnMember } from "./functions/warnMember";
import { Member, Message } from "eris";
import { kickMember } from "./functions/kickMember"; import { kickMember } from "./functions/kickMember";
import { banUserId } from "./functions/banUserId"; import { banUserId } from "./functions/banUserId";
import { MassmuteCmd } from "./commands/MassmuteCmd"; import { MassmuteCmd } from "./commands/MassmuteCmd";

View file

@ -4,7 +4,7 @@ import { sendErrorMessage } from "../../../pluginUtils";
import { trimLines, createChunkedMessage, emptyEmbedValue, sorter, resolveUser } from "../../../utils"; import { trimLines, createChunkedMessage, emptyEmbedValue, sorter, resolveUser } from "../../../utils";
import { CasesPlugin } from "../../Cases/CasesPlugin"; import { CasesPlugin } from "../../Cases/CasesPlugin";
import { asyncMap } from "../../../utils/async"; import { asyncMap } from "../../../utils/async";
import { EmbedOptions, User } from "eris";
import { getChunkedEmbedFields } from "../../../utils/getChunkedEmbedFields"; import { getChunkedEmbedFields } from "../../../utils/getChunkedEmbedFields";
import { getDefaultPrefix } from "knub/dist/commands/commandUtils"; import { getDefaultPrefix } from "knub/dist/commands/commandUtils";
import { getGuildPrefix } from "../../../utils/getGuildPrefix"; import { getGuildPrefix } from "../../../utils/getGuildPrefix";

View file

@ -12,7 +12,7 @@ import {
chunkArray, chunkArray,
} from "../../../utils"; } from "../../../utils";
import { getGuildPrefix } from "../../../utils/getGuildPrefix"; import { getGuildPrefix } from "../../../utils/getGuildPrefix";
import { EmbedOptions, User } from "eris";
import { getChunkedEmbedFields } from "../../../utils/getChunkedEmbedFields"; import { getChunkedEmbedFields } from "../../../utils/getChunkedEmbedFields";
import { asyncMap } from "../../../utils/async"; import { asyncMap } from "../../../utils/async";
import { CaseTypes } from "../../../data/CaseTypes"; import { CaseTypes } from "../../../data/CaseTypes";

View file

@ -3,7 +3,7 @@ import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { helpers } from "knub"; import { helpers } from "knub";
import { CasesPlugin } from "../../Cases/CasesPlugin"; import { CasesPlugin } from "../../Cases/CasesPlugin";
import { TextChannel } from "eris";
import { SECONDS, stripObjectToScalars, trimLines } from "../../../utils"; import { SECONDS, stripObjectToScalars, trimLines } from "../../../utils";
import { LogsPlugin } from "../../Logs/LogsPlugin"; import { LogsPlugin } from "../../Logs/LogsPlugin";
import { LogType } from "../../../data/LogType"; import { LogType } from "../../../data/LogType";

View file

@ -7,7 +7,7 @@ import { readContactMethodsFromArgs } from "../functions/readContactMethodsFromA
import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments"; import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments";
import { banUserId } from "../functions/banUserId"; import { banUserId } from "../functions/banUserId";
import { CaseTypes } from "../../../data/CaseTypes"; import { CaseTypes } from "../../../data/CaseTypes";
import { TextChannel } from "eris";
import { waitForReply } from "knub/dist/helpers"; import { waitForReply } from "knub/dist/helpers";
import { ignoreEvent } from "../functions/ignoreEvent"; import { ignoreEvent } from "../functions/ignoreEvent";
import { CasesPlugin } from "../../../plugins/Cases/CasesPlugin"; import { CasesPlugin } from "../../../plugins/Cases/CasesPlugin";
@ -46,7 +46,7 @@ export const MassbanCmd = modActionsCmd({
// Verify we can act on each of the users specified // Verify we can act on each of the users specified
for (const userId of args.userIds) { for (const userId of args.userIds) {
const member = pluginData.guild.members.get(userId); // TODO: Get members on demand? const member = pluginData.guild.members.cache.get(userId); // TODO: Get members on demand?
if (member && !canActOn(pluginData, msg.member, member)) { if (member && !canActOn(pluginData, msg.member, member)) {
sendErrorMessage(pluginData, msg.channel, "Cannot massban one or more users: insufficient permissions"); sendErrorMessage(pluginData, msg.channel, "Cannot massban one or more users: insufficient permissions");
return; return;

View file

@ -5,7 +5,7 @@ import { stripObjectToScalars } from "../../../utils";
import { isBanned } from "../functions/isBanned"; import { isBanned } from "../functions/isBanned";
import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments"; import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments";
import { CaseTypes } from "../../../data/CaseTypes"; import { CaseTypes } from "../../../data/CaseTypes";
import { TextChannel } from "eris";
import { waitForReply } from "knub/dist/helpers"; import { waitForReply } from "knub/dist/helpers";
import { ignoreEvent } from "../functions/ignoreEvent"; import { ignoreEvent } from "../functions/ignoreEvent";
import { CasesPlugin } from "../../Cases/CasesPlugin"; import { CasesPlugin } from "../../Cases/CasesPlugin";

View file

@ -3,7 +3,7 @@ import { commandTypeHelpers as ct } from "../../../commandTypes";
import { canActOn, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; import { canActOn, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { stripObjectToScalars } from "../../../utils"; import { stripObjectToScalars } from "../../../utils";
import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments"; import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments";
import { TextChannel } from "eris";
import { waitForReply } from "knub/dist/helpers"; import { waitForReply } from "knub/dist/helpers";
import { LogType } from "../../../data/LogType"; import { LogType } from "../../../data/LogType";
import { logger } from "../../../logger"; import { logger } from "../../../logger";
@ -43,7 +43,7 @@ export const MassmuteCmd = modActionsCmd({
// Verify we can act upon all users // Verify we can act upon all users
for (const userId of args.userIds) { for (const userId of args.userIds) {
const member = pluginData.guild.members.get(userId); const member = pluginData.guild.members.cache.get(userId);
if (member && !canActOn(pluginData, msg.member, member)) { if (member && !canActOn(pluginData, msg.member, member)) {
sendErrorMessage(pluginData, msg.channel, "Cannot massmute one or more users: insufficient permissions"); sendErrorMessage(pluginData, msg.channel, "Cannot massmute one or more users: insufficient permissions");
return; return;

View file

@ -11,7 +11,7 @@ import { isBanned } from "../functions/isBanned";
import { waitForReaction } from "knub/dist/helpers"; import { waitForReaction } from "knub/dist/helpers";
import { readContactMethodsFromArgs } from "../functions/readContactMethodsFromArgs"; import { readContactMethodsFromArgs } from "../functions/readContactMethodsFromArgs";
import { warnMember } from "../functions/warnMember"; import { warnMember } from "../functions/warnMember";
import { TextChannel } from "eris";
import { actualMuteUserCmd } from "../functions/actualMuteUserCmd"; import { actualMuteUserCmd } from "../functions/actualMuteUserCmd";
const opts = { const opts = {

View file

@ -11,7 +11,6 @@ import { isBanned } from "../functions/isBanned";
import { waitForReaction } from "knub/dist/helpers"; import { waitForReaction } from "knub/dist/helpers";
import { readContactMethodsFromArgs } from "../functions/readContactMethodsFromArgs"; import { readContactMethodsFromArgs } from "../functions/readContactMethodsFromArgs";
import { warnMember } from "../functions/warnMember"; import { warnMember } from "../functions/warnMember";
import { TextChannel } from "eris";
export const WarnCmd = modActionsCmd({ export const WarnCmd = modActionsCmd({
trigger: "warn", trigger: "warn",

View file

@ -1,7 +1,7 @@
import { IgnoredEventType, modActionsEvt } from "../types"; import { IgnoredEventType, modActionsEvt } from "../types";
import { isEventIgnored } from "../functions/isEventIgnored"; import { isEventIgnored } from "../functions/isEventIgnored";
import { clearIgnoredEvents } from "../functions/clearIgnoredEvents"; import { clearIgnoredEvents } from "../functions/clearIgnoredEvents";
import { Constants as ErisConstants, User } from "eris";
import { CasesPlugin } from "../../Cases/CasesPlugin"; import { CasesPlugin } from "../../Cases/CasesPlugin";
import { CaseTypes } from "../../../data/CaseTypes"; import { CaseTypes } from "../../../data/CaseTypes";
import { safeFindRelevantAuditLogEntry } from "../../../utils/safeFindRelevantAuditLogEntry"; import { safeFindRelevantAuditLogEntry } from "../../../utils/safeFindRelevantAuditLogEntry";

View file

@ -1,7 +1,7 @@
import { IgnoredEventType, modActionsEvt } from "../types"; import { IgnoredEventType, modActionsEvt } from "../types";
import { isEventIgnored } from "../functions/isEventIgnored"; import { isEventIgnored } from "../functions/isEventIgnored";
import { clearIgnoredEvents } from "../functions/clearIgnoredEvents"; import { clearIgnoredEvents } from "../functions/clearIgnoredEvents";
import { Constants as ErisConstants, User } from "eris";
import { CasesPlugin } from "../../Cases/CasesPlugin"; import { CasesPlugin } from "../../Cases/CasesPlugin";
import { CaseTypes } from "../../../data/CaseTypes"; import { CaseTypes } from "../../../data/CaseTypes";
import { logger } from "../../../logger"; import { logger } from "../../../logger";

View file

@ -1,7 +1,7 @@
import { IgnoredEventType, modActionsEvt } from "../types"; import { IgnoredEventType, modActionsEvt } from "../types";
import { isEventIgnored } from "../functions/isEventIgnored"; import { isEventIgnored } from "../functions/isEventIgnored";
import { clearIgnoredEvents } from "../functions/clearIgnoredEvents"; import { clearIgnoredEvents } from "../functions/clearIgnoredEvents";
import { Constants as ErisConstants, User } from "eris";
import { CasesPlugin } from "../../Cases/CasesPlugin"; import { CasesPlugin } from "../../Cases/CasesPlugin";
import { CaseTypes } from "../../../data/CaseTypes"; import { CaseTypes } from "../../../data/CaseTypes";
import { safeFindRelevantAuditLogEntry } from "../../../utils/safeFindRelevantAuditLogEntry"; import { safeFindRelevantAuditLogEntry } from "../../../utils/safeFindRelevantAuditLogEntry";

View file

@ -1,7 +1,7 @@
import { modActionsEvt } from "../types"; import { modActionsEvt } from "../types";
import { LogsPlugin } from "../../Logs/LogsPlugin"; import { LogsPlugin } from "../../Logs/LogsPlugin";
import { LogType } from "../../../data/LogType"; import { LogType } from "../../../data/LogType";
import { Constants, TextChannel } from "eris";
import { resolveMember } from "../../../utils"; import { resolveMember } from "../../../utils";
import { hasDiscordPermissions } from "../../../utils/hasDiscordPermissions"; import { hasDiscordPermissions } from "../../../utils/hasDiscordPermissions";
@ -22,7 +22,7 @@ export const PostAlertOnMemberJoinEvt = modActionsEvt({
const logs = pluginData.getPlugin(LogsPlugin); const logs = pluginData.getPlugin(LogsPlugin);
if (actions.length) { if (actions.length) {
const alertChannel = pluginData.guild.channels.get(alertChannelId); const alertChannel = pluginData.guild.channels.cache.get(alertChannelId);
if (!alertChannel) { if (!alertChannel) {
logs.log(LogType.BOT_ALERT, { logs.log(LogType.BOT_ALERT, {
body: `Unknown \`alert_channel\` configured for \`mod_actions\`: \`${alertChannelId}\``, body: `Unknown \`alert_channel\` configured for \`mod_actions\`: \`${alertChannelId}\``,
@ -37,8 +37,8 @@ export const PostAlertOnMemberJoinEvt = modActionsEvt({
return; return;
} }
const botMember = await resolveMember(pluginData.client, pluginData.guild, pluginData.client.user.id); const botMember = await resolveMember(pluginData.client, pluginData.guild, pluginData.client.user!.id);
const botPerms = alertChannel.permissionsOf(botMember ?? pluginData.client.user.id); const botPerms = alertChannel.permissionsOf(botMember ?? pluginData.client.user!.id);
if (!hasDiscordPermissions(botPerms, Constants.Permissions.sendMessages)) { if (!hasDiscordPermissions(botPerms, Constants.Permissions.sendMessages)) {
logs.log(LogType.BOT_ALERT, { logs.log(LogType.BOT_ALERT, {
body: `Missing "Send Messages" permissions for the \`alert_channel\` configured in \`mod_actions\`: \`${alertChannelId}\``, body: `Missing "Send Messages" permissions for the \`alert_channel\` configured in \`mod_actions\`: \`${alertChannelId}\``,

View file

@ -1,4 +1,3 @@
import { Member, TextChannel } from "eris";
import { LogType } from "../../../data/LogType"; import { LogType } from "../../../data/LogType";
import { IgnoredEventType, ModActionsPluginType } from "../types"; import { IgnoredEventType, ModActionsPluginType } from "../types";
import { errorMessage, resolveUser, resolveMember } from "../../../utils"; import { errorMessage, resolveUser, resolveMember } from "../../../utils";

View file

@ -1,4 +1,3 @@
import { GuildTextableChannel, Member, Message, TextChannel, User } from "eris";
import { asSingleLine, isDiscordRESTError, UnknownUser } from "../../../utils"; import { asSingleLine, isDiscordRESTError, UnknownUser } from "../../../utils";
import { hasPermission, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; import { hasPermission, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { GuildPluginData } from "knub"; import { GuildPluginData } from "knub";

View file

@ -1,6 +1,6 @@
import { GuildPluginData } from "knub"; import { GuildPluginData } from "knub";
import { ModActionsPluginType } from "../types"; import { ModActionsPluginType } from "../types";
import { User, Message, Member } from "eris";
import { UnknownUser, asSingleLine } from "../../../utils"; import { UnknownUser, asSingleLine } from "../../../utils";
import { sendErrorMessage, sendSuccessMessage, hasPermission } from "../../../pluginUtils"; import { sendErrorMessage, sendSuccessMessage, hasPermission } from "../../../pluginUtils";
import { formatReasonWithAttachments } from "./formatReasonWithAttachments"; import { formatReasonWithAttachments } from "./formatReasonWithAttachments";

View file

@ -8,7 +8,7 @@ import {
ucfirst, ucfirst,
UserNotificationResult, UserNotificationResult,
} from "../../../utils"; } from "../../../utils";
import { DiscordRESTError, User } from "eris";
import { renderTemplate } from "../../../templateFormatter"; import { renderTemplate } from "../../../templateFormatter";
import { getDefaultContactMethods } from "./getDefaultContactMethods"; import { getDefaultContactMethods } from "./getDefaultContactMethods";
import { LogType } from "../../../data/LogType"; import { LogType } from "../../../data/LogType";
@ -99,7 +99,7 @@ export async function banUserId(
const existingTempban = await pluginData.state.tempbans.findExistingTempbanForUserId(user.id); const existingTempban = await pluginData.state.tempbans.findExistingTempbanForUserId(user.id);
if (banTime && banTime > 0) { if (banTime && banTime > 0) {
const selfId = pluginData.client.user.id; const selfId = pluginData.client.user!.id;
if (existingTempban) { if (existingTempban) {
pluginData.state.tempbans.updateExpiryTime(user.id, banTime, banOptions.modId ?? selfId); pluginData.state.tempbans.updateExpiryTime(user.id, banTime, banOptions.modId ?? selfId);
} else { } else {
@ -108,7 +108,7 @@ export async function banUserId(
} }
// Create a case for this action // Create a case for this action
const modId = banOptions.caseArgs?.modId || pluginData.client.user.id; const modId = banOptions.caseArgs?.modId || pluginData.client.user!.id;
const casesPlugin = pluginData.getPlugin(CasesPlugin); const casesPlugin = pluginData.getPlugin(CasesPlugin);
const noteDetails: string[] = []; const noteDetails: string[] = [];

View file

@ -1,5 +1,3 @@
import { Attachment } from "eris";
export function formatReasonWithAttachments(reason: string, attachments: Attachment[]) { export function formatReasonWithAttachments(reason: string, attachments: Attachment[]) {
const attachmentUrls = attachments.map(a => a.url); const attachmentUrls = attachments.map(a => a.url);
return ((reason || "") + " " + attachmentUrls.join(" ")).trim(); return ((reason || "") + " " + attachmentUrls.join(" ")).trim();

View file

@ -1,7 +1,6 @@
import { GuildPluginData } from "knub"; import { GuildPluginData } from "knub";
import { ModActionsPluginType } from "../types"; import { ModActionsPluginType } from "../types";
import { UserNotificationMethod } from "../../../utils"; import { UserNotificationMethod } from "../../../utils";
import { TextChannel } from "eris";
export function getDefaultContactMethods( export function getDefaultContactMethods(
pluginData: GuildPluginData<ModActionsPluginType>, pluginData: GuildPluginData<ModActionsPluginType>,
@ -15,7 +14,7 @@ export function getDefaultContactMethods(
} }
if (config[`message_on_${type}`] && config.message_channel) { if (config[`message_on_${type}`] && config.message_channel) {
const channel = pluginData.guild.channels.get(config.message_channel); const channel = pluginData.guild.channels.cache.get(config.message_channel);
if (channel instanceof TextChannel) { if (channel instanceof TextChannel) {
methods.push({ methods.push({
type: "channel", type: "channel",

View file

@ -4,14 +4,13 @@ import { isDiscordHTTPError, isDiscordRESTError, SECONDS, sleep } from "../../..
import { LogsPlugin } from "../../Logs/LogsPlugin"; import { LogsPlugin } from "../../Logs/LogsPlugin";
import { LogType } from "../../../data/LogType"; import { LogType } from "../../../data/LogType";
import { hasDiscordPermissions } from "../../../utils/hasDiscordPermissions"; import { hasDiscordPermissions } from "../../../utils/hasDiscordPermissions";
import { Constants } from "eris";
export async function isBanned( export async function isBanned(
pluginData: GuildPluginData<ModActionsPluginType>, pluginData: GuildPluginData<ModActionsPluginType>,
userId: string, userId: string,
timeout: number = 5 * SECONDS, timeout: number = 5 * SECONDS,
): Promise<boolean> { ): Promise<boolean> {
const botMember = pluginData.guild.members.get(pluginData.client.user.id); const botMember = pluginData.guild.members.cache.get(pluginData.client.user!.id);
if (botMember && !hasDiscordPermissions(botMember.permissions, Constants.Permissions.banMembers)) { if (botMember && !hasDiscordPermissions(botMember.permissions, Constants.Permissions.banMembers)) {
pluginData.getPlugin(LogsPlugin).log(LogType.BOT_ALERT, { pluginData.getPlugin(LogsPlugin).log(LogType.BOT_ALERT, {
body: `Missing "Ban Members" permission to check for existing bans`, body: `Missing "Ban Members" permission to check for existing bans`,

View file

@ -1,6 +1,6 @@
import { GuildPluginData } from "knub"; import { GuildPluginData } from "knub";
import { IgnoredEventType, KickOptions, KickResult, ModActionsPluginType } from "../types"; import { IgnoredEventType, KickOptions, KickResult, ModActionsPluginType } from "../types";
import { Member } from "eris";
import { import {
createUserNotificationError, createUserNotificationError,
notifyUser, notifyUser,
@ -63,7 +63,7 @@ export async function kickMember(
}; };
} }
const modId = kickOptions.caseArgs?.modId || pluginData.client.user.id; const modId = kickOptions.caseArgs?.modId || pluginData.client.user!.id;
// Create a case for this action // Create a case for this action
const casesPlugin = pluginData.getPlugin(CasesPlugin); const casesPlugin = pluginData.getPlugin(CasesPlugin);

View file

@ -1,4 +1,3 @@
import { TextChannel } from "eris";
import { disableUserNotificationStrings, UserNotificationMethod } from "../../../utils"; import { disableUserNotificationStrings, UserNotificationMethod } from "../../../utils";
export function readContactMethodsFromArgs(args: { export function readContactMethodsFromArgs(args: {

View file

@ -1,4 +1,3 @@
import { Message } from "eris";
import { CaseTypes } from "../../../data/CaseTypes"; import { CaseTypes } from "../../../data/CaseTypes";
import { Case } from "../../../data/entities/Case"; import { Case } from "../../../data/entities/Case";
import { LogType } from "../../../data/LogType"; import { LogType } from "../../../data/LogType";

View file

@ -1,6 +1,6 @@
import { GuildPluginData } from "knub"; import { GuildPluginData } from "knub";
import { ModActionsPluginType, WarnOptions, WarnResult } from "../types"; import { ModActionsPluginType, WarnOptions, WarnResult } from "../types";
import { Member } from "eris";
import { getDefaultContactMethods } from "./getDefaultContactMethods"; import { getDefaultContactMethods } from "./getDefaultContactMethods";
import { import {
createUserNotificationError, createUserNotificationError,
@ -62,7 +62,7 @@ export async function warnMember(
} }
} }
const modId = warnOptions.caseArgs?.modId ?? pluginData.client.user.id; const modId = warnOptions.caseArgs?.modId ?? pluginData.client.user!.id;
const casesPlugin = pluginData.getPlugin(CasesPlugin); const casesPlugin = pluginData.getPlugin(CasesPlugin);
const createdCase = await casesPlugin.createCase({ const createdCase = await casesPlugin.createCase({

View file

@ -6,7 +6,7 @@ import { GuildCases } from "../../data/GuildCases";
import { GuildLogs } from "../../data/GuildLogs"; import { GuildLogs } from "../../data/GuildLogs";
import { Case } from "../../data/entities/Case"; import { Case } from "../../data/entities/Case";
import { CaseArgs } from "../Cases/types"; import { CaseArgs } from "../Cases/types";
import { TextChannel } from "eris";
import { GuildTempbans } from "../../data/GuildTempbans"; import { GuildTempbans } from "../../data/GuildTempbans";
import Timeout = NodeJS.Timeout; import Timeout = NodeJS.Timeout;
import { EventEmitter } from "events"; import { EventEmitter } from "events";

View file

@ -13,7 +13,7 @@ import { ClearMutesWithoutRoleCmd } from "./commands/ClearMutesWithoutRoleCmd";
import { ClearMutesCmd } from "./commands/ClearMutesCmd"; import { ClearMutesCmd } from "./commands/ClearMutesCmd";
import { muteUser } from "./functions/muteUser"; import { muteUser } from "./functions/muteUser";
import { unmuteUser } from "./functions/unmuteUser"; import { unmuteUser } from "./functions/unmuteUser";
import { Member } from "eris";
import { ClearActiveMuteOnMemberBanEvt } from "./events/ClearActiveMuteOnMemberBanEvt"; import { ClearActiveMuteOnMemberBanEvt } from "./events/ClearActiveMuteOnMemberBanEvt";
import { ReapplyActiveMuteOnJoinEvt } from "./events/ReapplyActiveMuteOnJoinEvt"; import { ReapplyActiveMuteOnJoinEvt } from "./events/ReapplyActiveMuteOnJoinEvt";
import { mapToPublicFn } from "../../pluginUtils"; import { mapToPublicFn } from "../../pluginUtils";

View file

@ -1,5 +1,5 @@
import { mutesCmd } from "../types"; import { mutesCmd } from "../types";
import { User } from "eris";
import { sendSuccessMessage } from "../../../pluginUtils"; import { sendSuccessMessage } from "../../../pluginUtils";
export const ClearBannedMutesCmd = mutesCmd({ export const ClearBannedMutesCmd = mutesCmd({

View file

@ -4,7 +4,6 @@ import { DBDateFormat, isFullMessage, MINUTES, noop, resolveMember } from "../..
import moment from "moment-timezone"; import moment from "moment-timezone";
import { humanizeDurationShort } from "../../../humanizeDurationShort"; import { humanizeDurationShort } from "../../../humanizeDurationShort";
import { getBaseUrl } from "../../../pluginUtils"; import { getBaseUrl } from "../../../pluginUtils";
import { Member } from "eris";
export const MutesCmd = mutesCmd({ export const MutesCmd = mutesCmd({
trigger: "mutes", trigger: "mutes",
@ -112,7 +111,7 @@ export const MutesCmd = mutesCmd({
const muteCasesById = muteCases.reduce((map, c) => map.set(c.id, c), new Map()); const muteCasesById = muteCases.reduce((map, c) => map.set(c.id, c), new Map());
lines = filteredMutes.map(mute => { lines = filteredMutes.map(mute => {
const user = pluginData.client.users.get(mute.user_id); const user = pluginData.client.user!.get(mute.user_id);
const username = user ? `${user.username}#${user.discriminator}` : "Unknown#0000"; const username = user ? `${user.username}#${user.discriminator}` : "Unknown#0000";
const theCase = muteCasesById.get(mute.case_id); const theCase = muteCasesById.get(mute.case_id);
const caseName = theCase ? `Case #${theCase.case_number}` : "No case"; const caseName = theCase ? `Case #${theCase.case_number}` : "No case";

View file

@ -2,7 +2,7 @@ import { GuildPluginData } from "knub";
import { MutesPluginType } from "../types"; import { MutesPluginType } from "../types";
import { LogType } from "../../../data/LogType"; import { LogType } from "../../../data/LogType";
import { resolveMember, stripObjectToScalars, UnknownUser } from "../../../utils"; import { resolveMember, stripObjectToScalars, UnknownUser } from "../../../utils";
import { MemberOptions } from "eris";
import { memberRolesLock } from "../../../utils/lockNameHelpers"; import { memberRolesLock } from "../../../utils/lockNameHelpers";
export async function clearExpiredMutes(pluginData: GuildPluginData<MutesPluginType>) { export async function clearExpiredMutes(pluginData: GuildPluginData<MutesPluginType>) {

View file

@ -1,4 +1,3 @@
import { Member } from "eris";
import { GuildPluginData } from "knub"; import { GuildPluginData } from "knub";
import { MutesPluginType } from "../types"; import { MutesPluginType } from "../types";

View file

@ -12,7 +12,7 @@ import {
UserNotificationMethod, UserNotificationMethod,
} from "../../../utils"; } from "../../../utils";
import { renderTemplate } from "../../../templateFormatter"; import { renderTemplate } from "../../../templateFormatter";
import { MemberOptions, TextChannel, User } from "eris";
import { CasesPlugin } from "../../Cases/CasesPlugin"; import { CasesPlugin } from "../../Cases/CasesPlugin";
import { CaseTypes } from "../../../data/CaseTypes"; import { CaseTypes } from "../../../data/CaseTypes";
import { LogType } from "../../../data/LogType"; import { LogType } from "../../../data/LogType";
@ -42,7 +42,7 @@ export async function muteUser(
// No mod specified -> mark Zeppelin as the mod // No mod specified -> mark Zeppelin as the mod
if (!muteOptions.caseArgs?.modId) { if (!muteOptions.caseArgs?.modId) {
muteOptions.caseArgs = muteOptions.caseArgs ?? {}; muteOptions.caseArgs = muteOptions.caseArgs ?? {};
muteOptions.caseArgs.modId = pluginData.client.user.id; muteOptions.caseArgs.modId = pluginData.client.user!.id;
} }
const user = await resolveUser(pluginData.client, userId); const user = await resolveUser(pluginData.client, userId);
@ -99,7 +99,7 @@ export async function muteUser(
throw new RecoverablePluginError(ERRORS.INVALID_MUTE_ROLE_ID); throw new RecoverablePluginError(ERRORS.INVALID_MUTE_ROLE_ID);
} }
const zep = await resolveMember(pluginData.client, pluginData.guild, pluginData.client.user.id); const zep = await resolveMember(pluginData.client, pluginData.guild, pluginData.client.user!.id);
const zepRoles = pluginData.guild.roles.filter(x => zep!.roles.includes(x.id)); const zepRoles = pluginData.guild.roles.filter(x => zep!.roles.includes(x.id));
// If we have roles and one of them is above the muted role, throw generic error // If we have roles and one of them is above the muted role, throw generic error
if (zepRoles.length >= 0 && zepRoles.some(zepRole => zepRole.position > actualMuteRole.position)) { if (zepRoles.length >= 0 && zepRoles.some(zepRole => zepRole.position > actualMuteRole.position)) {
@ -172,7 +172,7 @@ export async function muteUser(
} }
const useChannel = existingMute ? config.message_on_update : config.message_on_mute; const useChannel = existingMute ? config.message_on_update : config.message_on_mute;
const channel = config.message_channel && pluginData.guild.channels.get(config.message_channel); const channel = config.message_channel && pluginData.guild.channels.cache.get(config.message_channel);
if (useChannel && channel instanceof TextChannel) { if (useChannel && channel instanceof TextChannel) {
contactMethods.push({ type: "channel", channel }); contactMethods.push({ type: "channel", channel });
} }

View file

@ -7,7 +7,7 @@ import humanizeDuration from "humanize-duration";
import { CasesPlugin } from "../../Cases/CasesPlugin"; import { CasesPlugin } from "../../Cases/CasesPlugin";
import { CaseTypes } from "../../../data/CaseTypes"; import { CaseTypes } from "../../../data/CaseTypes";
import { LogType } from "../../../data/LogType"; import { LogType } from "../../../data/LogType";
import { MemberOptions } from "eris";
import { memberRolesLock } from "../../../utils/lockNameHelpers"; import { memberRolesLock } from "../../../utils/lockNameHelpers";
export async function unmuteUser( export async function unmuteUser(
@ -19,7 +19,7 @@ export async function unmuteUser(
const existingMute = await pluginData.state.mutes.findExistingMuteForUserId(userId); const existingMute = await pluginData.state.mutes.findExistingMuteForUserId(userId);
const user = await resolveUser(pluginData.client, userId); const user = await resolveUser(pluginData.client, userId);
const member = await resolveMember(pluginData.client, pluginData.guild, userId); // Grab the fresh member so we don't have stale role info const member = await resolveMember(pluginData.client, pluginData.guild, userId); // Grab the fresh member so we don't have stale role info
const modId = caseArgs.modId || pluginData.client.user.id; const modId = caseArgs.modId || pluginData.client.user!.id;
if (!existingMute && member && !memberHasMutedRole(pluginData, member)) return null; if (!existingMute && member && !memberHasMutedRole(pluginData, member)) return null;
@ -85,7 +85,7 @@ export async function unmuteUser(
}); });
// Log the action // Log the action
const mod = pluginData.client.users.get(modId); const mod = pluginData.client.user!.get(modId);
if (unmuteTime) { if (unmuteTime) {
pluginData.state.serverLogs.log(LogType.MEMBER_TIMED_UNMUTE, { pluginData.state.serverLogs.log(LogType.MEMBER_TIMED_UNMUTE, {
mod: stripObjectToScalars(mod), mod: stripObjectToScalars(mod),

View file

@ -1,7 +1,7 @@
import * as t from "io-ts"; import * as t from "io-ts";
import { tNullable, UserNotificationMethod, UserNotificationResult } from "../../utils"; import { tNullable, UserNotificationMethod, UserNotificationResult } from "../../utils";
import { Mute } from "../../data/entities/Mute"; import { Mute } from "../../data/entities/Mute";
import { Member } from "eris";
import { Case } from "../../data/entities/Case"; import { Case } from "../../data/entities/Case";
import { BasePluginType, typedGuildCommand, typedGuildEventListener } from "knub"; import { BasePluginType, typedGuildCommand, typedGuildEventListener } from "knub";
import { GuildLogs } from "../../data/GuildLogs"; import { GuildLogs } from "../../data/GuildLogs";

Some files were not shown because too many files have changed in this diff Show more