2025-08-21 15:08:52 +02:00
|
|
|
import times, strformat, strutils
|
2025-08-20 12:55:09 +02:00
|
|
|
import std/[dirs, paths]
|
|
|
|
|
import ../../common/[types, profile]
|
|
|
|
|
|
|
|
|
|
proc makeAgentLogDirectory*(cq: Conquest, agentId: string): bool =
|
|
|
|
|
try:
|
|
|
|
|
let cqDir = cq.profile.getString("conquest_directory")
|
|
|
|
|
createDir(cast[Path](fmt"{cqDir}/data/logs/{agentId}"))
|
|
|
|
|
return true
|
|
|
|
|
except OSError:
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
|
|
proc log*(cq: Conquest, logEntry: string) =
|
|
|
|
|
let
|
|
|
|
|
date = now().format("dd-MM-yyyy")
|
|
|
|
|
cqDir = cq.profile.getString("conquest_directory")
|
2025-08-21 15:08:52 +02:00
|
|
|
agentLogPath = fmt"{cqDir}/data/logs/{cq.interactAgent.agentId}/{date}.session.log"
|
2025-08-20 12:55:09 +02:00
|
|
|
|
|
|
|
|
# Write log entry to file
|
|
|
|
|
let file = open(agentLogPath, fmAppend)
|
2025-08-21 15:08:52 +02:00
|
|
|
file.writeLine(fmt"{logEntry}")
|
2025-08-20 12:55:09 +02:00
|
|
|
file.flushFile()
|
|
|
|
|
|
2025-08-21 15:08:52 +02:00
|
|
|
proc extractStrings*(args: string): string =
|
2025-08-20 12:55:09 +02:00
|
|
|
if not args.startsWith("("):
|
|
|
|
|
return args
|
|
|
|
|
|
|
|
|
|
# Remove styling arguments, such as fgRed, styleBright, resetStyle, etc. by extracting only arguments that are quoted
|
|
|
|
|
var message: string
|
|
|
|
|
for str in args[1..^2].split(", "):
|
|
|
|
|
if str.startsWith("\""):
|
|
|
|
|
message &= str
|
2025-08-21 15:08:52 +02:00
|
|
|
return message.replace("\"", "")
|