Skip to content

Commit

Permalink
Merge branch 'top_role_hoist_config' of git://github.com/scragly/modm…
Browse files Browse the repository at this point in the history
…ail into scragly-top_role_hoist_config
  • Loading branch information
fourjr committed Nov 19, 2021
2 parents 2a4bca8 + 655e063 commit 288a38c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
4 changes: 2 additions & 2 deletions cogs/modmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ async def anonadduser(self, ctx, *users_arg: Union[discord.Member, discord.Role,

tag = self.bot.config["mod_tag"]
if tag is None:
tag = str(get_top_hoisted_role(ctx.author))
tag = str(get_top_role(ctx.author, self.bot.config["use_hoisted_top_role"]))
name = self.bot.config["anon_username"]
if name is None:
name = tag
Expand Down Expand Up @@ -1003,7 +1003,7 @@ async def anonremoveuser(self, ctx, *users_arg: Union[discord.Member, discord.Ro

tag = self.bot.config["mod_tag"]
if tag is None:
tag = str(get_top_hoisted_role(ctx.author))
tag = str(get_top_role(ctx.author, self.bot.config["use_hoisted_top_role"]))
name = self.bot.config["anon_username"]
if name is None:
name = tag
Expand Down
2 changes: 2 additions & 0 deletions core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class ConfigManager:
"confirm_thread_creation_deny": "\N{NO ENTRY SIGN}",
# regex
"use_regex_autotrigger": False,
"use_hoisted_top_role": True,
}

private_keys = {
Expand Down Expand Up @@ -209,6 +210,7 @@ class ConfigManager:
"thread_show_roles",
"thread_show_account_age",
"thread_show_join_age",
"use_hoisted_top_role",
}

enums = {
Expand Down
11 changes: 11 additions & 0 deletions core/config_help.json
Original file line number Diff line number Diff line change
Expand Up @@ -1121,5 +1121,16 @@
"notes": [
"This configuration can only to be set through `.env` file or environment (config) variables."
]
},
"use_hoisted_top_role": {
"default": "Yes",
"description": "Controls if only hoisted roles are evaluated when finding top role.",
"examples": [
],
"notes": [
"Top role is displayed in embeds when replying or adding/removing users to a thread in the case mod_tag and anon_username are not set.",
"If this configuration is enabled, only roles that are hoisted (displayed seperately in member list) will be used. If a user has no hoisted roles, it will return 'None'.",
"If you would like to display the top role of a user regardless of if it's hoisted or not, disable `use_hoisted_top_role`."
]
}
}
6 changes: 3 additions & 3 deletions core/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
match_user_id,
match_other_recipients,
truncate,
get_top_hoisted_role,
get_top_role,
create_thread_channel,
get_joint_id,
)
Expand Down Expand Up @@ -938,7 +938,7 @@ async def send(
# Anonymously sending to the user.
tag = self.bot.config["mod_tag"]
if tag is None:
tag = str(get_top_hoisted_role(author))
tag = str(get_top_role(author, self.bot.config["use_hoisted_top_role"]))
name = self.bot.config["anon_username"]
if name is None:
name = tag
Expand Down Expand Up @@ -1055,7 +1055,7 @@ async def send(
elif not anonymous:
mod_tag = self.bot.config["mod_tag"]
if mod_tag is None:
mod_tag = str(get_top_hoisted_role(message.author))
mod_tag = str(get_top_role(message.author, self.bot.config["use_hoisted_top_role"]))
embed.set_footer(text=mod_tag) # Normal messages
else:
embed.set_footer(text=self.bot.config["anon_tag"])
Expand Down
6 changes: 4 additions & 2 deletions core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"trigger_typing",
"escape_code_block",
"tryint",
"get_top_hoisted_role",
"get_top_role",
"get_joint_id",
]

Expand Down Expand Up @@ -369,9 +369,11 @@ def tryint(x):
return x


def get_top_hoisted_role(member: discord.Member):
def get_top_role(member: discord.Member, hoisted=True):
roles = sorted(member.roles, key=lambda r: r.position, reverse=True)
for role in roles:
if not hoisted:
return role
if role.hoist:
return role

Expand Down

0 comments on commit 288a38c

Please sign in to comment.