diff --git a/rubyapi/__init__.py b/rubyapi/__init__.py new file mode 100644 index 0000000..a30e5fd --- /dev/null +++ b/rubyapi/__init__.py @@ -0,0 +1,4 @@ +from .rubyapi import RubyAPI + +async def setup(bot): + await bot.add_cog(RubyAPI(bot)) \ No newline at end of file diff --git a/rubyapi/info.json b/rubyapi/info.json new file mode 100644 index 0000000..c33800b --- /dev/null +++ b/rubyapi/info.json @@ -0,0 +1,10 @@ +{ + "name": "RubyAPI", + "author": ["Valerie"], + "description": "A cog to handle Discord interactions and linked roles verification through Ruby API endpoints.", + "short": "Ruby API integration for Discord interactions", + "tags": ["api", "interactions", "verification", "roles"], + "type": "COG", + "end_user_data_statement": "This cog stores guild configuration for API endpoints. No personal user data is stored.", + "min_bot_version": "3.5.0" +} \ No newline at end of file diff --git a/rubyapi/rubyapi.py b/rubyapi/rubyapi.py new file mode 100644 index 0000000..03b30cf --- /dev/null +++ b/rubyapi/rubyapi.py @@ -0,0 +1,97 @@ +from typing import Optional +import discord +from redbot.core import commands, Config +from redbot.core.bot import Red +from redbot.core.utils.chat_formatting import box + + +class RubyAPI(commands.Cog): + """Ruby API integration for interactions and linked roles verification.""" + + def __init__(self, bot: Red): + self.bot = bot + self.config = Config.get_conf(self, identifier=867530999, force_registration=True) + + default_guild = { + "interaction_url": "https://ruby.valerie.lol/api/interactions", + "verify_url": "https://ruby.valerie.lol/verify-user", + "enabled": False + } + + self.config.register_guild(**default_guild) + + @commands.group(name="rubyapi") + @commands.admin_or_permissions(manage_guild=True) + async def rubyapi(self, ctx: commands.Context): + """Ruby API configuration commands.""" + pass + + @rubyapi.command(name="enable") + async def enable_integration(self, ctx: commands.Context, toggle: bool): + """Enable or disable Ruby API integration.""" + await self.config.guild(ctx.guild).enabled.set(toggle) + status = "enabled" if toggle else "disabled" + await ctx.send(f"Ruby API integration has been {status}.") + + @rubyapi.command(name="setinteraction") + async def set_interaction_url(self, ctx: commands.Context, url: str): + """Set the interaction endpoint URL.""" + if not url.startswith(("http://", "https://")): + return await ctx.send("Please provide a valid URL starting with http:// or https://") + + await self.config.guild(ctx.guild).interaction_url.set(url) + await ctx.send("Interaction endpoint URL has been updated.") + + @rubyapi.command(name="setverify") + async def set_verify_url(self, ctx: commands.Context, url: str): + """Set the verification endpoint URL.""" + if not url.startswith(("http://", "https://")): + return await ctx.send("Please provide a valid URL starting with http:// or https://") + + await self.config.guild(ctx.guild).verify_url.set(url) + await ctx.send("Verification endpoint URL has been updated.") + + @rubyapi.command(name="settings") + async def show_settings(self, ctx: commands.Context): + """Show current Ruby API settings.""" + guild_config = await self.config.guild(ctx.guild).all() + + enabled = "Yes" if guild_config["enabled"] else "No" + interaction_url = guild_config["interaction_url"] + verify_url = guild_config["verify_url"] + + message = ( + "Ruby API Settings:\n" + f"Enabled: {enabled}\n" + f"Interaction URL: {interaction_url}\n" + f"Verify URL: {verify_url}" + ) + + await ctx.send(box(message)) + + @commands.command() + async def verifyuser(self, ctx: commands.Context, user: Optional[discord.Member] = None): + """Verify a user's linked roles.""" + if not await self.config.guild(ctx.guild).enabled(): + return await ctx.send("Ruby API integration is not enabled in this server.") + + user = user or ctx.author + verify_url = await self.config.guild(ctx.guild).verify_url() + + # Here you would implement the actual API call to verify the user + # For demonstration, we'll just show a message + await ctx.send(f"Verification would be performed for {user.mention} using {verify_url}") + + @commands.Cog.listener() + async def on_interaction(self, interaction: discord.Interaction): + """Handle incoming Discord interactions.""" + if not interaction.guild: + return + + if not await self.config.guild(interaction.guild).enabled(): + return + + # Here you would implement the actual interaction handling + # For demonstration, we'll just log the interaction + interaction_url = await self.config.guild(interaction.guild).interaction_url() + # You would typically make an API request to the interaction_url here \ No newline at end of file