Эх сурвалжийг харах

adding a function, with wich user can active search for players.

baumsplitter41 3 өдөр өмнө
parent
commit
28fe9bec22

+ 78 - 0
VPD_BOT/cogs/matesearch.py

@@ -0,0 +1,78 @@
+import discord
+from discord.ext import commands
+from discord.commands import Option
+from discord.commands import slash_command
+import configparser
+
+
+class Matesearch(commands.Cog):
+    def __init__(self, bot: discord.Bot):
+        self.bot = bot
+    
+    #Modal form
+    class Form(discord.ui.Modal):
+        def __init__(self, bot: discord.Bot, *args, **kwargs):
+            super().__init__(*args, **kwargs)
+            self.bot = bot
+
+            #Modal form layout
+            self.add_item(discord.ui.InputText(label="Date", placeholder="Insert the estimated date..", required=False, ))
+            self.add_item(discord.ui.InputText(label="Time", placeholder="Insert the estimated time."))
+            
+        #funktions to load the config and get the channels
+        def _load_config(self):
+            config = configparser.ConfigParser()
+            configFilePath = r'config.cfg'
+            config.read(configFilePath)
+            return config
+        def _get_channel(self):
+            config = self._load_config()
+            search_channel_id = int(config["Matesearch"]["search_channel_id"])
+            search_channel = self.bot.get_channel(search_channel_id)
+            if search_channel is None:
+                print(f"Log channel with ID {search_channel_id} not found.")
+                return None
+            return search_channel
+        def _get_role (self):
+            config = self._load_config()
+            search_role_id = int(config["Matesearch"]["search_role_id"])
+            search_role = self.bot.get_role(search_role_id)
+            if search_role is None:
+                print(f"Log channel with ID {search_role_id} not found.")
+                return None
+            return role_channel
+
+
+        #Output of the Modal form
+        async def callback(self, interaction: discord.Interaction):
+            #Public embed with less information
+            embed = discord.Embed(title="Mitspieler gesucht!")
+            embed.add_field(name="Ersteller", value=interaction.user.mention, inline=False)
+            embed.add_field(name="Datum", value=self.children[0].value, inline=False)
+            embed.add_field(name="Zeit", value=self.children[1].value, inline=False)
+            embed.add_field(value=self._get_role(), inline=False)
+            self.embed = embed
+
+            #sending the embed
+            await interaction.response.send_message("Your search for players has been submitted.", ephemeral=True)
+            search_channel = self._get_channel()
+            await search_channel.send(embeds=[embed])
+
+    #Slash command to trigger the Modal form
+    @slash_command()
+    async def search(self, ctx: discord.ApplicationContext):
+        """Start a search for players."""
+
+## Only be able to send if last request is min 20h old
+
+        config = self._load_config()
+        enable_search = config.getboolean("Matesearch","enable_search_mates")
+        if not enable_search:
+            return
+
+        modal = self.Situ(self.bot, title="Fill the form to search for players.") # type: ignore
+        await ctx.send_modal(modal)
+ 
+
+def setup(bot: discord.Bot):
+    bot.add_cog(Matesearch(bot))

+ 6 - 0
VPD_BOT/config.cfg

@@ -94,3 +94,9 @@ enable_inavtive_reminder_dm = true
 [Civ]
 [Civ]
 situ_channel_id = 1495509162652864644
 situ_channel_id = 1495509162652864644
 #situ_team_channel_id =
 #situ_team_channel_id =
+
+#Searching for players
+[Matesearch]
+enable_search_mates = true
+search_channel_id = 1505172552643776614
+search_role_id = 1498348483864821791