From 2f43d057d7523c9ba9884e7a1637009e4996f1f8 Mon Sep 17 00:00:00 2001 From: MrlolDev Date: Fri, 15 Dec 2023 22:37:09 +0100 Subject: [PATCH] fix: auto reset conversation --- src/bot/commands/chat.ts | 7 ++++++- src/bot/commands/describe.ts | 32 ++++++++++++++++++++++++++++++++ src/bot/utils/conversations.ts | 14 ++++++++++++++ src/bot/utils/settings.ts | 4 +++- 4 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 src/bot/commands/describe.ts diff --git a/src/bot/commands/chat.ts b/src/bot/commands/chat.ts index 5ca80e1..f84e442 100644 --- a/src/bot/commands/chat.ts +++ b/src/bot/commands/chat.ts @@ -154,7 +154,12 @@ async function buildInfo( content: "An error occurred", }); } - const loadingIndicator = LOADING_INDICATORS[Math.floor(Math.random() * 5)]; + let loadingIndicatorId: string | boolean | number | object = await getSettingsValue(user, "general:loadingIndicator"); + if (!loadingIndicatorId) { + loadingIndicatorId = (await getDefaultValues("general:loadingIndicator")) as string; + } + const loadingIndicator = LOADING_INDICATORS[loadingIndicatorId as number]; + let lastUpdate = Date.now(); let done = false; event.on("data", async (data) => { diff --git a/src/bot/commands/describe.ts b/src/bot/commands/describe.ts new file mode 100644 index 0000000..49c2995 --- /dev/null +++ b/src/bot/commands/describe.ts @@ -0,0 +1,32 @@ +import { ButtonStyles, CreateMessageOptions, MessageComponentTypes } from "@discordeno/bot"; +import config from "../../config.js"; +import { createCommand } from "../config/setup.js"; +import { IMAGE_MODELS } from "../models/index.js"; +import EventEmitter from "events"; +import { LOADING_INDICATORS } from "../../types/models/users.js"; +import { mergeImages } from "../utils/image-merge.js"; +import { getDefaultValues, getSettingsValue } from "../utils/settings.js"; +import { chargePlan, requiredPremium } from "../utils/premium.js"; + +export default createCommand({ + body: { + name: "describe", + description: "Describe an image using AI", + type: "ChatInput", + options: [ + { + type: "Attachment", + name: "image", + description: "The image to use", + required: true, + } + ], + }, + cooldown: { + user: 1.5 * 60 * 1000, + voter: 1.25 * 60 * 1000, + subscription: 1 * 60 * 1000, + }, + interaction: async ({ interaction, options, env, premium }) => { + } +}) \ No newline at end of file diff --git a/src/bot/utils/conversations.ts b/src/bot/utils/conversations.ts index 79fc264..ae51f46 100644 --- a/src/bot/utils/conversations.ts +++ b/src/bot/utils/conversations.ts @@ -8,6 +8,20 @@ export async function getConversation(userId: string, modelName: string) { id: `${userId}-${modelName}`, })) as Conversation; if (!conversation) return null; + const numberOfUserMessages = conversation.history.messages.filter((x) => x.role === "user").length; + const numberOfBotMessages = conversation.history.messages.filter((x) => x.role !== "user").length; + // for each 2 messages, there would be 1 bot message + if (numberOfUserMessages > numberOfBotMessages * 2) { + const updatedConversation = { + history: { + datasetId: conversation.history.datasetId, + messages: [], + }, + last_update: Date.now(), + }; + await update("conversations", conversation.id, updatedConversation); + conversation.history.messages = []; + } return conversation; } diff --git a/src/bot/utils/settings.ts b/src/bot/utils/settings.ts index 8247dca..d1e31e8 100644 --- a/src/bot/utils/settings.ts +++ b/src/bot/utils/settings.ts @@ -31,7 +31,7 @@ function key2data(key: string) { } export type EnabledSectionsTypes = "chat" | "image" | "premium" | string; -export const EnabledSections: Array = ["chat", "image"]; +export const EnabledSections: Array = ["chat", "image", "general"]; export async function generateSections(pageName: EnabledSectionsTypes, env: Environment): Promise { let message: null | CreateMessageOptions = null; const user = env.user; @@ -185,6 +185,7 @@ export function getMetadata( value: l.id, })), emoji: "🌐", + enabled: true, }; case "general:loadingIndicator": return { @@ -196,6 +197,7 @@ export function getMetadata( value: l.emoji?.id || "default", })), emoji: "🔄", + enabled: true, }; case "chat:model": return {