Prechádzať zdrojové kódy

Added a /unit command, where you can add a user to a specific unit role.

BaumSplitter41 4 mesiacov pred
rodič
commit
2e3f45fc87
2 zmenil súbory, kde vykonal 76 pridanie a 1 odobranie
  1. 75 0
      VPD_BOT/cogs/unit.py
  2. 1 1
      VPD_BOT/config.cfg

+ 75 - 0
VPD_BOT/cogs/unit.py

@@ -0,0 +1,75 @@
+import discord
+from discord.ext import commands
+from discord.commands import Option
+from discord.commands import slash_command
+import configparser
+
+
+class unit(commands.Cog):
+    def __init__(self, bot: discord.Bot):
+        self.bot = bot
+
+
+#Command initialization
+    @slash_command(name="unit", description= "Add or remove a department member to/from a unit")
+    async def unit(
+        self,
+        ctx,
+        user: str = Option(discord.User, "Select User", required=True),
+        unit: str = Option(str, "Select Unit", required=True)
+    , choices=["Detective", "SWAT", "Canine", "Air Support"]
+    ):
+        if user not in ctx.guild.members:
+            await ctx.respond("The selected user is not a member on this Server!", ephemeral=True)
+            return
+        elif user == self.bot.user:
+            await ctx.respond(f"This is me - the {self.bot.user}", ephemeral=True)
+            return
+        elif user == ctx.author:
+            await ctx.respond("You cannot promote yourself!", ephemeral=True)
+            return
+        server = ctx.guild
+        config = configparser.RawConfigParser()
+        configFilePath = r'config.cfg'
+        config.read_file(open(configFilePath))
+
+#Role configuration
+        department1_role_id = config.get('Einweisung', 'department1_role_id').split(', ')
+        department1_role = ctx.guild.get_role(int(department1_role_id))
+        #department2_role_id = config.get('Role Management', 'department2_role_id').split(', ')
+        #department2_role = ctx.guild.get_role(int(department2_role_id))
+
+        department1_units_id = config.get('Role Management', 'department1_units').split(', ')
+        department1_units = [ctx.guild.get_role(int(role_id)) for role_id in department1_units_id]
+        #department2_units_id = config.get('Role Management', 'department2_units').split(', ')
+        #department2_units = [ctx.guild.get_role(int(role_id)) for role_id in
+
+        if department1_role in user.roles:
+            units = "department1"
+        #elif department2_role in user.roles:
+            #units = "department2"
+        else:
+            await ctx.respond("The selected user is not a member of any department!", ephemeral=True)
+            return
+        
+
+#Command implementation
+        if unit == "Detective":
+            unit_role = department1_units[0]
+        elif unit == "SWAT":
+            unit_role = department1_units[1]
+        elif unit == "Canine":
+            unit_role = department1_units[2]
+        elif unit == "Air Support":
+            unit_role = department1_units[3]
+        else:
+            await ctx.respond("The selected unit does not exist!", ephemeral=True)
+            return
+
+
+
+
+
+
+def setup(bot: discord.Bot):
+    bot.add_cog(unit(bot))

+ 1 - 1
VPD_BOT/config.cfg

@@ -27,7 +27,7 @@ department2_deputy_id =
 [Role Management]
 department1_command = 1451668309648084992
 department1_ranks = 1459935618371948743, 1459935662102020279, 1459935773108338921, 1459935923608223766, 1459945390571782245, 1459945659548565634, 1459936064612466861, 1459936186922700912, 1459936215766667448, 1459936269168541736, 1459936307974373427 
-department1_units = 1448793349627838556, 1450499400488058930
+department1_units = 1448793349627838556, 1450499400488058930, 1461039851762876584, 1461039891633803364
 
 department2_command =
 department2_ranks =