add API comments
This commit is contained in:
parent
fe34c8a91c
commit
d62bf01b4a
7 changed files with 85 additions and 0 deletions
12
src/rules.ts
12
src/rules.ts
|
@ -1,6 +1,9 @@
|
|||
export type TargetRole = { guild_id: string; role_id: string };
|
||||
type SerializedRule = { group_id: string; target_role: TargetRole };
|
||||
|
||||
/**
|
||||
* A set of rules for associating CRI groups with Discord roles.
|
||||
*/
|
||||
export class RuleSet {
|
||||
private rules;
|
||||
|
||||
|
@ -8,6 +11,9 @@ export class RuleSet {
|
|||
this.rules = new Map<string, TargetRole[]>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a RuleSet from a JSON serialized file.
|
||||
*/
|
||||
public static async from_file(path: string) {
|
||||
const result = new RuleSet();
|
||||
const file_content = await Deno.readTextFile(path);
|
||||
|
@ -16,10 +22,16 @@ export class RuleSet {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets which Discord roles must be assigned to a user which is part of a given CRI group.
|
||||
*/
|
||||
public roles_for_group(group_id: string) {
|
||||
return this.rules.get(group_id) ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Number of managed Discord roles.
|
||||
*/
|
||||
public size() {
|
||||
let result = 0;
|
||||
for (const roles of this.rules.values()) result += roles.length;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue