1
1
"""Contains cog classes for tracking committee-actions."""
2
2
3
+ import contextlib
3
4
import logging
4
5
import random
5
6
from enum import Enum
11
12
12
13
from db .core .models import AssignedCommitteeAction , DiscordMember
13
14
from exceptions import (
15
+ CommitteeElectRoleDoesNotExistError ,
14
16
CommitteeRoleDoesNotExistError ,
15
17
InvalidActionDescriptionError ,
16
18
InvalidActionTargetError ,
@@ -129,11 +131,22 @@ async def autocomplete_get_committee_members(
129
131
except CommitteeRoleDoesNotExistError :
130
132
return set ()
131
133
134
+ committee_elect_role : discord .Role | None = None
135
+ with contextlib .suppress (CommitteeElectRoleDoesNotExistError ):
136
+ committee_elect_role = await ctx .bot .committee_elect_role
137
+
132
138
return {
133
139
discord .OptionChoice (
134
140
name = f"{ member .display_name } ({ member .global_name } )" , value = str (member .id )
135
141
)
136
- for member in committee_role .members
142
+ for member in (
143
+ set (committee_role .members )
144
+ | (
145
+ set (committee_elect_role .members )
146
+ if committee_elect_role is not None
147
+ else set ()
148
+ )
149
+ )
137
150
if not member .bot
138
151
}
139
152
@@ -281,9 +294,7 @@ async def create(
281
294
required = True ,
282
295
parameter_name = "status" ,
283
296
)
284
- @CommandChecks .check_interaction_user_has_committee_role
285
- @CommandChecks .check_interaction_user_in_main_guild
286
- async def update_status (
297
+ async def update_status ( # NOTE: Committee role check is not present because non-committee can have actions, and need to be able to list their own actions.
287
298
self , ctx : "TeXBotApplicationContext" , action_id : str , status : str
288
299
) -> None :
289
300
"""
@@ -561,9 +572,7 @@ async def action_all_committee(
561
572
default = None ,
562
573
parameter_name = "status" ,
563
574
)
564
- @CommandChecks .check_interaction_user_has_committee_role
565
- @CommandChecks .check_interaction_user_in_main_guild
566
- async def list_user_actions (
575
+ async def list_user_actions ( # NOTE: Committee role check is not present because non-committee can have actions, and need to be able to list their own actions.
567
576
self ,
568
577
ctx : "TeXBotApplicationContext" ,
569
578
* ,
@@ -575,15 +584,32 @@ async def list_user_actions(
575
584
Definition and callback of the "/list" command.
576
585
577
586
Takes in a user and lists out their current actions.
587
+ If no user is specified, the user issuing the command will be used.
588
+ If a user has the committee role, they can list actions for other users.
589
+ If a user does not have the committee role, they can only list their own actions.
578
590
"""
579
- action_member : discord .Member | discord .User
591
+ action_member_id = action_member_id .strip ()
592
+
593
+ action_member : discord .Member | discord .User = (
594
+ await self .bot .get_member_from_str_id (action_member_id )
595
+ if action_member_id
596
+ else ctx .user
597
+ )
580
598
581
- if action_member_id :
582
- action_member = await self .bot .get_member_from_str_id (
583
- action_member_id ,
599
+ if action_member != ctx .user and not await self .bot .check_user_has_committee_role (
600
+ ctx .user
601
+ ):
602
+ await ctx .respond (
603
+ content = "Committee role is required to list actions for other users." ,
604
+ ephemeral = True ,
584
605
)
585
- else :
586
- action_member = ctx .user
606
+ logger .debug (
607
+ "User: %s, tried to list actions for user: %s, "
608
+ "but did not have the committee role." ,
609
+ ctx .user ,
610
+ action_member ,
611
+ )
612
+ return
587
613
588
614
user_actions : list [AssignedCommitteeAction ]
589
615
0 commit comments