Skip to content

Commit

Permalink
ws for sinkingYachts
Browse files Browse the repository at this point in the history
  • Loading branch information
Larsundso committed Nov 28, 2023
1 parent 7c599db commit 45a3484
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
21 changes: 9 additions & 12 deletions src/BaseClient/ClientHelperModules/cache/urls/sinkingYachts.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import * as Jobs from 'node-schedule';
import fetch from 'node-fetch';
import constants from '../../../Other/constants.js';

/**
* Interface for the SinkingYachts cache module.
*/
export interface SinkingYachts {
/**
* The refresh job for the cache.
*/
refreshJob: Jobs.Job | null;

/**
* Starts the cache module.
*/
Expand All @@ -29,7 +22,6 @@ export interface SinkingYachts {
}

const self: SinkingYachts = {
refreshJob: null,
start: async () => {
const res = await fetch('https://phish.sinking.yachts/v2/all', {
headers: {
Expand All @@ -39,13 +31,18 @@ const self: SinkingYachts = {

if (!res.ok) throw new Error('Failed to fetch Sinking Yachts API');

self.refreshJob = Jobs.scheduleJob(new Date(Date.now() + 3600000), () => {
self.start();
});

self.cache = new Set();
const data = (await res.json()) as string[];
data.forEach((d) => self.cache.add(d));

const ws = new WebSocket('wss://phish.sinking.yachts/feed');
ws.onmessage = (message) => {
const msg = JSON.parse(message.data) as { type: 'add' | 'remove'; domains: string[] };
console.log(msg);

if (msg.type === 'add') msg.domains.forEach((d) => self.cache.add(d));
else msg.domains.forEach((d) => self.cache.delete(d));
};
},
toArray: () => [...self.cache],
cache: new Set(),
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const manager = new Discord.ShardingManager(
{
token: auth.token,
shardArgs: process.argv,
execArgv: ['--experimental-wasm-modules'],
execArgv: ['--experimental-wasm-modules', '--experimental-websocket'],
},
);

Expand Down

0 comments on commit 45a3484

Please sign in to comment.