(nowdoing): Migrate to merged LionCog.

This commit is contained in:
2024-09-08 16:35:37 +10:00
parent 99bb1958a8
commit 85c7aeb3b6
3 changed files with 19 additions and 19 deletions

View File

@@ -27,10 +27,10 @@ active_discord = [
'.streamalerts', '.streamalerts',
'.test', '.test',
'.counters', '.counters',
'.nowdoing',
] ]
active_twitch = [ active_twitch = [
'.nowdoing',
'.shoutouts', '.shoutouts',
'.tagstrings', '.tagstrings',
] ]

View File

@@ -4,6 +4,5 @@ logger = logging.getLogger(__name__)
from .cog import NowDoingCog from .cog import NowDoingCog
def prepare(bot): async def setup(bot):
logger.info("Preparing the nowdoing module.") await bot.add_cog(NowDoingCog(bot))
bot.add_cog(NowDoingCog(bot))

View File

@@ -8,7 +8,8 @@ from attr import dataclass
import twitchio import twitchio
from twitchio.ext import commands from twitchio.ext import commands
from meta import CrocBot from meta import CrocBot, LionCog
from meta.LionBot import LionBot
from meta.sockets import Channel, register_channel from meta.sockets import Channel, register_channel
from utils.lib import strfdelta, utc_now from utils.lib import strfdelta, utc_now
from . import logger from . import logger
@@ -78,10 +79,11 @@ class NowDoingChannel(Channel):
}) })
class NowDoingCog(commands.Cog): class NowDoingCog(LionCog):
def __init__(self, bot: CrocBot): def __init__(self, bot: LionBot):
self.bot = bot self.bot = bot
self.data = bot.data.load_registry(NowListData()) self.crocbot = bot.crocbot
self.data = bot.db.load_registry(NowListData())
self.channel = NowDoingChannel(self) self.channel = NowDoingChannel(self)
register_channel(self.channel.name, self.channel) register_channel(self.channel.name, self.channel)
@@ -94,21 +96,19 @@ class NowDoingCog(commands.Cog):
await self.data.init() await self.data.init()
await self.load_tasks() await self.load_tasks()
self._load_twitch_methods(self.crocbot)
self.loaded.set() self.loaded.set()
async def ensure_loaded(self): async def cog_unload(self):
""" self.loaded.clear()
Hack because lib devs decided to remove async cog loading. self.tasks.clear()
""" self._unload_twitch_methods(self.crocbot)
if not self.loaded.is_set():
await self.cog_load()
@commands.Cog.event('event_ready') # type: ignore
async def on_ready(self):
await self.ensure_loaded()
async def cog_check(self, ctx): async def cog_check(self, ctx):
await self.ensure_loaded() if not self.loaded.is_set():
await ctx.reply("Tasklists are still loading! Please wait a moment~")
return False
return True return True
async def load_tasks(self): async def load_tasks(self):
@@ -130,6 +130,7 @@ class NowDoingCog(commands.Cog):
@commands.command(aliases=['task', 'check']) @commands.command(aliases=['task', 'check'])
async def now(self, ctx: commands.Context, *, args: Optional[str] = None): async def now(self, ctx: commands.Context, *, args: Optional[str] = None):
userid = int(ctx.author.id) userid = int(ctx.author.id)
args = args.strip() if args else None
if args: if args:
await self.data.Task.table.delete_where(userid=userid) await self.data.Task.table.delete_where(userid=userid)
task = await self.data.Task.create( task = await self.data.Task.create(