mirror of
https://github.com/System-End/slack-end.git
synced 2026-04-19 22:05:10 +00:00
feat: ws directory
This commit is contained in:
parent
773c4d8c81
commit
700f2918e7
5 changed files with 43 additions and 2 deletions
|
|
@ -13,7 +13,8 @@
|
|||
"dotenv": "^16.4.5",
|
||||
"node-cron": "^3.0.3",
|
||||
"simple-json-db": "^2.0.0",
|
||||
"smee-client": "^2.0.3"
|
||||
"smee-client": "^2.0.3",
|
||||
"ws": "^8.18.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.7.4",
|
||||
|
|
|
|||
|
|
@ -86,6 +86,7 @@ async function sendRandomStuff() {
|
|||
text: await getResponse(db),
|
||||
});
|
||||
}
|
||||
utils.startWatchingDirectory(app);
|
||||
//TODO: add more random times
|
||||
cron.schedule("5 */12 * * *", sendRandomStuff);
|
||||
cron.schedule("25 */22 * * *", sendRandomStuff);
|
||||
|
|
|
|||
|
|
@ -2,4 +2,5 @@ export * from "./BaseCommand";
|
|||
export * from "./CommandLoader";
|
||||
export * from "./status";
|
||||
export * from "./randomResponseSystem";
|
||||
export * from "./howWasYourDay"
|
||||
export * from "./howWasYourDay"
|
||||
export * from "./wsDirectory"
|
||||
33
src/modules/wsDirectory.ts
Normal file
33
src/modules/wsDirectory.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import WebSocket from 'ws';
|
||||
import { ModifiedApp } from './slackapp';
|
||||
export const tempCache = []
|
||||
export function startWatchingDirectory(app: ModifiedApp) {
|
||||
const wss = new WebSocket(`wss://l.hack.club`)
|
||||
wss.on('open', () => {
|
||||
console.log('connected to wss://l.hack.club')
|
||||
})
|
||||
wss.on('message', async (data) => {
|
||||
const d = JSON.parse(data.toString())
|
||||
console.debug(d.channel,`C07ST3FF4S0`, d.ts)
|
||||
const uniqueId = Buffer.from(d.ts+d.channel).toString('base64')
|
||||
if(tempCache.includes(uniqueId)) {
|
||||
console.log(`Already processed ${uniqueId}`)
|
||||
return
|
||||
}
|
||||
if(d.channel == "C07ST3FF4S0") return;
|
||||
tempCache.push(uniqueId)
|
||||
console.log(d);
|
||||
//console.log(d)
|
||||
const messageLink = await app.client.chat.getPermalink({
|
||||
channel: d.channel,
|
||||
message_ts: d.ts,
|
||||
}).then(d=>d.permalink)
|
||||
await app.client.chat.postMessage({
|
||||
text: messageLink,
|
||||
channel: `C07ST3FF4S0`
|
||||
})
|
||||
})
|
||||
wss.on('close', () => {
|
||||
console.log(`Closing connection`)
|
||||
})
|
||||
}
|
||||
|
|
@ -1613,6 +1613,11 @@ ws@^7.5.3:
|
|||
resolved "https://registry.npmjs.org/ws/-/ws-7.5.10.tgz"
|
||||
integrity sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ==
|
||||
|
||||
ws@^8.18.0:
|
||||
version "8.18.0"
|
||||
resolved "https://registry.yarnpkg.com/ws/-/ws-8.18.0.tgz#0d7505a6eafe2b0e712d232b42279f53bc289bbc"
|
||||
integrity sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==
|
||||
|
||||
yn@3.1.1:
|
||||
version "3.1.1"
|
||||
resolved "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue