mirror of
https://github.com/System-End/slack-end.git
synced 2026-04-19 22:05:10 +00:00
update: actual code
This commit is contained in:
parent
6f0f885443
commit
1fed8532fe
1 changed files with 31 additions and 0 deletions
|
|
@ -1,3 +1,5 @@
|
|||
import { ModifiedApp } from "./slackapp";
|
||||
|
||||
// time to get fudge pt 2
|
||||
export interface UserSystem {
|
||||
username: string;
|
||||
|
|
@ -24,3 +26,32 @@ export async function getUsers() {
|
|||
return {data:parseTextAndExtractUsers(response), meta:getMetaInfo(response)}
|
||||
}
|
||||
|
||||
export function diffStrings(oldArray: UserSystem[], newArray: UserSystem[]) {
|
||||
const strings = []
|
||||
for(const user of newArray) {
|
||||
const oldUser = oldArray.find(e=>e.username === user.username)
|
||||
if(!oldUser) {
|
||||
strings.push(`✓ ${user.username} has started there first day!`)
|
||||
continue;
|
||||
}
|
||||
const daysDiffLength = user.days.length - oldUser.days.length
|
||||
if(daysDiffLength > 0) {
|
||||
strings.push(`:yay: ${user.username} has moved up to ${user.days.length + 1} days!`)
|
||||
}
|
||||
}
|
||||
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')}`
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue