diff --git a/src/apis/dicebear.py b/src/apis/dicebear.py new file mode 100644 index 0000000..2463373 --- /dev/null +++ b/src/apis/dicebear.py @@ -0,0 +1,46 @@ +from enum import Enum + + +class Style(Enum): + Adventurer = "adventurer" + AdventurerNeutral = "adventurer-neutral" + Avataaars = "avataaars" + AvataaarsNeutral = "avataaars-neutral" + BigEars = "big-ears" + BigEarsNeutral = "big-ears-neutral" + BigSmile = "big-smile" + Bottts = "bottts" + BotttsNeutral = "bottts-neutral" + Croodles = "croodles" + CroodlesNeutral = "croodles-neutral" + Dylan = "dylan" + FunEmoji = "fun-emoji" + Glass = "glass" + Icons = "icons" + Identicon = "identicon" + Initials = "initials" + Lorelei = "lorelei" + LoreleiNeutral = "lorelei-neutral" + Micah = "micah" + Miniavs = "miniavs" + Notionists = "notionists" + NotionistsNeutral = "notionists-neutral" + OpenPeeps = "open-peeps" + Personas = "personas" + PixelArt = "pixel-art" + PixelArtNeutral = "pixel-art-neutral" + Rings = "rings" + Shapes = "shapes" + Thumbs = "thumbs" + + +ALL_STYLES = [style.value for style in Style] + + +def get_avatar_url(style: Style, seed: str, **kwargs) -> str: + url = f"https://api.dicebear.com/9.x/{style.value}/png?seed={seed}" + + for k, v in kwargs.items(): + url += f"&{k}={v}" + + return url diff --git a/src/exts/fun/ai.py b/src/exts/tools/ai.py similarity index 99% rename from src/exts/fun/ai.py rename to src/exts/tools/ai.py index 206f6c5..8d62d39 100644 --- a/src/exts/fun/ai.py +++ b/src/exts/tools/ai.py @@ -1,7 +1,6 @@ import discord from discord.ext import commands from discord import app_commands -import random import pollinations as ai SYSTEM_PROMPT = """ diff --git a/src/exts/tools/dicebear.py b/src/exts/tools/dicebear.py new file mode 100644 index 0000000..cdd1845 --- /dev/null +++ b/src/exts/tools/dicebear.py @@ -0,0 +1,44 @@ +import discord +from discord.ext import commands +from discord import app_commands +import apis.dicebear as db + + +async def style_autocomplete(interaction: discord.Interaction, current: str): + try: + current = current or "" # Ensure current is a string + return [ + app_commands.Choice(name=style, value=style) + for style in db.ALL_STYLES + if current in style + ] + except Exception as e: + print(f"Autocomplete error: {e}") + return [] # Return empty list to avoid breaking autocomplete + + +class Dicebear(commands.GroupCog, name="dicebear"): + def __init__(self, bot): + super().__init__() + self.bot = bot + + @app_commands.command(name="generate", description="Generate an avatar") + @app_commands.autocomplete(style=style_autocomplete) + async def generate(self, interaction: discord.Interaction, seed: str, style: str): + url = db.get_avatar_url(db.Style(style), seed) + embed = discord.Embed(title=f"{style} on {seed}:", color=discord.Color.yellow()) + embed.set_image(url=url) + await interaction.response.send_message(embed=embed) + + @app_commands.command(name="get-styles", description="Get all available styles") + async def get_styles(self, interaction: discord.Interaction): + embed = discord.Embed( + title="All available styles:", + description="\n".join(db.ALL_STYLES), + color=discord.Color.yellow(), + ) + await interaction.response.send_message(embed=embed) + + +async def setup(bot: commands.Bot): + await bot.add_cog(Dicebear(bot)) diff --git a/src/exts/fun/github.py b/src/exts/tools/github.py similarity index 100% rename from src/exts/fun/github.py rename to src/exts/tools/github.py