Переглянути джерело

Fixed, that only lower ranks can be pro- or demoted

BaumSplitter41 3 місяців тому
батько
коміт
8fe64a3f5a
2 змінених файлів з 21 додано та 1 видалено
  1. 10 0
      VPD_BOT/cogs/demotion.py
  2. 11 1
      VPD_BOT/cogs/promotion.py

+ 10 - 0
VPD_BOT/cogs/demotion.py

@@ -65,13 +65,23 @@ class demotion(commands.Cog):
             if rank in user_roles:
                 user_rank = rank
                 break
+        author_roles = ctx.author.roles
+        author_rank = None
+        for rank in ranks:
+            if rank in author_roles:
+                author_rank = rank
+                break
         if user_rank is None:
             await ctx.respond("The selected user does not have a rank that can be demoted!", ephemeral=True)
             return
         current_rank_index = ranks.index(user_rank)
+        author_rank_index = ranks.index(author_rank)
         if current_rank_index == 0:
             await ctx.respond("The selected user is already at the lowest rank!", ephemeral=True)
             return
+        elif current_rank_index >= author_rank_index:
+            await ctx.respond("You cannot demote a user with an equal or higher rank than yourself!", ephemeral=True)
+            return
         new_rank = ranks[current_rank_index - 1]
         if new_rank == ranks[5]:
             await user.remove_roles(command_role)

+ 11 - 1
VPD_BOT/cogs/promotion.py

@@ -65,14 +65,24 @@ class promotion(commands.Cog):
             if rank in user_roles:
                 user_rank = rank
                 break
+        author_roles = ctx.author.roles
+        author_rank = None
+        for rank in ranks:
+            if rank in author_roles:
+                author_rank = rank
+                break
         if user_rank is None:
             await ctx.respond("The selected user does not have a rank that can be promoted!", ephemeral=True)
             return
         current_rank_index = ranks.index(user_rank)
+        author_rank_index = ranks.index(author_rank)
         if current_rank_index == len(ranks) - 1:
             await ctx.respond("The selected user is already at the highest rank!", ephemeral=True)
             return
-        new_rank = ranks[current_rank_index + 1]
+        elif current_rank_index >= author_rank_index:
+            await ctx.respond("You cannot promote a user with an equal or higher rank than yourself!", ephemeral=True)
+            return
+        new_rank = ranks[current_rank_index + 1] 
         if new_rank == ranks[6]:
             await user.add_roles(command_role)
         elif new_rank == ranks[4]: