Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
sogehige committed May 22, 2024
1 parent ba89fa0 commit 67655ab
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 48 deletions.
6 changes: 0 additions & 6 deletions d.ts/src/helpers/socket.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,6 @@ export type ClientToServerEventsWithNamespace = {
'configuration': (cb: (error: Error | string | null | unknown, data?: Configuration) => void) => void,
},
'/core/users': GenericEvents & {
'viewers::resetPointsAll': (cb?: (error: Error | string | null | unknown) => void) => void,
'viewers::resetMessagesAll': (cb?: (error: Error | string | null | unknown) => void) => void,
'viewers::resetWatchedTimeAll': (cb?: (error: Error | string | null | unknown) => void) => void,
'viewers::resetSubgiftsAll': (cb?: (error: Error | string | null | unknown) => void) => void,
'viewers::resetBitsAll': (cb?: (error: Error | string | null | unknown) => void) => void,
'viewers::resetTipsAll': (cb?: (error: Error | string | null | unknown) => void) => void,
'viewers::update': (data: [userId: string, update: Partial<UserInterface> & { tips?: UserTipInterface[], bits?: UserBitInterface[] }], cb: (error: Error | string | null | unknown) => void) => void,
'viewers::remove': (userId: string, cb: (error: Error | string | null | unknown) => void) => void,
'getNameById': (id: string, cb: (error: Error | string | null | unknown, user: string | null) => void) => void,
Expand Down
72 changes: 30 additions & 42 deletions src/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
Brackets, IsNull,
} from 'typeorm';

import { Get } from './decorators/endpoint.js';
import { Get, Post } from './decorators/endpoint.js';
import { HOUR } from './helpers/constants.js';
import { defaultPermissions } from './helpers/permissions/defaultPermissions.js';
import { getUserHighestPermission } from './helpers/permissions/getUserHighestPermission.js';
Expand Down Expand Up @@ -251,48 +251,36 @@ class Users extends Core {
return changelog.get(userId) as Promise<Readonly<Required<UserInterface>>>;
}

sockets () {
adminEndpoint('/core/users', 'viewers::resetPointsAll', async (cb) => {
await changelog.flush();
await AppDataSource.getRepository(User).update({}, { points: 0 });
if (cb) {
cb(null);
}
});
adminEndpoint('/core/users', 'viewers::resetMessagesAll', async (cb) => {
await changelog.flush();
await AppDataSource.getRepository(User).update({}, { messages: 0, pointsByMessageGivenAt: 0 });
if (cb) {
cb(null);
}
});
adminEndpoint('/core/users', 'viewers::resetWatchedTimeAll', async (cb) => {
await changelog.flush();
await AppDataSource.getRepository(User).update({}, { watchedTime: 0 });
if (cb) {
cb(null);
}
});
adminEndpoint('/core/users', 'viewers::resetSubgiftsAll', async (cb) => {
await changelog.flush();
await AppDataSource.getRepository(User).update({}, { giftedSubscribes: 0 });
if (cb) {
cb(null);
}
});
adminEndpoint('/core/users', 'viewers::resetBitsAll', async (cb) => {
await AppDataSource.getRepository(UserBit).clear();
if (cb) {
cb(null);
}
});
adminEndpoint('/core/users', 'viewers::resetTipsAll', async (cb) => {
await AppDataSource.getRepository(UserTip).clear();
if (cb) {
cb(null);
}
});
@Post('/', { action: 'resetPointsAll' })
async resetPointsAll () {
await changelog.flush();
await AppDataSource.getRepository(User).update({}, { points: 0 });
}
@Post('/', { action: 'resetMessagesAll' })
async resetMessagesAll () {
await changelog.flush();
await AppDataSource.getRepository(User).update({}, { messages: 0, pointsByMessageGivenAt: 0 });
}
@Post('/', { action: 'resetWatchedTimeAll' })
async resetWatchedTimeAll () {
await changelog.flush();
await AppDataSource.getRepository(User).update({}, { watchedTime: 0 });
}
@Post('/', { action: 'resetSubgiftsAll' })
async resetSubgiftsAll () {
await changelog.flush();
await AppDataSource.getRepository(User).update({}, { giftedSubscribes: 0 });
}
@Post('/', { action: 'resetBitsAll' })
async resetBitsAll () {
await AppDataSource.getRepository(UserBit).clear();
}
@Post('/', { action: 'resetTipsAll' })
async resetTipsAll () {
await AppDataSource.getRepository(UserTip).clear();
}

sockets () {
adminEndpoint('/core/users', 'viewers::update', async ([userId, update], cb) => {
try {
if (typeof update.tips !== 'undefined') {
Expand Down

0 comments on commit 67655ab

Please sign in to comment.