@@ -393,43 +393,64 @@ async def on_message_delete(self, message: discord.Message) -> None:
393
393
394
394
if not self .is_ready ():
395
395
return
396
-
397
396
if message .author == self .user :
398
397
return
399
-
400
- # Check if the message is in the channel
401
398
if message .channel .id != self ._config .channel_id :
402
399
return
403
- if not message . reactions :
404
- return
400
+
401
+ # Check if the deleted message was a legal message
405
402
if not all (c in POSSIBLE_CHARACTERS for c in message .content ):
406
- return
403
+ # The deleted message was not a legal message.
404
+ # But, it is possible that this message was edited prior to deletion,
405
+ # and the original message could have been a legal number.
406
+ # If so, the bot would have reacted to it in some way (tick or cross, we don't care).
407
+ # So we iterate through the reactions and check if any of those had been
408
+ # added by this bot.
409
+ dont_return : bool = False
410
+ if message .reactions :
411
+ for reaction in message .reactions :
412
+ if reaction .me :
413
+ # We found a reaction that was posted by this bot.
414
+ # => this message was a legal message in the past.
415
+ # Therefore, we need to show a deletion alert.
416
+ dont_return = True
417
+ break
418
+ if not dont_return :
419
+ # No reactions were found under the message that were posted
420
+ # by this bot. So we can safely ignore the message.
421
+ return
407
422
408
423
await message .channel .send (
409
- f'{ message .author .mention } deleted their number! '
410
- f'The **next** number is **{ self ._config .current_count + 1 } **.' )
424
+ f'{ message .author .mention } deleted their number!\n '
425
+ f'Please note that deleting numbers is **prohibited**, even if it has messed up the count. Repeated '
426
+ f'violation of this policy will force the Mods to revoke your access the counting channel permanently.\n \n '
427
+ f'The **NEXT** number is **{ self ._config .current_count + 1 } **.' )
411
428
412
429
async def on_message_edit (self , before : discord .Message , after : discord .Message ) -> None :
413
430
"""Send a message in the channel if a user modifies their input."""
414
431
415
432
if not self .is_ready ():
416
433
return
417
-
418
434
if before .author == self .user :
419
435
return
420
-
421
- # Check if the message is in the channel
422
436
if before .channel .id != self ._config .channel_id :
423
437
return
424
- if not before .reactions :
425
- return
426
- if not all (c in POSSIBLE_CHARACTERS for c in before .content ):
438
+
439
+ # Check whether the original message or the edited message are
440
+ # legal messages. If either of those is a legal message,
441
+ # we need to show an alert. No need to check for reactions.
442
+ if not (all (c in POSSIBLE_CHARACTERS for c in before .content )
443
+ or all (c in POSSIBLE_CHARACTERS for c in after .content )):
427
444
return
445
+
428
446
if before .content == after .content :
429
447
return
430
448
431
449
await after .channel .send (
432
- f'{ after .author .mention } edited their number! The **next** number is **{ self ._config .current_count + 1 } **.' )
450
+ f'{ after .author .mention } edited their number! { before .jump_url } \n '
451
+ f'Please note that editing numbers is **prohibited**, even if it has messed up the count. Repeated '
452
+ f'violation of this policy will force the Mods to revoke your access the counting channel permanently.\n \n '
453
+ f'The **NEXT** number is **{ self ._config .current_count + 1 } **.' )
433
454
434
455
async def setup_hook (self ) -> None :
435
456
await self .tree .sync ()
0 commit comments