Skip to content

Commit

Permalink
add some logging
Browse files Browse the repository at this point in the history
  • Loading branch information
snazzyfox committed Jun 28, 2023
1 parent f01b0f0 commit b09ea8f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions dingomata/cogs/text.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import random
import re
from datetime import datetime
Expand All @@ -20,6 +21,7 @@

_calendar = Calendar()
_includes = re.compile(r'http.+|<.+>')
_log = logging.getLogger(__name__)
openai.api_key = service_config.openai_api_key.get_secret_value()


Expand Down Expand Up @@ -299,7 +301,9 @@ async def on_message(self, message: discord.Message) -> None:
async def _post_rawtext_reply(self, message: discord.Message) -> None:
for reply in self._rawtext_replies:
if reply.regex.search(message.content):
await message.reply(random.choice(reply.responses))
response = random.choice(reply.responses)
_log.info(f'Responding to raw mention message. Message: {message.content}; Response: {response}')
await message.reply(response)
break # Stop after first match

async def _post_ai_reply(self, message: discord.Message) -> None:
Expand Down Expand Up @@ -331,7 +335,9 @@ async def _post_ai_reply(self, message: discord.Message) -> None:
presence_penalty=0.05,
frequency_penalty=0.10,
)
await message.reply(response['choices'][0]['message']['content'])
response_text = response['choices'][0]['message']['content']
_log.info(f'Responding to raw mention message with AI. Message: {message.content}; Response: {response_text}')
await message.reply(response_text)

async def _post_random_reply(self, ctx: discord.ApplicationContext, key: str, **kwargs) -> None:
await ctx.respond(self._random_replies[key].render(author=ctx.author.display_name, **kwargs))

0 comments on commit b09ea8f

Please sign in to comment.