mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
[V3 Streams] Fix streams race condition (#1834)
This commit is contained in:
parent
9e7bc94aab
commit
a070dffb93
@ -1,5 +1,7 @@
|
|||||||
from .streams import Streams
|
from .streams import Streams
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
async def setup(bot):
|
||||||
bot.add_cog(Streams(bot))
|
cog = Streams(bot)
|
||||||
|
await cog.initialize()
|
||||||
|
bot.add_cog(cog)
|
||||||
|
|||||||
@ -4,6 +4,7 @@ from redbot.core.utils.chat_formatting import pagify
|
|||||||
from redbot.core.bot import Red
|
from redbot.core.bot import Red
|
||||||
from redbot.core.i18n import Translator, cog_i18n
|
from redbot.core.i18n import Translator, cog_i18n
|
||||||
from .streamtypes import (
|
from .streamtypes import (
|
||||||
|
Stream,
|
||||||
TwitchStream,
|
TwitchStream,
|
||||||
HitboxStream,
|
HitboxStream,
|
||||||
MixerStream,
|
MixerStream,
|
||||||
@ -25,6 +26,7 @@ from . import streamtypes as StreamClasses
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
import asyncio
|
import asyncio
|
||||||
import re
|
import re
|
||||||
|
from typing import Optional, List
|
||||||
|
|
||||||
CHECK_DELAY = 60
|
CHECK_DELAY = 60
|
||||||
|
|
||||||
@ -50,9 +52,11 @@ class Streams:
|
|||||||
|
|
||||||
self.db.register_role(**self.role_defaults)
|
self.db.register_role(**self.role_defaults)
|
||||||
|
|
||||||
self.bot = bot
|
self.bot: Red = bot
|
||||||
|
|
||||||
self.bot.loop.create_task(self._initialize_lists())
|
self.streams: List[Stream] = []
|
||||||
|
self.communities: List[TwitchCommunity] = []
|
||||||
|
self.task: Optional[asyncio.Task] = None
|
||||||
|
|
||||||
self.yt_cid_pattern = re.compile("^UC[-_A-Za-z0-9]{21}[AQgw]$")
|
self.yt_cid_pattern = re.compile("^UC[-_A-Za-z0-9]{21}[AQgw]$")
|
||||||
|
|
||||||
@ -62,7 +66,8 @@ class Streams:
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
async def _initialize_lists(self):
|
async def initialize(self) -> None:
|
||||||
|
"""Should be called straight after cog instantiation."""
|
||||||
self.streams = await self.load_streams()
|
self.streams = await self.load_streams()
|
||||||
self.communities = await self.load_communities()
|
self.communities = await self.load_communities()
|
||||||
|
|
||||||
@ -662,4 +667,5 @@ class Streams:
|
|||||||
await self.db.communities.set(raw_communities)
|
await self.db.communities.set(raw_communities)
|
||||||
|
|
||||||
def __unload(self):
|
def __unload(self):
|
||||||
|
if self.task:
|
||||||
self.task.cancel()
|
self.task.cancel()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user