diff --git a/gpt/gpt.py b/gpt/gpt.py index 800f8ab..fcf9853 100644 --- a/gpt/gpt.py +++ b/gpt/gpt.py @@ -1,6 +1,5 @@ import json import urllib -import requests import io import base64 import asyncio @@ -14,7 +13,7 @@ from mautrix.types.event.message import BaseFileInfo, Format, TextMessageEventCo from mautrix.util.config import BaseProxyConfig, ConfigUpdateHelper from mautrix.util import markdown from maubot import Plugin, MessageEvent -from maubot.handlers import event +from maubot.handlers import event, command from mautrix.client import Client from .history import History @@ -138,3 +137,12 @@ class Gpt(Plugin): return content + @command.new(name="export") + async def export(self, event: MessageEvent) -> None: + await self.client.set_typing(event.room_id, timeout=9999) + result = await self.history.dump(event) + content = TextMessageEventContent(msgtype=MessageType.NOTICE, body=result, format=Format.HTML) + await event.respond(content, in_thread=self.config['reply_in_thread']) + await self.client.set_typing(event.room_id, timeout=0) + + diff --git a/gpt/history.py b/gpt/history.py index 0faaea7..1ae8b24 100644 --- a/gpt/history.py +++ b/gpt/history.py @@ -1,4 +1,5 @@ import redis.asyncio as redis +import requests import json class History(): @@ -38,4 +39,16 @@ class History(): history = await self.get(userData) if (len(history) == 0): return "You have no ChatGPT history at the moment." - # Going to add this at a later point via haste.snrd.eu + + text = "" + for i in range(0, len(history), 2): + text += f"You: {history[i]['content']}\nGPT: {history[i+1]['content']}\n\n" + + response = requests.post("https://haste.snrd.eu/documents", data=text) + + if response.status_code != 200: + return "Could not export the ChatGPT history! Please try again later!" + else: + haste = json.loads(response.text)['key'] + msg = "Your ChatGPT history: https://haste.snrd.eu/raw/{}".format(haste) + return msg diff --git a/maubot.yaml b/maubot.yaml index 8695415..9d02ec8 100644 --- a/maubot.yaml +++ b/maubot.yaml @@ -1,6 +1,6 @@ maubot: 0.1.0 id: sh.boehm.gpt -version: 0.0.008 +version: 0.0.02 license: MIT modules: - gpt