mirror of
https://github.com/System-End/slack-end.git
synced 2026-04-19 16:28:19 +00:00
enhancement(lint): Fix lint errors for src/modules/howWasYourDay.ts
Co-authored-by: NeonGamerBot-QK <neon@saahild.com> Signed-off-by: zeon-neon[bot] <136533918+zeon-neon[bot]@users.noreply.github.com>
This commit is contained in:
parent
c787791514
commit
cb0a64a6ae
1 changed files with 28 additions and 25 deletions
|
|
@ -133,8 +133,8 @@ export async function getMessageCount(db: JSONdb) {
|
|||
const message = `${emoji} <@${process.env.MY_USER_ID}> has sent *${messagesSent} messages* today.${differenceText}`;
|
||||
await db.set("messages_sent_yesterday", messagesSent);
|
||||
const messagesTotal = (await db.get("messages_total")) || [];
|
||||
messagesTotal.push(messagesSent)
|
||||
await db.set("messages_total", messagesTotal)
|
||||
messagesTotal.push(messagesSent);
|
||||
await db.set("messages_total", messagesTotal);
|
||||
return message;
|
||||
}
|
||||
|
||||
|
|
@ -194,31 +194,34 @@ export default async function (app: ModifiedApp, channel = `C07R8DYAZMM`) {
|
|||
thread_ts: mobj.ts,
|
||||
text: await getMessageCount(app.db),
|
||||
});
|
||||
if(app.db.get("messages_total") && app.db.get("messages_total").length >= 7){
|
||||
if (
|
||||
app.db.get("messages_total") &&
|
||||
app.db.get("messages_total").length >= 7
|
||||
) {
|
||||
// send weekly graph to channel
|
||||
sendWeeklyGraph(app, channel)
|
||||
sendWeeklyGraph(app, channel);
|
||||
}
|
||||
}
|
||||
|
||||
export async function sendWeeklyGraph(app: ModifiedApp, channel:string) {
|
||||
const messagesTotal = app.db.get("messages_total").slice(0,7)
|
||||
const graphUrl = `https://api.saahild.com/api/graph/line/simple?labels=Monday,Tuesday,Wensday,Thursday,Friday,Saturday,Sunday&y=${messagesTotal.join(",")}`
|
||||
// attach as file or something
|
||||
await fetch(graphUrl)
|
||||
.then((r) => r.arrayBuffer())
|
||||
.then(Buffer.from)
|
||||
.then((d) => {
|
||||
writeFileSync(path.join(__dirname, "..", "graph.png"), d);
|
||||
});
|
||||
const img = path.join(__dirname, "..", "graph.png");
|
||||
await app.client.files.uploadV2({
|
||||
file: img,
|
||||
filename: `graph.png`,
|
||||
// thread_ts: mobj.ts,
|
||||
channel_id: channel,
|
||||
alt_text: `Your weekly message graph.`,
|
||||
initial_comment: `Your weekly message graph! Average message count per day is *${(messagesTotal.reduce((a, b) => a + b, 0) / messagesTotal.length).toFixed(2)}*`,
|
||||
});
|
||||
export async function sendWeeklyGraph(app: ModifiedApp, channel: string) {
|
||||
const messagesTotal = app.db.get("messages_total").slice(0, 7);
|
||||
const graphUrl = `https://api.saahild.com/api/graph/line/simple?labels=Monday,Tuesday,Wensday,Thursday,Friday,Saturday,Sunday&y=${messagesTotal.join(",")}`;
|
||||
// attach as file or something
|
||||
await fetch(graphUrl)
|
||||
.then((r) => r.arrayBuffer())
|
||||
.then(Buffer.from)
|
||||
.then((d) => {
|
||||
writeFileSync(path.join(__dirname, "..", "graph.png"), d);
|
||||
});
|
||||
const img = path.join(__dirname, "..", "graph.png");
|
||||
await app.client.files.uploadV2({
|
||||
file: img,
|
||||
filename: `graph.png`,
|
||||
// thread_ts: mobj.ts,
|
||||
channel_id: channel,
|
||||
alt_text: `Your weekly message graph.`,
|
||||
initial_comment: `Your weekly message graph! Average message count per day is *${(messagesTotal.reduce((a, b) => a + b, 0) / messagesTotal.length).toFixed(2)}*`,
|
||||
});
|
||||
|
||||
app.db.set("messages_total", [])
|
||||
}
|
||||
app.db.set("messages_total", []);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue