Code style

This commit is contained in:
Hri7566 2024-02-04 08:39:21 -05:00
parent fadb92e544
commit 8f4f054a76
2 changed files with 15 additions and 25 deletions

View File

@ -1,4 +1,4 @@
import EventEmitter, { on } from "events"; import EventEmitter from "events";
import { Logger } from "../util/Logger"; import { Logger } from "../util/Logger";
import { import {
ChannelSettingValue, ChannelSettingValue,
@ -15,7 +15,6 @@ import Crown from "./Crown";
import { ChannelList } from "./ChannelList"; import { ChannelList } from "./ChannelList";
import { config } from "./config"; import { config } from "./config";
import { saveChatHistory, getChatHistory } from "../data/history"; import { saveChatHistory, getChatHistory } from "../data/history";
import { prisma } from "../data/prisma";
interface CachedKickban { interface CachedKickban {
userId: string; userId: string;
@ -31,7 +30,6 @@ export class Channel extends EventEmitter {
this.chatHistory = await getChatHistory(this.getID()); this.chatHistory = await getChatHistory(this.getID());
} }
public logger: Logger; public logger: Logger;
public bans = new Array<CachedKickban>(); public bans = new Array<CachedKickban>();
@ -46,7 +44,6 @@ export class Channel extends EventEmitter {
) { ) {
super(); super();
this.logger = new Logger("Channel - " + _id); this.logger = new Logger("Channel - " + _id);
// Validate settings in set // Validate settings in set
@ -89,7 +86,7 @@ export class Channel extends EventEmitter {
private bindEventListeners() { private bindEventListeners() {
if (this.alreadyBound) return; if (this.alreadyBound) return;
this.alreadyBound = true; this.alreadyBound = true;
this.loadChatHistory() this.loadChatHistory();
this.logger.info("Loaded Chat History."); this.logger.info("Loaded Chat History.");
this.on("update", () => { this.on("update", () => {
@ -134,7 +131,7 @@ export class Channel extends EventEmitter {
this.sendArray([outgoing]); this.sendArray([outgoing]);
this.chatHistory.push(outgoing); this.chatHistory.push(outgoing);
await saveChatHistory(this.getID(), this.chatHistory) await saveChatHistory(this.getID(), this.chatHistory);
try { try {
if (msg.message.startsWith("/")) { if (msg.message.startsWith("/")) {

View File

@ -1,32 +1,25 @@
// TODO Chat history
import { prisma } from "./prisma"; import { prisma } from "./prisma";
export async function saveChatHistory( export async function saveChatHistory(_id: string, chatHistory: object) {
_id: string,
chatHistory: object
) {
await prisma.chatHistory.upsert({ await prisma.chatHistory.upsert({
where:{ where: {
id: _id id: _id
}, },
update:{ update: {
messages: JSON.stringify(chatHistory) messages: JSON.stringify(chatHistory)
}, },
create: { create: {
id:_id, id: _id,
messages: JSON.stringify(chatHistory) messages: JSON.stringify(chatHistory)
} }
}) });
} }
export async function getChatHistory(_id: string) {
export async function getChatHistory( const history = await prisma.chatHistory.findFirst({ where: { id: _id } });
_id: string if (!history) {
) {
const history = await prisma.chatHistory.findFirst({where:{id:_id}})
if(!history) {
return []; return [];
} else { } else {
return JSON.parse(await history.messages); return JSON.parse(history.messages);
} }
} }