mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-10 08:14:47 -07:00
Webatrice: Add all ModeratorCommands (#5049)
* Move viewLogHistory to Moderator commands * Add Moderator.banFromServer * Add Moderator.getBanHistory * Add Moderator.getWarnHistory * Add Moderator.warnUser * Add Moderator.getWarnList
This commit is contained in:
parent
ce8092318e
commit
e45c4042fe
14 changed files with 217 additions and 943 deletions
32
webclient/src/websocket/commands/moderator/banFromServer.ts
Normal file
32
webclient/src/websocket/commands/moderator/banFromServer.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import webClient from '../../WebClient';
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
|
||||
export function banFromServer(minutes: number, userName?: string, address?: string, reason?: string,
|
||||
visibleReason?: string, clientid?: string, removeMessages?: number): void {
|
||||
const command = webClient.protobuf.controller.Command_BanFromServer.create({
|
||||
minutes, userName, address, reason, visibleReason, clientid, removeMessages
|
||||
});
|
||||
|
||||
const sc = webClient.protobuf.controller.ModeratorCommand.create({
|
||||
'.Command_BanFromServer.ext': command
|
||||
});
|
||||
|
||||
webClient.protobuf.sendModeratorCommand(sc, (raw) => {
|
||||
const { responseCode } = raw;
|
||||
|
||||
let error: string;
|
||||
|
||||
switch (responseCode) {
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
|
||||
ModeratorPersistence.banFromServer(userName);
|
||||
return;
|
||||
default:
|
||||
error = 'Failed to ban user.';
|
||||
break;
|
||||
}
|
||||
|
||||
if (error) {
|
||||
console.error(responseCode, error);
|
||||
}
|
||||
});
|
||||
}
|
||||
30
webclient/src/websocket/commands/moderator/getBanHistory.ts
Normal file
30
webclient/src/websocket/commands/moderator/getBanHistory.ts
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import webClient from '../../WebClient';
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
|
||||
export function getBanHistory(userName: string): void {
|
||||
const command = webClient.protobuf.controller.Command_GetBanHistory.create({ userName });
|
||||
|
||||
const sc = webClient.protobuf.controller.ModeratorCommand.create({
|
||||
'.Command_GetBanHistory.ext': command
|
||||
});
|
||||
|
||||
webClient.protobuf.sendModeratorCommand(sc, (raw) => {
|
||||
const { responseCode } = raw;
|
||||
|
||||
let error: string;
|
||||
|
||||
switch (responseCode) {
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
|
||||
const { banList } = raw['.Response_BanHistory.ext'];
|
||||
ModeratorPersistence.banHistory(banList);
|
||||
return;
|
||||
default:
|
||||
error = 'Failed to get ban history.';
|
||||
break;
|
||||
}
|
||||
|
||||
if (error) {
|
||||
console.error(responseCode, error);
|
||||
}
|
||||
});
|
||||
}
|
||||
30
webclient/src/websocket/commands/moderator/getWarnHistory.ts
Normal file
30
webclient/src/websocket/commands/moderator/getWarnHistory.ts
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import webClient from '../../WebClient';
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
|
||||
export function getWarnHistory(userName: string): void {
|
||||
const command = webClient.protobuf.controller.Command_GetWarnHistory.create({ userName });
|
||||
|
||||
const sc = webClient.protobuf.controller.ModeratorCommand.create({
|
||||
'.Command_GetWarnHistory.ext': command
|
||||
});
|
||||
|
||||
webClient.protobuf.sendModeratorCommand(sc, (raw) => {
|
||||
const { responseCode } = raw;
|
||||
|
||||
let error: string;
|
||||
|
||||
switch (responseCode) {
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
|
||||
const { warnList } = raw['.Response_WarnHistory.ext'];
|
||||
ModeratorPersistence.warnHistory(warnList);
|
||||
return;
|
||||
default:
|
||||
error = 'Failed to get warn history.';
|
||||
break;
|
||||
}
|
||||
|
||||
if (error) {
|
||||
console.error(responseCode, error);
|
||||
}
|
||||
});
|
||||
}
|
||||
30
webclient/src/websocket/commands/moderator/getWarnList.ts
Normal file
30
webclient/src/websocket/commands/moderator/getWarnList.ts
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import webClient from '../../WebClient';
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
|
||||
export function getWarnList(modName: string, userName: string, userClientid: string): void {
|
||||
const command = webClient.protobuf.controller.Command_GetWarnList.create({ modName, userName, userClientid });
|
||||
|
||||
const sc = webClient.protobuf.controller.ModeratorCommand.create({
|
||||
'.Command_GetWarnList.ext': command
|
||||
});
|
||||
|
||||
webClient.protobuf.sendModeratorCommand(sc, (raw) => {
|
||||
const { responseCode } = raw;
|
||||
|
||||
let error: string;
|
||||
|
||||
switch (responseCode) {
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
|
||||
const { warning } = raw['.Response_WarnList.ext'];
|
||||
ModeratorPersistence.warnList(warning);
|
||||
return;
|
||||
default:
|
||||
error = 'Failed to get warn list.';
|
||||
break;
|
||||
}
|
||||
|
||||
if (error) {
|
||||
console.error(responseCode, error);
|
||||
}
|
||||
});
|
||||
}
|
||||
6
webclient/src/websocket/commands/moderator/index.ts
Normal file
6
webclient/src/websocket/commands/moderator/index.ts
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
export * from './banFromServer';
|
||||
export * from './getBanHistory';
|
||||
export * from './getWarnHistory';
|
||||
export * from './getWarnList';
|
||||
export * from './viewLogHistory';
|
||||
export * from './warnUser';
|
||||
30
webclient/src/websocket/commands/moderator/viewLogHistory.ts
Normal file
30
webclient/src/websocket/commands/moderator/viewLogHistory.ts
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import webClient from '../../WebClient';
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
|
||||
export function viewLogHistory(filters): void {
|
||||
const command = webClient.protobuf.controller.Command_ViewLogHistory.create(filters);
|
||||
|
||||
const sc = webClient.protobuf.controller.ModeratorCommand.create({
|
||||
'.Command_ViewLogHistory.ext': command
|
||||
});
|
||||
|
||||
webClient.protobuf.sendModeratorCommand(sc, (raw) => {
|
||||
const { responseCode } = raw;
|
||||
|
||||
let error: string;
|
||||
|
||||
switch (responseCode) {
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
|
||||
const { logMessage } = raw['.Response_ViewLogHistory.ext'];
|
||||
ModeratorPersistence.viewLogs(logMessage)
|
||||
return;
|
||||
default:
|
||||
error = 'Failed to retrieve log history.';
|
||||
break;
|
||||
}
|
||||
|
||||
if (error) {
|
||||
console.error(responseCode, error);
|
||||
}
|
||||
});
|
||||
}
|
||||
29
webclient/src/websocket/commands/moderator/warnUser.ts
Normal file
29
webclient/src/websocket/commands/moderator/warnUser.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
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 sc = webClient.protobuf.controller.ModeratorCommand.create({
|
||||
'.Command_WarnUser.ext': command
|
||||
});
|
||||
|
||||
webClient.protobuf.sendModeratorCommand(sc, (raw) => {
|
||||
const { responseCode } = raw;
|
||||
|
||||
let error: string;
|
||||
|
||||
switch (responseCode) {
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
|
||||
ModeratorPersistence.warnUser(userName);
|
||||
return;
|
||||
default:
|
||||
error = 'Failed to warn user.';
|
||||
break;
|
||||
}
|
||||
|
||||
if (error) {
|
||||
console.error(responseCode, error);
|
||||
}
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue