50
50
""" .strip ()
51
51
52
52
53
+ class NotThreadOwner (commands .CheckFailure ):
54
+ pass
55
+
56
+
53
57
def is_forum_thread () -> Check [Context ]:
54
58
def predicate (ctx : Context ) -> bool :
55
59
channel = ctx .channel
@@ -67,6 +71,21 @@ def predicate(ctx: Context) -> bool:
67
71
return commands .check (predicate )
68
72
69
73
74
+ def can_close_thread () -> Check [Context ]:
75
+ def predicate (ctx : core .GuildContext ) -> bool :
76
+ assert isinstance (ctx .channel , discord .Thread )
77
+
78
+ if ctx .author_is_mod ():
79
+ return True
80
+
81
+ if ctx .author == ctx .channel .owner :
82
+ return True
83
+
84
+ raise NotThreadOwner ()
85
+
86
+ return commands .check (predicate )
87
+
88
+
70
89
class Help (commands .Cog ):
71
90
"""Commands relating to the help channels/forum of Pythonista."""
72
91
@@ -86,6 +105,7 @@ async def forum_post_created(self, thread: discord.Thread) -> None:
86
105
87
106
await thread .send (FORUM_BLURB )
88
107
108
+ @can_close_thread ()
89
109
@is_forum_thread ()
90
110
@commands .command ("solved" , brief = "Closes a forum post" , short_doc = "Closes a forum post in the help channels" )
91
111
async def solved (self , ctx : core .GuildContext ) -> None :
@@ -97,10 +117,6 @@ async def solved(self, ctx: core.GuildContext) -> None:
97
117
assert isinstance (ctx .channel , discord .Thread ) # guarded by the check
98
118
assert isinstance (ctx .channel .parent , discord .ForumChannel ) # guarded by the check
99
119
100
- if not ctx .author_is_mod () or ctx .author != ctx .channel .owner :
101
- await ctx .send ("You can only mark your own posts as solved" )
102
- return
103
-
104
120
try :
105
121
emoji = discord .utils .get (ctx .guild .emojis , id = 578575442383208468 )
106
122
if emoji :
@@ -128,6 +144,16 @@ async def solved(self, ctx: core.GuildContext) -> None:
128
144
msg : str = f"{ ctx .author } ({ ctx .author .id } ) marked thread '{ ctx .channel .name } ' ({ ctx .channel .id } ) as solved."
129
145
await channel .send (msg )
130
146
147
+ @solved .error
148
+ async def solved_error (self , ctx : Context , error : commands .CommandError ) -> None :
149
+ error = getattr (error , "original" , error )
150
+
151
+ if isinstance (error , NotThreadOwner ):
152
+ await ctx .send ("Sorry, you must be the owner of this thread to close it!" )
153
+
154
+ elif isinstance (error , commands .CheckFailure ):
155
+ await ctx .send ("Sorry, this doesn't appear to be a forum thread?" )
156
+
131
157
132
158
async def setup (bot : core .Bot ) -> None :
133
159
await bot .add_cog (Help (bot ))
0 commit comments