mirror of
https://github.com/System-End/slack-end.git
synced 2026-04-19 22:05:10 +00:00
enhancement(lint): Fix lint errors for src/modules/15daysofcode.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
08a577b09f
commit
de9ab96f40
1 changed files with 71 additions and 51 deletions
|
|
@ -3,68 +3,88 @@ import { ModifiedApp } from "./slackapp";
|
|||
|
||||
// time to get fudge pt 2
|
||||
interface Post {
|
||||
timestamp: number;
|
||||
content: string;
|
||||
}
|
||||
interface Leaderboard {
|
||||
user: string;
|
||||
posts: Post[];
|
||||
}
|
||||
timestamp: number;
|
||||
content: string;
|
||||
}
|
||||
interface Leaderboard {
|
||||
user: string;
|
||||
posts: Post[];
|
||||
}
|
||||
export interface RootObjectFor15Response {
|
||||
leaderboard: Leaderboard[];
|
||||
}
|
||||
export function parseTextAndExtractUsers(text:string) {
|
||||
return text.split('|--------------------')[2].split('\n').filter(Boolean).map(e=>e.split("|").filter(Boolean).map(d=>d.trim().replace('✓ ', ''))).filter(e=>e.length > 1).map(d=> {
|
||||
return {
|
||||
username: d[0],
|
||||
days: d.slice(1).filter(Boolean)
|
||||
}
|
||||
}).filter(e=>!e.username.startsWith('---'))
|
||||
leaderboard: Leaderboard[];
|
||||
}
|
||||
export function getMetaInfo(text:string) {
|
||||
const [Rstatus, Rwrote] = text.split('-------------------\nEND OF TRANSMISSION')[1].split('---')[0].split('\n').filter(Boolean)
|
||||
return {
|
||||
status: Rstatus.split(' ')[1],
|
||||
wrote: Rwrote.split(':')[1].trim()
|
||||
export function parseTextAndExtractUsers(text: string) {
|
||||
return text
|
||||
.split("|--------------------")[2]
|
||||
.split("\n")
|
||||
.filter(Boolean)
|
||||
.map((e) =>
|
||||
e
|
||||
.split("|")
|
||||
.filter(Boolean)
|
||||
.map((d) => d.trim().replace("✓ ", "")),
|
||||
)
|
||||
.filter((e) => e.length > 1)
|
||||
.map((d) => {
|
||||
return {
|
||||
username: d[0],
|
||||
days: d.slice(1).filter(Boolean),
|
||||
};
|
||||
})
|
||||
.filter((e) => !e.username.startsWith("---"));
|
||||
}
|
||||
export function getMetaInfo(text: string) {
|
||||
const [Rstatus, Rwrote] = text
|
||||
.split("-------------------\nEND OF TRANSMISSION")[1]
|
||||
.split("---")[0]
|
||||
.split("\n")
|
||||
.filter(Boolean);
|
||||
return {
|
||||
status: Rstatus.split(" ")[1],
|
||||
wrote: Rwrote.split(":")[1].trim(),
|
||||
};
|
||||
}
|
||||
export async function getUsers() {
|
||||
// this will take a hot sec
|
||||
const response = await fetch("https://daysinpublic.blaisee.me/").then(r=>r.json()).then(d=> (d as RootObjectFor15Response).leaderboard)
|
||||
return response
|
||||
// this will take a hot sec
|
||||
const response = await fetch("https://daysinpublic.blaisee.me/")
|
||||
.then((r) => r.json())
|
||||
.then((d) => (d as RootObjectFor15Response).leaderboard);
|
||||
return response;
|
||||
}
|
||||
|
||||
export function diffStrings(oldArray: Leaderboard[], newArray: Leaderboard[]) {
|
||||
const strings = []
|
||||
for(const user of newArray) {
|
||||
const oldUser = oldArray.find(e=>e.user === user.user)
|
||||
if(!oldUser) {
|
||||
strings.push(`✓ ${user.user} has started there first day!`)
|
||||
continue;
|
||||
const strings = [];
|
||||
for (const user of newArray) {
|
||||
const oldUser = oldArray.find((e) => e.user === user.user);
|
||||
if (!oldUser) {
|
||||
strings.push(`✓ ${user.user} has started there first day!`);
|
||||
continue;
|
||||
}
|
||||
const daysDiffLength = user.posts.length - oldUser.posts.length
|
||||
if(daysDiffLength > 0) {
|
||||
strings.push(`:yay: ${user.user} has is now at ${user.posts.length} days!`)
|
||||
const daysDiffLength = user.posts.length - oldUser.posts.length;
|
||||
if (daysDiffLength > 0) {
|
||||
strings.push(
|
||||
`:yay: ${user.user} has is now at ${user.posts.length} days!`,
|
||||
);
|
||||
}
|
||||
}
|
||||
return strings
|
||||
}
|
||||
return strings;
|
||||
}
|
||||
export async function cronMoment(app: ModifiedApp) {
|
||||
const oldData = app.db.get('15daysofcode') || []
|
||||
const data = await getUsers()
|
||||
const strings = diffStrings(oldData, data)
|
||||
app.db.set('15daysofcode', data)
|
||||
if(strings.length > 0) {
|
||||
// diff moment
|
||||
app.client.chat.postMessage({
|
||||
channel: `C045S4393CY`,
|
||||
thread_ts: `1740283783.721689`,
|
||||
text: `Diff for \`${new Date().toISOString()}\` (EST)\n\n${strings.join('\n')}`
|
||||
})
|
||||
}
|
||||
const oldData = app.db.get("15daysofcode") || [];
|
||||
const data = await getUsers();
|
||||
const strings = diffStrings(oldData, data);
|
||||
app.db.set("15daysofcode", data);
|
||||
if (strings.length > 0) {
|
||||
// diff moment
|
||||
app.client.chat.postMessage({
|
||||
channel: `C045S4393CY`,
|
||||
thread_ts: `1740283783.721689`,
|
||||
text: `Diff for \`${new Date().toISOString()}\` (EST)\n\n${strings.join("\n")}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
export function cronJobFor15daysofcode(app: ModifiedApp) {
|
||||
new Cron("*/15 * * * *", async () => {
|
||||
await cronMoment(app)
|
||||
})
|
||||
}
|
||||
new Cron("*/15 * * * *", async () => {
|
||||
await cronMoment(app);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue