|
|
@ -3,6 +3,7 @@ import os, sys |
|
|
|
import time |
|
|
|
import importlib |
|
|
|
import re |
|
|
|
import json |
|
|
|
import logging |
|
|
|
from functools import partial |
|
|
|
from .memory.chatlog import ChatLog |
|
|
@ -38,14 +39,26 @@ class ChatBot(object): |
|
|
|
|
|
|
|
#self.example_dialogue = self.example_dialogue.replace('{{char}}', self.name) |
|
|
|
|
|
|
|
def persist(self, data_dir): |
|
|
|
self.chatlog_path = f"{data_dir}/chatlogs" |
|
|
|
self.images_path = f"{data_dir}/images" |
|
|
|
self.memory_path = f"{data_dir}/memory" |
|
|
|
async def persist(self, data_dir): |
|
|
|
self.chatlog_path = os.path.join(data_dir, "chatlogs/") |
|
|
|
self.images_path = os.path.join(data_dir, "images/") |
|
|
|
self.memory_path = os.path.join(data_dir, "memory/") |
|
|
|
self.rooms_conf_file = os.path.join(data_dir, "rooms.conf") |
|
|
|
os.makedirs(self.chatlog_path, exist_ok=True) |
|
|
|
os.makedirs(self.images_path, exist_ok=True) |
|
|
|
os.makedirs(self.memory_path, exist_ok=True) |
|
|
|
self.chatlog.enable_logging(self.chatlog_path) |
|
|
|
self.rooms = await self.read_conf2() |
|
|
|
|
|
|
|
async def read_conf2(self): |
|
|
|
if not os.path.isfile(self.rooms_conf_file): |
|
|
|
return {} |
|
|
|
with open(self.rooms_conf_file, "r") as f: |
|
|
|
return json.load(f) |
|
|
|
|
|
|
|
async def write_conf2(self, data): |
|
|
|
with open(self.rooms_conf_file, "w") as f: |
|
|
|
json.dump(data, f) |
|
|
|
|
|
|
|
async def connect(self): |
|
|
|
await self.connection.login() |
|
|
@ -114,6 +127,7 @@ class ChatBot(object): |
|
|
|
|
|
|
|
if not room.room_id in self.rooms: |
|
|
|
self.rooms[room.room_id] = {} |
|
|
|
self.write_conf2(self.rooms) |
|
|
|
# ToDo: set ticks 0 / start |
|
|
|
|
|
|
|
if not self.connection.synced: |
|
|
@ -209,8 +223,10 @@ class ChatBot(object): |
|
|
|
await reply_fn(self.greeting) |
|
|
|
elif message.message.startswith('!start'): |
|
|
|
self.rooms[message.room_id]["disabled"] = False |
|
|
|
self.write_conf2(self.rooms) |
|
|
|
elif message.message.startswith('!stop'): |
|
|
|
self.rooms[message.room_id]["disabled"] = True |
|
|
|
self.write_conf2(self.rooms) |
|
|
|
elif message.message.startswith('!!'): |
|
|
|
if self.chatlog.chat_history_len(message.room_id) > 2: |
|
|
|
for _ in range(2): |
|
|
|