3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 12:25:02 +00:00

upgrade discord.js

This commit is contained in:
almeidx 2021-08-04 20:45:42 +01:00
parent 036d46f08a
commit 3537305c59
No known key found for this signature in database
GPG key ID: 8558FBFF849BD664
32 changed files with 232 additions and 107 deletions

View file

@ -45,9 +45,9 @@ export class GuildSavedMessages extends BaseGuildRepository {
timestamp: msg.createdTimestamp,
};
if (msg.attachments.size) data.attachments = msg.attachments.array();
if (msg.attachments.size) data.attachments = [...msg.attachments.values()];
if (msg.embeds.length) data.embeds = msg.embeds;
if (msg.stickers?.size) data.stickers = msg.stickers.array();
if (msg.stickers?.size) data.stickers = [...msg.stickers.values()];
return data;
}

View file

@ -53,7 +53,7 @@ export const AddRolesAction = automodAction({
await Promise.all(
members.map(async member => {
const memberRoles = new Set(member.roles.cache.keyArray());
const memberRoles = new Set(member.roles.cache.keys());
for (const roleId of rolesToAssign) {
memberRoles.add(roleId as Snowflake);
ignoreRoleChange(pluginData, member.id, roleId);

View file

@ -54,7 +54,7 @@ export const RemoveRolesAction = automodAction({
await Promise.all(
members.map(async member => {
const memberRoles = new Set(member.roles.cache.keyArray());
const memberRoles = new Set(member.roles.cache.keys());
for (const roleId of rolesToRemove) {
memberRoles.delete(roleId as Snowflake);
ignoreRoleChange(pluginData, member.id, roleId);

View file

@ -31,6 +31,6 @@ export async function addRoleAction(
const rolesToAdd = Array.isArray(action.role) ? action.role : [action.role];
await target.edit({
roles: Array.from(new Set([...target.roles.cache.array(), ...rolesToAdd])) as Snowflake[],
roles: Array.from(new Set([...target.roles.cache.values(), ...rolesToAdd])) as Snowflake[],
});
}

View file

@ -27,8 +27,8 @@ export const LogsGuildMemberUpdateEvt = logsEvt({
}
if (!isEqual(oldMember.roles, member.roles)) {
const addedRoles = diff(member.roles.cache.keyArray(), oldMember.roles.cache.keyArray());
const removedRoles = diff(oldMember.roles.cache.keyArray(), member.roles.cache.keyArray());
const addedRoles = diff([...member.roles.cache.keys()], [...oldMember.roles.cache.keys()]);
const removedRoles = diff([...oldMember.roles.cache.keys()], [...member.roles.cache.keys()]);
let skip = false;
if (

View file

@ -16,7 +16,7 @@ export const SavePinsToDBCmd = messageSaverCmd({
await msg.channel.send(`Saving pins from <#${args.channel.id}>...`);
const pins = await args.channel.messages.fetchPinned();
const { savedCount, failed } = await saveMessagesToDB(pluginData, args.channel, pins.keyArray());
const { savedCount, failed } = await saveMessagesToDB(pluginData, args.channel, [...pins.keys()]);
if (failed.length) {
sendSuccessMessage(

View file

@ -60,7 +60,7 @@ export const AddCaseCmd = modActionsCmd({
return;
}
const reason = formatReasonWithAttachments(args.reason, msg.attachments.array());
const reason = formatReasonWithAttachments(args.reason, [...msg.attachments.values()]);
// Create the case
const casesPlugin = pluginData.getPlugin(CasesPlugin);

View file

@ -51,7 +51,7 @@ export const BanCmd = modActionsCmd({
}
const time = args["time"] ? args["time"] : null;
const reason = formatReasonWithAttachments(args.reason, msg.attachments.array());
const reason = formatReasonWithAttachments(args.reason, [...msg.attachments.values()]);
const memberToBan = await resolveMember(pluginData.client, pluginData.guild, user.id);
// The moderator who did the action is the message author or, if used, the specified -mod
let mod = msg.member;

View file

@ -61,7 +61,7 @@ export const ForcebanCmd = modActionsCmd({
mod = args.mod;
}
const reason = formatReasonWithAttachments(args.reason, msg.attachments.array());
const reason = formatReasonWithAttachments(args.reason, [...msg.attachments.values()]);
ignoreEvent(pluginData, IgnoredEventType.Ban, user.id);
pluginData.state.serverLogs.ignoreLog(LogType.MEMBER_BAN, user.id);

View file

@ -39,7 +39,7 @@ export const MassbanCmd = modActionsCmd({
return;
}
const banReason = formatReasonWithAttachments(banReasonReply.content, msg.attachments.array());
const banReason = formatReasonWithAttachments(banReasonReply.content, [...msg.attachments.values()]);
// Verify we can act on each of the users specified
for (const userId of args.userIds) {

View file

@ -37,7 +37,7 @@ export const MassunbanCmd = modActionsCmd({
return;
}
const unbanReason = formatReasonWithAttachments(unbanReasonReply.content, msg.attachments.array());
const unbanReason = formatReasonWithAttachments(unbanReasonReply.content, [...msg.attachments.values()]);
// Ignore automatic unban cases and logs for these users
// We'll create our own cases below and post a single "mass unbanned" log instead

View file

@ -39,7 +39,7 @@ export const MassmuteCmd = modActionsCmd({
return;
}
const muteReason = formatReasonWithAttachments(muteReasonReceived.content, msg.attachments.array());
const muteReason = formatReasonWithAttachments(muteReasonReceived.content, [...msg.attachments.values()]);
// Verify we can act upon all users
for (const userId of args.userIds) {

View file

@ -31,7 +31,7 @@ export const NoteCmd = modActionsCmd({
}
const userName = user.tag;
const reason = formatReasonWithAttachments(args.note, msg.attachments.array());
const reason = formatReasonWithAttachments(args.note, [...msg.attachments.values()]);
const casesPlugin = pluginData.getPlugin(CasesPlugin);
const createdCase = await casesPlugin.createCase({

View file

@ -47,7 +47,7 @@ export const UnbanCmd = modActionsCmd({
}
pluginData.state.serverLogs.ignoreLog(LogType.MEMBER_UNBAN, user.id);
const reason = formatReasonWithAttachments(args.reason, msg.attachments.array());
const reason = formatReasonWithAttachments(args.reason, [...msg.attachments.values()]);
try {
ignoreEvent(pluginData, IgnoredEventType.Unban, user.id);

View file

@ -63,7 +63,7 @@ export const WarnCmd = modActionsCmd({
}
const config = pluginData.config.get();
const reason = formatReasonWithAttachments(args.reason, msg.attachments.array());
const reason = formatReasonWithAttachments(args.reason, [...msg.attachments.values()]);
const casesPlugin = pluginData.getPlugin(CasesPlugin);
const priorWarnAmount = await casesPlugin.getCaseTypeAmountForUserId(memberToWarn.id, CaseTypes.Warn);

View file

@ -42,7 +42,7 @@ export async function actualMuteUserCmd(
}
const timeUntilUnmute = args.time && humanizeDuration(args.time);
const reason = args.reason ? formatReasonWithAttachments(args.reason, msg.attachments.array()) : undefined;
const reason = args.reason ? formatReasonWithAttachments(args.reason, [...msg.attachments.values()]) : undefined;
let muteResult: MuteResult;
const mutesPlugin = pluginData.getPlugin(MutesPlugin);

View file

@ -27,7 +27,7 @@ export async function actualUnmuteCmd(
pp = msg.author;
}
const reason = args.reason ? formatReasonWithAttachments(args.reason, msg.attachments.array()) : undefined;
const reason = args.reason ? formatReasonWithAttachments(args.reason, [...msg.attachments.values()]) : undefined;
const mutesPlugin = pluginData.getPlugin(MutesPlugin);
const result = await mutesPlugin.unmuteUser(user.id, args.time, {

View file

@ -24,7 +24,7 @@ export async function updateCase(pluginData, msg: Message, args) {
return;
}
const note = formatReasonWithAttachments(args.note, msg.attachments.array());
const note = formatReasonWithAttachments(args.note, [...msg.attachments.values()]);
const casesPlugin = pluginData.getPlugin(CasesPlugin);
await casesPlugin.createCaseNote({

View file

@ -21,7 +21,7 @@ export async function clearExpiredMutes(pluginData: GuildPluginData<MutesPluginT
}
if (mute.roles_to_restore) {
const guildRoles = pluginData.guild.roles.cache;
let newRoles: string[] = member.roles.cache.keyArray();
let newRoles = [...member.roles.cache.keys()];
newRoles =
muteRole && newRoles.includes(muteRole) ? newRoles.splice(newRoles.indexOf(muteRole), 1) : newRoles;
for (const toRestore of mute.roles_to_restore) {

View file

@ -58,7 +58,7 @@ export async function muteUser(
if (member) {
const logs = pluginData.getPlugin(LogsPlugin);
// remove and store any roles to be removed/restored
const currentUserRoles = member.roles.cache.keyArray();
const currentUserRoles = [...member.roles.cache.keys()];
let newRoles: string[] = currentUserRoles;
const removeRoles = removeRolesOnMuteOverride ?? config.remove_roles_on_mute;
const restoreRoles = restoreRolesOnMuteOverride ?? config.restore_roles_on_mute;

View file

@ -42,7 +42,7 @@ export async function unmuteUser(
}
if (existingMute?.roles_to_restore) {
const guildRoles = pluginData.guild.roles.cache;
let newRoles: string[] = member.roles.cache.keyArray();
let newRoles = [...member.roles.cache.keys()];
newRoles = muteRole && newRoles.includes(muteRole) ? newRoles.splice(newRoles.indexOf(muteRole), 1) : newRoles;
for (const toRestore of existingMute.roles_to_restore) {
if (guildRoles.has(toRestore as Snowflake) && toRestore !== muteRole) newRoles.push(toRestore);

View file

@ -141,7 +141,7 @@ export async function actualPostCmd(
author_name: msg.author.tag,
channel_id: targetChannel.id,
content,
attachments: msg.attachments.array(),
attachments: [...msg.attachments.values()],
post_at: postAt
.clone()
.tz("Etc/UTC")
@ -180,7 +180,7 @@ export async function actualPostCmd(
// When the message isn't scheduled for later, post it immediately
if (!opts.schedule) {
await postMessage(pluginData, targetChannel, content, msg.attachments.array(), opts["enable-mentions"]);
await postMessage(pluginData, targetChannel, content, [...msg.attachments.values()], opts["enable-mentions"]);
}
if (opts.repeat) {

View file

@ -24,7 +24,7 @@ export async function addMemberPendingRoleChange(
const member = await resolveMember(pluginData.client, pluginData.guild, memberId);
if (member) {
const newRoleIds = new Set(member.roles.cache.keyArray());
const newRoleIds = new Set(member.roles.cache.keys());
for (const change of newPendingRoleChangeObj.changes) {
if (change.mode === "+") newRoleIds.add(change.roleId as Snowflake);
else newRoleIds.delete(change.roleId as Snowflake);

View file

@ -31,7 +31,7 @@ export const MigratePinsCmd = starboardCmd({
msg.channel.send(`Migrating pins from <#${args.pinChannel.id}> to <#${starboardChannel.id}>...`);
const pins = (await args.pinChannel.messages.fetchPinned()).array();
const pins = [...(await args.pinChannel.messages.fetchPinned().catch(() => [])).values()];
pins.reverse(); // Migrate pins starting from the oldest message
for (const pin of pins) {

View file

@ -118,7 +118,7 @@ export const CleanCmd = utilityCmd({
const deletePins = args["delete-pins"] != null ? args["delete-pins"] : false;
let pins: Message[] = [];
if (!deletePins) {
pins = (await msg.channel.messages.fetchPinned()).array();
pins = [...(await msg.channel.messages.fetchPinned().catch(() => [])).values()];
}
while (messagesToClean.length < args.count) {
@ -128,14 +128,14 @@ export const CleanCmd = utilityCmd({
});
if (potentialMessages.size === 0) break;
const existingStored = await pluginData.state.savedMessages.getMultiple(potentialMessages.keyArray());
const existingStored = await pluginData.state.savedMessages.getMultiple([...potentialMessages.keys()]);
const alreadyStored = existingStored.map(stored => stored.id);
const messagesToStore = potentialMessages
.array()
.filter(potentialMsg => !alreadyStored.includes(potentialMsg.id));
const messagesToStore = [
...potentialMessages.filter(potentialMsg => !alreadyStored.includes(potentialMsg.id)).values(),
];
await pluginData.state.savedMessages.createFromMessages(messagesToStore);
const potentialMessagesToClean = await pluginData.state.savedMessages.getMultiple(potentialMessages.keyArray());
const potentialMessagesToClean = await pluginData.state.savedMessages.getMultiple([...potentialMessages.keys()]);
if (potentialMessagesToClean.length === 0) break;
const filtered: SavedMessage[] = [];

View file

@ -32,7 +32,7 @@ export const VcdisconnectCmd = utilityCmd({
const channel = pluginData.guild.channels.cache.get(args.member.voice.channelId) as VoiceChannel;
try {
await args.member.voice.kick();
await args.member.voice.disconnect();
} catch {
sendErrorMessage(pluginData, msg.channel, "Failed to disconnect member");
return;

View file

@ -9,6 +9,7 @@ import { LogType } from "../../../data/LogType";
import { canActOn, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { channelMentionRegex, isSnowflake, simpleClosestStringMatch } from "../../../utils";
import { utilityCmd } from "../types";
import { ChannelTypeStrings } from "../../../types";
export const VcmoveCmd = utilityCmd({
trigger: "vcmove",
@ -45,9 +46,11 @@ export const VcmoveCmd = utilityCmd({
channel = potentialChannel;
} else {
// Search string -> find closest matching voice channel name
const voiceChannels = pluginData.guild.channels.cache.array().filter(theChannel => {
return theChannel instanceof VoiceChannel;
}) as VoiceChannel[];
const voiceChannels = [
...pluginData.guild.channels.cache
.filter((c): c is VoiceChannel => c.type === ChannelTypeStrings.VOICE)
.values(),
];
const closestMatch = simpleClosestStringMatch(args.channel, voiceChannels, ch => ch.name);
if (!closestMatch) {
sendErrorMessage(pluginData, msg.channel, "No matching voice channels");
@ -124,9 +127,11 @@ export const VcmoveAllCmd = utilityCmd({
channel = potentialChannel;
} else {
// Search string -> find closest matching voice channel name
const voiceChannels = pluginData.guild.channels.cache.array().filter(theChannel => {
return theChannel instanceof VoiceChannel;
}) as VoiceChannel[];
const voiceChannels = [
...pluginData.guild.channels.cache
.filter((c): c is VoiceChannel => c.type === ChannelTypeStrings.VOICE)
.values(),
];
const closestMatch = simpleClosestStringMatch(args.channel, voiceChannels, ch => ch.name);
if (!closestMatch) {
sendErrorMessage(pluginData, msg.channel, "No matching voice channels");

View file

@ -130,11 +130,13 @@ export async function getChannelInfoEmbed(
if (channel.type === ChannelTypeStrings.PRIVATE_THREAD || channel.type === ChannelTypeStrings.PUBLIC_THREAD) {
const thread = channel as ThreadChannel;
const parentChannelName = thread.parent?.name ? thread.parent.name : `<#${thread.parentId}>`;
const parentChannelName = thread.parent?.name ?? `<#${thread.parentId}>`;
const memberCount = thread.memberCount ?? thread.members.cache.size;
const owner = await pluginData.guild.members.fetch(thread.ownerId).catch(() => null);
const ownerMention = owner ? verboseUserMention(owner.user) : "Unknown#0000";
const humanizedArchiveTime = `Archive duration: **${humanizeDuration(thread.autoArchiveDuration * MINUTES)}**`;
const owner = await thread.fetchOwner().catch(() => null);
const ownerMention = owner?.user ? verboseUserMention(owner.user) : "Unknown#0000";
const humanizedArchiveTime = `Archive duration: **${humanizeDuration(
(thread.autoArchiveDuration ?? 0) * MINUTES,
)}**`;
embed.fields.push({
name: preEmbedPadding + "Thread information",

View file

@ -535,7 +535,7 @@ export async function findRelevantAuditLogEntry(
}
}
const entries = auditLogs ? auditLogs.entries.array() : [];
const entries = auditLogs ? [...auditLogs.entries.values()] : [];
entries.sort((a, b) => {
if (a.createdAt > b.createdAt) return -1;
@ -1302,7 +1302,7 @@ export async function resolveInvite<T extends boolean>(
return promise as ResolveInviteReturnType<T>;
}
const internalStickerCache: LimitedCollection<Snowflake, Sticker> = new LimitedCollection(500);
const internalStickerCache: LimitedCollection<Snowflake, Sticker> = new LimitedCollection({ maxSize: 500 });
export async function resolveStickerId(bot: Client, id: Snowflake): Promise<Sticker | null> {
const cachedSticker = internalStickerCache.get(id);

View file

@ -87,7 +87,7 @@ export function memberToConfigAccessibleMember(member: GuildMember | PartialGuil
...user,
user,
nick: member.nickname ?? "*None*",
roles: member.roles.cache.mapValues(r => roleToConfigAccessibleRole(r)).array(),
roles: [...member.roles.cache.mapValues(r => roleToConfigAccessibleRole(r)).values()],
joinedAt: member.joinedTimestamp ?? undefined,
guildName: member.guild.name,
};