Skip to content

Commit

Permalink
remove buttons + update algo
Browse files Browse the repository at this point in the history
  • Loading branch information
dispherical committed Jul 3, 2024
1 parent 61d951d commit b435ca2
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 51 deletions.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Array.prototype.random = function () {

await require("./utils/pull")({ app, client });

cron.schedule("0,10,20,30,40,50 * * * * *", async () => {
cron.schedule("0,7,14,21,28,35,42,49,56 * * * * *", async () => {
await require("./utils/pull")({ app, client });
});

Expand Down
5 changes: 2 additions & 3 deletions sections/30-recent.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const pms = require("pretty-ms");
const utils = require("../utils");
const util = require("util");
const generateFullTimeline = require("../utils/allTimeline");
const generateMessageString = require("../utils/allTimeline");

//const timeline = require("../utils/timeline.disabled.js")
module.exports = {
Expand Down Expand Up @@ -54,11 +54,10 @@ module.exports = {
}),
).then((texts) => texts.join(""));
await prisma.$disconnect();

return (
`This is a list of conversations that are actively ongoing and that you can jump in at any time and meet new people :yay:\n\n:siren-real: Latest message: (in <#${messages.messages.matches[0].channel.id}>) ${pms(Date.now() - Math.floor(messages.messages.matches[0].ts * 1000))} ago
${await generateFullTimeline(channels)}
${await generateMessageString(channels, Math.floor(Date.now() / 1000))}
` + text.replaceAll("@", "​@").replaceAll(/[\u{1F3FB}-\u{1F3FF}]/gmu, "")
);
Expand Down
86 changes: 43 additions & 43 deletions utils/allTimeline.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
const emojis = require("./emojis");
const { PrismaClient } = require("@prisma/client");
const prisma = new PrismaClient();
module.exports = async function generateFullTimeline(messages) {
const intervalMessages = {};
messages.forEach((message) => {
const timestamp = parseFloat(message.ts);
const interval = Math.floor(timestamp / 10) * 10;

if (!intervalMessages[interval]) {
intervalMessages[interval] = new Set();




async function getChannelEmoji(channelId) {
const channel = await prisma.channel.findFirst({
where: {
id: channelId
}
})
if (!channel || !channel.emoji) return "💥"
return channel.emoji
}


async function generateMessageString(messages, currentTime) {
const interval = 10;
const secondsInDay = 86400;
const intervalsInDay = secondsInDay / interval;

let messageString = '';
const timeToEmojiMap = {};

for (const message of messages) {
const messageTime = parseInt(message.ts.split('.')[0], 10);
const timeDiff = currentTime - messageTime;
const intervalIndex = Math.floor(timeDiff / interval);

if (intervalIndex < intervalsInDay) {
const emoji = await getChannelEmoji(message.channel.id);
timeToEmojiMap[intervalIndex] = { emoji, permalink: message.permalink };
}
}

intervalMessages[interval].add(message.channel.id);
});

const startTime = Math.min(...Object.keys(intervalMessages).map(Number));
const endTime = Math.max(...Object.keys(intervalMessages).map(Number));
let output = "";
await prisma.$connect();

for (let time = startTime; time <= endTime; time += 10) {
if (intervalMessages[time]) {
for (const channelId of intervalMessages[time]) {
var emoji = "💥,";
const channelRecord = await prisma.channel.findFirst({
where: {
id: channelId,
},
});
if (!channelRecord || !channelRecord.emoji) {
output += `<https://hackclub.slack.com/archives/${channelId}|${emoji}>`;
continue;
}
output += `<https://hackclub.slack.com/archives/${channelId}|${channelRecord.emoji}>,`;
}
for (let i = 0; i < intervalsInDay; i++) {
if (timeToEmojiMap[i]) {
const { emoji, permalink } = timeToEmojiMap[i];
messageString += `<${permalink}|${emoji}>,`;
} else {
output += "-,";
messageString += '-,';
}
}

let chars = output.split(",");
chars = chars
.map((char) => (emojis.includes(char) || char == "-" ? char : ""))
.slice(chars.length - 40, chars.length);
await prisma.$disconnect();
return chars
.join(",")
.replaceAll(",", "")
.replaceAll("@", "​@")
.replaceAll(/[\u{1F3FB}-\u{1F3FF}]/gmu, "");
};
return messageString.split(",").slice(0, 10).join(",").replaceAll(",", "");
}


module.exports = generateMessageString

8 changes: 4 additions & 4 deletions utils/pull.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ module.exports = async function ({ app, client }) {
});

await Promise.all(bPromises);

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

*/
try {
await updateMessage({
app,
Expand All @@ -69,10 +69,10 @@ module.exports = async function ({ app, client }) {
.replaceAll(/[\u{1F3FB}-\u{1F3FF}]/gmu, ""),
},
},
{
/*{
type: "actions",
elements: subBlocks,
},
},*/
],
priority: "high",
});
Expand Down
10 changes: 10 additions & 0 deletions utils/redo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/**
* @param {{app: import('@slack/bolt').App}} param1
*/
const figlet = require("figlet");
module.exports = async function ({ app, client }) {
const data = await app.client.conversations.history({
channel: process.env.SLACK_CHANNEL,
Expand All @@ -23,6 +24,15 @@ module.exports = async function ({ app, client }) {
}),
),
);
await app.client.chat.postMessage({
channel: process.env.SLACK_CHANNEL,
text: "```\n"+figlet.textSync("Library", {
horizontalLayout: "default",
verticalLayout: "default",
width: 60,
whitespaceBreak: true,
})+"\n```",
});
const tmesg = await app.client.chat.postMessage({
channel: process.env.SLACK_CHANNEL,
text: ":spin-loading: Loading library",
Expand Down

0 comments on commit b435ca2

Please sign in to comment.