2023-03-05 09:07:25 -05:00
|
|
|
import json
|
2023-04-09 22:52:18 -04:00
|
|
|
import os
|
2023-03-05 09:07:25 -05:00
|
|
|
import asyncio
|
|
|
|
from bot import Bot
|
2023-04-09 22:52:18 -04:00
|
|
|
from log import getlogger
|
2023-03-05 09:07:25 -05:00
|
|
|
|
2023-04-09 22:52:18 -04:00
|
|
|
logger = getlogger()
|
2023-03-05 09:07:25 -05:00
|
|
|
|
|
|
|
async def main():
|
2023-04-09 22:52:18 -04:00
|
|
|
|
2023-04-10 09:40:39 -04:00
|
|
|
if os.path.exists('config.json'):
|
|
|
|
fp = open('config.json', 'r', encoding="utf8")
|
|
|
|
config = json.load(fp)
|
|
|
|
|
|
|
|
matrix_bot = Bot(homeserver=config.get('homeserver'),
|
|
|
|
user_id=config.get('user_id') ,
|
|
|
|
password=config.get('password'),
|
|
|
|
device_id=config.get('device_id'),
|
|
|
|
room_id=config.get('room_id'),
|
|
|
|
api_key=config.get('api_key'),
|
|
|
|
bing_api_endpoint=config.get('bing_api_endpoint'),
|
|
|
|
access_token=config.get('access_token'),
|
|
|
|
jailbreakEnabled=config.get('jailbreakEnabled'),
|
|
|
|
bing_auth_cookie=config.get('bing_auth_cookie'),
|
|
|
|
)
|
|
|
|
|
|
|
|
else:
|
|
|
|
matrix_bot = Bot(homeserver=os.environ.get('HOMESERVER'),
|
|
|
|
user_id=os.environ.get('USER_ID') ,
|
|
|
|
password=os.environ.get('PASSWORD'),
|
|
|
|
device_id=os.environ.get("DEVICE_ID"),
|
|
|
|
room_id=os.environ.get("ROOM_ID"),
|
|
|
|
api_key=os.environ.get("OPENAI_API_KEY"),
|
|
|
|
bing_api_endpoint=os.environ.get("BING_API_ENDPOINT"),
|
|
|
|
access_token=os.environ.get("ACCESS_TOKEN"),
|
|
|
|
jailbreakEnabled=os.environ.get("JAILBREAKENABLED"),
|
|
|
|
bing_auth_cookie=os.environ.get("BING_AUTH_COOKIE"),
|
|
|
|
)
|
2023-04-09 22:52:18 -04:00
|
|
|
|
|
|
|
await matrix_bot.login()
|
2023-04-10 07:37:43 -04:00
|
|
|
await matrix_bot.sync_encryption_key()
|
2023-04-09 22:52:18 -04:00
|
|
|
|
2023-04-10 09:00:22 -04:00
|
|
|
# await matrix_bot.trust_own_devices()
|
2023-04-09 22:52:18 -04:00
|
|
|
|
2023-04-10 07:37:43 -04:00
|
|
|
await matrix_bot.sync_forever(timeout=30000, full_state=True)
|
2023-03-05 09:07:25 -05:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2023-04-10 09:40:39 -04:00
|
|
|
logger.info("matrix chatgpt bot start.....")
|
2023-03-09 11:21:12 -05:00
|
|
|
asyncio.run(main())
|
2023-04-10 07:37:43 -04:00
|
|
|
|
|
|
|
|