-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
65 lines (52 loc) · 1.61 KB
/
main.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
59
60
61
62
63
64
65
from revChatGPT.revChatGPT import Chatbot
import json
import discord
from discord.ext import commands
import os
# bot setup
intents = discord.Intents.default()
intents.message_content = True
client = commands.Bot(command_prefix="!",
case_insensitive=True,
intents=intents)
BOT_SECRET = os.environ['BOT_SECRET']
# chatGPT config
with open("config.json", "r") as f:
config = json.load(f)
config['Authorization'] = os.environ['AUTH']
config['session_token'] = os.environ['SESS_TOKEN']
config['email'] = os.environ['EMAIL']
config['password'] = os.environ['PASSWORD']
chatbot = Chatbot(config, conversation_id=None)
# on ready
@client.event
async def on_ready():
print(f'Logged in as {client.user}')
# ask command
@client.command()
async def ask(ctx, *arg):
try:
async with ctx.typing():
chatbot.refresh_session()
prompt = " ".join(arg)
resp = chatbot.get_chat_response(prompt, output="text")
if (len(resp['message']) > 1999):
await ctx.send((resp['message'])[:1999])
await ctx.send("-" + (resp['message'])[1999:])
else:
await ctx.send(resp['message'])
except Exception as e:
await ctx.send("An error occurred during the request")
print("Something went wrong")
print(e)
# reset chat
@client.command()
async def reset(ctx):
try:
chatbot.reset_chat()
await ctx.send("Chat was reset")
except Exception as e:
await ctx.send("An error occurred during the request")
print(e)
# run bot
client.run(BOT_SECRET)