Fix the bug with Twitch display name being set as Twitch login (#5066)

This commit is contained in:
jack1142 2021-05-25 10:32:32 +02:00 committed by GitHub
parent 982feda858
commit f8ecc32dbc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 13 deletions

View File

@ -200,7 +200,10 @@ Use ``{mention}`` in the message to insert the selected mentions.
Use ``{stream}`` in the message to insert the channel or user name. Use ``{stream}`` in the message to insert the channel or user name.
For example: ``[p]streamset message mention {mention}, {stream} is live!`` Use ``{stream.display_name}`` in the message to insert the channel's display name
(on Twitch, this may be different from ``{stream}``).
For example: ``[p]streamset message mention {mention}, {stream.display_name} is live!``
**Arguments** **Arguments**
@ -224,7 +227,10 @@ Sets a stream alert message for when mentions are disabled.
Use ``{stream}`` in the message to insert the channel or user name. Use ``{stream}`` in the message to insert the channel or user name.
For example: ``[p]streamset message nomention {stream} is live!`` Use ``{stream.display_name}`` in the message to insert the channel's display name
(on Twitch, this may be different from ``{stream}``).
For example: ``[p]streamset message nomention {stream.display_name} is live!``
**Arguments** **Arguments**

View File

@ -528,9 +528,10 @@ class Streams(commands.Cog):
"""Set stream alert message when mentions are enabled. """Set stream alert message when mentions are enabled.
Use `{mention}` in the message to insert the selected mentions. Use `{mention}` in the message to insert the selected mentions.
Use `{stream}` in the message to insert the channel or user name. Use `{stream}` in the message to insert the channel or username.
Use `{stream.display_name}` in the message to insert the channel's display name (on Twitch, this may be different from `{stream}`).
For example: `[p]streamset message mention {mention}, {stream} is live!` For example: `[p]streamset message mention {mention}, {stream.display_name} is live!`
""" """
guild = ctx.guild guild = ctx.guild
await self.config.guild(guild).live_message_mention.set(message) await self.config.guild(guild).live_message_mention.set(message)
@ -541,9 +542,10 @@ class Streams(commands.Cog):
async def without_mention(self, ctx: commands.Context, *, message: str): async def without_mention(self, ctx: commands.Context, *, message: str):
"""Set stream alert message when mentions are disabled. """Set stream alert message when mentions are disabled.
Use `{stream}` in the message to insert the channel or user name. Use `{stream}` in the message to insert the channel or username.
Use `{stream.display_name}` in the message to insert the channel's display name (on Twitch, this may be different from `{stream}`).
For example: `[p]streamset message nomention {stream} is live!` For example: `[p]streamset message nomention {stream.display_name} is live!`
""" """
guild = ctx.guild guild = ctx.guild
await self.config.guild(guild).live_message_nomention.set(message) await self.config.guild(guild).live_message_nomention.set(message)
@ -808,13 +810,18 @@ class Streams(commands.Cog):
content = content.replace( content = content.replace(
"{stream.name}", str(stream.name) "{stream.name}", str(stream.name)
) # Backwards compatibility ) # Backwards compatibility
content = content.replace(
"{stream.display_name}", str(stream.display_name)
)
content = content.replace("{stream}", str(stream.name)) content = content.replace("{stream}", str(stream.name))
content = content.replace("{mention}", mention_str) content = content.replace("{mention}", mention_str)
else: else:
content = _("{mention}, {stream} is live!").format( content = _("{mention}, {display_name} is live!").format(
mention=mention_str, mention=mention_str,
stream=escape( display_name=escape(
str(stream.name), mass_mentions=True, formatting=True str(stream.display_name),
mass_mentions=True,
formatting=True,
), ),
) )
else: else:
@ -826,11 +833,16 @@ class Streams(commands.Cog):
content = content.replace( content = content.replace(
"{stream.name}", str(stream.name) "{stream.name}", str(stream.name)
) # Backwards compatibility ) # Backwards compatibility
content = content.replace(
"{stream.display_name}", str(stream.display_name)
)
content = content.replace("{stream}", str(stream.name)) content = content.replace("{stream}", str(stream.name))
else: else:
content = _("{stream} is live!").format( content = _("{display_name} is live!").format(
stream=escape( display_name=escape(
str(stream.name), mass_mentions=True, formatting=True str(stream.display_name),
mass_mentions=True,
formatting=True,
) )
) )
await self._send_stream_alert(stream, channel, embed, content) await self._send_stream_alert(stream, channel, embed, content)

View File

@ -65,6 +65,10 @@ class Stream:
self.messages = kwargs.pop("messages", []) self.messages = kwargs.pop("messages", [])
self.type = self.__class__.__name__ self.type = self.__class__.__name__
@property
def display_name(self) -> Optional[str]:
return self.name
async def is_online(self): async def is_online(self):
raise NotImplementedError() raise NotImplementedError()
@ -299,12 +303,21 @@ class TwitchStream(Stream):
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.id = kwargs.pop("id", None) self.id = kwargs.pop("id", None)
self._display_name = None
self._client_id = kwargs.pop("token", None) self._client_id = kwargs.pop("token", None)
self._bearer = kwargs.pop("bearer", None) self._bearer = kwargs.pop("bearer", None)
self._rate_limit_resets: set = set() self._rate_limit_resets: set = set()
self._rate_limit_remaining: int = 0 self._rate_limit_remaining: int = 0
super().__init__(**kwargs) super().__init__(**kwargs)
@property
def display_name(self) -> Optional[str]:
return self._display_name or self.name
@display_name.setter
def display_name(self, value: str) -> None:
self._display_name = value
async def wait_for_rate_limit_reset(self) -> None: async def wait_for_rate_limit_reset(self) -> None:
"""Check rate limits in response header and ensure we're following them. """Check rate limits in response header and ensure we're following them.
@ -378,7 +391,7 @@ class TwitchStream(Stream):
final_data["view_count"] = user_profile_data["view_count"] final_data["view_count"] = user_profile_data["view_count"]
stream_data = stream_data["data"][0] stream_data = stream_data["data"][0]
final_data["user_name"] = self.name = stream_data["user_name"] final_data["user_name"] = self.display_name = stream_data["user_name"]
final_data["game_name"] = stream_data["game_name"] final_data["game_name"] = stream_data["game_name"]
final_data["thumbnail_url"] = stream_data["thumbnail_url"] final_data["thumbnail_url"] = stream_data["thumbnail_url"]
final_data["title"] = stream_data["title"] final_data["title"] = stream_data["title"]