feat: use the docs as input for the AI

This commit is contained in:
2025-04-15 21:24:13 +02:00
parent 727d717b60
commit 83ed3f0d86
8 changed files with 260 additions and 13 deletions

View File

@@ -5,6 +5,7 @@ import discord
from discord.ext import tasks, commands
from bot.utils import aware_utcnow, fetch_api_data
from bot.discourse.handle_request import fetch_cooked_posts, combine_posts_text
from database import migrate_users_with_role
@@ -116,6 +117,36 @@ class SteamSaleChecker(commands.Cog):
await self.bot.wait_until_ready()
class DiscourseUpdater(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.update_discourse_data.start() # Start the task when the cog is loaded
def cog_unload(self):
self.update_discourse_data.cancel() # Stop the task when the cog is unloaded
@tasks.loop(hours=6)
async def update_discourse_data(self):
"""
Periodically fetches and updates Discourse data for the bot.
"""
tag_name = "docs"
print("Fetching Discourse data...")
cooked_posts = fetch_cooked_posts(tag_name)
if cooked_posts:
combined_text = combine_posts_text(
[{"cooked": post} for post in cooked_posts]
)
self.bot.ai_helper.set_discourse_data(combined_text)
print("Discourse data updated successfully.")
else:
print(f"No posts found for tag '{tag_name}'.")
@update_discourse_data.before_loop
async def before_update_discourse_data(self):
await self.bot.wait_until_ready()
async def setup(bot):
@tasks.loop(minutes=10)
async def update_status():
@@ -152,5 +183,6 @@ async def setup(bot):
heat_death.start()
await bot.add_cog(SteamSaleChecker(bot))
await bot.add_cog(DiscourseUpdater(bot))
print("Tasks extension loaded!")