Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
sogehige committed May 29, 2024
1 parent a540757 commit 2569d9f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 72 deletions.
5 changes: 0 additions & 5 deletions d.ts/src/helpers/socket.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,6 @@ export type ClientToServerEventsWithNamespace = {
'alert': (data: any) => void,
'cache': (cacheLimit: number, cb: (err: Error | string | null | unknown, data: any) => void) => void,
},
'/overlays/chat': GenericEvents & {
'test': (data: { message: string; username: string }) => void,
'timeout': (userName: string) => void,
'message': (data: { id: string, show: boolean; message: string; username: string, timestamp: number, badges: any }) => void,
},
'/overlays/texttospeech': GenericEvents & {
'speak': (data: { text: string; highlight: boolean, key: string }) => void,
},
Expand Down
19 changes: 0 additions & 19 deletions src/overlays/chat.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { randomUUID } from 'node:crypto';

import Overlay from './_interface.js';
import { badgesCache } from '../services/twitch/calls/getChannelChatBadges.js';

import { onMessage } from '~/decorators/on.js';
import { timer } from '~/decorators.js';
import { ioServer } from '~/helpers/panel.js';
import { parseTextWithEmotes } from '~/helpers/parseTextWithEmotes.js';
import { adminEndpoint } from '~/helpers/socket.js';

export const getBadgeImagesFromBadgeSet = (badgesMap: Map<string, string>) => {
const badgeImages: {url: string }[] = [];
Expand Down Expand Up @@ -50,22 +47,6 @@ class Chat extends Overlay {
});
});
}

sockets() {
adminEndpoint('/overlays/chat', 'test', (data) => {
this.withEmotes(data.message).then(message => {
ioServer?.of('/overlays/chat').emit('message', {
id: randomUUID(),
timestamp: Date.now(),
displayName: data.username,
userName: data.username,
message,
show: false,
badges: [],
});
});
});
}
}

export default new Chat();
90 changes: 42 additions & 48 deletions src/registries/randomizer.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Randomizer as RandomizerEntity } from '@entity/randomizer.js';
import { Request } from 'express';

import Registry from './_interface.js';
import { parser } from '../decorators.js';

import { AppDataSource } from '~/database.js';
import { Delete, Get, Post } from '~/decorators/endpoint.js';
import { LOW } from '~/helpers/constants.js';
import { app } from '~/helpers/panel.js';
import { check } from '~/helpers/permissions/check.js';
import { withScope } from '~/helpers/socket.js';

class Randomizer extends Registry {
constructor() {
Expand All @@ -17,56 +17,50 @@ class Randomizer extends Registry {
});
}

sockets () {
if (!app) {
setTimeout(() => this.sockets(), 100);
return;
}
@Get('/')
async getAll () {
return RandomizerEntity.find();
}

app.get('/api/registries/randomizer', withScope(['randomizer:read']), async (req, res) => {
res.send({
data: await RandomizerEntity.find(),
});
});
app.get('/api/registries/randomizer/visible', async (req, res) => {
res.send({
data: await RandomizerEntity.findOneBy({ isShown: true }),
});
});
app.get('/api/registries/randomizer/:id', withScope(['randomizer:read']), async (req, res) => {
res.send({
data: await RandomizerEntity.findOneBy({ id: req.params.id }),
});
});
app.post('/api/registries/randomizer/hide', withScope(['randomizer:manage']), async (req, res) => {
await AppDataSource.getRepository(RandomizerEntity).update({}, { isShown: false });
res.status(204).send();
});
app.post('/api/registries/randomizer/:id/show', withScope(['randomizer:manage']), async (req, res) => {
await AppDataSource.getRepository(RandomizerEntity).update({}, { isShown: false });
await AppDataSource.getRepository(RandomizerEntity).update({ id: String(req.params.id) }, { isShown: true });
res.status(204).send();
});
app.post('/api/registries/randomizer/:id/spin', withScope(['randomizer:manage']), async (req, res) => {
const { generateAndAddSecureKey } = await import ('../tts.js');
this.socket?.emit('spin', {
key: generateAndAddSecureKey(),
});
res.status(204).send();
});
app.delete('/api/registries/randomizer/:id', withScope(['randomizer:manage']), async (req, res) => {
await RandomizerEntity.delete({ id: req.params.id });
res.status(404).send();
});
app.post('/api/registries/randomizer', withScope(['randomizer:manage']), async (req, res) => {
try {
res.send({ data: await RandomizerEntity.create(req.body).save() });
} catch (e) {
res.status(400).send({ errors: e });
}
@Get('/visible')
async getVisible () {
return RandomizerEntity.findOneBy({ isShown: true });
}

@Get('/:id')
async getOne (req: Request) {
return RandomizerEntity.findOneBy({ id: req.params.id });
}

@Post('/hide')
async hide () {
await AppDataSource.getRepository(RandomizerEntity).update({}, { isShown: false });
}

@Post('/:id/show')
async show (req: Request) {
await AppDataSource.getRepository(RandomizerEntity).update({}, { isShown: false });
await AppDataSource.getRepository(RandomizerEntity).update({ id: String(req.params.id) }, { isShown: true });
}

@Post('/:id/spin')
async spin (req: Request) {
const { generateAndAddSecureKey } = await import ('../tts.js');
this.socket?.emit('spin', {
key: generateAndAddSecureKey(),
});
}

@Delete('/:id')
async delete (req: Request) {
await RandomizerEntity.delete({ id: req.params.id });
}

@Post('/')
async create (req: Request) {
return RandomizerEntity.create(req.body).save();
}

/**
* Check if command is in randomizer (priority: low, fireAndForget)
*
Expand Down

0 comments on commit 2569d9f

Please sign in to comment.