コード例 #1
0
def _initalise(user_id, force_initialise):
    if _exists(user_id) is False or force_initialise is True:
        bet = d.retrieve("bet.json")
        bet["id"] += [user_id]
        bet["wallet"] += [500]
        bet["bank"] += [1000]
        d.save("bet.json", bet)
コード例 #2
0
    async def waifu(self, ctx):
        name, image_url, url = await get_waifu()

        embed = discord.Embed(title=f"{name}",
                              color=discord.Colour.from_rgb(0, 250, 141),
                              timestamp=ctx.message.created_at,
                              url=url)
        embed.set_footer(text=f"Requested by {ctx.author}",
                         icon_url=ctx.author.avatar_url)
        embed.set_image(url=image_url)
        embed_react = await ctx.send(embed=embed)

        await embed_react.add_reaction('⭐')
        reacted = [self.bot.user]

        def rcheck(reaction, user):
            print(reaction.message.embeds[0].to_dict())
            if str(
                    reaction.emoji
            ) == '⭐' and user not in reacted and reaction.message.embeds[
                    0].to_dict()['timestamp'] == embed.to_dict(
                    )['timestamp'] and reaction.message.embeds[0].to_dict(
                    )['footer']['text'] == embed.to_dict()['footer']['text']:
                reacted.append(user)
                return True
            return False

        while 1:
            try:
                reaction, user = await self.bot.wait_for('reaction_add',
                                                         timeout=60,
                                                         check=rcheck)
            except asyncio.TimeoutError:
                try:
                    await embed_react.clear_reactions()
                except discord.errors.Forbidden:
                    pass
                break

            _id = str(user.id)
            profiles = d.retrieve("waifu.json")
            if _id in profiles:
                profiles = d.retrieve("waifu.json")
                profiles[_id].append(f"{name} {image_url}")
                d.save("waifu.json", profiles)

            elif _id not in profiles:
                profiles = d.retrieve("waifu.json")
                profiles[_id] = [f"{name} {image_url}"]
                d.save("waifu.json", profiles)

            await ctx.send(
                f"**{name}** added to <@!{int(user.id)}> favourite list!")
コード例 #3
0
        async def info(index):
            profiles = d.retrieve("waifu.json")
            query = profiles[str(ctx.message.author.id)][index]
            temp = query.split(' ')

            image_url = temp[len(temp) - 1]
            temp.pop(len(temp) - 1)
            name = ""
            for i in temp:
                name += i + " "

            d.save("waifu.json", profiles)
            return name, image_url
コード例 #4
0
ファイル: levels.py プロジェクト: 0Mayank/Albedo
def _initialise(user_id, force_initialise=False, index=0):
    if _exist(user_id) is False or force_initialise is True:
        profiles = d.retrieve("profile.json")
        if force_initialise is True:
            for colors in profiles.keys():
                del profiles[colors][index]
        profiles["id"] += [user_id]
        profiles["arc color"] += ["#00adb5"]
        profiles["bg color"] += ["#303841"]
        profiles["text color"] += ["#eeeeee"]
        profiles["banner"] += ["#3a4750"]
        profiles["number color"] += ["#00adb5"]
        profiles["ranker color"] += ["#eeeeee"]
        profiles["arc path color"] += ["#bbbcbd"]
        d.save("profile.json", profiles)
コード例 #5
0
def update_token():
    data = d.retrieve("token.json")

    refresh_token = data["refresh"]
    param = {
        'client_id': client_id,
        'client_secret': client_secret,
        'grant_type': 'refresh_token',
        'refresh_token': refresh_token
    }
    url = f"https://myanimelist.net/v1/oauth2/token?"
    response = requests.post(url, param).json()

    data["bearer"] = response["access_token"]
    data["refresh"] = response["refresh_token"]
    d.save("token.json", data)
コード例 #6
0
ファイル: levels.py プロジェクト: 0Mayank/Albedo
    async def on_message(self, message):
        if message.author.bot:
            return

        exp = random.randint(15, 25)
        levels = d.retrieve("levels.json")

        if str(message.guild.id) in levels.keys():
            pass  #users = levels[message.guild]
        else:
            levels[str(message.guild.id)] = {}

        users = levels[str(message.guild.id)]

        users = await self._initialise_data(users, message.author)
        await self._add_exp(users, message.author, exp)
        await self._level_up(users, message.author, message.channel)

        levels[str(message.guild.id)]
        d.save("levels.json", levels)
