From 71ce034f9f4b910b4fc38a6a225b0ad0e0e86e87 Mon Sep 17 00:00:00 2001 From: Saahil Date: Sun, 13 Apr 2025 20:22:40 -0400 Subject: [PATCH] feat: zchannel --- src/commands/zchannel.ts | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/commands/zchannel.ts diff --git a/src/commands/zchannel.ts b/src/commands/zchannel.ts new file mode 100644 index 0000000..23f90cf --- /dev/null +++ b/src/commands/zchannel.ts @@ -0,0 +1,44 @@ +import { Command, onlyForMe } from "../modules/BaseCommand"; +import { ModifiedApp } from "../modules/slackapp"; + +export default class ChannelPing implements Command { + name: string; + description: string; + constructor() { + this.name = `/zchannel`; + this.description = `Pings @channel`; + } + run(app: ModifiedApp) { + app.command(this.name, async ({ command, ack, respond }) => { + await ack(); + + if (!onlyForMe(command.user_id)) + return respond(`:x: You cannot use this command.`); + const user = await app.client.users.info({ user: command.user_id }); + const displayName = + user?.user?.profile?.display_name || user?.user?.name || ""; + const avatar = + user?.user?.profile?.image_original || user?.user?.profile?.image_512; + + const payload = { + text: command.text, + username: displayName, + icon_url: avatar, + blocks: [ + { + type: "section", + text: { + type: "mrkdwn", + text: command.text, + }, + }, + ], + }; + + const response = await app.client.chat.postMessage({ + channel: command.channel_id, + ...payload, + }); + }); + } +}