(tags): Migrated to merged LionCog.
This commit is contained in:
@@ -29,17 +29,9 @@ active_discord = [
|
|||||||
'.counters',
|
'.counters',
|
||||||
'.nowdoing',
|
'.nowdoing',
|
||||||
'.shoutouts',
|
'.shoutouts',
|
||||||
]
|
|
||||||
|
|
||||||
active_twitch = [
|
|
||||||
'.tagstrings',
|
'.tagstrings',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def prepare(bot):
|
|
||||||
for ext in active_twitch:
|
|
||||||
bot.load_module(this_package + ext)
|
|
||||||
|
|
||||||
async def setup(bot):
|
async def setup(bot):
|
||||||
for ext in active_discord:
|
for ext in active_discord:
|
||||||
await bot.load_extension(ext, package=this_package)
|
await bot.load_extension(ext, package=this_package)
|
||||||
|
|||||||
@@ -4,5 +4,5 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
from .cog import TagCog
|
from .cog import TagCog
|
||||||
|
|
||||||
def prepare(bot):
|
async def setup(bot):
|
||||||
bot.add_cog(TagCog(bot))
|
await bot.add_cog(TagCog(bot))
|
||||||
|
|||||||
@@ -6,16 +6,17 @@ import difflib
|
|||||||
import twitchio
|
import twitchio
|
||||||
from twitchio.ext import commands
|
from twitchio.ext import commands
|
||||||
|
|
||||||
from meta import CrocBot
|
from meta import CrocBot, LionBot, LionCog
|
||||||
from utils.lib import utc_now
|
from utils.lib import utc_now
|
||||||
from . import logger
|
from . import logger
|
||||||
from .data import TagData
|
from .data import TagData
|
||||||
|
|
||||||
|
|
||||||
class TagCog(commands.Cog):
|
class TagCog(LionCog):
|
||||||
def __init__(self, bot: CrocBot):
|
def __init__(self, bot: LionBot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.data = bot.data.load_registry(TagData())
|
self.crocbot = bot.crocbot
|
||||||
|
self.data = bot.db.load_registry(TagData())
|
||||||
|
|
||||||
self.loaded = asyncio.Event()
|
self.loaded = asyncio.Event()
|
||||||
|
|
||||||
@@ -31,19 +32,24 @@ class TagCog(commands.Cog):
|
|||||||
|
|
||||||
self.tags.clear()
|
self.tags.clear()
|
||||||
self.tags.update(tags)
|
self.tags.update(tags)
|
||||||
|
logger.info(f"Loaded {len(tags)} into cache.")
|
||||||
|
|
||||||
async def cog_load(self):
|
async def cog_load(self):
|
||||||
await self.data.init()
|
await self.data.init()
|
||||||
await self.load_tags()
|
await self.load_tags()
|
||||||
|
self._load_twitch_methods(self.crocbot)
|
||||||
self.loaded.set()
|
self.loaded.set()
|
||||||
|
|
||||||
async def ensure_loaded(self):
|
async def cog_unload(self):
|
||||||
if not self.loaded.is_set():
|
self.loaded.clear()
|
||||||
await self.cog_load()
|
self.tags.clear()
|
||||||
|
self._unload_twitch_methods(self.crocbot)
|
||||||
|
|
||||||
@commands.Cog.event('event_ready')
|
async def cog_check(self, ctx):
|
||||||
async def on_ready(self):
|
if not self.loaded.is_set():
|
||||||
await self.ensure_loaded()
|
await ctx.reply("Tasklists are still loading! Please wait a moment~")
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
# API
|
# API
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user