Skip to content

Commit

Permalink
finish adding customs emojis
Browse files Browse the repository at this point in the history
  • Loading branch information
dispherical committed Jun 28, 2024
1 parent 4a98e24 commit 0daa697
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
2 changes: 1 addition & 1 deletion interactions/channel_created.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { PrismaClient } = require("@prisma/client");
const prisma = new PrismaClient();
const emojis = require("./utils/emojis");
const emojis = require("../utils/emojis");

Array.prototype.random = function () {
return this[Math.floor(Math.random() * this.length)];
Expand Down
18 changes: 15 additions & 3 deletions sections/30-recent.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ const pms = require("pretty-ms");
const utils = require("../utils");
const util = require("util");
const generateFullTimeline = require("../utils/allTimeline");
//const timeline = require("../utils/timeline.disabled")
const { PrismaClient } = require("@prisma/client");
const prisma = new PrismaClient();
//const timeline = require("../utils/timeline.disabled.js")
module.exports = {
title: "🆕 Most Recent Activity",
description: "This gets the most recently updates channels",
Expand Down Expand Up @@ -36,14 +38,24 @@ module.exports = {
.slice(0, 10);
let text = await Promise.all(
sortedChannels.map(async (channel) => {
const channelRecord = await prisma.channel.findFirst({
where: {
id: channel
}
})
if (!channelRecord || !channelRecord.emoji) {
return `- <#${channel}>\n`;
} else {
return `- ${channelRecord.emoji} <#${channel}>\n`;

}
// (${await timeline({ app, channel })})
return `- <#${channel}>\n`;
}),
).then((texts) => texts.join(""));
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
${generateFullTimeline(channels)}
${await generateFullTimeline(channels)}
` + text
);
Expand Down
21 changes: 16 additions & 5 deletions utils/allTimeline.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { channelEmojis } = require("../utils");
const emojis = require("./emojis");
module.exports = function generateFullTimeline(messages) {
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);
Expand All @@ -19,9 +20,19 @@ module.exports = function generateFullTimeline(messages) {

for (let time = startTime; time <= endTime; time += 10) {
if (intervalMessages[time]) {
intervalMessages[time].forEach((channelId) => {
output += channelEmojis[channelId] || "💥";
});
for (const channelId of intervalMessages[time]) {
var emoji = "💥"
const channelRecord = await prisma.channel.findFirst({
where: {
id: channelId
}
})
if (!channelRecord || !channelRecord.emoji) {
output += emoji
continue
}
output += channelRecord.emoji
}
} else {
output += "-";
}
Expand Down

0 comments on commit 0daa697

Please sign in to comment.