Add types for Moderator commands (#5084)

* Add types for Moderator commands

* Support User Priv Level & userLevel
This commit is contained in:
Zach H 2024-07-29 01:16:29 +00:00 committed by GitHub
parent 9f515fc804
commit c5bb38e907
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 51 additions and 34 deletions

View file

@ -13,7 +13,7 @@ export function getBanHistory(userName: string): void {
switch (responseCode) {
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
const { banList } = raw['.Response_BanHistory.ext'];
ModeratorPersistence.banHistory(banList);
ModeratorPersistence.banHistory(userName, banList);
return;
default:
error = 'Failed to get ban history.';

View file

@ -13,7 +13,7 @@ export function getWarnHistory(userName: string): void {
switch (responseCode) {
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
const { warnList } = raw['.Response_WarnHistory.ext'];
ModeratorPersistence.warnHistory(warnList);
ModeratorPersistence.warnHistory(userName, warnList);
return;
default:
error = 'Failed to get warn history.';

View file

@ -2,7 +2,7 @@ import webClient from '../../WebClient';
import { ModeratorPersistence } from '../../persistence';
export function warnUser(userName: string, reason: string, clientid?: string, removeMessage?: boolean): void {
const command = webClient.protobuf.controller.Command_BanFromServer.create({ userName, reason, clientid, removeMessage });
const command = webClient.protobuf.controller.Command_WarnUser.create({ userName, reason, clientid, removeMessage });
const sc = webClient.protobuf.controller.ModeratorCommand.create({ '.Command_WarnUser.ext': command });
webClient.protobuf.sendModeratorCommand(sc, (raw) => {

View file

@ -1,30 +1,30 @@
import { ServerDispatch } from 'store';
import { Log } from 'types';
import { BanHistoryItem, LogItem, WarnHistoryItem, WarnListItem } from 'types';
import NormalizeService from '../utils/NormalizeService';
export class ModeratorPersistence {
static banFromServer(userName: any) {
static banFromServer(userName: string): void {
console.log(userName);
}
static banHistory(banHistory: any) {
console.log(banHistory);
static banHistory(userName: string, banHistory: BanHistoryItem[]): void {
console.log(userName, banHistory);
}
static viewLogs(logs: Log[]) {
static viewLogs(logs: LogItem[]): void {
ServerDispatch.viewLogs(NormalizeService.normalizeLogs(logs));
}
static warnHistory(warnList: any) {
static warnHistory(userName: string, warnHistory: WarnHistoryItem[]): void {
console.log(userName, warnHistory);
}
static warnList(warnList: WarnListItem[]): void {
console.log(warnList);
}
static warnList(warning: any) {
console.log(warning);
}
static warnUser(userName: any) {
static warnUser(userName: string): void {
console.log(userName);
}
}

View file

@ -1,4 +1,4 @@
import { Game, GametypeMap, Log, LogGroups, Message, Room } from 'types';
import { Game, GametypeMap, LogItem, LogGroups, Message, Room } from 'types';
export default class NormalizeService {
// Flatten room gameTypes into map object
@ -26,7 +26,7 @@ export default class NormalizeService {
}
// Flatten logs[] into object mapped by targetType (room, game, chat)
static normalizeLogs(logs: Log[]): LogGroups {
static normalizeLogs(logs: LogItem[]): LogGroups {
return logs.reduce((obj, log) => {
const { targetType } = log;
obj[targetType] = obj[targetType] || [];