|
3 | 3 | """ |
4 | 4 | Majority Judgment Bar Chart Distribution Discord Bot |
5 | 5 | """ |
6 | | - |
| 6 | +import asyncio |
7 | 7 | import sys |
8 | 8 | import os |
9 | 9 |
|
|
39 | 39 | # custom_id => str(UUID) + "button_" + GRADES[i] + "_" + str(user) + "_" + choice |
40 | 40 | BUTTONS = {} |
41 | 41 |
|
| 42 | +# Keep the original interaction to edit (ephemeral trick) |
| 43 | +# ORIGINAL_INTER {"user1": inter, "user2": inter...} |
| 44 | +ORIGINAL_INTER = {} |
| 45 | + |
42 | 46 | # Validations storage allow a global button deactivation |
43 | 47 | # Keep in memory [user1, user2 ...] |
44 | 48 | VALIDATIONS = [] |
@@ -106,6 +110,8 @@ async def major_update(inter: disnake.MessageInteraction): |
106 | 110 | global CHOICES |
107 | 111 | global RESULTS |
108 | 112 | global VALIDATIONS |
| 113 | + global ORIGINAL_INTER |
| 114 | + |
109 | 115 | user = inter.author.id |
110 | 116 | user_name = inter.author.name |
111 | 117 |
|
@@ -180,25 +186,31 @@ async def major_update(inter: disnake.MessageInteraction): |
180 | 186 | next_choice = CHOICES[c_index + 1] |
181 | 187 | except: |
182 | 188 | logging.info("User %s has finished '%s'", user_name, QUESTION) |
183 | | - await inter.response.send_message( |
184 | | - "Vous avez répondu à toutes les questions, merci pour votre participation !\n\n Résume de vos choix :\n" |
| 189 | + await ORIGINAL_INTER[user].edit_original_response( |
| 190 | + content="Vous avez répondu à toutes les questions, merci pour votre participation !\n\n Résume de vos choix :\n" |
185 | 191 | + str(RESULTS[user]) + "\n" |
186 | 192 | + "\nCommande pour afficher les résultats : **/major_display**\n" |
187 | 193 | + "\nVoulez-vous valider vos choix ou recommencer le jugement majoritaire ?", |
188 | | - ephemeral=True, |
189 | 194 | components=[disnake.ui.Button(label="Valider", style=disnake.ButtonStyle.success, |
190 | 195 | custom_id=str(UUID) + "button_validate_" + str(user)), |
191 | 196 | disnake.ui.Button(label="Recommencer", style=disnake.ButtonStyle.primary, |
192 | 197 | custom_id=str(UUID) + "button_reset_" + str(user))] |
193 | 198 | ) |
| 199 | + await inter.response.defer() |
194 | 200 | return |
195 | 201 | break # do not continue, break loop for the next "choice" |
196 | 202 |
|
197 | 203 | # Display buttons |
198 | | - await inter.response.send_message( |
199 | | - "Que pensez-vous de **" + next_choice + "** ?", |
| 204 | + content_msg = "Que pensez-vous de **" + next_choice + "** ?" |
| 205 | + if ORIGINAL_INTER.get(user) is not None: |
| 206 | + await ORIGINAL_INTER[user].edit_original_response(content=content_msg, components=BUTTONS[user][next_choice]) |
| 207 | + await inter.response.defer() |
| 208 | + else: |
| 209 | + await inter.response.send_message( |
| 210 | + content_msg, |
200 | 211 | ephemeral=True, |
201 | 212 | components=BUTTONS[user][next_choice]) |
| 213 | + ORIGINAL_INTER[user] = inter |
202 | 214 |
|
203 | 215 | def dict_to_csv(data, filename="output.csv"): |
204 | 216 | # Filter out any entries where a sub-dictionary contains None values |
|
0 commit comments