adds renaming and rule for historical participation
This commit is contained in:
parent
fb141abd05
commit
09e05c5c53
5 changed files with 114 additions and 36 deletions
14
src/main.ts
14
src/main.ts
|
@ -2,7 +2,7 @@
|
|||
|
||||
import { log_from, read_conf, root_path, SimpleResult } from "./utils.ts";
|
||||
import { State } from "./state.ts";
|
||||
import { RuleSet } from "./rules.ts";
|
||||
import { RuleSet, TargetRole } from "./rules.ts";
|
||||
import { EpitlsBot } from "./bot.ts";
|
||||
import { CriApi } from "./cri.ts";
|
||||
import { Emailer } from "./email.ts";
|
||||
|
@ -86,6 +86,7 @@ class Service {
|
|||
const promises = [] as Promise<void>[];
|
||||
for await (const { cri_login, discord_user_id } of this.state.users()) {
|
||||
promises.push(this.update_user_roles(cri_login, discord_user_id));
|
||||
promises.push(this.update_user_name(cri_login, discord_user_id));
|
||||
}
|
||||
await Promise.all(promises);
|
||||
}
|
||||
|
@ -93,11 +94,20 @@ class Service {
|
|||
async update_user_roles(cri_login: string, discord_user_id: string) {
|
||||
const groups = await this.cri_api.groups_of(cri_login);
|
||||
// log("found groups", groups);
|
||||
const roles = groups.map((group) => [...this.rules.roles_for_group(group)]).flat();
|
||||
const roles = [] as TargetRole[];
|
||||
|
||||
for (const group of groups.current) roles.push(...this.rules.roles_for_group(group, false));
|
||||
for (const group of groups.history) roles.push(...this.rules.roles_for_group(group, true));
|
||||
// log("found setting roles", roles);
|
||||
for (const { guild_id, role_id } of roles) await this.bot.assign_role(discord_user_id, guild_id, role_id);
|
||||
}
|
||||
|
||||
async update_user_name(cri_login: string, discord_user_id: string) {
|
||||
const { first_name, last_name } = await this.cri_api.get_user_name(cri_login);
|
||||
const suffix = ` [${first_name} .${last_name[0] ?? ""}]`;
|
||||
await this.bot.update_user_name(discord_user_id, first_name, suffix);
|
||||
}
|
||||
|
||||
async association_procedure(discord_user_id: string, cri_login: string): Promise<SimpleResult> {
|
||||
try {
|
||||
if (!await this.cri_api.user_exists(cri_login)) return "No such login.";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue