Migrate scripts to voicelink, rewrite handlers and views

This commit is contained in:
Choco
2025-09-29 19:39:19 +08:00
parent 7a4f85a74d
commit ef54f96f51
52 changed files with 2048 additions and 1642 deletions

View File

@@ -26,7 +26,6 @@ import discord
import function as func
from discord.ext import commands, tasks
from addons import Placeholders
class Task(commands.Cog):
def __init__(self, bot: commands.Bot):
@@ -36,7 +35,7 @@ class Task(commands.Cog):
self.cache_cleaner.start()
self.current_act = 0
self.placeholder = Placeholders(bot)
self.placeholder = voicelink.BotPlaceholder(bot)
def cog_unload(self):
self.activity_update.cancel()
@@ -48,7 +47,7 @@ class Task(commands.Cog):
await self.bot.wait_until_ready()
try:
act_data = func.settings.activity[(self.current_act + 1) % len(func.settings.activity) - 1]
act_data = voicelink.Config().activity[(self.current_act + 1) % len(voicelink.Config().activity) - 1]
act_original = self.bot.activity
act_type = getattr(discord.ActivityType, act_data.get("type", "").lower(), discord.ActivityType.playing)
act_name = self.placeholder.replace(act_data.get("name", ""))
@@ -58,7 +57,7 @@ class Task(commands.Cog):
if act_original.type != act_type or act_original.name != act_name:
self.bot.activity = discord.Activity(type=act_type, name=act_name)
await self.bot.change_presence(activity=self.bot.activity, status=status_type)
self.current_act = (self.current_act + 1) % len(func.settings.activity)
self.current_act = (self.current_act + 1) % len(voicelink.Config().activity)
func.logger.info(f"Changed the bot status to {act_name}")
@@ -104,8 +103,7 @@ class Task(commands.Cog):
@tasks.loop(hours=12.0)
async def cache_cleaner(self):
func.SETTINGS_BUFFER.clear()
func.USERS_BUFFER.clear()
await voicelink.MongoDBHandler.cleanup_cache()
async def setup(bot: commands.Bot):
await bot.add_cog(Task(bot))