Skip to content

Commit

Permalink
Allow top role's hoisted check to be configurable.
Browse files Browse the repository at this point in the history
  • Loading branch information
scragly committed Sep 7, 2021
1 parent fc156f9 commit 7922a97
Show file tree
Hide file tree
Showing 4 changed files with 11 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
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 7922a97

Please sign in to comment.