Remove daily adjectives feature
This commit is contained in:
72
bot.py
72
bot.py
@@ -86,84 +86,12 @@ class CustomBot(commands.Bot):
|
|||||||
"Ranked Minesweeper"
|
"Ranked Minesweeper"
|
||||||
])
|
])
|
||||||
self.remove_command("help")
|
self.remove_command("help")
|
||||||
self.adjectives_data = None
|
|
||||||
|
|
||||||
async def setup_hook(self):
|
async def setup_hook(self):
|
||||||
logger.info("Syncing commands...")
|
logger.info("Syncing commands...")
|
||||||
await self.tree.sync()
|
await self.tree.sync()
|
||||||
logger.info("Commands synced!")
|
logger.info("Commands synced!")
|
||||||
|
|
||||||
# Load adjectives asynchronously
|
|
||||||
adjectives_path = Path('adjectives.json')
|
|
||||||
if adjectives_path.exists():
|
|
||||||
try:
|
|
||||||
async with aiohttp.ClientSession() as session:
|
|
||||||
# Use aiofiles-like approach with asyncio
|
|
||||||
loop = asyncio.get_event_loop()
|
|
||||||
self.adjectives_data = await loop.run_in_executor(
|
|
||||||
None,
|
|
||||||
lambda: json.loads(adjectives_path.read_text())
|
|
||||||
)
|
|
||||||
logger.info("Adjectives data loaded successfully")
|
|
||||||
self.daily_adjective.start()
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Failed to load adjectives.json: {e}")
|
|
||||||
else:
|
|
||||||
logger.warning("adjectives.json not found, daily adjective task disabled")
|
|
||||||
|
|
||||||
@tasks.loop(time=datetime_time(hour=14))
|
|
||||||
async def daily_adjective(self):
|
|
||||||
try:
|
|
||||||
channel = self.get_channel(ANNOUNCEMENT_CHANNEL_ID)
|
|
||||||
if not channel:
|
|
||||||
logger.error(f"Failed to get announcement channel {ANNOUNCEMENT_CHANNEL_ID}")
|
|
||||||
return
|
|
||||||
|
|
||||||
if not self.adjectives_data or not self.adjectives_data.get("adjectives"):
|
|
||||||
logger.warning("No adjectives available")
|
|
||||||
return
|
|
||||||
|
|
||||||
# Get and remove today's adjective
|
|
||||||
adjective = self.adjectives_data["adjectives"].pop(0)
|
|
||||||
|
|
||||||
# Create and send embed
|
|
||||||
embed = discord.Embed(
|
|
||||||
title="📚 Adjective of the Day",
|
|
||||||
color=discord.Color.from_rgb(152, 0, 0),
|
|
||||||
timestamp=datetime.now()
|
|
||||||
)
|
|
||||||
embed.add_field(
|
|
||||||
name=adjective["word"].capitalize(),
|
|
||||||
value=adjective["definition"].capitalize(),
|
|
||||||
inline=False
|
|
||||||
)
|
|
||||||
embed.set_footer(text="Expand your vocabulary!")
|
|
||||||
|
|
||||||
await channel.send(embed=embed)
|
|
||||||
|
|
||||||
# Save updated adjectives list back to file asynchronously
|
|
||||||
loop = asyncio.get_event_loop()
|
|
||||||
await loop.run_in_executor(
|
|
||||||
None,
|
|
||||||
lambda: Path('adjectives.json').write_text(
|
|
||||||
json.dumps(self.adjectives_data, indent=4)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
# Reload list if empty
|
|
||||||
if not self.adjectives_data["adjectives"]:
|
|
||||||
logger.info("Adjectives list empty, reloading from file")
|
|
||||||
self.adjectives_data = await loop.run_in_executor(
|
|
||||||
None,
|
|
||||||
lambda: json.loads(Path('adjectives.json').read_text())
|
|
||||||
)
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Error in daily_adjective task: {e}", exc_info=True)
|
|
||||||
|
|
||||||
@daily_adjective.before_loop
|
|
||||||
async def before_daily_adjective(self):
|
|
||||||
await self.wait_until_ready()
|
|
||||||
|
|
||||||
@tasks.loop(seconds=STATUS_UPDATE_INTERVAL)
|
@tasks.loop(seconds=STATUS_UPDATE_INTERVAL)
|
||||||
async def change_status(self):
|
async def change_status(self):
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user