-
Notifications
You must be signed in to change notification settings - Fork 1
/
commands.py
58 lines (45 loc) · 1.62 KB
/
commands.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import aiohttp
from config import (
API_ENDPOINT,
API_KEY,
COMMAND,
COMMAND_PREFIX,
AUTH_TOKEN,
format_output,
)
async def handle_command(message):
if message.content.startswith(COMMAND_PREFIX):
command_body = message.content[len(COMMAND_PREFIX) :].strip()
command, *args = command_body.split(" ")
if command == COMMAND:
async with aiohttp.ClientSession() as session:
async with session.post(
API_ENDPOINT,
json={
"message": " ".join(args),
"previewToken": API_KEY,
"authToken": AUTH_TOKEN,
},
) as response:
response_content = await response.text()
await message.channel.send(format_output(response_content))
SLASH_PROMPT = "You see discord chat history, understand the problem and answer it. MAX 1500 Character"
async def handle_slash_command(msg, messages):
messages.reverse()
history_str = ""
for message in messages:
for username, text in message.items():
history_str += f"{username}: {text}\n"
print(history_str)
ai_request = SLASH_PROMPT + " " + history_str + " " + msg
async with aiohttp.ClientSession() as session:
async with session.post(
API_ENDPOINT,
json={
"message": ai_request,
"previewToken": API_KEY,
"authToken": AUTH_TOKEN,
},
) as response:
response_content = await response.text()
return response_content