[commands] Add special extension function 'teardown' for clean-up.
This is to support people who want to clean up some external resource that the extension is maintaining outside of a cog, where __unload should be used instead. The callable is the antipode of 'setup' and takes the same sole parameter, the bot, after all commands, events, and cogs have been unloaded. Fixes #405.
This commit is contained in:
		| @@ -764,10 +764,20 @@ class Bot(GroupMixin, discord.Client): | |||||||
|             for index in reversed(remove): |             for index in reversed(remove): | ||||||
|                 del event_list[index] |                 del event_list[index] | ||||||
|  |  | ||||||
|         # finally remove the import.. |         try: | ||||||
|         del lib |             func = getattr(lib, 'teardown') | ||||||
|         del self.extensions[name] |         except AttributeError: | ||||||
|         del sys.modules[name] |             pass | ||||||
|  |         else: | ||||||
|  |             try: | ||||||
|  |                 func(bot) | ||||||
|  |             except: | ||||||
|  |                 pass | ||||||
|  |         finally: | ||||||
|  |             # finally remove the import.. | ||||||
|  |             del lib | ||||||
|  |             del self.extensions[name] | ||||||
|  |             del sys.modules[name] | ||||||
|  |  | ||||||
|     # command processing |     # command processing | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user