mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
[V3 Streams] Duplicate stream alerts fix (#1244)
case insensitive on twitch streams, with a fast dedupe on load toany prior bad entries.
This commit is contained in:
parent
4ac606b468
commit
f1a20e1677
@ -108,13 +108,13 @@ class Streams:
|
|||||||
@_twitch.command(name="channel")
|
@_twitch.command(name="channel")
|
||||||
async def twitch_alert_channel(self, ctx: RedContext, channel_name: str):
|
async def twitch_alert_channel(self, ctx: RedContext, channel_name: str):
|
||||||
"""Sets a Twitch stream alert notification in the channel"""
|
"""Sets a Twitch stream alert notification in the channel"""
|
||||||
await self.stream_alert(ctx, TwitchStream, channel_name)
|
await self.stream_alert(ctx, TwitchStream, channel_name.lower())
|
||||||
|
|
||||||
@_twitch.command(name="community")
|
@_twitch.command(name="community")
|
||||||
async def twitch_alert_community(self, ctx: RedContext, community: str):
|
async def twitch_alert_community(self, ctx: RedContext, community: str):
|
||||||
"""Sets a Twitch stream alert notification in the channel
|
"""Sets a Twitch stream alert notification in the channel
|
||||||
for the specified community."""
|
for the specified community."""
|
||||||
await self.community_alert(ctx, TwitchCommunity, community)
|
await self.community_alert(ctx, TwitchCommunity, community.lower())
|
||||||
|
|
||||||
@streamalert.command(name="hitbox")
|
@streamalert.command(name="hitbox")
|
||||||
async def hitbox_alert(self, ctx, channel_name: str):
|
async def hitbox_alert(self, ctx, channel_name: str):
|
||||||
@ -171,7 +171,7 @@ class Streams:
|
|||||||
for stream in self.streams:
|
for stream in self.streams:
|
||||||
for channel_id in stream.channels:
|
for channel_id in stream.channels:
|
||||||
if channel_id in guild_channels_ids:
|
if channel_id in guild_channels_ids:
|
||||||
streams_list[channel_id].append(stream.name)
|
streams_list[channel_id].append(stream.name.lower())
|
||||||
|
|
||||||
if not streams_list:
|
if not streams_list:
|
||||||
await ctx.send("There are no active stream alerts in this server.")
|
await ctx.send("There are no active stream alerts in this server.")
|
||||||
@ -185,7 +185,7 @@ class Streams:
|
|||||||
await ctx.send(page)
|
await ctx.send(page)
|
||||||
|
|
||||||
async def stream_alert(self, ctx, _class, channel_name):
|
async def stream_alert(self, ctx, _class, channel_name):
|
||||||
stream = self.get_stream(_class, channel_name)
|
stream = self.get_stream(_class, channel_name.lower())
|
||||||
if not stream:
|
if not stream:
|
||||||
token = await self.db.tokens.get_attr(_class.__name__)
|
token = await self.db.tokens.get_attr(_class.__name__)
|
||||||
stream = _class(name=channel_name,
|
stream = _class(name=channel_name,
|
||||||
@ -365,12 +365,12 @@ class Streams:
|
|||||||
# isinstance will always return False
|
# isinstance will always return False
|
||||||
# As a workaround, we'll compare the class' name instead.
|
# As a workaround, we'll compare the class' name instead.
|
||||||
# Good enough.
|
# Good enough.
|
||||||
if stream.type == _class.__name__ and stream.name == name:
|
if stream.type == _class.__name__ and stream.name.lower() == name.lower():
|
||||||
return stream
|
return stream
|
||||||
|
|
||||||
def get_community(self, _class, name):
|
def get_community(self, _class, name):
|
||||||
for community in self.communities:
|
for community in self.communities:
|
||||||
if community.type == _class.__name__ and community.name == name:
|
if community.type == _class.__name__ and community.name.lower() == name.lower():
|
||||||
return community
|
return community
|
||||||
|
|
||||||
async def check_exists(self, stream):
|
async def check_exists(self, stream):
|
||||||
@ -480,7 +480,14 @@ class Streams:
|
|||||||
token = await self.db.tokens.get_attr(_class.__name__)
|
token = await self.db.tokens.get_attr(_class.__name__)
|
||||||
streams.append(_class(token=token, **raw_stream))
|
streams.append(_class(token=token, **raw_stream))
|
||||||
|
|
||||||
return streams
|
# issue 1191 extended resolution: Remove this after suitable period
|
||||||
|
# Fast dedupe below
|
||||||
|
seen = set()
|
||||||
|
seen_add = seen.add
|
||||||
|
return [x for x in streams
|
||||||
|
if not (x.name.lower() in seen or seen_add(x.name.lower()))]
|
||||||
|
|
||||||
|
# return streams
|
||||||
|
|
||||||
async def load_communities(self):
|
async def load_communities(self):
|
||||||
communities = []
|
communities = []
|
||||||
@ -493,7 +500,13 @@ class Streams:
|
|||||||
token = await self.db.tokens.get_attr(_class.__name__)
|
token = await self.db.tokens.get_attr(_class.__name__)
|
||||||
communities.append(_class(token=token, **raw_community))
|
communities.append(_class(token=token, **raw_community))
|
||||||
|
|
||||||
return communities
|
# issue 1191 extended resolution: Remove this after suitable period
|
||||||
|
# Fast dedupe below
|
||||||
|
seen = set()
|
||||||
|
seen_add = seen.add
|
||||||
|
return [x for x in communities
|
||||||
|
if not (x.name.lower() in seen or seen_add(x.name.lower()))]
|
||||||
|
# return communities
|
||||||
|
|
||||||
async def save_streams(self):
|
async def save_streams(self):
|
||||||
raw_streams = []
|
raw_streams = []
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user