mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-13 13:25:03 +00:00
Migrate SelfGrantableRoles to new Plugin structure
This commit is contained in:
parent
140ba84544
commit
763bdd0b19
10 changed files with 418 additions and 0 deletions
|
@ -0,0 +1,15 @@
|
|||
import { TSelfGrantableRoleEntry } from "../types";
|
||||
|
||||
export function findMatchingRoles(roleNames, entries: TSelfGrantableRoleEntry[]): string[] {
|
||||
const aliasToRoleId = entries.reduce((map, entry) => {
|
||||
for (const [roleId, aliases] of Object.entries(entry.roles)) {
|
||||
for (const alias of aliases) {
|
||||
map.set(alias, roleId);
|
||||
}
|
||||
}
|
||||
|
||||
return map;
|
||||
}, new Map());
|
||||
|
||||
return roleNames.map(roleName => aliasToRoleId.get(roleName)).filter(Boolean);
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
import { TSelfGrantableRoleEntry, SelfGrantableRolesPluginType } from "../types";
|
||||
import { PluginData } from "knub";
|
||||
|
||||
export function getApplyingEntries(
|
||||
pluginData: PluginData<SelfGrantableRolesPluginType>,
|
||||
msg,
|
||||
): TSelfGrantableRoleEntry[] {
|
||||
const config = pluginData.config.getForMessage(msg);
|
||||
return Object.entries(config.entries)
|
||||
.filter(
|
||||
([k, e]) =>
|
||||
e.can_use && !(!e.can_ignore_cooldown && pluginData.state.cooldowns.isOnCooldown(`${k}:${msg.author.id}`)),
|
||||
)
|
||||
.map(pair => pair[1]);
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
export function normalizeRoleNames(roleNames: string[]) {
|
||||
return roleNames.map(v => v.toLowerCase());
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
export function splitRoleNames(roleNames: string[]) {
|
||||
return roleNames
|
||||
.map(v => v.split(/[\s,]+/))
|
||||
.flat()
|
||||
.filter(Boolean);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue