@astrofoundry/pi-astro 0.22.1 → 0.22.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -31,10 +31,13 @@ export class ApprovalServer {
|
|
|
31
31
|
private server: Server | null = null;
|
|
32
32
|
private port = 0;
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
) {
|
|
34
|
+
private readonly events: ApprovalEvents;
|
|
35
|
+
private readonly timeoutMs: number;
|
|
36
|
+
|
|
37
|
+
constructor(events: ApprovalEvents, timeoutMs: number) {
|
|
38
|
+
this.events = events;
|
|
39
|
+
this.timeoutMs = timeoutMs;
|
|
40
|
+
}
|
|
38
41
|
|
|
39
42
|
get url(): string {
|
|
40
43
|
return `http://127.0.0.1:${this.port}`;
|
|
@@ -95,8 +95,11 @@ export class GatewayClient {
|
|
|
95
95
|
private heartbeat: ReturnType<typeof setInterval> | null = null;
|
|
96
96
|
private stopped = false;
|
|
97
97
|
private attempts = 0;
|
|
98
|
+
private readonly options: GatewayClientOptions;
|
|
98
99
|
|
|
99
|
-
constructor(
|
|
100
|
+
constructor(options: GatewayClientOptions) {
|
|
101
|
+
this.options = options;
|
|
102
|
+
}
|
|
100
103
|
|
|
101
104
|
start(): void {
|
|
102
105
|
this.stopped = false;
|
|
@@ -70,12 +70,12 @@ class Bridge {
|
|
|
70
70
|
private readonly approvalMessages = new Map<string, { channelId: string; messageId: string; userMessage: ActiveTask }>();
|
|
71
71
|
private config: DiscordConfig;
|
|
72
72
|
private botUserId = "";
|
|
73
|
+
private readonly ctx: ExtensionContext;
|
|
74
|
+
private readonly token: string;
|
|
73
75
|
|
|
74
|
-
constructor(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
private readonly token: string,
|
|
78
|
-
) {
|
|
76
|
+
constructor(ctx: ExtensionContext, config: DiscordConfig, token: string) {
|
|
77
|
+
this.ctx = ctx;
|
|
78
|
+
this.token = token;
|
|
79
79
|
this.config = config;
|
|
80
80
|
this.rest = new DiscordRest(token);
|
|
81
81
|
this.approvals = new ApprovalServer({ onTicket: (t) => void this.askApproval(t), onExpired: (t) => void this.expireApproval(t) }, config.approvalTimeoutMinutes * 60_000);
|
|
@@ -31,11 +31,15 @@ interface RateLimit {
|
|
|
31
31
|
* 429 using the returned `retry_after`; anything else non-2xx throws.
|
|
32
32
|
*/
|
|
33
33
|
export class DiscordRest {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
) {
|
|
34
|
+
private readonly token: string;
|
|
35
|
+
private readonly fetchImpl: typeof fetch;
|
|
36
|
+
private readonly base: string;
|
|
37
|
+
|
|
38
|
+
constructor(token: string, fetchImpl: typeof fetch = fetch, base = API) {
|
|
39
|
+
this.token = token;
|
|
40
|
+
this.fetchImpl = fetchImpl;
|
|
41
|
+
this.base = base;
|
|
42
|
+
}
|
|
39
43
|
|
|
40
44
|
private async call(method: string, path: string, body?: BodyInit, contentType?: string, attempt = 0): Promise<Response> {
|
|
41
45
|
const headers: Record<string, string> = { Authorization: `Bot ${this.token}`, "User-Agent": "DiscordBot (https://github.com/astrofoundry/pi-astro, astro-discord)" };
|