add administration commands

This commit is contained in:
Matthieu Jolimaitre 2024-02-05 03:56:16 +01:00
parent c106b1f21d
commit 9dda450728
4 changed files with 241 additions and 39 deletions

View file

@ -18,7 +18,7 @@ async function main() {
const state = await State.from_dir(root_path() + "/local");
log("Loaded state with", await state.users_count(), "users.");
const bot = new EpitlsBot(conf.discord.bot_token);
const bot = new EpitlsBot(conf.discord.bot_token, rules);
await bot.start();
log(`Started bot '${bot.bot_name()}' .`);
@ -73,6 +73,13 @@ class Service {
this.emailer.send_confirmation_mail(username ?? "<unknown>", cri_login + "@epita.fr", link);
}
})();
// for all updates to rule set, reassign all roles.
(async () => {
for await (const _ of this.rules.receive_rule_update()) {
await this.update_all_users_roles();
}
});
}
async update_all_users_roles() {
@ -86,7 +93,7 @@ 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 = groups.map((group) => [...this.rules.roles_for_group(group)]).flat();
// 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);
}