3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-12 04:55:01 +00:00

Type fixes for djs

This commit is contained in:
Dark 2021-06-30 04:56:56 +02:00
parent 653d6c1dc2
commit 0822fc15e5
No known key found for this signature in database
GPG key ID: 2CD6ACB6B0A87B8A
130 changed files with 8877 additions and 411 deletions

View file

@ -1,4 +1,4 @@
import { Permissions } from "discord.js";
import { Permissions, Snowflake } from "discord.js";
import * as t from "io-ts";
import { LogType } from "../../../data/LogType";
import { nonNullish, unique } from "../../../utils";
@ -41,7 +41,7 @@ export const AddRolesAction = automodAction({
if (rolesWeCannotAssign.length) {
const roleNamesWeCannotAssign = rolesWeCannotAssign.map(
roleId => pluginData.guild.roles.cache.get(roleId)?.name || roleId,
roleId => pluginData.guild.roles.cache.get(roleId as Snowflake)?.name || roleId,
);
const logs = pluginData.getPlugin(LogsPlugin);
logs.log(LogType.BOT_ALERT, {
@ -55,7 +55,7 @@ export const AddRolesAction = automodAction({
members.map(async member => {
const memberRoles = new Set(member.roles.cache.keyArray());
for (const roleId of rolesToAssign) {
memberRoles.add(roleId);
memberRoles.add(roleId as Snowflake);
ignoreRoleChange(pluginData, member.id, roleId);
}

View file

@ -1,4 +1,4 @@
import { TextChannel } from "discord.js";
import { Snowflake, TextChannel } from "discord.js";
import * as t from "io-ts";
import { erisAllowedMentionsToDjsMentionOptions } from "src/utils/erisAllowedMentionsToDjsMentionOptions";
import { LogType } from "../../../data/LogType";
@ -24,7 +24,7 @@ export const AlertAction = automodAction({
defaultConfig: {},
async apply({ pluginData, contexts, actionConfig, ruleName, matchResult }) {
const channel = pluginData.guild.channels.cache.get(actionConfig.channel);
const channel = pluginData.guild.channels.cache.get(actionConfig.channel as Snowflake);
const logs = pluginData.getPlugin(LogsPlugin);
if (channel && channel instanceof TextChannel) {

View file

@ -1,4 +1,4 @@
import { TextChannel } from "discord.js";
import { Snowflake, TextChannel } from "discord.js";
import * as t from "io-ts";
import { LogType } from "../../../data/LogType";
import { noop } from "../../../utils";
@ -30,8 +30,8 @@ export const CleanAction = automodAction({
pluginData.state.logs.ignoreLog(LogType.MESSAGE_DELETE, id);
}
const channel = pluginData.guild.channels.cache.get(channelId) as TextChannel;
await channel.bulkDelete(messageIds).catch(noop);
const channel = pluginData.guild.channels.cache.get(channelId as Snowflake) as TextChannel;
await channel.bulkDelete(messageIds as Snowflake[]).catch(noop);
}
},
});

View file

@ -1,4 +1,4 @@
import { Permissions } from "discord.js";
import { Permissions, Snowflake } from "discord.js";
import * as t from "io-ts";
import { LogType } from "../../../data/LogType";
import { nonNullish, unique } from "../../../utils";
@ -42,7 +42,7 @@ export const RemoveRolesAction = automodAction({
if (rolesWeCannotRemove.length) {
const roleNamesWeCannotRemove = rolesWeCannotRemove.map(
roleId => pluginData.guild.roles.cache.get(roleId)?.name || roleId,
roleId => pluginData.guild.roles.cache.get(roleId as Snowflake)?.name || roleId,
);
const logs = pluginData.getPlugin(LogsPlugin);
logs.log(LogType.BOT_ALERT, {
@ -56,7 +56,7 @@ export const RemoveRolesAction = automodAction({
members.map(async member => {
const memberRoles = new Set(member.roles.cache.keyArray());
for (const roleId of rolesToRemove) {
memberRoles.delete(roleId);
memberRoles.delete(roleId as Snowflake);
ignoreRoleChange(pluginData, member.id, roleId);
}

View file

@ -1,4 +1,4 @@
import { MessageOptions, Permissions, TextChannel, User } from "discord.js";
import { MessageOptions, Permissions, Snowflake, TextChannel, User } from "discord.js";
import * as t from "io-ts";
import { LogType } from "../../../data/LogType";
import { renderTemplate } from "../../../templateFormatter";
@ -31,7 +31,7 @@ export const ReplyAction = automodAction({
async apply({ pluginData, contexts, actionConfig, ruleName }) {
const contextsWithTextChannels = contexts
.filter(c => c.message?.channel_id)
.filter(c => pluginData.guild.channels.cache.get(c.message!.channel_id) instanceof TextChannel);
.filter(c => pluginData.guild.channels.cache.get(c.message!.channel_id as Snowflake) instanceof TextChannel);
const contextsByChannelId = contextsWithTextChannels.reduce((map: Map<string, AutomodContext[]>, context) => {
if (!map.has(context.message!.channel_id)) {
@ -56,7 +56,7 @@ export const ReplyAction = automodAction({
: ((await renderRecursively(actionConfig.text, renderReplyText)) as MessageOptions);
if (formatted) {
const channel = pluginData.guild.channels.cache.get(channelId) as TextChannel;
const channel = pluginData.guild.channels.cache.get(channelId as Snowflake) as TextChannel;
// Check for basic Send Messages and View Channel permissions
if (
@ -90,7 +90,6 @@ export const ReplyAction = automodAction({
allowedMentions: {
users: [user.id],
},
split: false,
});
if (typeof actionConfig === "object" && actionConfig.auto_delete) {

View file

@ -1,4 +1,4 @@
import { TextChannel } from "discord.js";
import { Snowflake, TextChannel } from "discord.js";
import * as t from "io-ts";
import { ChannelTypeStrings } from "src/types";
import { LogType } from "../../../data/LogType";
@ -19,7 +19,7 @@ export const SetSlowmodeAction = automodAction({
const slowmodeMs = Math.max(actionConfig.duration ? convertDelayStringToMS(actionConfig.duration)! : 0, 0);
for (const channelId of actionConfig.channels) {
const channel = pluginData.guild.channels.cache.get(channelId);
const channel = pluginData.guild.channels.cache.get(channelId as Snowflake);
// Only text channels and text channels within categories support slowmodes
if (!channel || !(channel.type === ChannelTypeStrings.TEXT || ChannelTypeStrings.CATEGORY)) {

View file

@ -1,3 +1,4 @@
import { Snowflake } from "discord.js";
import { GuildPluginData } from "knub";
import moment from "moment-timezone";
import { SavedMessage } from "../../../data/entities/SavedMessage";
@ -11,8 +12,8 @@ export function runAutomodOnMessage(
message: SavedMessage,
isEdit: boolean,
) {
const user = pluginData.client.users.cache!.get(message.user_id);
const member = pluginData.guild.members.cache.get(message.user_id);
const user = pluginData.client.users.cache!.get(message.user_id as Snowflake);
const member = pluginData.guild.members.cache.get(message.user_id as Snowflake);
const context: AutomodContext = {
timestamp: moment.utc(message.posted_at).valueOf(),

View file

@ -1,3 +1,4 @@
import { Snowflake, TextChannel } from "discord.js";
import { GuildPluginData } from "knub";
import { messageSummary, verboseChannelMention } from "../../../utils";
import { AutomodContext, AutomodPluginType } from "../types";
@ -10,13 +11,13 @@ export function getTextMatchPartialSummary(
) {
if (type === "message") {
const message = context.message!;
const channel = pluginData.guild.channels.cache.get(message.channel_id);
const channel = pluginData.guild.channels.cache.get(message.channel_id as Snowflake) as TextChannel;
const channelMention = channel ? verboseChannelMention(channel) : `\`#${message.channel_id}\``;
return `message in ${channelMention}:\n${messageSummary(message)}`;
} else if (type === "embed") {
const message = context.message!;
const channel = pluginData.guild.channels.cache.get(message.channel_id);
const channel = pluginData.guild.channels.cache.get(message.channel_id as Snowflake) as TextChannel;
const channelMention = channel ? verboseChannelMention(channel) : `\`#${message.channel_id}\``;
return `message embed in ${channelMention}:\n${messageSummary(message)}`;
@ -28,6 +29,6 @@ export function getTextMatchPartialSummary(
const visibleName = context.member?.nickname || context.user!.username;
return `visible name: ${visibleName}`;
} else if (type === "customstatus") {
return `custom status: ${context.member!.presence.activities.find(a => a.type === "CUSTOM_STATUS")?.name}`;
return `custom status: ${context.member!.presence.activities.find(a => a.type === "CUSTOM")?.name}`;
}
}

View file

@ -1,4 +1,4 @@
import { TextChannel } from "discord.js";
import { Snowflake, TextChannel } from "discord.js";
import { GuildPluginData } from "knub";
import { ERRORS, RecoverablePluginError } from "../../../RecoverablePluginError";
import { disableUserNotificationStrings, UserNotificationMethod } from "../../../utils";
@ -18,7 +18,7 @@ export function resolveActionContactMethods(
throw new RecoverablePluginError(ERRORS.NO_USER_NOTIFICATION_CHANNEL);
}
const channel = pluginData.guild.channels.cache.get(actionConfig.notifyChannel);
const channel = pluginData.guild.channels.cache.get(actionConfig.notifyChannel as Snowflake);
if (!(channel instanceof TextChannel)) {
throw new RecoverablePluginError(ERRORS.INVALID_USER_NOTIFICATION_CHANNEL);
}

View file

@ -1,4 +1,4 @@
import { TextChannel } from "discord.js";
import { Snowflake, TextChannel } from "discord.js";
import { GuildPluginData } from "knub";
import { availableActions } from "../actions/availableActions";
import { CleanAction } from "../actions/clean";
@ -9,10 +9,10 @@ import { checkAndUpdateCooldown } from "./checkAndUpdateCooldown";
export async function runAutomod(pluginData: GuildPluginData<AutomodPluginType>, context: AutomodContext) {
const userId = context.user?.id || context.member?.id || context.message?.user_id;
const user = context.user || (userId && pluginData.client.users!.cache.get(userId));
const member = context.member || (userId && pluginData.guild.members.cache.get(userId)) || null;
const user = context.user || (userId && pluginData.client.users!.cache.get(userId as Snowflake));
const member = context.member || (userId && pluginData.guild.members.cache.get(userId as Snowflake)) || null;
const channelId = context.message?.channel_id;
const channel = channelId ? (pluginData.guild.channels.cache.get(channelId) as TextChannel) : null;
const channel = channelId ? (pluginData.guild.channels.cache.get(channelId as Snowflake) as TextChannel) : null;
const categoryId = channel?.parentID;
const config = await pluginData.config.getMatchingConfig({

View file

@ -1,3 +1,4 @@
import { Snowflake, TextChannel } from "discord.js";
import * as t from "io-ts";
import { verboseChannelMention } from "../../../utils";
import { automodTrigger } from "../helpers";
@ -21,7 +22,7 @@ export const AnyMessageTrigger = automodTrigger<AnyMessageResultType>()({
},
renderMatchInformation({ pluginData, contexts, matchResult }) {
const channel = pluginData.guild.channels.cache.get(contexts[0].message!.channel_id);
const channel = pluginData.guild.channels.cache.get(contexts[0].message!.channel_id as Snowflake) as TextChannel;
return `Matched message (\`${contexts[0].message!.id}\`) in ${
channel ? verboseChannelMention(channel) : "Unknown Channel"
}`;

View file

@ -1,3 +1,4 @@
import { Snowflake, TextChannel } from "discord.js";
import * as t from "io-ts";
import { asSingleLine, disableInlineCode, messageSummary, verboseChannelMention } from "../../../utils";
import { automodTrigger } from "../helpers";
@ -67,7 +68,7 @@ export const MatchAttachmentTypeTrigger = automodTrigger<MatchResultType>()({
},
renderMatchInformation({ pluginData, contexts, matchResult }) {
const channel = pluginData.guild.channels.cache.get(contexts[0].message!.channel_id)!;
const channel = pluginData.guild.channels.cache.get(contexts[0].message!.channel_id as Snowflake) as TextChannel;
const prettyChannel = verboseChannelMention(channel);
return (

View file

@ -1,3 +1,4 @@
import { Snowflake } from "discord.js";
import * as t from "io-ts";
import { consumeIgnoredRoleChange } from "../functions/ignoredRoleChanges";
import { automodTrigger } from "../helpers";
@ -33,7 +34,7 @@ export const RoleAddedTrigger = automodTrigger<RoleAddedMatchResult>()({
},
renderMatchInformation({ matchResult, pluginData, contexts }) {
const role = pluginData.guild.roles.cache.get(matchResult.extra.matchedRoleId);
const role = pluginData.guild.roles.cache.get(matchResult.extra.matchedRoleId as Snowflake);
const roleName = role?.name || "Unknown";
const member = contexts[0].member!;
const memberName = `**${member.user.username}#${member.user.discriminator}** (\`${member.id}\`)`;

View file

@ -1,3 +1,4 @@
import { Snowflake } from "discord.js";
import * as t from "io-ts";
import { consumeIgnoredRoleChange } from "../functions/ignoredRoleChanges";
import { automodTrigger } from "../helpers";
@ -33,7 +34,7 @@ export const RoleRemovedTrigger = automodTrigger<RoleAddedMatchResult>()({
},
renderMatchInformation({ matchResult, pluginData, contexts }) {
const role = pluginData.guild.roles.cache.get(matchResult.extra.matchedRoleId);
const role = pluginData.guild.roles.cache.get(matchResult.extra.matchedRoleId as Snowflake);
const roleName = role?.name || "Unknown";
const member = contexts[0].member!;
const memberName = `**${member.user.username}#${member.user.discriminator}** (\`${member.id}\`)`;