Properly order reaction roles
This commit is contained in:
parent
7124898568
commit
43c23263f0
7 changed files with 41 additions and 9 deletions
|
@ -103,6 +103,7 @@ export const InitReactionRolesCmd = reactionRolesCmd({
|
|||
const progressMessage = msg.channel.send("Adding reaction roles...");
|
||||
|
||||
// Save the new reaction roles to the database
|
||||
let pos = 0;
|
||||
for (const pair of emojiRolePairs) {
|
||||
await pluginData.state.reactionRoles.add(
|
||||
args.message.channel.id,
|
||||
|
@ -110,7 +111,9 @@ export const InitReactionRolesCmd = reactionRolesCmd({
|
|||
pair[0],
|
||||
pair[1],
|
||||
args.exclusive,
|
||||
pos,
|
||||
);
|
||||
pos++;
|
||||
}
|
||||
|
||||
// Apply the reactions themselves
|
||||
|
|
|
@ -61,7 +61,7 @@ export const AddReactionRoleEvt = reactionRolesEvt({
|
|||
setTimeout(() => {
|
||||
pluginData.state.reactionRemoveQueue.add(async () => {
|
||||
const wait = sleep(1500);
|
||||
await meta.args.reaction.remove().catch(noop);
|
||||
await meta.args.reaction.users.remove(userId).catch(noop);
|
||||
await wait;
|
||||
});
|
||||
}, 1500);
|
||||
|
|
|
@ -71,18 +71,16 @@ export async function applyReactionRoleReactionsToMessage(
|
|||
emojisToAdd.push(CLEAR_ROLES_EMOJI);
|
||||
|
||||
for (const rawEmoji of emojisToAdd) {
|
||||
const emoji = isSnowflake(rawEmoji) ? `foo:${rawEmoji}` : rawEmoji;
|
||||
|
||||
try {
|
||||
await targetMessage.reactions.add(emoji);
|
||||
await sleep(1250); // Make sure we don't hit rate limits
|
||||
await targetMessage.react(rawEmoji);
|
||||
await sleep(750); // Make sure we don't hit rate limits
|
||||
} catch (e) {
|
||||
if (isDiscordRESTError(e)) {
|
||||
if (e.code === 10014) {
|
||||
pluginData.state.reactionRoles.removeFromMessage(messageId, rawEmoji);
|
||||
errors.push(`Unknown emoji: ${emoji}`);
|
||||
errors.push(`Unknown emoji: ${rawEmoji}`);
|
||||
logs.log(LogType.BOT_ALERT, {
|
||||
body: `Could not add unknown reaction role emoji ${emoji} to message ${channelId}/${messageId}`,
|
||||
body: `Could not add unknown reaction role emoji ${rawEmoji} to message ${channelId}/${messageId}`,
|
||||
});
|
||||
continue;
|
||||
} else if (e.code === 50013) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue