|
|
@ -60,7 +60,7 @@ class Callbacks(object): |
|
|
|
chat_message = self.bot.chat_history.room(room.display_name).add(event.event_id, event.server_timestamp, room.user_name(event.sender), event.sender == self.client.user, is_command, relates_to, event.body, language, english_original_message) |
|
|
|
if self.bot.not_synced: |
|
|
|
return |
|
|
|
print( |
|
|
|
logger.info( |
|
|
|
"Message received for room {} | {}: {}".format( |
|
|
|
room.display_name, room.user_name(event.sender), event.body |
|
|
|
) |
|
|
@ -149,8 +149,8 @@ class Callbacks(object): |
|
|
|
|
|
|
|
full_prompt = await ai.get_full_prompt(chat_message.getTranslation("en"), self.bot, self.bot.chat_history.room(room.display_name)) |
|
|
|
num_tokens = await ai.num_tokens(full_prompt) |
|
|
|
logger.info(full_prompt) |
|
|
|
logger.info(f"num tokens:" + str(num_tokens)) |
|
|
|
logger.debug(full_prompt) |
|
|
|
logger.debug(f"Prompt has " + str(num_tokens) + " tokens") |
|
|
|
# answer = "" |
|
|
|
# time = 0 |
|
|
|
# error = None |
|
|
@ -181,11 +181,10 @@ class Callbacks(object): |
|
|
|
async def invite_cb(self, room: MatrixRoom, event: InviteEvent) -> None: |
|
|
|
"""Automatically join all rooms we get invited to""" |
|
|
|
result = await self.client.join(room.room_id) |
|
|
|
print('Invited to room: {} {}'.format(room.name, room.room_id)) |
|
|
|
if isinstance(result, nio.responses.JoinResponse): |
|
|
|
print('Joined') |
|
|
|
logger.info('Invited and joined room: {} {}'.format(room.name, room.room_id)) |
|
|
|
else: |
|
|
|
print("Error joining room: {}".format(str(result))) |
|
|
|
logger.error("Error joining room: {}".format(str(result))) |
|
|
|
|
|
|
|
class ChatBot(object): |
|
|
|
"""Main chatbot""" |
|
|
@ -243,7 +242,7 @@ class ChatBot(object): |
|
|
|
item = item.strip() |
|
|
|
event = Event(int(items[0]), int(items[1]), float(items[2]), int(items[3]), items[4].lstrip()) |
|
|
|
self.events.append(event) |
|
|
|
logger.info("event added to event_loop") |
|
|
|
logger.debug("event added to event_loop") |
|
|
|
pass |
|
|
|
|
|
|
|
async def login(self): |
|
|
@ -261,17 +260,17 @@ class ChatBot(object): |
|
|
|
|
|
|
|
try: |
|
|
|
response = await self.client.login(self.password) |
|
|
|
print(response) |
|
|
|
logger.info(response) |
|
|
|
#sync_forever_task = asyncio.create_task(self.client.sync_forever(timeout=30000, full_state=True)) |
|
|
|
except (asyncio.CancelledError, KeyboardInterrupt): |
|
|
|
print("Received interrupt.") |
|
|
|
logger.error("Received interrupt while login.") |
|
|
|
await self.client.close() |
|
|
|
#return sync_forever_task |
|
|
|
|
|
|
|
async def watch_for_sync(self, sync_event): |
|
|
|
print("Awaiting sync") |
|
|
|
logger.debug("Awaiting sync") |
|
|
|
await sync_event.wait() |
|
|
|
print("Client is synced") |
|
|
|
logger.debug("Client is synced") |
|
|
|
self.not_synced = False |
|
|
|
|
|
|
|
async def read_conf2(self, section): |
|
|
@ -319,9 +318,9 @@ class ChatBot(object): |
|
|
|
filesize=file_stat.st_size, |
|
|
|
) |
|
|
|
if isinstance(resp, UploadResponse): |
|
|
|
print("Image was uploaded successfully to server. ") |
|
|
|
logger.info("Image was uploaded successfully to server. ") |
|
|
|
else: |
|
|
|
print(f"Failed to upload image. Failure response: {resp}") |
|
|
|
logger.error(f"Failed to upload image. Failure response: {resp}") |
|
|
|
|
|
|
|
content = { |
|
|
|
"body": os.path.basename(image), # descriptive title |
|
|
@ -339,9 +338,9 @@ class ChatBot(object): |
|
|
|
|
|
|
|
try: |
|
|
|
await client.room_send(room_id, message_type="m.room.message", content=content) |
|
|
|
print("Image was sent successfully") |
|
|
|
logger.info("Image was sent successfully") |
|
|
|
except Exception: |
|
|
|
print(f"Image send of file {image} failed.") |
|
|
|
logger.error(f"Image send of file {image} failed.") |
|
|
|
|
|
|
|
async def main() -> None: |
|
|
|
config.read('bot.conf') |
|
|
@ -372,7 +371,7 @@ async def main() -> None: |
|
|
|
await bot.read_conf2(section) |
|
|
|
bots.append(bot) |
|
|
|
await bot.login() |
|
|
|
print("gather") |
|
|
|
#logger.info("gather") |
|
|
|
if sys.version_info[0] == 3 and sys.version_info[1] < 11: |
|
|
|
tasks = [] |
|
|
|
for bot in bots: |
|
|
|