Skip to content

Commit

Permalink
feat: add /loggedin
Browse files Browse the repository at this point in the history
  • Loading branch information
rutmanz committed Sep 13, 2023
1 parent c9f413b commit 3adfda0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import { handleLogoutCommand } from "./logout";
import { handleRejectButton, handleRejectModal } from "./reject";
import { handleOpenSettingsModal, handleSettingsSave } from "./settings";
import { handleVoidCommand } from "./void";
import { handleGetLoggedInCommand } from "./loggedin";

export function register_listeners(app: App) {
// Commands and Shortcuts
app.command('/log', handleLogCommand)
app.command('/graph', handleGraphCommand)
app.command('/clearlogin', handleLogoutCommand)
app.command("/voidtime", handleVoidCommand)
app.command("/loggedin", handleGetLoggedInCommand)
app.shortcut('log_hours', handleLogShortcut)

// Buttons
Expand Down
14 changes: 14 additions & 0 deletions src/handlers/loggedin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { SlackCommandMiddlewareArgs, AllMiddlewareArgs } from "@slack/bolt";
import { getLoggedIn } from "../utils/drive";

export async function handleGetLoggedInCommand({ logger, ack, respond }: SlackCommandMiddlewareArgs & AllMiddlewareArgs) {
await ack()
try {
const users = await getLoggedIn()
await respond({response_type:"ephemeral", text: users.length > 0 ? `*Currently Logged In:*\n${users.join("\n")}`: "Nobody is logged in", mrkdwn:true})
} catch (e) {
logger.error(e)
await respond({response_type:"ephemeral", text: `Could not get logged in users: ${e}`})
return
}
}
5 changes: 5 additions & 0 deletions src/utils/drive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ export async function voidHours(name:string):Promise<number>{
return response.status
}


export async function getLoggedIn():Promise<string[]> {
const response = await fetch(cluck_baseurl + "/api/loggedin")
return Object.keys(await response.json() as object)
}
export async function getHours(): Promise<LogRow[]> {
if (!googleDriveAuthed) return [];
await sheet.loadCells()
Expand Down

0 comments on commit 3adfda0

Please sign in to comment.