sir-lancebot
sir-lancebot copied to clipboard
Add logic for preserving unloaded Cogs.
This PR makes a Redis cache in bot.bot
to store all the unloaded extensions, on every unload and load this cache would be edited in the desired manner, either removing it from it or adding it in the cache.
Now, coming to not loading the unloaded commands, on bot startup, just after Redis gets connected, the bot would run bot.get_unloaded_extensions
and get all the unloaded extensions from the cache. These extensions would be skipped and not loaded, the skipping message would be logged. Once all these extensions are loaded, we compare and check which
extensions are present in the cache and not the bot. This means these cogs are either removed or renamed.
A message containing all these "extra" cogs are sent to #dev-alerts and these cogs are removed from the cache.
Resolves: #705
Flow with screenshots
1: Cache containing 'bot.exts.evergreen.catify | bot.exts.evergreen.xkd'
2: After bot sends ^
3: On doing .exts unload ping
4: On doing .exts load ping
Todo
- [x] There is a small bug in this, I will fix that soon, since the bot removes the cogs from the cache first and then performs the action, it will also remove the cogs which have been failed to auction.
- [ ] Remove testing code
- [ ] Add core-developers role to allowed mention, need to discuss if it should be allowed overall or just while the alert message is sent.
With your current approach, you store the cached unloads into a dict, then remove successfully unloaded cogs from the dict in
load_extension
, then compare the dict with the cached unloads to find missing cogs.A better solution would be to just go ahead with loading the extension (and checking presence in the cache before loading), and storing a set of successfully unloaded cogs instead. Then, you can get all the unloads from the cache and clean up the ones that were not in the successful dict.
This can be done with a
load_extensions
method on the bot that keep tracks of extensions that were successfully unloaded locally. That way, there's no need to store a redundant instance attribute after startup. It would also reduce the chances of race conditions with getting the unloaded cogs/loading cogs/checking for not found cogs.
That would be possible if we make load_extensions
an async function, since to check whether it exists within the async redis-cache or not it would be awaited. Hence I didn't do that.
Would that be an issue? It wouldn't be much unlike how you're getting the unloaded extensions after all. I'm not an async expert though
Would that be an issue? It wouldn't be much unlike how you're getting the unloaded extensions after all. I'm not an async expert though
Not really but I would need to add await
/async
in the some places (The extensions cog, and bot/__main__.py
probably).
File restructure has occurred, it may have been the cause of these conflicts.
This PR is now up for grabs. Would anyone that's currently subscribed to this thread or just happened to see this comment like to take over this feature?
Hello, Iād like to have a go at this in a separate PR.
@Xithrius Currently this PR is complete, only needs another core-dev approval. IIRC Chris was looking to review this, not sure how far he has got.
Cool okay šš» , let me know if you need any help while going through the code @ToxicKidz.
Whoops, didn't mean to request another review from you, @Bluenix2. Sorry about that. You can ignore this notification.
@ToxicKidz When you have the time, please resolve the file conflicts within this PR. Thanks!
Due to the staleness of this PR, I'll be closing it. If anyone wants to pick it back up, feel free to do so.