Fix and optimize boreness.

This commit is contained in:
OK 2024-03-17 00:00:00 +01:00
parent 53ed068519
commit 36190745c9
2 changed files with 11 additions and 10 deletions

View File

@ -73,16 +73,17 @@ class FjerkroaBot(commands.Bot):
boreness_interval = float(self.config.get('boreness-interval', 12.0)) boreness_interval = float(self.config.get('boreness-interval', 12.0))
elapsed_time = (time.monotonic() - self.last_activity_time) / 3600.0 elapsed_time = (time.monotonic() - self.last_activity_time) / 3600.0
probability = 1 / (1 + math.exp(-1 * (elapsed_time - (boreness_interval / 2.0)) + math.log(1 / 0.2 - 1))) probability = 1 / (1 + math.exp(-1 * (elapsed_time - (boreness_interval / 2.0)) + math.log(1 / 0.2 - 1)))
prev_messages = await self.chat_channel.history(limit=2).flatten() if random.random() < probability:
last_author = prev_messages[1].author.id if len(prev_messages) > 1 else None prev_messages = [msg async for msg in self.chat_channel.history(limit=2)]
if random.random() < probability and last_author and last_author != self.user.id: last_author = prev_messages[1].author.id if len(prev_messages) > 1 else None
logging.info(f'Borred with {probability} probability after {elapsed_time}') if last_author and last_author != self.user.id:
boreness_prompt = self.config.get('boreness-prompt', 'Pretend that you just now thought of something, be creative.') logging.info(f'Borred with {probability} probability after {elapsed_time}')
message = AIMessage('system', boreness_prompt, self.config.get('chat-channel', 'chat'), True, False) boreness_prompt = self.config.get('boreness-prompt', 'Pretend that you just now thought of something, be creative.')
try: message = AIMessage('system', boreness_prompt, self.config.get('chat-channel', 'chat'), True, False)
await self.respond(message, self.chat_channel) try:
except Exception as err: await self.respond(message, self.chat_channel)
logging.warning(f"Failed to activate borringness: {repr(err)}") except Exception as err:
logging.warning(f"Failed to activate borringness: {repr(err)}")
await asyncio.sleep(7) await asyncio.sleep(7)
async def on_ready(self): async def on_ready(self):

Binary file not shown.