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 {
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<IChannelSettings> = config.defaultSettings;
private ppl = new Array<Participant>();
public chatHistory = new Array<ClientEvents["a"]>();
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<CachedKickban>();
@ -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("/")) {

View File

@ -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);
}
}
}