From 8f4f054a7648ccbf3a9002a2c2525c18ef1d6ae7 Mon Sep 17 00:00:00 2001 From: Hri7566 Date: Sun, 4 Feb 2024 08:39:21 -0500 Subject: [PATCH] Code style --- src/channel/Channel.ts | 13 +++++-------- src/data/history.ts | 27 ++++++++++----------------- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/src/channel/Channel.ts b/src/channel/Channel.ts index 8c35687..eebf125 100644 --- a/src/channel/Channel.ts +++ b/src/channel/Channel.ts @@ -1,4 +1,4 @@ -import EventEmitter, { on } from "events"; +import EventEmitter from "events"; import { Logger } from "../util/Logger"; import { ChannelSettingValue, @@ -15,7 +15,6 @@ import Crown from "./Crown"; import { ChannelList } from "./ChannelList"; import { config } from "./config"; import { saveChatHistory, getChatHistory } from "../data/history"; -import { prisma } from "../data/prisma"; interface CachedKickban { userId: string; @@ -27,11 +26,10 @@ export class Channel extends EventEmitter { private settings: Partial = config.defaultSettings; private ppl = new Array(); public chatHistory = new Array(); - private async loadChatHistory() { - this.chatHistory = await getChatHistory(this.getID()); + private async loadChatHistory() { + this.chatHistory = await getChatHistory(this.getID()); } - public logger: Logger; public bans = new Array(); @@ -46,7 +44,6 @@ export class Channel extends EventEmitter { ) { super(); - this.logger = new Logger("Channel - " + _id); // Validate settings in set @@ -89,7 +86,7 @@ export class Channel extends EventEmitter { private bindEventListeners() { if (this.alreadyBound) return; this.alreadyBound = true; - this.loadChatHistory() + this.loadChatHistory(); this.logger.info("Loaded Chat History."); this.on("update", () => { @@ -134,7 +131,7 @@ export class Channel extends EventEmitter { this.sendArray([outgoing]); this.chatHistory.push(outgoing); - await saveChatHistory(this.getID(), this.chatHistory) + await saveChatHistory(this.getID(), this.chatHistory); try { if (msg.message.startsWith("/")) { diff --git a/src/data/history.ts b/src/data/history.ts index 89926c7..bab7aad 100644 --- a/src/data/history.ts +++ b/src/data/history.ts @@ -1,32 +1,25 @@ -// TODO Chat history import { prisma } from "./prisma"; -export async function saveChatHistory( - _id: string, - chatHistory: object -) { +export async function saveChatHistory(_id: string, chatHistory: object) { await prisma.chatHistory.upsert({ - where:{ + where: { id: _id }, - update:{ + update: { messages: JSON.stringify(chatHistory) }, create: { - id:_id, + id: _id, messages: JSON.stringify(chatHistory) } - }) + }); } - -export async function getChatHistory( - _id: string -) { - const history = await prisma.chatHistory.findFirst({where:{id:_id}}) - if(!history) { +export async function getChatHistory(_id: string) { + const history = await prisma.chatHistory.findFirst({ where: { id: _id } }); + if (!history) { return []; } else { - return JSON.parse(await history.messages); + return JSON.parse(history.messages); } -} \ No newline at end of file +}