Repository: Cog-Creators/Red-DiscordBot

Issue:
[V3 Core] Unable to load streams cog with a set mixer alerts
# Command bugs

<!-- 
Did you find a bug with a command? Fill out the following:
-->

#### Command name

[p]load streams

#### What cog is this command from?

Core and Streams

#### What were you expecting to happen?

For the streams cog to load.

#### What actually happened?
I added a mixer stream and it worked but I updated to version 17 and noticed the streams cog wasn't loaded. so I did the load command and got this error. I deleted the json file and then it loaded jsut fine. Once I added a mixer stream the tried to reload the cog by first doing the unload command then doing the load command. I got the error again.

```
Exception during loading of cog
Traceback (most recent call last):
  File "/home/jjay/rewrite/lib/python3.6/site-packages/redbot/core/core_commands.py", line 87, in _load
    await bot.load_extension(spec)
  File "/home/jjay/rewrite/lib/python3.6/site-packages/redbot/core/bot.py", line 222, in load_extension
    await lib.setup(self)
  File "/home/jjay/rewrite/lib/python3.6/site-packages/redbot/cogs/streams/__init__.py", line 6, in setup
    await cog.initialize()
  File "/home/jjay/rewrite/lib/python3.6/site-packages/redbot/cogs/streams/streams.py", line 71, in initialize
    self.streams = await self.load_streams()
  File "/home/jjay/rewrite/lib/python3.6/site-packages/redbot/cogs/streams/streams.py", line 611, in load_streams
    token = await self.db.tokens.get_raw(_class.__name__)
  File "/home/jjay/rewrite/lib/python3.6/site-packages/redbot/core/config.py", line 342, in get_raw
    return await self.driver.get(*self.identifiers, *path)
  File "/home/jjay/rewrite/lib/python3.6/site-packages/redbot/core/drivers/red_json.py", line 100, in get
    partial = partial[i]
KeyError: 'MixerStream'
```

#### How can we reproduce this issue?

1. Add a mixer stream alert
2. Unload the stream cog
3. Load the streams cog


Discussion:
Hi, thanks for reporting this issue! I've set the milestone for the next beta (19), and I'll assign myself to try and get it done by then :)

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
@@ -608,16 +608,12 @@ async def load_streams(self):
                 chn = self.bot.get_channel(raw_msg["channel"])
                 msg = await chn.get_message(raw_msg["message"])
                 raw_stream["_messages_cache"].append(msg)
-            token = await self.db.tokens.get_raw(_class.__name__)
-            streams.append(_class(token=token, **raw_stream))
-
-        # 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()))]
+            token = await self.db.tokens.get_raw(_class.__name__, default=None)
+            if token is not None:
+                raw_stream["token"] = token
+            streams.append(_class(**raw_stream))
 
-        # return streams
+        return streams
 
     async def load_communities(self):
         communities = []


Test patch: