diff options
| author | 2020-04-18 21:00:38 -0700 | |
|---|---|---|
| committer | 2020-04-18 21:03:40 -0700 | |
| commit | ce0ec7db55a9f12f55ac5ba019a95bc0b7d5cbd7 (patch) | |
| tree | da3c1e1f8b0fe232040c3f5020c1c42f98aefbea | |
| parent | simpl (diff) | |
Tags: always use top-most folder for role restrictions
Ensures that nested directories aren't used as the value for the role
name.
| -rw-r--r-- | bot/cogs/tags.py | 19 | 
1 files changed, 11 insertions, 8 deletions
| diff --git a/bot/cogs/tags.py b/bot/cogs/tags.py index e5492971d..1c124b25a 100644 --- a/bot/cogs/tags.py +++ b/bot/cogs/tags.py @@ -34,25 +34,28 @@ class Tags(Cog):      @staticmethod      def get_tags() -> dict:          """Get all tags.""" -        # Save all tags in memory.          cache = {} -        tag_files = Path("bot", "resources", "tags").glob("**/*") -        for file in tag_files: +        base_path = Path("bot", "resources", "tags") +        for file in base_path.glob("**/*"):              if file.is_file():                  tag_title = file.stem                  tag = {                      "title": tag_title,                      "embed": { -                        "description": file.read_text() +                        "description": file.read_text(),                      }, -                    "restricted_to": "developers" +                    "restricted_to": "developers",                  } -                parent_folder = file.parent.stem -                if parent_folder != "tags": -                    tag["restricted_to"] = parent_folder + +                # Convert to a list to allow negative indexing. +                parents = list(file.relative_to(base_path).parents) +                if len(parents) > 1: +                    # -1 would be '.' hence -2 is used as the index. +                    tag["restricted_to"] = parents[-2].name                  cache[tag_title] = tag +          return cache      @staticmethod | 
