mirror of
https://github.com/System-End/slack-end.git
synced 2026-04-19 19:45:11 +00:00
enhancement(lint): Fix lint errors for src/modules/thething.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
85f07a3cbf
commit
d00957e524
1 changed files with 78 additions and 77 deletions
|
|
@ -1,77 +1,78 @@
|
|||
import crypto from 'crypto';
|
||||
import { ModifiedApp } from "./slackapp";
|
||||
|
||||
|
||||
export interface RootInterface {
|
||||
'Slack ID': string;
|
||||
'GitHub username': string;
|
||||
'Schedule match': boolean;
|
||||
'Can stream'?: boolean;
|
||||
'Planning on adding...'?: string;
|
||||
'Display name': string;
|
||||
'Avatar URL': string;
|
||||
}
|
||||
|
||||
function sha256OfJson(obj: any): string {
|
||||
const json = JSON.stringify(obj, Object.keys(obj).sort()); // sort keys
|
||||
return crypto.createHash('sha256').update(json).digest('hex');
|
||||
}
|
||||
|
||||
export async function cronThingy(app: ModifiedApp) {
|
||||
const object = await fetch("https://thing.hackclub.com/queue").then(r => r.json()).then(d => d as RootInterface[])
|
||||
for (const obj of object) {
|
||||
const objHash = sha256OfJson(obj)
|
||||
if (app.dbs.thething.get(objHash)) continue;
|
||||
|
||||
app.client.chat.postMessage({
|
||||
"blocks": [
|
||||
{
|
||||
"type": "section",
|
||||
"text": {
|
||||
"type": "mrkdwn",
|
||||
"text": `:wave:\n*<https://github.com/${obj['GitHub username']}|${obj['Display name']}>*`
|
||||
},
|
||||
"accessory": {
|
||||
"type": "image",
|
||||
"image_url": obj['Avatar URL'],
|
||||
"alt_text": obj['Display name']
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "context",
|
||||
"elements": [
|
||||
{
|
||||
"type": "mrkdwn",
|
||||
"text": `:slack: *Slack ID:* \`${obj['Slack ID']}\``
|
||||
},
|
||||
{
|
||||
"type": "mrkdwn",
|
||||
"text": `:calendar: *Schedule match:* ${obj['Schedule match']}`
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "context",
|
||||
"elements": [
|
||||
{
|
||||
"type": "mrkdwn",
|
||||
"text": `:video_camera: *Can stream:* ${obj['Can stream']}`
|
||||
},
|
||||
{
|
||||
"type": "mrkdwn",
|
||||
"text": `:bulb: *Planning to add:* _${obj['Planning on adding...']}..._`
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
channel: `C08MFTG96BH`
|
||||
})
|
||||
app.dbs.thething.set(objHash, true)
|
||||
await new Promise(r=>setTimeout(r,250))
|
||||
}
|
||||
}
|
||||
export async function cronTS(app: ModifiedApp) {
|
||||
await cronThingy(app);
|
||||
await new Promise(r => setTimeout(r, 60 * 1000))
|
||||
await cronTS(app)
|
||||
}
|
||||
import crypto from "crypto";
|
||||
import { ModifiedApp } from "./slackapp";
|
||||
|
||||
export interface RootInterface {
|
||||
"Slack ID": string;
|
||||
"GitHub username": string;
|
||||
"Schedule match": boolean;
|
||||
"Can stream"?: boolean;
|
||||
"Planning on adding..."?: string;
|
||||
"Display name": string;
|
||||
"Avatar URL": string;
|
||||
}
|
||||
|
||||
function sha256OfJson(obj: any): string {
|
||||
const json = JSON.stringify(obj, Object.keys(obj).sort()); // sort keys
|
||||
return crypto.createHash("sha256").update(json).digest("hex");
|
||||
}
|
||||
|
||||
export async function cronThingy(app: ModifiedApp) {
|
||||
const object = await fetch("https://thing.hackclub.com/queue")
|
||||
.then((r) => r.json())
|
||||
.then((d) => d as RootInterface[]);
|
||||
for (const obj of object) {
|
||||
const objHash = sha256OfJson(obj);
|
||||
if (app.dbs.thething.get(objHash)) continue;
|
||||
|
||||
app.client.chat.postMessage({
|
||||
blocks: [
|
||||
{
|
||||
type: "section",
|
||||
text: {
|
||||
type: "mrkdwn",
|
||||
text: `:wave:\n*<https://github.com/${obj["GitHub username"]}|${obj["Display name"]}>*`,
|
||||
},
|
||||
accessory: {
|
||||
type: "image",
|
||||
image_url: obj["Avatar URL"],
|
||||
alt_text: obj["Display name"],
|
||||
},
|
||||
},
|
||||
{
|
||||
type: "context",
|
||||
elements: [
|
||||
{
|
||||
type: "mrkdwn",
|
||||
text: `:slack: *Slack ID:* \`${obj["Slack ID"]}\``,
|
||||
},
|
||||
{
|
||||
type: "mrkdwn",
|
||||
text: `:calendar: *Schedule match:* ${obj["Schedule match"]}`,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: "context",
|
||||
elements: [
|
||||
{
|
||||
type: "mrkdwn",
|
||||
text: `:video_camera: *Can stream:* ${obj["Can stream"]}`,
|
||||
},
|
||||
{
|
||||
type: "mrkdwn",
|
||||
text: `:bulb: *Planning to add:* _${obj["Planning on adding..."]}..._`,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
channel: `C08MFTG96BH`,
|
||||
});
|
||||
app.dbs.thething.set(objHash, true);
|
||||
await new Promise((r) => setTimeout(r, 250));
|
||||
}
|
||||
}
|
||||
export async function cronTS(app: ModifiedApp) {
|
||||
await cronThingy(app);
|
||||
await new Promise((r) => setTimeout(r, 60 * 1000));
|
||||
await cronTS(app);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue