add API constraints
This commit is contained in:
parent
431c184690
commit
fe34c8a91c
5 changed files with 48 additions and 34 deletions
24
src/rules.ts
24
src/rules.ts
|
@ -1,12 +1,14 @@
|
|||
type SerializedRule = { group_id: string; target_role: TargetRole };
|
||||
export type TargetRole = { guild_id: string; role_id: string };
|
||||
type SerializedRule = { group_id: string; target_role: TargetRole };
|
||||
|
||||
export class RuleSet {
|
||||
rules;
|
||||
constructor() {
|
||||
private rules;
|
||||
|
||||
public constructor() {
|
||||
this.rules = new Map<string, TargetRole[]>();
|
||||
}
|
||||
|
||||
static async from_file(path: string) {
|
||||
public static async from_file(path: string) {
|
||||
const result = new RuleSet();
|
||||
const file_content = await Deno.readTextFile(path);
|
||||
const parsed = JSON.parse(file_content) as SerializedRule[];
|
||||
|
@ -14,6 +16,16 @@ export class RuleSet {
|
|||
return result;
|
||||
}
|
||||
|
||||
public roles_for_group(group_id: string) {
|
||||
return this.rules.get(group_id) ?? [];
|
||||
}
|
||||
|
||||
public size() {
|
||||
let result = 0;
|
||||
for (const roles of this.rules.values()) result += roles.length;
|
||||
return result;
|
||||
}
|
||||
|
||||
private append_rule(group_id: string, target_role: TargetRole) {
|
||||
let roles = this.rules.get(group_id);
|
||||
if (roles === undefined) {
|
||||
|
@ -22,8 +34,4 @@ export class RuleSet {
|
|||
}
|
||||
roles.push(target_role);
|
||||
}
|
||||
|
||||
roles_for_group(group_id: string) {
|
||||
return this.rules.get(group_id) ?? [];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue