added history command
This commit is contained in:
parent
5bdd0cd810
commit
2c838d5456
3 changed files with 25 additions and 4 deletions
12
gpt/gpt.py
12
gpt/gpt.py
|
@ -1,6 +1,5 @@
|
||||||
import json
|
import json
|
||||||
import urllib
|
import urllib
|
||||||
import requests
|
|
||||||
import io
|
import io
|
||||||
import base64
|
import base64
|
||||||
import asyncio
|
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.config import BaseProxyConfig, ConfigUpdateHelper
|
||||||
from mautrix.util import markdown
|
from mautrix.util import markdown
|
||||||
from maubot import Plugin, MessageEvent
|
from maubot import Plugin, MessageEvent
|
||||||
from maubot.handlers import event
|
from maubot.handlers import event, command
|
||||||
from mautrix.client import Client
|
from mautrix.client import Client
|
||||||
from .history import History
|
from .history import History
|
||||||
|
|
||||||
|
@ -138,3 +137,12 @@ class Gpt(Plugin):
|
||||||
|
|
||||||
return content
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import redis.asyncio as redis
|
import redis.asyncio as redis
|
||||||
|
import requests
|
||||||
import json
|
import json
|
||||||
|
|
||||||
class History():
|
class History():
|
||||||
|
@ -38,4 +39,16 @@ class History():
|
||||||
history = await self.get(userData)
|
history = await self.get(userData)
|
||||||
if (len(history) == 0):
|
if (len(history) == 0):
|
||||||
return "You have no ChatGPT history at the moment."
|
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
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
maubot: 0.1.0
|
maubot: 0.1.0
|
||||||
id: sh.boehm.gpt
|
id: sh.boehm.gpt
|
||||||
version: 0.0.008
|
version: 0.0.02
|
||||||
license: MIT
|
license: MIT
|
||||||
modules:
|
modules:
|
||||||
- gpt
|
- gpt
|
||||||
|
|
Loading…
Reference in a new issue