2023-04-13 15:22:24 +00:00
|
|
|
import asyncio
|
2023-03-05 14:07:25 +00:00
|
|
|
import json
|
2023-04-10 02:52:18 +00:00
|
|
|
import os
|
2023-03-05 14:07:25 +00:00
|
|
|
from bot import Bot
|
2023-04-10 02:52:18 +00:00
|
|
|
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
|
|
|
|
2023-04-11 05:42:43 +00:00
|
|
|
|
2023-03-05 14:07:25 +00:00
|
|
|
async def main():
|
2023-04-20 07:39:14 +00:00
|
|
|
need_import_keys = False
|
2023-04-10 13:40:39 +00:00
|
|
|
if os.path.exists('config.json'):
|
|
|
|
fp = open('config.json', 'r', encoding="utf8")
|
|
|
|
config = json.load(fp)
|
2023-04-11 05:42:43 +00:00
|
|
|
|
2023-04-10 13:40:39 +00:00
|
|
|
matrix_bot = Bot(homeserver=config.get('homeserver'),
|
2023-04-11 05:42:43 +00:00
|
|
|
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'),
|
2023-04-13 15:22:24 +00:00
|
|
|
bard_token=config.get('bard_token'),
|
2023-04-11 05:42:43 +00:00
|
|
|
jailbreakEnabled=config.get('jailbreakEnabled'),
|
|
|
|
bing_auth_cookie=config.get('bing_auth_cookie'),
|
|
|
|
markdown_formatted=config.get('markdown_formatted'),
|
2023-05-20 01:46:16 +00:00
|
|
|
output_four_images=config.get('output_four_images'),
|
2023-04-20 07:39:14 +00:00
|
|
|
import_keys_path=config.get('import_keys_path'),
|
|
|
|
import_keys_password=config.get(
|
|
|
|
'import_keys_password'),
|
2023-04-11 05:42:43 +00:00
|
|
|
)
|
2023-05-20 01:46:16 +00:00
|
|
|
if config.get('import_keys_path') and \
|
|
|
|
config.get('import_keys_password') is not None:
|
2023-04-20 07:39:14 +00:00
|
|
|
need_import_keys = True
|
2023-04-10 13:40:39 +00:00
|
|
|
|
|
|
|
else:
|
|
|
|
matrix_bot = Bot(homeserver=os.environ.get('HOMESERVER'),
|
2023-04-11 05:42:43 +00:00
|
|
|
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"),
|
2023-04-13 15:22:24 +00:00
|
|
|
bard_token=os.environ.get("BARD_TOKEN"),
|
2023-04-11 05:42:43 +00:00
|
|
|
jailbreakEnabled=os.environ.get(
|
2023-05-20 01:46:16 +00:00
|
|
|
"JAILBREAKENABLED", "false").lower() \
|
|
|
|
in ('true', '1', 't'),
|
2023-04-11 05:42:43 +00:00
|
|
|
bing_auth_cookie=os.environ.get("BING_AUTH_COOKIE"),
|
|
|
|
markdown_formatted=os.environ.get(
|
2023-05-20 01:46:16 +00:00
|
|
|
"MARKDOWN_FORMATTED", "false").lower() \
|
|
|
|
in ('true', '1', 't'),
|
|
|
|
output_four_images=os.environ.get(
|
|
|
|
"OUTPUT_FOUR_IMAGES", "false").lower() \
|
|
|
|
in ('true', '1', 't'),
|
2023-04-20 07:39:14 +00:00
|
|
|
import_keys_path=os.environ.get("IMPORT_KEYS_PATH"),
|
|
|
|
import_keys_password=os.environ.get(
|
|
|
|
"IMPORT_KEYS_PASSWORD"),
|
2023-04-11 05:42:43 +00:00
|
|
|
)
|
2023-05-20 01:46:16 +00:00
|
|
|
if os.environ.get("IMPORT_KEYS_PATH") \
|
|
|
|
and os.environ.get("IMPORT_KEYS_PASSWORD") is not None:
|
2023-04-20 07:39:14 +00:00
|
|
|
need_import_keys = True
|
2023-04-10 02:52:18 +00:00
|
|
|
|
|
|
|
await matrix_bot.login()
|
2023-04-20 07:39:14 +00:00
|
|
|
if need_import_keys:
|
2023-05-20 01:46:16 +00:00
|
|
|
logger.info("start import_keys process, this may take a while...")
|
|
|
|
await matrix_bot.import_keys()
|
2023-04-10 11:37:43 +00:00
|
|
|
await matrix_bot.sync_forever(timeout=30000, full_state=True)
|
2023-03-05 14:07:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2023-04-10 13:40:39 +00:00
|
|
|
logger.info("matrix chatgpt bot start.....")
|
2023-03-09 16:21:12 +00:00
|
|
|
asyncio.run(main())
|