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