Skip to content

Commit cff0b37

Browse files
committed
Merge branch 'scragly-top_role_hoist_config' into development
2 parents 2a4bca8 + 288a38c commit cff0b37

File tree

5 files changed

+22
-7
lines changed

5 files changed

+22
-7
lines changed

cogs/modmail.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ async def anonadduser(self, ctx, *users_arg: Union[discord.Member, discord.Role,
918918

919919
tag = self.bot.config["mod_tag"]
920920
if tag is None:
921-
tag = str(get_top_hoisted_role(ctx.author))
921+
tag = str(get_top_role(ctx.author, self.bot.config["use_hoisted_top_role"]))
922922
name = self.bot.config["anon_username"]
923923
if name is None:
924924
name = tag
@@ -1003,7 +1003,7 @@ async def anonremoveuser(self, ctx, *users_arg: Union[discord.Member, discord.Ro
10031003

10041004
tag = self.bot.config["mod_tag"]
10051005
if tag is None:
1006-
tag = str(get_top_hoisted_role(ctx.author))
1006+
tag = str(get_top_role(ctx.author, self.bot.config["use_hoisted_top_role"]))
10071007
name = self.bot.config["anon_username"]
10081008
if name is None:
10091009
name = tag

core/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ class ConfigManager:
123123
"confirm_thread_creation_deny": "\N{NO ENTRY SIGN}",
124124
# regex
125125
"use_regex_autotrigger": False,
126+
"use_hoisted_top_role": True,
126127
}
127128

128129
private_keys = {
@@ -209,6 +210,7 @@ class ConfigManager:
209210
"thread_show_roles",
210211
"thread_show_account_age",
211212
"thread_show_join_age",
213+
"use_hoisted_top_role",
212214
}
213215

214216
enums = {

core/config_help.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,5 +1121,16 @@
11211121
"notes": [
11221122
"This configuration can only to be set through `.env` file or environment (config) variables."
11231123
]
1124+
},
1125+
"use_hoisted_top_role": {
1126+
"default": "Yes",
1127+
"description": "Controls if only hoisted roles are evaluated when finding top role.",
1128+
"examples": [
1129+
],
1130+
"notes": [
1131+
"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.",
1132+
"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'.",
1133+
"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`."
1134+
]
11241135
}
11251136
}

core/thread.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
match_user_id,
2222
match_other_recipients,
2323
truncate,
24-
get_top_hoisted_role,
24+
get_top_role,
2525
create_thread_channel,
2626
get_joint_id,
2727
)
@@ -938,7 +938,7 @@ async def send(
938938
# Anonymously sending to the user.
939939
tag = self.bot.config["mod_tag"]
940940
if tag is None:
941-
tag = str(get_top_hoisted_role(author))
941+
tag = str(get_top_role(author, self.bot.config["use_hoisted_top_role"]))
942942
name = self.bot.config["anon_username"]
943943
if name is None:
944944
name = tag
@@ -1055,7 +1055,7 @@ async def send(
10551055
elif not anonymous:
10561056
mod_tag = self.bot.config["mod_tag"]
10571057
if mod_tag is None:
1058-
mod_tag = str(get_top_hoisted_role(message.author))
1058+
mod_tag = str(get_top_role(message.author, self.bot.config["use_hoisted_top_role"]))
10591059
embed.set_footer(text=mod_tag) # Normal messages
10601060
else:
10611061
embed.set_footer(text=self.bot.config["anon_tag"])

core/utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"trigger_typing",
3131
"escape_code_block",
3232
"tryint",
33-
"get_top_hoisted_role",
33+
"get_top_role",
3434
"get_joint_id",
3535
]
3636

@@ -369,9 +369,11 @@ def tryint(x):
369369
return x
370370

371371

372-
def get_top_hoisted_role(member: discord.Member):
372+
def get_top_role(member: discord.Member, hoisted=True):
373373
roles = sorted(member.roles, key=lambda r: r.position, reverse=True)
374374
for role in roles:
375+
if not hoisted:
376+
return role
375377
if role.hoist:
376378
return role
377379

0 commit comments

Comments
 (0)