2023-03-05 14:07:25 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import json
|
2023-04-10 02:52:18 +00:00
|
|
|
import os
|
2023-03-05 14:07:25 +00:00
|
|
|
import asyncio
|
|
|
|
from bot import Bot
|
2023-04-10 02:52:18 +00:00
|
|
|
from nio import Api, SyncResponse
|
|
|
|
from log import getlogger
|
2023-03-05 14:07:25 +00:00
|
|
|
|
2023-04-10 02:52:18 +00:00
|
|
|
logger = getlogger()
|
2023-03-05 14:07:25 +00:00
|
|
|
|
|
|
|
async def main():
|
2023-04-10 02:52:18 +00:00
|
|
|
if os.path.exists('config.json'):
|
|
|
|
fp = open('config.json', 'r', encoding="utf8")
|
|
|
|
config = json.load(fp)
|
|
|
|
|
|
|
|
matrix_bot = Bot(homeserver=os.environ.get("HOMESERVER") or config.get('homeserver'),
|
|
|
|
user_id=os.environ.get("USER_ID") or config.get('user_id') ,
|
|
|
|
password=os.environ.get("PASSWORD") or config.get('password'),
|
|
|
|
device_id=os.environ.get("DEVICE_ID") or config.get('device_id'),
|
|
|
|
room_id=os.environ.get("ROOM_ID") or config.get('room_id'),
|
|
|
|
api_key=os.environ.get("OPENAI_API_KEY") or config.get('api_key'),
|
|
|
|
bing_api_endpoint=os.environ.get("BING_API_ENDPOINT") or config.get('bing_api_endpoint'),
|
|
|
|
access_token=os.environ.get("ACCESS_TOKEN") or config.get('access_token'),
|
|
|
|
jailbreakEnabled=os.environ.get("JAILBREAKENABLED", "False").lower() in ('true', '1') or config.get('jailbreakEnabled'),
|
|
|
|
bing_auth_cookie=os.environ.get("BING_AUTH_COOKIE") or config.get('bing_auth_cookie'),
|
2023-03-10 00:29:12 +00:00
|
|
|
)
|
2023-04-10 02:52:18 +00:00
|
|
|
# if not set access_token, then login via password
|
|
|
|
# if os.path.exists('config.json'):
|
|
|
|
# fp = open('config.json', 'r', encoding="utf8")
|
|
|
|
# config = json.load(fp)
|
|
|
|
# if os.environ.get("ACCESS_TOKEN") is None and config.get("access_token") is None:
|
|
|
|
# await matrix_bot.login()
|
|
|
|
|
|
|
|
# elif os.environ.get("ACCESS_TOKEN") is None:
|
|
|
|
# await matrix_bot.login()
|
|
|
|
|
|
|
|
await matrix_bot.login()
|
|
|
|
|
|
|
|
# await matrix_bot.sync_encryption_key()
|
|
|
|
|
|
|
|
# await matrix_bot.trust_own_devices()
|
|
|
|
|
|
|
|
try:
|
|
|
|
await matrix_bot.sync_forever(timeout=3000, full_state=True)
|
|
|
|
finally:
|
|
|
|
await matrix_bot.client.close()
|
2023-03-05 14:07:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2023-04-10 02:52:18 +00:00
|
|
|
logger.debug("matrix chatgpt bot start.....")
|
2023-03-05 14:07:25 +00:00
|
|
|
try:
|
2023-03-09 16:21:12 +00:00
|
|
|
loop = asyncio.get_running_loop()
|
|
|
|
except RuntimeError:
|
|
|
|
loop = asyncio.new_event_loop()
|
|
|
|
asyncio.set_event_loop(loop)
|
|
|
|
asyncio.run(main())
|