improvements, fixes

This commit is contained in:
2026-04-29 19:48:38 +03:00
parent c003d443e3
commit a7fcb8074c
5 changed files with 33 additions and 8 deletions
+6 -3
View File
@@ -9,7 +9,7 @@ import {
collectReplyChainText, collectReplyChainText,
escapeMarkdownV2Text, escapeMarkdownV2Text,
logError, logError,
oldReplyToMessage, oldReplyToMessage, replyToMessage,
startIntervalEditor startIntervalEditor
} from "../util/utils"; } from "../util/utils";
import {ChatCommand} from "../base/chat-command"; import {ChatCommand} from "../base/chat-command";
@@ -108,7 +108,7 @@ export class GeminiChat extends ChatCommand {
chat_id: chatId, chat_id: chatId,
message_id: waitMessage.message_id, message_id: waitMessage.message_id,
text: escapeMarkdownV2Text(text), text: escapeMarkdownV2Text(text),
parse_mode: "Markdown" parse_mode: "MarkdownV2"
} }
).catch(logError); ).catch(logError);
@@ -167,7 +167,10 @@ export class GeminiChat extends ChatCommand {
waitMessage.reply_to_message = msg; waitMessage.reply_to_message = msg;
waitMessage.text = currentText; waitMessage.text = currentText;
await MessageStore.put(waitMessage); await MessageStore.put(waitMessage);
await oldReplyToMessage(waitMessage, `⏱️ ${diff}s`);
if (Environment.SEND_TIME_TOOK) {
await replyToMessage({message: waitMessage, text: `⏱️ ${diff}s`});
}
} }
} catch (error) { } catch (error) {
logError(error); logError(error);
+5 -2
View File
@@ -143,7 +143,7 @@ export class OllamaChat extends ChatCommand {
chat_id: chatId, chat_id: chatId,
message_id: waitMessage.message_id, message_id: waitMessage.message_id,
text: escapeMarkdownV2Text(text), text: escapeMarkdownV2Text(text),
parse_mode: "Markdown", parse_mode: "MarkdownV2",
reply_markup: cancelMarkup reply_markup: cancelMarkup
}).catch(logError); }).catch(logError);
@@ -220,7 +220,10 @@ export class OllamaChat extends ChatCommand {
waitMessage.reply_to_message = msg; waitMessage.reply_to_message = msg;
waitMessage.text = currentText; waitMessage.text = currentText;
await MessageStore.put(waitMessage); await MessageStore.put(waitMessage);
await oldReplyToMessage(waitMessage, `⏱️ ${diff}s`);
if (Environment.SEND_TIME_TOOK) {
await replyToMessage({message: waitMessage, text: `⏱️ ${diff}s`});
}
break; break;
} }
} }
+4 -1
View File
@@ -100,7 +100,7 @@ export class OpenAIChat extends ChatCommand {
chat_id: chatId, chat_id: chatId,
message_id: waitMessage.message_id, message_id: waitMessage.message_id,
text: escapeMarkdownV2Text(text), text: escapeMarkdownV2Text(text),
parse_mode: "Markdown" parse_mode: "MarkdownV2"
} }
).catch(logError); ).catch(logError);
@@ -151,8 +151,11 @@ export class OpenAIChat extends ChatCommand {
waitMessage.reply_to_message = msg; waitMessage.reply_to_message = msg;
waitMessage.text = currentText; waitMessage.text = currentText;
await MessageStore.put(waitMessage); await MessageStore.put(waitMessage);
if (Environment.SEND_TIME_TOOK) {
await replyToMessage({message: waitMessage, text: `⏱️ ${diff}s`}); await replyToMessage({message: waitMessage, text: `⏱️ ${diff}s`});
} }
}
} catch (error) { } catch (error) {
logError(error); logError(error);
await replyToMessage({ await replyToMessage({
+3
View File
@@ -37,6 +37,7 @@ export class Environment {
static IMAGE_HANDLE_FALLBACK_POLICY: ImageHandleFallbackPolicy; static IMAGE_HANDLE_FALLBACK_POLICY: ImageHandleFallbackPolicy;
static SYSTEM_PROMPT?: string; static SYSTEM_PROMPT?: string;
static SEND_TIME_TOOK: boolean;
static OLLAMA_ADDRESS?: string; static OLLAMA_ADDRESS?: string;
static OLLAMA_MODEL?: string; static OLLAMA_MODEL?: string;
@@ -112,6 +113,8 @@ export class Environment {
Environment.IMAGE_HANDLE_FALLBACK_POLICY = ImageHandleFallbackPolicy.NOTIFY_USER; Environment.IMAGE_HANDLE_FALLBACK_POLICY = ImageHandleFallbackPolicy.NOTIFY_USER;
} }
Environment.SEND_TIME_TOOK = ifTrue(process.env.SEND_TOOK_TIME || false);
Environment.OLLAMA_ADDRESS = process.env.OLLAMA_ADDRESS; Environment.OLLAMA_ADDRESS = process.env.OLLAMA_ADDRESS;
Environment.OLLAMA_MODEL = process.env.OLLAMA_MODEL || "gemma3:4b"; Environment.OLLAMA_MODEL = process.env.OLLAMA_MODEL || "gemma3:4b";
Environment.OLLAMA_IMAGE_MODEL = process.env.OLLAMA_IMAGE_MODEL || Environment.OLLAMA_MODEL; Environment.OLLAMA_IMAGE_MODEL = process.env.OLLAMA_IMAGE_MODEL || Environment.OLLAMA_MODEL;
+14 -1
View File
@@ -312,6 +312,8 @@ export async function sendMessage(options: SendOptions): Promise<Message> {
reply_markup: options.reply_markup, reply_markup: options.reply_markup,
}); });
await MessageStore.put(response);
return Promise.resolve(response); return Promise.resolve(response);
} }
@@ -338,6 +340,8 @@ export async function replyToMessage(options: SendOptions): Promise<Message> {
link_preview_options: options.link_preview_options link_preview_options: options.link_preview_options
}); });
await MessageStore.put(response);
return Promise.resolve(response); return Promise.resolve(response);
} }
@@ -563,7 +567,14 @@ function escapeMarkdownV2PreservingAllowedFormatting(s: string): string {
} }
function unescapeAccidentalMarkdownV2(s: string): string { function unescapeAccidentalMarkdownV2(s: string): string {
return s.replace(/\\([_*\[\]()~`>#+\-=|{}.!\\])/g, "$1"); let prev: string;
do {
prev = s;
s = s.replace(/\\([_*\[\]()~`>#+\-=|{}.!\\])/g, "$1");
} while (s !== prev);
return s;
} }
function escapeTelegramQuoteLine(line: string): string { function escapeTelegramQuoteLine(line: string): string {
@@ -726,6 +737,8 @@ export function cutPrefixes(msg: Message | StoredMessage | string): string {
}); });
const text = extractTextMessage(msg); const text = extractTextMessage(msg);
if (!text || !text.length) return "";
let newText = text; let newText = text;
for (const prefix of prefixes) { for (const prefix of prefixes) {