diff options
| author | 2021-07-08 13:52:28 +0200 | |
|---|---|---|
| committer | 2021-07-08 23:02:29 +0200 | |
| commit | 7049a0052b375d8fa28288ab8ca63f7b99c069ed (patch) | |
| tree | e7652f267caa4d83c02d601eff6aaa051055613e | |
| parent | Disable more filters in jam channels (#1675) (diff) | |
Create `join_role_stats` function in helpers
Add `join_role_stats` function that joins the relevant information (number of members) of the given roles into one group under a pre-specified `name`
| -rw-r--r-- | bot/utils/helpers.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/bot/utils/helpers.py b/bot/utils/helpers.py index 3501a3933..1da5da5a3 100644 --- a/bot/utils/helpers.py +++ b/bot/utils/helpers.py @@ -1,6 +1,8 @@ from abc import ABCMeta -from typing import Optional +from types import List +from typing import Dict, Optional +from discord import Guild from discord.ext.commands import CogMeta @@ -30,3 +32,11 @@ def has_lines(string: str, count: int) -> bool: def pad_base64(data: str) -> str: """Return base64 `data` with padding characters to ensure its length is a multiple of 4.""" return data + "=" * (-len(data) % 4) + + +def join_role_stats(role_ids: List[int], name: str, guild: Guild) -> Dict[str, int]: + """Return a dict object with the number of `members` of each role given, and the `name` for this joined group.""" + members = [] + for role_id in role_ids: + members += guild.get_role(role_id).members + return {name: len(set(members))} |