mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-21 18:27:59 -05:00
[Audio] Redefine max length with livestream exception (#3878)
* Redefine max length with livestream exception * Address review * is_track_too_long -> is_track_length_allowed for a more accurate description of what the function actually is doing * we now rely on Track.is_stream for determining whether item is a livestream (or unseekable/non-known audio length like OGG files) for determining whether it can bypass the user-set max track length * Removal of passing track length/an int to is_track_length_allowed - will always pass the full Track object now * Address review
This commit is contained in:
@@ -165,7 +165,7 @@ class FormattingUtilities(MixinMeta, metaclass=CompositeMetaClass):
|
||||
)
|
||||
elif guild_data["maxlength"] > 0:
|
||||
|
||||
if self.is_track_too_long(search_choice.length, guild_data["maxlength"]):
|
||||
if self.is_track_length_allowed(search_choice, guild_data["maxlength"]):
|
||||
player.add(ctx.author, search_choice)
|
||||
player.maybe_shuffle()
|
||||
self.bot.dispatch(
|
||||
|
||||
@@ -435,7 +435,7 @@ class PlayerUtilities(MixinMeta, metaclass=CompositeMetaClass):
|
||||
log.debug(f"Query is not allowed in {ctx.guild} ({ctx.guild.id})")
|
||||
continue
|
||||
elif guild_data["maxlength"] > 0:
|
||||
if self.is_track_too_long(track, guild_data["maxlength"]):
|
||||
if self.is_track_length_allowed(track, guild_data["maxlength"]):
|
||||
track_len += 1
|
||||
player.add(ctx.author, track)
|
||||
self.bot.dispatch(
|
||||
@@ -514,7 +514,7 @@ class PlayerUtilities(MixinMeta, metaclass=CompositeMetaClass):
|
||||
ctx, title=_("This track is not allowed in this server.")
|
||||
)
|
||||
elif guild_data["maxlength"] > 0:
|
||||
if self.is_track_too_long(single_track, guild_data["maxlength"]):
|
||||
if self.is_track_length_allowed(single_track, guild_data["maxlength"]):
|
||||
player.add(ctx.author, single_track)
|
||||
player.maybe_shuffle()
|
||||
self.bot.dispatch(
|
||||
@@ -661,12 +661,10 @@ class PlayerUtilities(MixinMeta, metaclass=CompositeMetaClass):
|
||||
else:
|
||||
return False
|
||||
|
||||
def is_track_too_long(self, track: Union[lavalink.Track, int], maxlength: int) -> bool:
|
||||
try:
|
||||
length = round(track.length / 1000)
|
||||
except AttributeError:
|
||||
length = round(track / 1000)
|
||||
|
||||
if maxlength < length <= 92233720368547758070: # livestreams return 9223372036854775807ms
|
||||
def is_track_length_allowed(self, track: lavalink.Track, maxlength: int) -> bool:
|
||||
if track.is_stream:
|
||||
return True
|
||||
length = track.length / 1000
|
||||
if length > maxlength:
|
||||
return False
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user