From c59f2e405552b861e30bafb1dad4ca38b491cd3e Mon Sep 17 00:00:00 2001 From: Hri7566 Date: Tue, 9 Jul 2024 04:22:41 -0400 Subject: [PATCH] Add kickban notifications --- src/channel/Channel.ts | 32 ++++++++++++++++++++++++++++++-- src/ws/Socket.ts | 2 +- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/channel/Channel.ts b/src/channel/Channel.ts index 6682a71..7beb53d 100644 --- a/src/channel/Channel.ts +++ b/src/channel/Channel.ts @@ -660,8 +660,9 @@ export class Channel extends EventEmitter { * @param _id User ID to ban * @param t Time in millseconds to ban for **/ - public kickban(_id: string, t: number = 1000 * 60 * 30) { + public kickban(_id: string, t: number = 1000 * 60 * 30, banner?: string) { const now = Date.now(); + if (t < 0 || t > 300 * 60 * 1000) return; let shouldUpdate = false; @@ -704,12 +705,39 @@ export class Channel extends EventEmitter { for (const socket of socketsBySocketID.values()) { if (uuidsToKick.includes(socket.getUUID())) { + socket.sendNotification({ + title: "Notice", + text: `Banned from "${this.getID()}" for ${Math.floor(t / 1000 / 60)} minutes.`, + duration: 7000, + target: "#room", + class: "short" + }); socket.setChannel(banChannel.getID()); } } - if (shouldUpdate) + if (shouldUpdate) { this.emit("update", this); + + if (typeof banner !== "undefined") { + this.sendNotification({ + title: "Notice", + text: `${this.getParticipantListUnsanitized().find(p => p._id == banner)?.name} banned ${this.getParticipantListUnsanitized().find(p => p._id == _id)?.name} from the channel for ${Math.floor(t / 1000 / 60)} minutes.`, + duration: 7000, + target: "#room", + class: "short" + }); + + if (banner == _id) { + this.sendNotification({ + title: "Certificate of Award", + text: `Let it be known that ${this.getParticipantListUnsanitized().find(p => p._id == banner)?.name} kickbanned him/her self.`, + duration: 7000, + target: "#room" + }); + } + } + } } public isBanned(_id: string) { diff --git a/src/ws/Socket.ts b/src/ws/Socket.ts index ed5d849..270b4bc 100644 --- a/src/ws/Socket.ts +++ b/src/ws/Socket.ts @@ -471,7 +471,7 @@ export class Socket extends EventEmitter { if (!channel) return; if (this.isOwner()) { - channel.kickban(_id, ms); + channel.kickban(_id, ms, this.getUserID()); } }