Init.
This commit is contained in:
commit
c872cad278
11 changed files with 1052 additions and 0 deletions
29
src/rules.ts
Normal file
29
src/rules.ts
Normal file
|
@ -0,0 +1,29 @@
|
|||
type SerializedRule = { group_id: string; target_role: TargetRole };
|
||||
export type TargetRole = { guild_id: string; role_id: string };
|
||||
export class RuleSet {
|
||||
rules;
|
||||
constructor() {
|
||||
this.rules = new Map<string, TargetRole[]>();
|
||||
}
|
||||
|
||||
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[];
|
||||
for (const { group_id, target_role } of parsed) result.append_rule(group_id, target_role);
|
||||
return result;
|
||||
}
|
||||
|
||||
private append_rule(group_id: string, target_role: TargetRole) {
|
||||
let roles = this.rules.get(group_id);
|
||||
if (roles === undefined) {
|
||||
roles = [];
|
||||
this.rules.set(group_id, roles);
|
||||
}
|
||||
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