Code style
This commit is contained in:
parent
fadb92e544
commit
8f4f054a76
|
@ -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;
|
||||
|
@ -31,7 +30,6 @@ export class Channel extends EventEmitter {
|
|||
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("/")) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue