示例#1
0
 async def _list_macros(self, ctx):
     database = SnakyData("data")
     base_macros = database.get_data("macros.json")
     user_macros = database.get_data(f"users/{ctx.author.id}/macros.json",
                                     base_macros)
     guild_macros = {} if not ctx.guild else database.get_data(
         f"guilds/{ctx.guild.id}/macros.json", base_macros)
     em = {
         "author": {
             "name": str(ctx.author),
             "icon_url": str(ctx.author.avatar_url_as(static_format='png'))
         },
         "color":
         9276813,
         "fields": [{
             "name":
             "Your macros are:",
             "value":
             ' '.join([f"`{macro}`" for macro in user_macros]),
             "inline":
             False
         }]
     }
     if guild_macros:
         em["fields"].append({
             "name":
             "This guild's macros are:",
             "value":
             ' '.join([f"`{macro}`" for macro in guild_macros]),
             "inline":
             False
         })
     await ctx.send(embed=discord.Embed.from_dict(em))
示例#2
0
def load_macros(user_folder: str, guild_folder: str):
    database = SnakyData("data")
    base_macros = database.get_data("macros.json")
    user_macros = database.get_data(f"{user_folder}/macros.json", base_macros)
    guild_macros = {} if not guild_folder else database.get_data(
        f"{guild_folder}/macros.json", base_macros)
    return {**user_macros, **guild_macros}
示例#3
0
    async def _add_pack(self, ctx, user: commands.UserConverter, pack):
        database = SnakyData(f"data/users/{user.id}/emojis/")
        emojis = database.get_data(f"{pack}.json")
        if not emojis:
            await ctx.send(f"{ctx.author.mention}, this pack doesn't exist :c")
            return

        for name, url in emojis.items():
            try:
                await ctx.guild.create_custom_emoji(
                    name=name, image=get_bytes_request(url))
            except Exception as e:
                await ctx.send(
                    f"Skipped emoji {name} because an error occured ({e})",
                    delete_after=3)
        await ctx.send(
            f"{ctx.author.mention}, added the pack {pack} by {user} to the server!"
        )
示例#4
0
    async def _list_emojis(self, ctx, user: commands.UserConverter, pack):
        database = SnakyData(f"data/users/{user.id}/emojis/")
        emojis = database.get_data(f"{pack}.json")
        if not emojis:
            await ctx.send(f"{ctx.author.mention}, this pack doesn't exist :c")
            return

        em = {
            "author": {
                "name": str(ctx.author),
                "icon_url": str(ctx.author.avatar_url_as(static_format='png'))
            },
            "fields": [{
                "name": f"Emojis from pack {pack} by {user}",
                "inline": True,
                "value": ' '.join([f"`{emoji}`" for emoji in emojis])
            }]
        }
        await ctx.send(embed=discord.Embed.from_dict(em))
示例#5
0
 async def _list_packs(self, ctx, user: commands.UserConverter):
     database = SnakyData(f"data/users/{user.id}/emojis/")
     packs = ''.join([
         f"`{pck.replace('.json', '')}`\n" for pck in database.list_dir()
         if pck.endswith('.json')
     ])
     if not packs:
         packs = "This user doesn't have any pack"
     em = {
         "author": {
             "name": str(ctx.author),
             "icon_url": str(ctx.author.avatar_url_as(static_format='png'))
         },
         "fields": [{
             "name": f"Emoji packs by {user}",
             "inline": True,
             "value": packs
         }]
     }
     await ctx.send(embed=discord.Embed.from_dict(em))
示例#6
0
 async def _del_pack(self, ctx, name):
     database = SnakyData(f"data/users/{ctx.author.id}/emojis/")
     database.delete_data(f"{name}.json")
     await ctx.send(f"{ctx.author.mention}, deleted the pack {name} ^w^")
示例#7
0
def del_emojis(user, pack, emojis: list):
    database = SnakyData(f"data/users/{user}/emojis")
    database.get_data(f"{pack}.json", {})
    for name in emojis:
        database.del_data(name, f"{pack}.json")
示例#8
0
def add_emojis(user, pack, emojis: dict):
    database = SnakyData(f"data/users/{user}/emojis")
    database.get_data(f"{pack}.json", {})
    for name, url in emojis.items():
        database.set_data(name, str(url), f"{pack}.json")
示例#9
0
def del_macro(folder: str, name: str):
    database = SnakyData("data")
    load_macros(folder, "")
    database.get_ref(folder).del_data(name, "macros.json")
示例#10
0
def set_macro(folder: str, name: str, macro: dict):
    database = SnakyData("data")
    load_macros(folder, "")
    database.get_ref(folder).set_data(name, macro, "macros.json")