Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# Hack Hour Mk. 3
![](https://api.checklyhq.com/v1/badges/checks/271a416b-7810-47b0-b58c-7cd9e9e37f82?style=flat&theme=default&responseTime=false)
52 changes: 46 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/clock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { prisma } from "./lib/prisma.js";
import { emitter } from "./lib/emitter.js";
import { Constants } from "./lib/constants.js";
import { handleError } from "./lib/handleError.js";

emitter.on('minute', async () => {
try {
Expand Down Expand Up @@ -109,7 +110,7 @@ emitter.on('minute', async () => {
}
}
} catch (error) {
emitter.emit('error', { error });
handleError(error)
}
});

Expand Down
12 changes: 10 additions & 2 deletions src/extensions/arcade/lib/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ export const fetchEvidence = async (messageTs: string, slackId: string) => {
return { activity, evidenced };
}

const acceptedImageTypes = [
"image/gif",
"image/jpeg",
"image/png",
"image/jpg"
]

// Take any media sent in the thread and attach it to the session
export const surfaceEvidence = async (messageTs: string, slackId: string) => {
const evidence = await Slack.conversations.replies({
Expand All @@ -48,8 +55,9 @@ export const surfaceEvidence = async (messageTs: string, slackId: string) => {
return;
}

console.log(image.files[0]);
session.metadata.slack.attachment = image.files[0]?.permalink;
if (acceptedImageTypes.includes(image.files[0]?.mimetype ?? "")) {
session.metadata.slack.attachment = image.files[0]?.permalink;
}

const updatedSession = await prisma.session.update({
where: {
Expand Down
155 changes: 78 additions & 77 deletions src/extensions/arcade/slack/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,80 +9,81 @@ import { Hack } from "../../slack/views/hack.js";
import { emitter } from "../../../lib/emitter.js";
import { firstTime } from "../watchers/hackhour.js";
import { Loading } from "../../slack/views/loading.js";
import { openModal } from "../../slack/lib/open-modal.js";

Slack.action(Actions.CHOOSE_SESSIONS, async ({ ack, body }) => {
try {
await ack();
if (body.type !== "block_actions") return;

if (body.type !== "block_actions") return;
// const view = await Slack.views.open({
// trigger_id: body.trigger_id,
// view: Loading.loading()
// });

const view = await Slack.views.open({
trigger_id: body.trigger_id,
view: Loading.loading()
});
const flowTs = body.message!.ts;

const flowTs = body.message!.ts;
const scrapbook = await prisma.scrapbook.findUniqueOrThrow({
where: {
flowTs,
}
});

const scrapbook = await prisma.scrapbook.findUniqueOrThrow({
where: {
flowTs,
}
});
// // Get the latest post
// const scrapbooks = await prisma.scrapbook.findMany({
// where: {
// userId: scrapbook?.userId,
// },
// select: {
// createdAt: true,
// },
// orderBy: {
// createdAt: "desc",
// },
// });

const sessions = await prisma.session.findMany({
where: {
userId: scrapbook?.userId,
// createdAt: {
// // Before today & after the last post
// // Assuming the latest post is the last post (scrapbook)
// gte: scrapbooks.length > 1 ? scrapbooks[1].createdAt : undefined,
// lte: scrapbook?.createdAt,
// },
metadata: {
path: ["banked"],
equals: false,
},

// // Get the latest post
// const scrapbooks = await prisma.scrapbook.findMany({
// where: {
// userId: scrapbook?.userId,
// },
// select: {
// createdAt: true,
// },
// orderBy: {
// createdAt: "desc",
// },
// });

const sessions = await prisma.session.findMany({
where: {
userId: scrapbook?.userId,
// createdAt: {
// // Before today & after the last post
// // Assuming the latest post is the last post (scrapbook)
// gte: scrapbooks.length > 1 ? scrapbooks[1].createdAt : undefined,
// lte: scrapbook?.createdAt,
// },
metadata: {
path: ["banked"],
equals: false,
OR: [
{
completed: true
},
{
cancelled: true
}
]
},
});

OR: [
{
completed: true
},
{
cancelled: true
}
]
},
});

log(`\`\`\`${JSON.stringify(sessions, null, 2)}\`\`\``)
// log(`\`\`\`${JSON.stringify(sessions, null, 2)}\`\`\``)

// await Slack.views.update({
// view_id: view?.view?.id,
// view: ChooseSessions.chooseSessionsModal(sessions, scrapbook?.internalId),
// }).catch((err) => console.log(err));

await Slack.views.update({
view_id: view?.view?.id,
view: ChooseSessions.chooseSessionsModal(sessions, scrapbook?.internalId),
}).catch((err) => console.log(err));
} catch (error) {
console.log(error);
emitter.emit("error", error);
}
await openModal({
triggerId: body.trigger_id,
view: ChooseSessions.chooseSessionsModal(sessions, scrapbook?.internalId),
});
} catch (error) {
console.log(error);
emitter.emit("error", error);
}
});

Slack.view(Callbacks.CHOOSE_SESSIONS, async ({ ack, body, view }) => {
await ack();

const scrapbook = await prisma.scrapbook.findUniqueOrThrow({
where: {
internalId: view.private_metadata,
Expand Down Expand Up @@ -112,20 +113,20 @@ Slack.view(Callbacks.CHOOSE_SESSIONS, async ({ ack, body, view }) => {
},
},
});
for (const session of selectedSessions) {
if (session.metadata?.airtable?.status === "Approved") {
session.metadata.airtable.status = "Banked";

await AirtableAPI.Session.update(session.metadata?.airtable?.id, {
"Scrapbook": [scrapbook.data.record],
"Status": "Banked",
});
} else {
await AirtableAPI.Session.update(session.metadata?.airtable?.id!, {
"Scrapbook": [scrapbook.data.record],
});
}

for (const session of selectedSessions) {
// if (session.metadata?.airtable?.status === "Approved") {
// session.metadata.airtable.status = "Banked";

// await AirtableAPI.Session.update(session.metadata?.airtable?.id, {
// "Scrapbook": [scrapbook.data.record],
// "Status": "Banked",
// });
// } else {
await AirtableAPI.Session.update(session.metadata?.airtable?.id!, {
"Scrapbook": [scrapbook.data.record],
});
// }

session.metadata.banked = true;

Expand Down Expand Up @@ -280,11 +281,11 @@ Slack.command(Commands.ADMIN, async ({ command }) => {
await Slack.chat.postEphemeral({
user: command.user_id,
channel: command.channel_id,
text: "You are not authorized to use this command",
text: "here's a cookie :cookie:"
});
return;
}

const subCommand = command.text.split(" ")[0];
const subArgs = command.text.split(" ").slice(1);

Expand All @@ -307,7 +308,7 @@ Slack.command(Commands.ADMIN, async ({ command }) => {
channel,
thread_ts: ts,
text: subArgs.slice(1).join(" "),
username: Constants.USERNAME,
username: Constants.USERNAME,
icon_emoji: pfps[pfp as keyof typeof pfps],
});
} else if (subCommand === 'pfp') {
Expand All @@ -321,7 +322,7 @@ Slack.command(Commands.ADMIN, async ({ command }) => {
}

if (Object.keys(pfps).includes(subArgs[0]) || subArgs[0] === "none") {
pfp = subArgs[0];
pfp = subArgs[0];
}

Slack.chat.postEphemeral({
Expand Down
Loading