-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
28 lines (26 loc) · 1.49 KB
/
Copy pathclient.py
File metadata and controls
28 lines (26 loc) · 1.49 KB
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
import discord
import conversation as convers
import config
discord_client = discord.Client(intents=config.bot_intents)
@discord_client.event
async def on_message(message):
if message.content.startswith(config.chat_command) or discord_client.user in message.mentions or message.reference is not None and message.author != discord_client.user:
mention_string = f'<@{discord_client.user.id}>'
server_id = message.guild.id
conversation = await convers.MemoryManagement.get_conversation(server_id)
user_message = message.content
if mention_string in user_message:
user_message = user_message.replace(mention_string, config.mention_replacement)
if config.chat_command in message.content:
user_message = user_message[len(config.chat_command):]
prompt = conversation + user_message + config.seperator
response, failstate = await convers.ResponseManagement.create_response(server_id, conversation, user_message, prompt)
message_blocks = []
message_blocks = await convers.ResponseManagement.create_messages(server_id, response, conversation, user_message, failstate)
for block in message_blocks:
await message.channel.send(block)
if message.content.startswith(config.reset_command):
server_id = message.guild.id
await convers.MemoryManagement.clear_conversation(server_id)
await message.channel.send("Conversation reset, memory cleared.")
discord_client.run(config.discord_token)