fix(role patch): fix buggy arrayMatches tester

This commit is contained in:
41666 2020-02-09 19:45:48 -05:00
parent 951d6c41bf
commit 11e7a9b9d4
No known key found for this signature in database
GPG key ID: BC51D07640DC10AF

View file

@ -136,7 +136,11 @@ module.exports = (R, $) => {
newRoles = [...newRoles, ...sanitizedAdded]
if (!arrayMatches(currentRoles, newRoles)) {
console.log("updating!", { currentRoles, newRoles });
await $.discord.updateRoles(gm, newRoles)
} else {
console.log("not updating!", { currentRoles, newRoles });
}
ctx.body = { ok: true }
@ -146,4 +150,18 @@ module.exports = (R, $) => {
})
}
const arrayMatches = (a, b) => a.length === b.length && a.reduce((_, aValue) => b.includes(aValue), true)
// if length is the same, check elements.
const arrayMatches = (a, b) => {
if (a.length === b.length) {
for (let item of a) {
if (!b.includes(item)) {
return false
}
}
return true
}
return false
}