コード例 #7
0
ファイル: levels.py プロジェクト: 0Mayank/Albedo
    async def show(self, ctx, member: discord.Member = None):
        """Shows the profile color set"""

        member = ctx.author if not member else member
        _initialise(str(member.id), False)
        ind = _get_index(str(member.id))
        profiles = d.retrieve("profile.json")

        arc = profiles["arc color"][ind]
        bg = profiles["bg color"][ind]
        text = profiles["text color"][ind]
        number = profiles["number color"][ind]
        banner = profiles["banner"][ind]
        arcpathc = profiles["arc path color"][ind]
        ranker = profiles["ranker color"][ind]

        d.save("profile.json", profiles)

        await ctx.send(
            f"Profile colors of **{str(member)[:-5]}**\n\n**Arc color** `{arc}`\n**Arc path color** `{arcpathc}`\n**Background color** `{bg}`\n**Text color** `{text}`\n**Number color** `{number}`\n**Banner color** `{banner}`\n**#Rank color** `{ranker}`\n"
        )
コード例 #8
0
    async def favourite(self, ctx):
        ind = 0

        async def info(index):
            profiles = d.retrieve("waifu.json")
            query = profiles[str(ctx.message.author.id)][index]
            temp = query.split(' ')

            image_url = temp[len(temp) - 1]
            temp.pop(len(temp) - 1)
            name = ""
            for i in temp:
                name += i + " "

            d.save("waifu.json", profiles)
            return name, image_url

        async def emoji(message):
            emo = ['◀️', '▶️', '🗑️']
            for i in emo:
                await message.add_reaction(i)

        async def edit_embed(index):
            try:
                name, image_url = await info(index)
                embed = discord.Embed(
                    title=f"{name}",
                    color=discord.Colour.from_rgb(0, 250, 141),
                    timestamp=ctx.message.created_at,
                )
                embed.set_footer(text=f"Requested by {ctx.author}",
                                 icon_url=ctx.author.avatar_url)
                embed.set_image(url=image_url)

                return embed

            except ValueError:
                embed_error = await info(index)
                return embed_error

        def rcheck(reaction, user):
            reacted = [self.bot.user]
            try:
                if str(reaction.emoji) == '▶️' or str(
                        reaction.emoji
                ) == '◀️' or str(
                        reaction.emoji
                ) == '🗑️' and reaction.message.embeds[0].to_dict(
                )['timestamp'] == embed.to_dict(
                )['timestamp'] and reaction.message.embeds[0].to_dict(
                )['footer']['text'] == embed.to_dict()['footer']['text']:
                    if user not in reacted:
                        reacted.append(user)
                        return True
            except:
                pass
            return False

        try:
            name, image_url = await info(0)
            embed = discord.Embed(
                title=f"{name}",
                color=discord.Colour.from_rgb(0, 250, 141),
                timestamp=ctx.message.created_at,
            )
            embed.set_footer(text=f"Requested by {ctx.author}",
                             icon_url=ctx.author.avatar_url)
            embed.set_image(url=image_url)

            embed_react = await ctx.send(embed=embed)

            await emoji(embed_react)

        except IndexError:
            embed = discord.Embed(title="Favourite list is empty ;-;")
            await ctx.send(embed=embed)

        while 1:
            # ind = 0
            try:
                reaction, user = await self.bot.wait_for('reaction_add',
                                                         timeout=60,
                                                         check=rcheck)
            except asyncio.TimeoutError:
                try:
                    await embed_react.clear_reactions()
                except discord.errors.Forbidden:
                    pass
                break
            if str(reaction.emoji) == '▶️' and user == ctx.author:
                ind += 1
                # name, image_url = await info(ind)
                try:
                    r = await edit_embed(ind)
                    await embed_react.edit(embed=r)
                except IndexError:
                    ind -= 1
                    r = await edit_embed(ind)
                    await embed_react.edit(embed=r)

            elif str(reaction.emoji) == '◀️' and user == ctx.author:
                ind -= 1
                try:
                    r = await edit_embed(ind)
                    await embed_react.edit(embed=r)
                except IndexError:
                    ind += 1
                    r = await edit_embed(ind)
                    await embed_react.edit(embed=r)

            elif str(reaction.emoji) == '🗑️' and user == ctx.author:
                profiles = d.retrieve("waifu.json")
                l_query = profiles[str(ctx.message.author.id)]
                actual_l = len(l_query)
                if actual_l != 0:
                    await ctx.send(
                        f"**{name}** got eliminated from <@!{int(user.id)}> favourite list."
                    )
                    try:
                        query = profiles[str(ctx.message.author.id)][ind]
                        temp = query.split(' ')
                        name = temp[0]
                        profiles[str(ctx.message.author.id)].pop(ind)
                        ind -= 1
                    except:
                        profiles[str(ctx.message.author.id)] = []

                    if len(profiles[str(ctx.message.author.id)]) != 0:
                        r = await edit_embed(ind)
                        await embed_react.edit(embed=r)
                    else:
                        embed = discord.Embed(
                            title="Favourite list is empty  ;-;")
                        ind += 1
                        d.save("waifu.json", profiles)
                        await embed_react.edit(embed=embed)
                        try:
                            await embed_react.clear_reactions()
                        except:
                            pass
                        break
                else:
                    embed = discord.Embed(title="Favourite list is empty  ;-;")
                    await ctx.send(embed=embed)
                d.save("waifu.json", profiles)
