Compare commits
2 Commits
be50c2e203
...
057d21e531
| Author | SHA1 | Date | |
|---|---|---|---|
| 057d21e531 | |||
| a821b914c9 |
75
bot.py
75
bot.py
@@ -36,6 +36,7 @@ AUDIT_CHANNEL_ID = int(os.getenv('AUDIT_CHANNEL_ID', '1340861451392520233'))
|
|||||||
ANNOUNCEMENT_CHANNEL_ID = int(os.getenv('ANNOUNCEMENT_CHANNEL_ID', '605864889940050088'))
|
ANNOUNCEMENT_CHANNEL_ID = int(os.getenv('ANNOUNCEMENT_CHANNEL_ID', '605864889940050088'))
|
||||||
ADMIN_ROLE_ID = int(os.getenv('ADMIN_ROLE_ID', '605867042104541194'))
|
ADMIN_ROLE_ID = int(os.getenv('ADMIN_ROLE_ID', '605867042104541194'))
|
||||||
MINECRAFT_ROLE_ID = int(os.getenv('MINECRAFT_ROLE_ID', '821163520942145556'))
|
MINECRAFT_ROLE_ID = int(os.getenv('MINECRAFT_ROLE_ID', '821163520942145556'))
|
||||||
|
HYTALE_ROLE_ID = int(os.getenv('HYTALE_ROLE_ID', '1460750779848589548'))
|
||||||
COOL_KIDS_ROLE_ID = int(os.getenv('COOL_KIDS_ROLE_ID', '788968178117902347'))
|
COOL_KIDS_ROLE_ID = int(os.getenv('COOL_KIDS_ROLE_ID', '788968178117902347'))
|
||||||
OWNER_ID = int(os.getenv('OWNER_ID', '238728085342519296'))
|
OWNER_ID = int(os.getenv('OWNER_ID', '238728085342519296'))
|
||||||
REACTION_MESSAGE_ID = int(os.getenv('REACTION_MESSAGE_ID', '744047519696420914'))
|
REACTION_MESSAGE_ID = int(os.getenv('REACTION_MESSAGE_ID', '744047519696420914'))
|
||||||
@@ -86,84 +87,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:
|
||||||
@@ -662,7 +591,7 @@ async def minecraft(interaction: discord.Interaction, minecraft_username: str):
|
|||||||
|
|
||||||
@client.tree.command(name="hytale", description="Request whitelist on the Hytale server")
|
@client.tree.command(name="hytale", description="Request whitelist on the Hytale server")
|
||||||
@app_commands.describe(hytale_username="Your Hytale username")
|
@app_commands.describe(hytale_username="Your Hytale username")
|
||||||
@has_role_check(MINECRAFT_ROLE_ID)
|
@has_role_check(HYTALE_ROLE_ID)
|
||||||
async def hytale(interaction: discord.Interaction, hytale_username: str):
|
async def hytale(interaction: discord.Interaction, hytale_username: str):
|
||||||
"""Request whitelist on the Hytale server"""
|
"""Request whitelist on the Hytale server"""
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user