Skip to content

Conversation

@onerandomusername
Copy link
Contributor

@onerandomusername onerandomusername commented Aug 4, 2021

Description

Adds the ability to load extensions, and manage them.

Most of the code of the first commit is taken from this project, at that position in time.

Added

  • Bot modes to determine behaviour. Multiple can be applied at once.
    • PROD: the default mode, no dev extensions or dev plugins load
    • DEVELOP: the bot developer mode, most useful for people adding features to modmail
      • Enables the extension_manager extension.
    • PLUGIN_DEV: the plugin developer mode, useful for enabling plugin-specific features
      • This is not used yet.
  • Extension loading system
    • scans for extensions in the modmail/extensions folder and loads them if they are of the right format.
  • Plugin loading system
    • scans for plugins in the modmail/plugins folder and loads them.
  • Extension management commands
    • load, reload, unload, list, refresh commands for dealing with extensions
    • Run the ext command for more details when the bot is in DEVELOP mode.
  • Plugin management commands
    • load, reload, unload, list, refresh commands for dealing with plugins
    • Run the plugins command for more details.
  • Extension metadata
    • used to determine if a cog should load or not depending on the bot mode
  • Plugin helper file
    • modmail/plugin_helpers.py contains several helpers for making plugins
      • PluginCog
      • ModmailBot, imported from modmail.bot
      • ModmailLogger, imported from modmail.log
  • Meta Cog
    • NOTE: The commands in this cog is not stabilized yet and should not be relied upon.
    • Prefix command for getting the set prefix. Most useful by mentioning the bot.
    • Uptime command tells the end-user how long the bot has been online.
    • Ping command to see the bot latency.
  • Guide on how to contribute to modmail, see CONTRIBUTING.md
  • Start a Changelog
  • Add changelog style verify CI check

Fixed

  • Make the bot http_session within an event loop.

Todo in later issues:

  • manage installing plugins and updating them from Github
  • metadata to determine when in bot start to load extensions (deferred to later pull)
  • metadata to determine dependencies on any other extensions/plugins (deferred to later pull)
  • test suite for all of this new code (deferred to later pull)
  • mock attributes for discord py components (deferred to later pull)

@onerandomusername onerandomusername added a: bot l: intermediate p: high High Priority s: approved The issue has received a maintainer's approval s: WIP Waiting for author to address a review or respond to a comment t: feature Relating to the functionality of the application. labels Aug 4, 2021
@onerandomusername onerandomusername self-assigned this Aug 4, 2021
@codecov
Copy link

codecov bot commented Aug 4, 2021

Codecov Report

Merging #43 (f708632) into main (a65e576) will decrease coverage by 54.59%.
The diff coverage is 23.15%.

Impacted file tree graph

@@             Coverage Diff             @@
##             main      #43       +/-   ##
===========================================
- Coverage   91.51%   36.92%   -54.60%     
===========================================
  Files           5       12        +7     
  Lines         283      520      +237     
  Branches        7       60       +53     
===========================================
- Hits          259      192       -67     
- Misses         20      323      +303     
- Partials        4        5        +1     
Impacted Files Coverage Δ
modmail/extensions/extension_manager.py 0.00% <0.00%> (ø)
modmail/extensions/meta.py 0.00% <0.00%> (ø)
modmail/extensions/plugin_manager.py 0.00% <0.00%> (ø)
modmail/plugin_helpers.py 0.00% <0.00%> (ø)
modmail/bot.py 43.05% <32.65%> (-21.05%) ⬇️
modmail/utils/plugins.py 39.53% <39.53%> (ø)
modmail/__main__.py 47.05% <50.00%> (-2.95%) ⬇️
modmail/utils/extensions.py 60.46% <60.46%> (ø)
modmail/utils/cogs.py 90.00% <90.00%> (ø)
modmail/__init__.py 100.00% <100.00%> (ø)
... and 9 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a65e576...f708632. Read the comment docs.

cogs will now load or not load depending on current bot mode.
- all cogs now require a variable named "COG_METADATA" which is an
instance of "CogMetadata" from "modmail.utils.cogs"
  - if a cog does not have it a warning will be logged and will assume
that the cog should be loaded.
- there are two modes, development mode and plugin dev mode
  - development mode can be set with DEVEL=True in environment variables
  - plugin dev mode can be set with PLUGIN_DEV=True
  - by defalt, both modes are false.
cogs that load all the time were not loading all of the time,
specifically when no mode was explicitly set.
Originally when you would resync the cogs, it would check
whether `(ext, status)` is present in the extensions which
is a dict. But this would always return `False`, for example

```pycon
a = {"a": "a"}

>>> print(("a", "a") in a)
False
```

A fix to this, as committed is to just check whether `ext`
is present in the extension keys.
@onerandomusername
Copy link
Contributor Author

Once @bast0006 re-reviews, I'm planning to merge this tomorrow.

@onerandomusername onerandomusername merged commit cc66544 into main Aug 13, 2021
@onerandomusername onerandomusername deleted the feat/extensions branch August 13, 2021 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

l: intermediate p: high High Priority s: approved The issue has received a maintainer's approval s: needs review Ready for review and merge t: feature Relating to the functionality of the application.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants