Example #1
0
    async def show_repos(self, ctx, user: discord.Member = None):
        """
        Viser mest stjernede repoene til brukeren. maks  5 repoer
        """
        is_self = False
        if not user:
            user = ctx.author
            is_self = True
        gh_user = get_user(self, user.id)

        if gh_user is None:
            usr = user.name
            if is_self:
                usr = "******"
            return await ctx.reply(f"{usr} har ikke registrert en bruker enda."
                                   )

        embed = easy_embed(self, ctx)
        embed.set_author(name=f"{user.name}#{user.discriminator}",
                         icon_url=user.avatar_url)
        (_id, discord_id, auth_token, github_username) = gh_user

        gh_repos = self._get_repos(github_username, auth_token)

        if len(gh_repos) == 0:
            return await ctx.reply("Denne brukeren har ingen repos")

        stars = {}
        new_obj = {}

        for gh_repo in gh_repos:
            if gh_repo["private"]:
                continue
            stars[gh_repo["id"]] = gh_repo["stargazers_count"]
            new_obj[gh_repo["id"]] = gh_repo

        stars = dict(
            sorted(stars.items(), key=operator.itemgetter(1), reverse=True))
        stop = 5 if (len(stars) >= 5) else len(stars)
        idrr = list(stars.items())
        embed.title = f"{stop} mest stjernede repoer"

        for n in range(0, stop):
            repo_id, *overflow = idrr[n]
            repo = new_obj[repo_id]
            title = f"{repo['name']} - ⭐:{repo['stargazers_count']}"
            desc = repo["description"]
            if not repo["description"]:
                desc = "Ingen beskrivelse oppgitt"
            desc += f"\n[Link]({repo['html_url']})"
            embed.add_field(name=title, value=desc, inline=False)

        await ctx.reply(embed=embed)
Example #2
0
    async def show_user(self, ctx, user: discord.Member = None):
        """
        Kommando som viser et sammendrag fra github brukeren
        """
        is_self = False
        if not user:
            user = ctx.author
            is_self = True
        gh_user = get_user(self, user.id)

        if gh_user is None:
            usr = user.name
            if is_self:
                usr = "******"
            return await ctx.reply(f"{usr} har ikke registrert en bruker enda."
                                   )

        (_id, discord_id, auth_token, github_username) = gh_user

        gh_user = requests.get("https://api.github.com/user",
                               headers={
                                   "Authorization": "token " + auth_token,
                                   "Accept": "application/json"
                               }).json()

        embed = easy_embed(self, ctx)

        embed.title = gh_user["login"]
        embed.description = gh_user["html_url"]

        embed.set_author(name=f"{user.name}#{user.discriminator}",
                         icon_url=user.avatar_url)
        embed.set_thumbnail(url=gh_user["avatar_url"])

        embed.add_field(
            name="Følgere / Følger",
            value=f"{gh_user['followers']} / {gh_user['following']}",
            inline=False)
        embed.add_field(name="Biografi", value=gh_user["bio"], inline=False)
        embed.add_field(name="Offentlige repos",
                        value=gh_user["public_repos"],
                        inline=False)

        return await ctx.reply(embed=embed)