set typing

pull/3/head
Michael Yang 2023-08-04 00:42:08 -07:00
parent 2a39686d43
commit 715e866430
1 changed files with 18 additions and 18 deletions

View File

@ -76,31 +76,31 @@ async def on_message(message):
await message.channel.send('What can I do for you?', reference=message) await message.channel.send('What can I do for you?', reference=message)
return return
await message.add_reaction('🤔')
response = None
# TODO: discord has a 2000 character limit, so we need to split the response # TODO: discord has a 2000 character limit, so we need to split the response
response = None
buffer = '' buffer = ''
response_content = '' response_content = ''
async for chunk in generate_response(raw_content, **load_session(message.reference)): async with message.channel.typing():
if chunk['done']: await message.add_reaction('🤔')
response_content += buffer async for chunk in generate_response(raw_content, **load_session(message.reference)):
save_session(response, chunk) if chunk['done']:
break response_content += buffer
save_session(response, chunk)
break
buffer += chunk['response'] buffer += chunk['response']
if len(buffer) >= args.buffer_size: if len(buffer) >= args.buffer_size:
# buffer the edit so as to not call Discord API too often # buffer the edit so as to not call Discord API too often
response_content += buffer response_content += buffer
if response: if response:
await response.edit(content=response_content + '...') await response.edit(content=response_content + '...')
else: else:
response = await message.reply(response_content) response = await message.reply(response_content)
await message.remove_reaction('🤔', client.user) await message.remove_reaction('🤔', client.user)
buffer = '' buffer = ''
await response.edit(content=response_content) await response.edit(content=response_content)