diff --git a/commands/optout.js b/commands/optout.js index f64dc4c..e234f8b 100644 --- a/commands/optout.js +++ b/commands/optout.js @@ -5,7 +5,7 @@ const prisma = new PrismaClient(); */ module.exports = async function ({ app }) { app.command("/optout-library", async ({ command, body, ack, respond }) => { - await prisma.$connect() + await prisma.$connect(); await ack(); const channelId = body.channel_id; const channel = await app.client.conversations.info({ @@ -57,6 +57,6 @@ module.exports = async function ({ app }) { channel: channel.channel.id, }); - await prisma.$disconnect() + await prisma.$disconnect(); }); }; diff --git a/commands/setemoji.js b/commands/setemoji.js index a50de8e..3de9917 100644 --- a/commands/setemoji.js +++ b/commands/setemoji.js @@ -1,70 +1,72 @@ - -const emojis = require("../utils/emojis") +const emojis = require("../utils/emojis"); /** * @param {{app: import('@slack/bolt').App}} param1 */ module.exports = async function ({ app }) { - const { PrismaClient } = require("@prisma/client"); - const prisma = new PrismaClient(); - app.command("/setemoji", async ({ command, body, ack, respond }) => { - await prisma.$connect() - await ack(); - if (!command.text) - return await respond( - "Please provide an emoji. I.e. /setemoji 🎒 or /setemoji :hackclub:", - ); - const channelId = body.channel_id; - const channel = await app.client.conversations.info({ - channel: body.channel_id, - }); - const user = await app.client.users.info({ - user: command.user_id, - }); - if (command.user_id != channel.channel.creator && !user.user.is_admin) - return await respond( - "Only channel managers and workspace admins can opt .", - ); - const channelRecord = await prisma.channel.findFirst({ - where: { - id: channelId, - }, - }); - if (!command.text && !command.text.match(/:[a-zA-Z0-9_-]+:/) && !emojis.includes(command.text)) - return await respond("Please provide an emoji") - - - if (!channel.channel.is_member) - try { - await app.client.conversations.join({ - channel: channel.channel.id, - }); - } catch (e) { } - if (!channelRecord) - await prisma.channel.create({ - data: { - id: channelId, - emoji: command.text - }, - }); - else if (channelRecord.locked && !user.user.is_admin) - return await respond( - "This channel cannot be locked as it is locked in the database. Usually, this is because it is a public, community-owned channel, i.e. #lounge, #code, etc.", - ); + const { PrismaClient } = require("@prisma/client"); + const prisma = new PrismaClient(); + app.command("/setemoji", async ({ command, body, ack, respond }) => { + await prisma.$connect(); + await ack(); + if (!command.text) + return await respond( + "Please provide an emoji. I.e. /setemoji 🎒 or /setemoji :hackclub:", + ); + const channelId = body.channel_id; + const channel = await app.client.conversations.info({ + channel: body.channel_id, + }); + const user = await app.client.users.info({ + user: command.user_id, + }); + if (command.user_id != channel.channel.creator && !user.user.is_admin) + return await respond( + "Only channel managers and workspace admins can opt .", + ); + const channelRecord = await prisma.channel.findFirst({ + where: { + id: channelId, + }, + }); + if ( + !command.text && + !command.text.match(/:[a-zA-Z0-9_-]+:/) && + !emojis.includes(command.text) + ) + return await respond("Please provide an emoji"); - await prisma.channel.update({ - where: { - id: channelId, - }, - data: { - optout: false, - emoji: command.text - }, + if (!channel.channel.is_member) + try { + await app.client.conversations.join({ + channel: channel.channel.id, }); - await app.client.chat.postEphemeral({ - channel: channel.channel.id, - user: command.user_id, - text: `Set your channel emoji to ${command.text}`, - }); - await prisma.$disconnect() + } catch (e) {} + if (!channelRecord) + await prisma.channel.create({ + data: { + id: channelId, + emoji: command.text, + }, + }); + else if (channelRecord.locked && !user.user.is_admin) + return await respond( + "This channel cannot be locked as it is locked in the database. Usually, this is because it is a public, community-owned channel, i.e. #lounge, #code, etc.", + ); + + await prisma.channel.update({ + where: { + id: channelId, + }, + data: { + optout: false, + emoji: command.text, + }, + }); + await app.client.chat.postEphemeral({ + channel: channel.channel.id, + user: command.user_id, + text: `Set your channel emoji to ${command.text}`, }); + await prisma.$disconnect(); + }); }; diff --git a/commands/setlocation.js b/commands/setlocation.js index 68e320a..fef6358 100644 --- a/commands/setlocation.js +++ b/commands/setlocation.js @@ -1,5 +1,3 @@ - - /** * @param {{app: import('@slack/bolt').App}} param1 */ @@ -7,7 +5,7 @@ module.exports = async function ({ app }) { const { PrismaClient } = require("@prisma/client"); const prisma = new PrismaClient(); app.command("/setlocation", async ({ command, body, ack, respond }) => { - await prisma.$connect() + await prisma.$connect(); await ack(); if (!command.text) return await respond( @@ -32,10 +30,10 @@ module.exports = async function ({ app }) { var locations = await ( await fetch( `https://nominatim.openstreetmap.org/search?` + - new URLSearchParams({ - q: command.text.trim(), - format: "jsonv2", - }), + new URLSearchParams({ + q: command.text.trim(), + format: "jsonv2", + }), ) ).json(); if (!channel.channel.is_member) @@ -43,7 +41,7 @@ module.exports = async function ({ app }) { await app.client.conversations.join({ channel: channel.channel.id, }); - } catch (e) { } + } catch (e) {} if (!locations.length) return await respond( "No locations found. If this keeps failing, please add it to OpenStreetMaps.", @@ -77,6 +75,6 @@ module.exports = async function ({ app }) { user: command.user_id, text: `Set your channel location to \`${display_name}\`. Others near you will be able to discover your channel via their location.`, }); - await prisma.$disconnect() + await prisma.$disconnect(); }); }; diff --git a/commands/setuserlocation.js b/commands/setuserlocation.js index 424b34e..c0406bc 100644 --- a/commands/setuserlocation.js +++ b/commands/setuserlocation.js @@ -1,5 +1,3 @@ - - /** * @param {{app: import('@slack/bolt').App}} param1 */ @@ -7,7 +5,7 @@ module.exports = async function ({ app }) { const { PrismaClient } = require("@prisma/client"); const prisma = new PrismaClient(); app.command("/setuserlocation", async ({ command, body, ack, respond }) => { - await prisma.$connect() + await prisma.$connect(); await ack(); if (!command.text) return await respond( @@ -22,10 +20,10 @@ module.exports = async function ({ app }) { var locations = await ( await fetch( `https://nominatim.openstreetmap.org/search?` + - new URLSearchParams({ - q: command.text.trim(), - format: "jsonv2", - }), + new URLSearchParams({ + q: command.text.trim(), + format: "jsonv2", + }), ) ).json(); if (!locations.length) @@ -56,6 +54,6 @@ module.exports = async function ({ app }) { user: command.user_id, text: `Set your user location to \`${display_name}\`.`, }); - await prisma.$disconnect() + await prisma.$disconnect(); }); }; diff --git a/sections/30-recent.js b/sections/30-recent.js index e6bdd1c..926ea3d 100644 --- a/sections/30-recent.js +++ b/sections/30-recent.js @@ -13,7 +13,7 @@ module.exports = { render: async function ({ app, client }) { const { PrismaClient } = require("@prisma/client"); const prisma = new PrismaClient(); - await prisma.$connect() + await prisma.$connect(); var messages = await app.client.search.messages({ query: utils.queries.topChannels, sort: "timestamp", @@ -42,14 +42,13 @@ module.exports = { sortedChannels.map(async (channel) => { const channelRecord = await prisma.channel.findFirst({ where: { - id: channel - } - }) + id: channel, + }, + }); if (!channelRecord || !channelRecord.emoji) { return `- <#${channel}>\n`; } else { return `- ${channelRecord.emoji} <#${channel}>\n`; - } // (${await timeline({ app, channel })}) }), @@ -63,6 +62,5 @@ ${await generateFullTimeline(channels)} ` + text ); - }, }; diff --git a/utils/allTimeline.js b/utils/allTimeline.js index 42c40c6..1e32c12 100644 --- a/utils/allTimeline.js +++ b/utils/allTimeline.js @@ -17,22 +17,22 @@ module.exports = async function generateFullTimeline(messages) { const startTime = Math.min(...Object.keys(intervalMessages).map(Number)); const endTime = Math.max(...Object.keys(intervalMessages).map(Number)); let output = ""; - await prisma.$connect() + await prisma.$connect(); for (let time = startTime; time <= endTime; time += 10) { if (intervalMessages[time]) { for (const channelId of intervalMessages[time]) { - var emoji = "💥," + var emoji = "💥,"; const channelRecord = await prisma.channel.findFirst({ where: { - id: channelId - } - }) + id: channelId, + }, + }); if (!channelRecord || !channelRecord.emoji) { - output += emoji - continue + output += emoji; + continue; } - output += channelRecord.emoji + "," + output += channelRecord.emoji + ","; } } else { output += "-,"; @@ -43,6 +43,6 @@ module.exports = async function generateFullTimeline(messages) { chars = chars .map((char) => (emojis.includes(char) || char == "-" ? char : "")) .slice(chars.length - 40, chars.length); - await prisma.$disconnect() + await prisma.$disconnect(); return chars.join(",").replaceAll(",", ""); }; diff --git a/utils/joinall.js b/utils/joinall.js index 5b596e8..08e0a7f 100644 --- a/utils/joinall.js +++ b/utils/joinall.js @@ -1,4 +1,3 @@ - /** * @param {{app: import('@slack/bolt').App}} param1 */ @@ -10,7 +9,7 @@ Array.prototype.random = function () { module.exports = async function ({ app, client }) { const { PrismaClient } = require("@prisma/client"); const prisma = new PrismaClient(); - await prisma.$connect() + await prisma.$connect(); async function rake(cursor) { const convos = await app.client.conversations.list({ @@ -36,13 +35,13 @@ module.exports = async function ({ app, client }) { await app.client.conversations.join({ channel: channel.id, }); - if (!channelRecord){ + if (!channelRecord) { await prisma.channel.create({ - data:{ + data: { id: channel.id, - emoji: emojis.random() - } - }) + emoji: emojis.random(), + }, + }); } console.log(`Joined ${channel.name_normalized} (${channel.id})`); setTimeout(resolve, 1200); @@ -60,9 +59,8 @@ module.exports = async function ({ app, client }) { }, 3000); else { console.log("Finished joining all channels"); - await prisma.$disconnect() + await prisma.$disconnect(); } - } rake(); }; diff --git a/utils/updateMessage.js b/utils/updateMessage.js index 2351fe8..5a9e807 100644 --- a/utils/updateMessage.js +++ b/utils/updateMessage.js @@ -21,10 +21,7 @@ module.exports = async function ({ app, text, blocks, priority, client }) { await app.client.chat.update({ channel: process.env.SLACK_CHANNEL, ts: messageId, - text: text.replaceAll( - "@", - "​@", - ), + text: text.replaceAll("@", "​@").replaceAll(/[\u{1F3FB}-\u{1F3FF}]/gmu, ""), blocks, }); await client.set(