Add clear_chat

This commit is contained in:
Hri7566 2024-07-09 03:21:12 -04:00
parent e830f0deb1
commit 4cc3040180
4 changed files with 40 additions and 13 deletions

View File

@ -725,6 +725,16 @@ export class Channel extends EventEmitter {
return false; return false;
} }
public async clearChat() {
this.chatHistory = [];
await saveChatHistory(this.getID(), this.chatHistory);
this.sendArray([{
m: "c",
c: this.chatHistory
}]);
}
} }
export default Channel; export default Channel;

28
src/util/types.d.ts vendored
View File

@ -83,18 +83,18 @@ declare type Notification = Partial<{
declare type CustomTarget = { declare type CustomTarget = {
global?: boolean; global?: boolean;
} & ( } & (
| { | {
mode: "subscribed"; mode: "subscribed";
} }
| { | {
mode: "ids"; mode: "ids";
ids: string[]; ids: string[];
} }
| { | {
mode: "id"; mode: "id";
id: string; id: string;
} }
); );
declare interface Crown { declare interface Crown {
userId: string; userId: string;
@ -230,6 +230,10 @@ declare interface ServerEvents {
key: keyof UserFlags; key: keyof UserFlags;
value: UserFlags[keyof UserFlags]; value: UserFlags[keyof UserFlags];
}; };
clear_chat: {
m: "clear_chat"
}
} }
declare interface ClientEvents { declare interface ClientEvents {

View File

@ -0,0 +1,12 @@
import { ServerEventListener } from "../../../../util/types";
export const clear_chat: ServerEventListener<"clear_chat"> = {
id: "clear_chat",
callback: async (msg, socket) => {
// Reset chat in channel
const ch = socket.getCurrentChannel();
if (!ch) return;
await ch.clearChat();
}
};

View File

@ -1,4 +1,5 @@
import { EventGroup, eventGroups } from "../../events"; import { EventGroup, eventGroups } from "../../events";
import { clear_chat } from "./handlers/clear_chat";
export const EVENT_GROUP_ADMIN = new EventGroup("admin"); export const EVENT_GROUP_ADMIN = new EventGroup("admin");
@ -10,6 +11,6 @@ import { user_flag } from "./handlers/user_flag";
// EVENT_GROUP_ADMIN.add(name); // EVENT_GROUP_ADMIN.add(name);
// EVENT_GROUP_ADMIN.add(user_flag); // EVENT_GROUP_ADMIN.add(user_flag);
EVENT_GROUP_ADMIN.addMany(color, name, user_flag); EVENT_GROUP_ADMIN.addMany(color, name, user_flag, clear_chat);
eventGroups.push(EVENT_GROUP_ADMIN); eventGroups.push(EVENT_GROUP_ADMIN);