3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-07-14 05:57:18 +00:00

Add locks to starboard and include example of level-only starring

This commit is contained in:
Dark 2020-11-19 19:32:28 +01:00
parent bc5455bf9f
commit ba0b5df166
2 changed files with 23 additions and 0 deletions

View file

@ -88,6 +88,27 @@ export const StarboardPlugin = zeppelinGuildPlugin<StarboardPluginType>()("starb
basic: basic:
enabled: true enabled: true
~~~ ~~~
### Limit starboard to a specific level (and above)
This is identical to the channel-specific starboard above, but only works for a specific level (>=50).
It is noteworthy that this only properly works if the starboard requires just one star.
Only the new reaction is taken into account when determining valid starboards.
~~~yml
starboard:
config:
boards:
levelonly:
enabled: false # The starboard starts disabled and is then enabled in a level override below
channel_id: "604342689038729226"
stars_required: 1
overrides:
- level: ">=50"
config:
boards:
levelonly:
enabled: true
~~~
`), `),
}, },

View file

@ -58,6 +58,7 @@ export const StarboardReactionAddEvt = starboardEvt({
}); });
for (const starboard of applicableStarboards) { for (const starboard of applicableStarboards) {
const boardLock = await pluginData.locks.acquire(`starboards-channel-${starboard.channel_id}`);
// Save reaction into the database // Save reaction into the database
await pluginData.state.starboardReactions.createStarboardReaction(msg.id, userId).catch(noop); await pluginData.state.starboardReactions.createStarboardReaction(msg.id, userId).catch(noop);
@ -73,6 +74,7 @@ export const StarboardReactionAddEvt = starboardEvt({
if (reactionsCount >= starboard.stars_required) { if (reactionsCount >= starboard.stars_required) {
await saveMessageToStarboard(pluginData, msg, starboard); await saveMessageToStarboard(pluginData, msg, starboard);
} }
boardLock.unlock();
} }
}, },
}); });