Skip to content

Commit 6bd704c

Browse files
committed
feat: Setup Sentinel's Live exports
1 parent 5e5cfd1 commit 6bd704c

3 files changed

Lines changed: 38 additions & 18 deletions

File tree

src/ps/handlers/cron.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ export class PSCronJobManager {
2424
}
2525
}
2626

27-
export function startPSCron(client: Client): PSCronJobManager {
27+
export function startPSCron(this: Client): PSCronJobManager {
2828
const Jobs = new PSCronJobManager();
2929

3030
// TODO Move back to Hindi and remove 'CRON:'
3131
Jobs.register('hindi-automodchat-enable', '0 0 * * *', TimeZone.IST, () => {
32-
client.rooms.get('botdevelopment')?.send('CRON: /automodchat 10, +');
32+
this.rooms.get('botdevelopment')?.send('CRON: /automodchat 10, +');
3333
});
3434
Jobs.register('hindi-automodchat-disable', '0 7 * * *', TimeZone.IST, () => {
35-
const room = client.rooms.get('botdevelopment');
35+
const room = this.rooms.get('botdevelopment');
3636
room?.send('CRON: /modchat ac');
3737
room?.send('CRON: /automodchat off');
3838
});

src/ps/index.ts

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,27 @@ import { Client } from 'ps-client';
22

33
import { password, rooms, username } from '@/config/ps';
44
import { IS_ENABLED } from '@/enabled';
5-
import { autoResHandler } from '@/ps/handlers/autores';
6-
import { commandHandler } from '@/ps/handlers/commands';
75
import { startPSCron } from '@/ps/handlers/cron';
86
import { transformHTML } from '@/ps/handlers/html';
9-
import { interfaceHandler } from '@/ps/handlers/interface';
10-
import { joinHandler, leaveHandler, nickHandler } from '@/ps/handlers/joins';
11-
import { pageHandler } from '@/ps/handlers/page';
12-
import { rawHandler } from '@/ps/handlers/raw';
137
import loadPS from '@/ps/loaders';
8+
import { LivePS } from '@/sentinel/live';
149
import { log } from '@/utils/logger';
1510

1611
const PS = new Client({ username, password, rooms, transformHTML });
1712
PS.on('login', () => log(`Connected to PS! [${username}]`));
1813

1914
if (IS_ENABLED.PS) loadPS().then(() => PS.connect());
2015

21-
PS.on('message', commandHandler);
22-
PS.on('message', interfaceHandler);
23-
PS.on('message', autoResHandler);
24-
PS.on('message', pageHandler);
16+
PS.on('message', LivePS.commandHandler.bind(PS));
17+
PS.on('message', LivePS.interfaceHandler.bind(PS));
18+
PS.on('message', LivePS.autoResHandler.bind(PS));
19+
PS.on('message', LivePS.pageHandler.bind(PS));
2520

26-
PS.on('join', joinHandler);
27-
PS.on('name', nickHandler);
28-
PS.on('leave', leaveHandler);
29-
PS.on('raw', rawHandler);
21+
PS.on('join', LivePS.joinHandler.bind(PS));
22+
PS.on('name', LivePS.nickHandler.bind(PS));
23+
PS.on('leave', LivePS.leaveHandler.bind(PS));
24+
PS.on('raw', LivePS.rawHandler.bind(PS));
3025

31-
if (IS_ENABLED.PS) startPSCron(PS);
26+
if (IS_ENABLED.PS) startPSCron.bind(PS);
3227

3328
export default PS;

src/sentinel/live.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Exports the 'live' versions of functions from Sentinel.
2+
// Hotpatching will mutate the exposed object here wherever applicable.
3+
4+
// Note that some hotpatchable entries (eg: cron) will have entirely different logic.
5+
// Those cases will not need to be kept here.
6+
7+
// The first versions can be imported directly; we'll update them via dynamic import calls.
8+
9+
import { autoResHandler } from '@/ps/handlers/autores';
10+
import { commandHandler } from '@/ps/handlers/commands';
11+
import { interfaceHandler } from '@/ps/handlers/interface';
12+
import { joinHandler, leaveHandler, nickHandler } from '@/ps/handlers/joins';
13+
import { pageHandler } from '@/ps/handlers/page';
14+
import { rawHandler } from '@/ps/handlers/raw';
15+
16+
export const LivePS = {
17+
autoResHandler,
18+
commandHandler,
19+
interfaceHandler,
20+
joinHandler,
21+
leaveHandler,
22+
nickHandler,
23+
pageHandler,
24+
rawHandler,
25+
};

0 commit comments

Comments
 (0)