mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-15 05:41:51 +00:00
Add a shared lock for Persist and ReactionRoles plugins to prevent race conditions
This commit is contained in:
parent
a5178dc78f
commit
47c5722060
2 changed files with 14 additions and 3 deletions
|
@ -71,8 +71,13 @@ export class PersistPlugin extends ZeppelinPlugin<TConfigSchema> {
|
|||
|
||||
@d.event("guildMemberAdd")
|
||||
async onGuildMemberAdd(_, member: Member) {
|
||||
const memberRolesLock = await this.locks.acquire(`member-roles-${member.id}`);
|
||||
|
||||
const persistedData = await this.persistedData.find(member.id);
|
||||
if (!persistedData) return;
|
||||
if (!persistedData) {
|
||||
memberRolesLock.unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
const toRestore: MemberOptions = {};
|
||||
const config = this.getConfig();
|
||||
|
@ -101,5 +106,7 @@ export class PersistPlugin extends ZeppelinPlugin<TConfigSchema> {
|
|||
restoredData: restoredData.join(", "),
|
||||
});
|
||||
}
|
||||
|
||||
memberRolesLock.unlock();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -189,6 +189,10 @@ export class ReactionRolesPlugin extends ZeppelinPlugin<TConfigSchema> {
|
|||
timeout: null,
|
||||
changes: [],
|
||||
applyFn: async () => {
|
||||
this.pendingRoleChanges.delete(memberId);
|
||||
|
||||
const lock = await this.locks.acquire(`member-roles-${memberId}`);
|
||||
|
||||
const member = await this.getMember(memberId);
|
||||
if (member) {
|
||||
const newRoleIds = new Set(member.roles);
|
||||
|
@ -206,9 +210,9 @@ export class ReactionRolesPlugin extends ZeppelinPlugin<TConfigSchema> {
|
|||
`Failed to apply role changes to ${member.username}#${member.discriminator} (${member.id}): ${e.message}`,
|
||||
);
|
||||
}
|
||||
|
||||
this.pendingRoleChanges.delete(memberId);
|
||||
}
|
||||
|
||||
lock.unlock();
|
||||
},
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue