Skip to content

Commit 2d3e71b

Browse files
committed
feat: Leave queue shortcut completed
1 parent 9dc09d6 commit 2d3e71b

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/app.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { App } from '@slack/bolt';
21
import { joinQueue } from '@bot/joinQueue';
2+
import { leaveQueue } from '@bot/leaveQueue';
33
import { database } from '@database';
4+
import { App } from '@slack/bolt';
45

56
export async function startApp(): Promise<void> {
67
// Check connection to google sheets
@@ -14,6 +15,7 @@ export async function startApp(): Promise<void> {
1415
});
1516

1617
joinQueue.setup(app);
18+
leaveQueue.setup(app);
1719

1820
let port = Number(process.env.PORT);
1921
if (!port || isNaN(port)) port = 3000;

src/bot/leaveQueue.ts

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { userRepo } from '@repos/userRepo';
2+
import { App, Middleware, SlackShortcut, SlackShortcutMiddlewareArgs } from '@slack/bolt';
3+
import { codeBlock, compose } from '@utils/text';
4+
import { BOT_ICON_URL, BOT_USERNAME } from './constants';
5+
import { Interaction } from './enums';
6+
7+
type ShortcutParam = Parameters<Middleware<SlackShortcutMiddlewareArgs<SlackShortcut>>>[0];
8+
9+
export const leaveQueue = {
10+
app: (undefined as unknown) as App,
11+
12+
setup(app: App): void {
13+
this.app = app;
14+
app.shortcut(Interaction.SHORTCUT_LEAVE_QUEUE, this.shortcut.bind(this));
15+
},
16+
17+
async shortcut({ ack, shortcut, client, logger }: ShortcutParam): Promise<void> {
18+
await ack();
19+
20+
const userId = shortcut.user.id;
21+
22+
let text: string;
23+
try {
24+
await userRepo.remove(userId);
25+
text = "You've been removed from the HackerRank review queue";
26+
} catch (err) {
27+
text = compose('Something went wrong :/', codeBlock(err.message));
28+
}
29+
await client.chat.postMessage({
30+
channel: userId,
31+
text,
32+
username: BOT_USERNAME,
33+
icon_url: BOT_ICON_URL,
34+
});
35+
},
36+
};

0 commit comments

Comments
 (0)