Repository: Cog-Creators/Red-DiscordBot

Issue:
Bot sends messages to owners on each load of streams cog
# Other bugs

#### What were you trying to do?

Load streams cog

#### What were you expecting to happen?

Nothing

#### What actually happened?

I got a message that I need to set up a client secret key

#### How can we reproduce this issue?

1. Set twitch client_id (can be invalid) in shared api tokens:
`[p]set api twitch client_id anything`
2. Reload cog
3. Bot sends message to owners about missing client secret
4. Repeat step 2
5. Bot does sends the message again.

I wouldn't even mind this error if there were option to clear api tokens for a service but since there isn't, this is getting annoying.



Discussion:

Resolving patch:
diff --git a/redbot/cogs/streams/streams.py b/redbot/cogs/streams/streams.py
--- a/redbot/cogs/streams/streams.py
+++ b/redbot/cogs/streams/streams.py
@@ -39,7 +39,12 @@
 @cog_i18n(_)
 class Streams(commands.Cog):
 
-    global_defaults = {"refresh_timer": 300, "tokens": {}, "streams": []}
+    global_defaults = {
+        "refresh_timer": 300,
+        "tokens": {},
+        "streams": [],
+        "notified_owner_missing_twitch_secret": False,
+    }
 
     guild_defaults = {
         "autodelete": False,
@@ -109,11 +114,16 @@ async def move_api_keys(self) -> None:
     async def get_twitch_bearer_token(self) -> None:
         tokens = await self.bot.get_shared_api_tokens("twitch")
         if tokens.get("client_id"):
+            notified_owner_missing_twitch_secret = (
+                await self.config.notified_owner_missing_twitch_secret()
+            )
             try:
                 tokens["client_secret"]
+                if notified_owner_missing_twitch_secret is True:
+                    await self.config.notified_owner_missing_twitch_secret.set(False)
             except KeyError:
                 message = _(
-                    "You need a client secret key to use correctly Twitch API on this cog.\n"
+                    "You need a client secret key if you want to use the Twitch API on this cog.\n"
                     "Follow these steps:\n"
                     "1. Go to this page: https://dev.twitch.tv/console/apps.\n"
                     '2. Click "Manage" on your application.\n'
@@ -121,10 +131,13 @@ async def get_twitch_bearer_token(self) -> None:
                     "5. Copy your client ID and your client secret into:\n"
                     "`[p]set api twitch client_id <your_client_id_here> "
                     "client_secret <your_client_secret_here>`\n\n"
-                    "Note: These tokens are sensitive and should only be used in a private channel "
+                    "Note: These tokens are sensitive and should "
+                    "only be used in a private channel "
                     "or in DM with the bot."
                 )
-                await send_to_owners_with_prefix_replaced(self.bot, message)
+                if notified_owner_missing_twitch_secret is False:
+                    await send_to_owners_with_prefix_replaced(self.bot, message)
+                    await self.config.notified_owner_missing_twitch_secret.set(True)
         async with aiohttp.ClientSession() as session:
             async with session.post(
                 "https://id.twitch.tv/oauth2/token",


Test patch: