add API comments
This commit is contained in:
parent
fe34c8a91c
commit
d62bf01b4a
7 changed files with 85 additions and 0 deletions
16
src/bot.ts
16
src/bot.ts
|
@ -12,6 +12,9 @@ import {
|
|||
import { channel, log_from, SimpleResult, split_promise } from "./utils.ts";
|
||||
const log = (...args: unknown[]) => log_from(import.meta.url, ...args);
|
||||
|
||||
/**
|
||||
* Wraps a discord bot and implements required actions.
|
||||
*/
|
||||
export class EpitlsBot {
|
||||
private bot;
|
||||
private token;
|
||||
|
@ -29,6 +32,10 @@ export class EpitlsBot {
|
|||
>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Connects to discord API server and registers slash commands.\
|
||||
* Needs to be run after construction as it is an asynchronous operation.
|
||||
*/
|
||||
public async start() {
|
||||
const { promise, resolver } = split_promise<void>();
|
||||
this.bot.on("ready", () => resolver());
|
||||
|
@ -37,6 +44,9 @@ export class EpitlsBot {
|
|||
await this.register_commands();
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns a discord role to a discord user.
|
||||
*/
|
||||
public async assign_role(user_id: string, guild_id: string, role_id: string) {
|
||||
const guild = await this.bot.guilds.fetch(guild_id);
|
||||
const member = await guild.members.fetch({ user: user_id });
|
||||
|
@ -46,10 +56,16 @@ export class EpitlsBot {
|
|||
log(`Assigned role '${role.name}' to user '${member.displayName}'.`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pull-style API to wait for and receive account association requests.
|
||||
*/
|
||||
public async *receive_associations() {
|
||||
while (true) yield await this.assoc_channel.receive();
|
||||
}
|
||||
|
||||
/**
|
||||
* Connected bot name accessor.
|
||||
*/
|
||||
public bot_name() {
|
||||
return this.bot.user?.displayName;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue