2222
2323Author: Samuel Guo (64931063+rf20008@users.noreply.github.com)
2424"""
25+
2526import time
2627
2728import disnake
3031from helpful_modules .custom_bot import TheDiscordMathProblemBot
3132from helpful_modules .custom_embeds import SuccessEmbed , ErrorEmbed
3233from helpful_modules .my_modals import MyModal
33- from helpful_modules .problems_module import Appeal , AppealViewInfo , AppealType , AppealQuestion , APPEAL_QUESTION_TYPE_NAMES
34+ from helpful_modules .problems_module import (
35+ Appeal ,
36+ AppealViewInfo ,
37+ AppealType ,
38+ AppealQuestion ,
39+ APPEAL_QUESTION_TYPE_NAMES ,
40+ )
3441from .appeal_views import AppealView
3542from helpful_modules .threads_or_useful_funcs import generate_new_id
3643
4148 AppealType .SUPPORT_SERVER_BAN : "Support Server Ban Appeal" ,
4249 AppealType .OTHER : "Appeal" ,
4350 AppealType .NOT_SET : "NOT SET Appeal" ,
44- AppealType .UNKNOWN : "Unknown Appeal"
51+ AppealType .UNKNOWN : "Unknown Appeal" ,
4552}
46- async def get_highest_appeal_num_for (cache : problems_module .MathProblemCache | problems_module .RedisCache , author : int ):
53+
54+
55+ async def get_highest_appeal_num_for (
56+ cache : problems_module .MathProblemCache | problems_module .RedisCache , author : int
57+ ):
4758 highest_appeal_num = 0
4859 all_appeals = await cache .get_all_appeals ()
4960 for appeal in all_appeals :
@@ -53,15 +64,17 @@ async def get_highest_appeal_num_for(cache: problems_module.MathProblemCache | p
5364 highest_appeal_num = appeal .appeal_num
5465 highest_appeal_num += 1
5566 return highest_appeal_num
67+
68+
5669async def handle_appeal (
57- * ,
58- bot : TheDiscordMathProblemBot ,
59- modal_inter : disnake .ModalInteraction ,
60- reason : str ,
61- cache : problems_module .MathProblemCache | problems_module .RedisCache ,
62- custom_ids : dict [AppealQuestion , str ],
63- guild_id : int | None = None ,
64- appeal_type : AppealType = AppealType .NOT_SET
70+ * ,
71+ bot : TheDiscordMathProblemBot ,
72+ modal_inter : disnake .ModalInteraction ,
73+ reason : str ,
74+ cache : problems_module .MathProblemCache | problems_module .RedisCache ,
75+ custom_ids : dict [AppealQuestion , str ],
76+ guild_id : int | None = None ,
77+ appeal_type : AppealType = AppealType .NOT_SET ,
6578):
6679 try :
6780 await cache .update_cache ()
@@ -75,24 +88,29 @@ async def handle_appeal(
7588 special_id = generate_new_id (),
7689 appeal_num = highest_appeal_num ,
7790 user_id = modal_inter .author .id ,
78- #guild_id=guild_id,
91+ # guild_id=guild_id,
7992 type = appeal_type .value ,
8093 )
8194 await cache .set_appeal_data (appeal )
8295 await modal_inter .send (embed = SuccessEmbed ("Appeal should be sent?" ))
8396
84-
85-
8697 appeals_channel = bot .appeals_channel
8798 # reason = f"This appeal is from {modal_inter.author.mention} and appeals. The reason they appealed is below:. \n\n **Their reason:**\n" + reason
8899
89- our_view = AppealView (cache = bot .cache , user_id = modal_inter .author .id , pages = [], special_color = disnake .Color .red (),
90- guild_id = guild_id , appeal_type = AppealType .GUILD_DENYLIST_APPEAL )
91- our_view .add_pages (AppealView .break_into_pages (
92- f"This { APPEAL_TYPE_REASONS [appeal_type ]} is from { modal_inter .author .mention } and appeals for the guild with guild id { guild_id } ." +
93- f"This is appeal#{ highest_appeal_num } "
94-
95- ))
100+ our_view = AppealView (
101+ cache = bot .cache ,
102+ user_id = modal_inter .author .id ,
103+ pages = [],
104+ special_color = disnake .Color .red (),
105+ guild_id = guild_id ,
106+ appeal_type = AppealType .GUILD_DENYLIST_APPEAL ,
107+ )
108+ our_view .add_pages (
109+ AppealView .break_into_pages (
110+ f"This { APPEAL_TYPE_REASONS [appeal_type ]} is from { modal_inter .author .mention } and appeals for the guild with guild id { guild_id } ."
111+ + f"This is appeal#{ highest_appeal_num } "
112+ )
113+ )
96114 for question in bot .appeal_questions [APPEAL_QUESTION_TYPE_NAMES [appeal_type ]]:
97115 try :
98116 # Attempt to add pages
@@ -105,7 +123,9 @@ async def handle_appeal(
105123 # Determine what went wrong
106124 if question not in custom_ids :
107125 # Handle missing question key
108- raise KeyError (f"{ question } doesn't have a key in `custom_ids`, which is { custom_ids } " ) from kerr
126+ raise KeyError (
127+ f"{ question } doesn't have a key in `custom_ids`, which is { custom_ids } "
128+ ) from kerr
109129 elif custom_ids [question ] not in modal_inter .text_values :
110130 # Handle missing text value key
111131 raise KeyError (
@@ -117,31 +137,38 @@ async def handle_appeal(
117137
118138 msg = await appeals_channel .send (view = our_view , embed = our_view .create_embed ())
119139 our_view .message_id = msg .id
120- await cache .set_appeal_view_info (AppealViewInfo (
121- message_id = msg .id ,
122- user_id = modal_inter .author .id ,
123- guild_id = None ,
124- done = False ,
125- pages = our_view .pages ,
126- appeal_type = AppealType .DENYLIST_APPEAL
127- ))
140+ await cache .set_appeal_view_info (
141+ AppealViewInfo (
142+ message_id = msg .id ,
143+ user_id = modal_inter .author .id ,
144+ guild_id = None ,
145+ done = False ,
146+ pages = our_view .pages ,
147+ appeal_type = AppealType .DENYLIST_APPEAL ,
148+ )
149+ )
128150
129151
130152class AppealModal (MyModal ):
131153 bot : TheDiscordMathProblemBot
132154 custom_ids : dict [AppealQuestion , str ]
155+
133156 def __init__ (self , * args , ** kwargs ):
134157 self .custom_ids = kwargs .pop ("custom_ids" , {})
135158
136159 super ().__init__ (* args , ** kwargs )
160+
137161 async def callback (self , modal_inter : disnake .ModalInteraction ):
138162 if not isinstance (modal_inter .bot , TheDiscordMathProblemBot ):
139163 raise TypeError ("The bot is of the wrong type" )
140- self .bot = modal_inter .bot # type: ignore # (we did a type check earlier)
164+ self .bot = modal_inter .bot # type: ignore # (we did a type check earlier)
141165 assert isinstance (self .bot , TheDiscordMathProblemBot )
142- assert hasattr (self .bot , 'cache' )
166+ assert hasattr (self .bot , "cache" )
167+
168+
143169class UserDenylistAppealModal (AppealModal ):
144170 undenylist_custom_id : str
171+
145172 def __init__ (self , * args , ** kwargs ):
146173 self .undenylist_custom_id = kwargs .pop ("undenylist_custom_id" , None )
147174 super ().__init__ (* args , ** kwargs )
@@ -151,7 +178,9 @@ async def callback(self, modal_inter: disnake.ModalInteraction):
151178 cache = self .bot .cache
152179 # nonlocal reason
153180 reason = modal_inter .text_values [self .undenylist_custom_id ]
154- await modal_inter .send (embed = SuccessEmbed ("Thanks! I'm now going to add this to the database :)" ))
181+ await modal_inter .send (
182+ embed = SuccessEmbed ("Thanks! I'm now going to add this to the database :)" )
183+ )
155184
156185 # Create an appeal
157186 # find the appeal
@@ -167,19 +196,22 @@ async def callback(self, modal_inter: disnake.ModalInteraction):
167196 cache = self .bot .cache ,
168197 guild_id = None ,
169198 appeal_type = AppealType .DENYLIST_APPEAL ,
170- custom_ids = self .custom_ids
199+ custom_ids = self .custom_ids ,
171200 )
201+
202+
172203class GuildDenylistAppealModal (AppealModal ):
173204 guild_id_custom_id : str
174205 custom_ids : dict [AppealQuestion , str ]
175206 represent_custom_id : str
176207 reason_custom_id : str
208+
177209 async def callback (self , modal_inter : disnake .ModalInteraction ):
178210 await super ().callback (modal_inter )
179211 bot = modal_inter .bot
180212 if not isinstance (bot , TheDiscordMathProblemBot ):
181213 raise TypeError
182- assert hasattr (bot , ' cache' )
214+ assert hasattr (bot , " cache" )
183215 cache = bot .cache
184216 # nonlocal reason
185217
@@ -192,22 +224,24 @@ async def callback(self, modal_inter: disnake.ModalInteraction):
192224 data = await self .bot .cache .get_guild_data (guild_id = guild_id , default = None )
193225
194226 if not self .bot .is_denylisted_by_guild_id (guild_id ):
195- await modal_inter .send (embed = ErrorEmbed ("Your Guild is not actually denylisted" ))
227+ await modal_inter .send (
228+ embed = ErrorEmbed ("Your Guild is not actually denylisted" )
229+ )
196230 return
197231 reason = modal_inter .text_values [self .reason_custom_id ]
198- await modal_inter .send (embed = SuccessEmbed ("Thanks! I'm now going to add this to the database :)" ))
232+ await modal_inter .send (
233+ embed = SuccessEmbed ("Thanks! I'm now going to add this to the database :)" )
234+ )
199235
200236 # Create an appeal
201237 # find the appeal
202238
203239 await handle_appeal (
204240 bot = bot ,
205241 modal_inter = modal_inter ,
206- reason = reason ,
207- cache = bot .cache ,
242+ reason = reason ,
243+ cache = bot .cache ,
208244 guild_id = guild_id ,
209245 appeal_type = AppealType .GUILD_DENYLIST_APPEAL ,
210- custom_ids = self .custom_ids
246+ custom_ids = self .custom_ids ,
211247 )
212-
213-
0 commit comments