generated from ubiquity-os/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathplugin.ts
37 lines (34 loc) · 1.12 KB
/
plugin.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { createClient } from "@supabase/supabase-js";
import { CommanderError } from "commander";
import { createAdapters } from "./adapters";
import { CommandParser } from "./handlers/command-parser";
import { Context } from "./types";
import { handleCommand } from "./handlers/query-wallet";
/**
* How a worker executes the plugin.
*/
export async function plugin(context: Context) {
const supabase = createClient(context.env.SUPABASE_URL, context.env.SUPABASE_KEY);
context.adapters = createAdapters(supabase, context);
if (context.command) {
await handleCommand(context);
return;
}
if (context.eventName === "issue_comment.created") {
const commandParser = new CommandParser(context);
try {
const args = context.payload.comment.body.trim().split(/\s+/);
await commandParser.parse(args);
} catch (err) {
if (err instanceof CommanderError) {
if (err.code !== "commander.unknownCommand") {
throw context.logger.error(err.message);
}
} else {
throw err;
}
}
} else {
context.logger.error(`Unsupported event: ${context.eventName}`);
}
}