コード例 #9
0
ファイル: levels.py プロジェクト: 0Mayank/Albedo
def _change_color(index, color, location):
    profiles = d.retrieve("profile.json")
    profiles[location][index] = color
    d.save("profile.json", profiles)
コード例 #10
0
ファイル: levels.py プロジェクト: 0Mayank/Albedo
    async def profile(self, ctx, member: discord.Member = None):
        r"""Shows the profile \-\_\-"""

        member = ctx.author if not member else member
        _initialise(str(member.id), False)
        profiles = d.retrieve("profile.json")
        ind = _get_index(str(member.id))

        # VARIABLES
        member_rank = _get_rank(str(ctx.guild.id), str(member.id))
        if member_rank == False:
            return await ctx.send(
                f"**{member.name}** has not messaged yet, so their profile doesn't exist."
            )

        member_total_exp = _get_total_exp(str(ctx.guild.id), str(member.id))
        member_current_exp = _get_current_exp(str(ctx.guild.id),
                                              str(member.id))
        member_level = _get_level(str(ctx.guild.id), str(member.id))
        exp_for_levelup = 50 * member_level**2 + 50 * member_level + 100
        arc_end = (member_current_exp / exp_for_levelup) * 360 - 90
        bgc = _get_color(ind, "bg color")
        banner_id = _get_color(ind, "banner")
        numberc = _get_color(ind, "number color")
        textc = _get_color(ind, "text color")
        arcc = _get_color(ind, "arc color")
        rankerc = _get_color(ind, "ranker color")
        arcpathc = _get_color(ind, "arc path color")
        bannerc = banner_id

        # PROCESSING THE VARIABLES
        for image in os.listdir(
                'banners'
        ):  # process the banner of the user based on the color, url or the downloaded file
            if str(banner_id) == image.split(".")[0]:
                bannerc = image
                break

        member_total_exp = d.implement_numeral(
            member_total_exp)  #Adds, k, m, etc.

        try:
            # LOADING THE AVATAR AND BANNER
            response = requests.get(member.avatar_url)
            im = Image.open(io.BytesIO(response.content))

            try:
                banner = Image.new("RGB", (700, 280), color=bannerc)
            except:
                try:
                    response = requests.get(bannerc)
                    banner = Image.open(io.BytesIO(response.content))
                except:
                    banner = Image.open(f"banners\{bannerc}")

            banner = banner.resize((700, 280))

            # MASK FOR AVATAR

            im = im.resize((300, 300))
            bigsize = (im.size[0] * 4, im.size[1] * 4)
            mask = Image.new('L', bigsize, 0)
            draw = ImageDraw.Draw(mask)
            draw.ellipse((0, 0) + bigsize, fill=255)
            mask = mask.resize(im.size, Image.ANTIALIAS)
            im.putalpha(mask)

            output = ImageOps.fit(im, mask.size, centering=(0.5, 0.5))
            output.putalpha(mask)
            output.save('output.png')

            w, h = 350, 350
            shape = [(0, 0), (w, h)]

            # CREATING IMAGES
            background = Image.new("RGB", (700, 1100), color="white")
            small_bg = Image.new("RGB", (700, 820), color=bgc)
            small_circle_img = Image.new("RGB", (w, h))
            small_circle = ImageDraw.Draw(small_circle_img)
            small_circle.ellipse(shape, fill=bgc)

            # MASK FOR SMALL CIRCLE
            im2 = im.resize((350, 350))
            bigsize2 = (im2.size[0] * 4, im2.size[1] * 4)
            mask2 = Image.new('L', bigsize2, 0)
            draw2 = ImageDraw.Draw(mask2)
            try:
                draw2.ellipse((0, 0) + bigsize2, fill=bannerc)
            except:
                draw2.ellipse((0, 0) + bigsize2, fill=bgc)
            mask2 = mask2.resize(im2.size, Image.ANTIALIAS)
            small_circle_img.putalpha(mask2)

            # TEXT
            text = str(member)
            font_size = 70
            font = ImageFont.truetype('fonts/monofonto.ttf', font_size)
            text_draw = ImageDraw.Draw(small_bg)
            w1, h1 = font.getsize(text)
            text_draw.text(((700 - w1) / 2, (230 - h1) / 2),
                           text,
                           font=font,
                           fill=numberc)
            # RANK, LEVEL, EXP TEXT
            font_size2 = 45
            font2 = ImageFont.truetype('fonts/soloist1.ttf', font_size2)
            rank_draw = ImageDraw.Draw(background)
            # MAIN TEXT
            font_size3 = 90
            # font3 = ImageFont.truetype('fonts/Fragmentcore.ttf', font_size3)
            number_draw = ImageDraw.Draw(background)
            font3 = ImageFont.truetype('fonts/NewAthleticM54-31vz.ttf',
                                       font_size3)
            # TOP LEFT RANK
            font_size4 = 130
            font4 = ImageFont.truetype('fonts/ROBOTECH_GP.ttf', font_size4)
            ranker = ImageDraw.Draw(background)

            # PASTING

            background.paste(small_bg, (0, 280))
            background.paste(banner, (0, 0))
            background.paste(small_circle_img, (175, 5), im2)
            background.paste(im, (200, 30), im)

            # ARC
            arc_draw = ImageDraw.Draw(background)
            #             x0  y0  x1   y1
            # GREY EXP ARC
            arc_draw.arc((190, 700, 510, 1030),
                         start=-90,
                         end=270,
                         fill=arcpathc,
                         width=7)

            # EXP ARC
            arc_draw.arc((190, 700, 510, 1030),
                         start=-90,
                         end=arc_end,
                         fill=arcc,
                         width=12)

            # OUTER GREY CIRCLE
            arc_draw.arc((165, 675, 535, 1055),
                         start=-90,
                         end=270,
                         fill=arcc,
                         width=1)

            # TEXT FOR RANK & LEVEL
            rw = font2.getsize("Rank")[0]
            lw = font2.getsize("Level")[0]
            ew = font2.getsize("Exp")[0]
            rank_draw.text(((700 - rw) / 2, 770),
                           "Rank",
                           font=font2,
                           fill=textc)
            rank_draw.text(((500 - lw) / 4, 500),
                           "Level",
                           font=font2,
                           fill=textc)
            rank_draw.text((3 * (750 - ew) / 4, 500),
                           "Exp",
                           font=font2,
                           fill=textc)

            # TEXT FOR NUMBER

            rnw = font3.getsize(str(member_rank))[0]
            lnw = font3.getsize(str(member_level))[0]
            enw = font3.getsize(str(member_total_exp))[0]
            number_draw.text(((700 - rnw) / 2, 840),
                             str(d.implement_numeral(member_rank)),
                             font=font3,
                             fill=numberc)
            number_draw.text(((540 - lnw) / 4, 565),
                             str(d.implement_numeral(member_level)),
                             font=font3,
                             fill=numberc)
            number_draw.text((3 * (750 - enw) / 4, 565),
                             str(member_total_exp),
                             font=font3,
                             fill=numberc)

            if member_rank < 10:
                ranker.text((30, 0),
                            f"#{str(member_rank)}",
                            font=font4,
                            fill=rankerc)
            background.save('overlap.png')
            d.save("profile.json", profiles)
            await ctx.send(file=discord.File('overlap.png'))

        except ValueError:
            await ctx.send("Invalid colors, setting to default.")
            _initialise(member.id, True, ind)
コード例 #11
0
def _remove_dollars(index, amount, location):
    bet = d.retrieve("bet.json")
    bet[location][index] -= amount
    d.save("bet.json", bet)