Skip to content

Commit

Permalink
Add buttons support
Browse files Browse the repository at this point in the history
  • Loading branch information
dispherical committed Jun 14, 2024
1 parent 6cb7667 commit 99e76cc
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 2 deletions.
26 changes: 26 additions & 0 deletions buttons/events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const figlet = require("figlet")
module.exports = {
title: "Upcoming Events",
action_id: "hardware_btn",
description: "Channels featured by Hack Club",
/**
* @param {{app: import('@slack/bolt').App}} param1
*/
render: async function ({ app }) {
const events = (await (await fetch("https://hackathons.hackclub.com/api/events/upcoming")).json())
var text = ""
events.forEach(event => {
text += `<${event.website}|${event.name}> (${!event.virtual ? event.hybrid ? "Hybrid" : "In person" : "Virtual" }) - ${event.city || "Unknown city"}, ${event.state || "Unknown area"}, ${event.country || event.countryCode, "Unknown country"}\n`
})
return `\`\`\`
${figlet.textSync("Events", {
horizontalLayout: "default",
verticalLayout: "default",
width: 60,
whitespaceBreak: true,
})}
\`\`\`
Here are a list of upcoming Hackathons:
${text}`
},
};
28 changes: 28 additions & 0 deletions buttons/hardware.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const figlet = require("figlet")
module.exports = {
title: "Hardware",
action_id: "hardware_btn",
description: "Channels featured by Hack Club",
/**
* @param {{app: import('@slack/bolt').App}} param1
*/
render: async function ({ app }) {
return `\`\`\`
${figlet.textSync("Hardware", {
horizontalLayout: "default",
verticalLayout: "default",
width: 60,
whitespaceBreak: true,
})}
\`\`\`
Hack Club has started the process of getting teenagers into more hardware-based projects!
Trail: 30 Hack Clubbers build PCBs that will be useful on the trail and hike for 7 days on the Pacific Crest Trail from July 12th to July 19th. Travel stipends/aid available to help you go. Learn more at https://trail.hackclub.com (<#C06RQ9TTEG3>)
OnBoard: Get $100 to build your own custom PCB. Learn more at https://hackclub.com/onboard (<#C056AMWSFKJ>)
Bin: Get a free custom hardware kit made for you shipped to your doorstep. Learn more at https://hackclub.com/bin (<#C056AMWSFKJ>)
All of these events and programs are *free* for you to attend.`
},
};
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Array.prototype.random = function () {
// This runs the same thing on startup
await require("./utils/redo")({ app, client });
// app.message functions go here
require("./interactions/message")({ app, client });
await require("./interactions/message")({ app, client });

await require("./utils/pull")({ app, client });
setInterval(async function () {
Expand Down
46 changes: 45 additions & 1 deletion utils/pull.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,56 @@ module.exports = async function ({ app, client }) {
});

await Promise.all(sPromises);
var subBlocks = []
let bPromises = fs
.readdirSync("./buttons")
.filter((str) => str.endsWith(".js"))
.sort()
.map(async (fn) => {

const id = Math.random().toString(32).slice(2)
const button = await require(`../buttons/${fn}`);
subBlocks.push({
"type": "button",
"text": {
"type": "plain_text",
"text": button.title,
"emoji": true
},
"value": `../buttons/${fn}`,
"action_id": id
})
app.action(id, async ({ ack, respond, say, body }) => {
console.log("hello")
await ack();
//await say("hello")

text += `\nLast Updated on ${new Date().toLocaleString("en-US", { timeZone: "America/New_York", timeStyle: "short", dateStyle: "long" })} (EST)`;
await app.client.chat.postEphemeral({
channel: body.channel.id,
user: body.user.id,
text: (await require(body.actions[0].value).render({ app }))
})
});
});

await Promise.all(bPromises)

text += `\nLast Updated on ${new Date().toLocaleString("en-US", { timeZone: "America/New_York", timeStyle: "short", dateStyle: "long" })} (EST)\nWant to dive into a specific subject? Click one of the buttons below:`;
client.set("messageText", text);

app.client.chat.update({
channel: process.env.SLACK_CHANNEL,
ts: await client.get("messageId"),
blocks: [{
"type": "section",
"text": {
"type": "mrkdwn",
"text": text
}
}, {
"type": "actions",
elements: subBlocks
}],
text,
});
};

0 comments on commit 99e76cc

Please sign in to comment.