Esempio n. 1
0
 def neko_api(self, ctx, x):
     try:
         req = requests.get(f'https://nekos.life/api/v2/img/{x}')
         if req.status_code != 200:
             print("Could not get a neko")
         apijson = json.loads(req.text)
         url = apijson["url"]
         em = dmbd.newembed().set_image(url=url)
         return em
     except:
         return teapot.messages.error(
             f"obtaining image ({req.status_code})")
Esempio n. 2
0
 async def dog(self, ctx):
     """ Get a dog image """
     req = requests.get('http://random.dog/')
     if req.status_code != 200:
         await ctx.message.add_reaction(emoji='❌')
         await ctx.send("API error, could not get a woof")
         print("Could not get a woof")
     doglink = BeautifulSoup(req.text, 'html.parser')
     rngdog = 'http://random.dog/' + doglink.img['src']
     em = dmbd.newembed()
     em.set_image(url=rngdog)
     await ctx.send(embed=em)
     await ctx.message.add_reaction(emoji='✅')
Esempio n. 3
0
 async def cat(self, ctx):
     """ Get a cat image """
     req = requests.get('https://api.thecatapi.com/v1/images/search')
     if req.status_code != 200:
         await ctx.message.add_reaction(emoji='❌')
         await ctx.send("API error, could not get a meow")
         print("Could not get a meow")
     catlink = json.loads(req.text)[0]
     rngcat = catlink["url"]
     em = dmbd.newembed()
     em.set_image(url=rngcat)
     await ctx.send(embed=em)
     await ctx.message.add_reaction(emoji='✅')
Esempio n. 4
0
 def display(self, author):
     em = dmbd.newembed()
     em.set_author(name=f"{self.country.upper()} | {self.username}",
                   url=f"https://osu.ppy.sh/u/{self.username}")
     em.add_field(name='Performance', value=self.pp_raw + 'pp')
     em.add_field(name='Accuracy',
                  value="{0:.2f}%".format(float(self.accuracy)))
     lvl = int(float(self.level))
     percent = int((float(self.level) - lvl) * 100)
     em.add_field(name='Level', value=f"{lvl} ({percent}%)")
     em.add_field(name='Rank', value=self.pp)
     em.add_field(name='Country Rank', value=self.pp_country_rank)
     em.add_field(name='Playcount', value=self.playcount)
     em.add_field(name='Total Score', value=self.total)
     em.add_field(name='Ranked Score', value=self.ranked)
     em.add_field(name='Registered At', value=self.join_date)
     return em
Esempio n. 5
0
    async def github(self, ctx, arg):
        """Fetch repository info"""

        req = requests.get(f'https://api.github.com/repos/{arg}')
        apijson = json.loads(req.text)
        if req.status_code == 200:
            em = dmbd.newembed()
            em.set_author(name=apijson['owner']['login'],
                          icon_url=apijson['owner']['avatar_url'],
                          url=apijson['owner']['html_url'])
            em.set_thumbnail(url=apijson['owner']['avatar_url'])
            em.add_field(name="Repository:",
                         value=f"[{apijson['name']}]({apijson['html_url']})",
                         inline=True)
            em.add_field(name="Language:",
                         value=apijson['language'],
                         inline=True)

            try:
                license = f"[{apijson['license']['spdx_id']}]({json.loads(requests.get(apijson['license']['url']).text)['html_url']})"
            except:
                license = "None"
            em.add_field(name="License:", value=license, inline=True)
            if apijson['stargazers_count'] != 0:
                em.add_field(name="Star:",
                             value=apijson['stargazers_count'],
                             inline=True)
            if apijson['forks_count'] != 0:
                em.add_field(name="Fork:",
                             value=apijson['forks_count'],
                             inline=True)
            if apijson['open_issues'] != 0:
                em.add_field(name="Issues:",
                             value=apijson['open_issues'],
                             inline=True)
            em.add_field(name="Description:",
                         value=apijson['description'],
                         inline=False)

            for meta in BeautifulSoup(requests.get(apijson['html_url']).text,
                                      features="html.parser").find_all('meta'):
                try:
                    if meta.attrs['property'] == "og:image":
                        em.set_image(url=meta.attrs['content'])
                        break
                except:
                    pass

            await ctx.send(embed=em)
        elif req.status_code == 404:
            """if repository not found"""
            await ctx.send(embed=teapot.messages.notfound("repository"))
        elif req.status_code == 503:
            """GithubAPI down"""
            await ctx.send("GithubAPI down")
            await ctx.send(
                embed=teapot.messages.notfound("Fetch repository info"))
        else:
            """some error occurred while fetching repository info"""
            await ctx.send(embed=teapot.messages.error("Fetch repository info")
                           )