Finish preliminary rework, ready to test

This commit is contained in:
Dark 2021-06-02 04:07:50 +02:00
parent 57893e7f76
commit d0a1beb809
No known key found for this signature in database
GPG key ID: 2CD6ACB6B0A87B8A
177 changed files with 854 additions and 707 deletions

View file

@ -3,6 +3,7 @@ import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { isDiscordRESTError } from "../../../utils";
import { Message } from "discord.js";
export const ClearReactionRolesCmd = reactionRolesCmd({
trigger: "reaction_roles clear",
@ -21,9 +22,9 @@ export const ClearReactionRolesCmd = reactionRolesCmd({
pluginData.state.reactionRoles.removeFromMessage(args.message.messageId);
let targetMessage: Message<TextChannel>;
let targetMessage: Message;
try {
targetMessage = await args.message.channel.getMessage(args.message.messageId);
targetMessage = await args.message.channel.messages.fetch(args.message.messageId);
} catch (err) {
if (isDiscordRESTError(err) && err.code === 50001) {
sendErrorMessage(pluginData, msg.channel, "Missing access to the specified message");
@ -33,7 +34,7 @@ export const ClearReactionRolesCmd = reactionRolesCmd({
throw err;
}
await targetMessage.removeReactions();
await targetMessage.reactions.removeAll();
sendSuccessMessage(pluginData, msg.channel, "Reaction roles cleared");
},

View file

@ -1,8 +1,6 @@
import { reactionRolesCmd, TReactionRolePair } from "../types";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { RecoverablePluginError, ERRORS } from "../../../RecoverablePluginError";
import { canUseEmoji, isDiscordRESTError, isValidEmoji, noop, trimPluginDescription } from "../../../utils";
import { applyReactionRoleReactionsToMessage } from "../util/applyReactionRoleReactionsToMessage";
import { canReadChannel } from "../../../utils/canReadChannel";
@ -41,7 +39,7 @@ export const InitReactionRolesCmd = reactionRolesCmd({
let targetMessage;
try {
targetMessage = await args.message.channel.getMessage(args.message.messageId).catch(noop);
targetMessage = await args.message.channel.messages.fetch(args.message.messageId).catch(noop);
} catch (e) {
if (isDiscordRESTError(e)) {
sendErrorMessage(pluginData, msg.channel, `Error ${e.code} while getting message: ${e.message}`);
@ -96,13 +94,13 @@ export const InitReactionRolesCmd = reactionRolesCmd({
return;
}
if (!pluginData.guild.roles.has(pair[1])) {
if (!pluginData.guild.roles.cache.has(pair[1])) {
sendErrorMessage(pluginData, msg.channel, `Unknown role ${pair[1]}`);
return;
}
}
const progressMessage = msg.channel.createMessage("Adding reaction roles...");
const progressMessage = msg.channel.send("Adding reaction roles...");
// Save the new reaction roles to the database
for (const pair of emojiRolePairs) {

View file

@ -4,6 +4,7 @@ import { addMemberPendingRoleChange } from "../util/addMemberPendingRoleChange";
import { LogsPlugin } from "../../Logs/LogsPlugin";
import { LogType } from "../../../data/LogType";
import { Message } from "discord.js";
const CLEAR_ROLES_EMOJI = "❌";
@ -12,9 +13,9 @@ export const AddReactionRoleEvt = reactionRolesEvt({
async listener(meta) {
const pluginData = meta.pluginData;
const msg = meta.args.message as Message;
const emoji = meta.args.emoji;
const userId = meta.args.member.id;
const msg = meta.args.reaction.message as Message;
const emoji = meta.args.reaction.emoji;
const userId = meta.args.user.id;
if (userId === pluginData.client.user!.id) {
// Don't act on own reactions
@ -39,7 +40,7 @@ export const AddReactionRoleEvt = reactionRolesEvt({
// User reacted with a reaction role emoji -> add the role
const matchingReactionRole = await pluginData.state.reactionRoles.getByMessageAndEmoji(
msg.id,
emoji.id || emoji.name,
emoji.id || emoji.name!,
);
if (!matchingReactionRole) return;
@ -59,9 +60,8 @@ export const AddReactionRoleEvt = reactionRolesEvt({
if (config.remove_user_reactions) {
setTimeout(() => {
pluginData.state.reactionRemoveQueue.add(async () => {
const reaction = emoji.id ? `${emoji.name}:${emoji.id}` : emoji.name;
const wait = sleep(1500);
await msg.channel.removeMessageReaction(msg.id, reaction, userId).catch(noop);
await meta.args.reaction.remove().catch(noop);
await wait;
});
}, 1500);

View file

@ -23,7 +23,7 @@ export async function addMemberPendingRoleChange(
const member = await resolveMember(pluginData.client, pluginData.guild, memberId);
if (member) {
const newRoleIds = new Set(member.roles);
const newRoleIds = new Set(member.roles.cache.keyArray());
for (const change of newPendingRoleChangeObj.changes) {
if (change.mode === "+") newRoleIds.add(change.roleId);
else newRoleIds.delete(change.roleId);
@ -38,7 +38,7 @@ export async function addMemberPendingRoleChange(
);
} catch (e) {
logger.warn(
`Failed to apply role changes to ${member.username}#${member.discriminator} (${member.id}): ${e.message}`,
`Failed to apply role changes to ${member.user.username}#${member.user.discriminator} (${member.id}): ${e.message}`,
);
}
}

View file

@ -6,6 +6,7 @@ import { isDiscordRESTError, sleep, isSnowflake } from "../../../utils";
import { logger } from "../../../logger";
import { LogsPlugin } from "../../Logs/LogsPlugin";
import { LogType } from "../../../data/LogType";
import { TextChannel } from "discord.js";
const CLEAR_ROLES_EMOJI = "❌";
@ -26,7 +27,7 @@ export async function applyReactionRoleReactionsToMessage(
let targetMessage;
try {
targetMessage = await channel.getMessage(messageId);
targetMessage = await channel.messages.fetch(messageId);
} catch (e) {
if (isDiscordRESTError(e)) {
if (e.code === 10008) {