Пример #1
0
 async def osu(self, ctx, *, username:str):
     """Gets an osu! profile stats with the specified name"""
     if not config.enableOsu:
         await ctx.send(Language.get("information.osu_command_disabled", ctx))
         return
     try:
         import osuapi
     except ImportError:
         log.critical("The osu api is enabled, but the osuapi module was not found! Please run \"pip install osuapi\"")
         await ctx.send(Language.get("osu_import_fail", ctx))
         return
     await ctx.channel.trigger_typing()
     api = osuapi.OsuApi(config._osuKey, connector=osuapi.AHConnector())
     try:
         user = await api.get_user(username)
     except osuapi.HTTPError as e:
         if e.code == 401:
             log.critical("An invalid osu! api key was set, please check the config for instructions on how to get a proper api key!")
             await ctx.send(Language.get("information.osu_invalid_key", ctx))
             return
         else:
             log.critical("An unknown error occured while trying to get an osu! profile.")
             await ctx.send(Language.get("information.osu_unknown_error", ctx))
             return
     try:
         user = user[0]
     except IndexError:
         await ctx.send(Language.get("information.no_osu_profile_found", ctx).format(username))
         return
     fields = {Language.get("information.id", ctx):user.user_id, Language.get("information.country", ctx):user.country, Language.get("information.level", ctx):int(user.level), Language.get("information.hits", ctx):user.total_hits, Language.get("information.score", ctx):user.total_score, Language.get("information.accuracy", ctx):"{0:.2f}%".format(user.accuracy), Language.get("information.play_count", ctx):user.playcount, Language.get("information.ranked_score", ctx):user.ranked_score, Language.get("information.a_rank", ctx):user.count_rank_a, Language.get("information.s_rank", ctx):user.count_rank_s, Language.get("information.ss_rank", ctx):user.count_rank_ss}
     embed = make_list_embed(fields)
     embed.title = Language.get("information.osu_stats_title", ctx).format(user.username)
     embed.color = 0xFF00FF
     embed.set_thumbnail(url="http://s.ppy.sh/a/{}".format(user.user_id))
     await ctx.send(embed=embed)
Пример #2
0
 async def osu(self, ctx, *, username: str):
     """Gets an osu! profile stats with the specified name"""
     if not config.enableOsu:
         await self.bot.say("The osu! command has been disabled.")
         return
     try:
         import osuapi
     except ImportError:
         log.critical(
             "The osu api is enabled, but the osuapi module was not found! Please run \"pip install osuapi\""
         )
         await self.bot.say(
             "Couldn't import the osu! api module, contact the bot developer!"
         )
         return
     await self.bot.send_typing(ctx.message.channel)
     api = osuapi.OsuApi(config._osuKey, connector=osuapi.AHConnector())
     try:
         user = await api.get_user(username)
     except osuapi.HTTPError as e:
         if e.code == 401:
             log.critical(
                 "An invalid osu! api key was set, please check the config for instructions on how to get a proper api key!"
             )
             await self.bot.say(
                 "An invalid osu! api key was set, contact the bot developer!"
             )
             return
         else:
             log.critical(
                 "An unknown error occured while trying to get an osu! profile."
             )
             await self.bot.say(
                 "An unknown error occured while trying to get that user's osu! profile, contact the bot developer!"
             )
             return
     try:
         user = user[0]
     except IndexError:
         await self.bot.say(
             "Could find any osu! profile named `{}`".format(username))
         return
     fields = {
         "ID": user.user_id,
         "Country": user.country,
         "Level": int(user.level),
         "Hits": user.total_hits,
         "Score": user.total_score,
         "Accuracy": "{0:.2f}%".format(user.accuracy),
         "Play Count": user.playcount,
         "Ranked Score": user.ranked_score,
         "A rank": user.count_rank_a,
         "S rank": user.count_rank_s,
         "SS rank": user.count_rank_ss
     }
     embed = make_list_embed(fields)
     embed.title = "{}'s Osu! Stats".format(user.username)
     embed.color = 0xFF00FF
     embed.set_thumbnail(url="http://s.ppy.sh/a/{}".format(user.user_id))
     await self.bot.say(embed=embed)
Пример #3
0
 async def osu(self, ctx, *, username: str):
     """Gets an osu! profile stats with the specified name"""
     if not config.enableOsu:
         await self.bot.say("The osu command is currently disabled.")
         return
     try:
         import osuapi
     except ImportError:
         log.critical(
             "The osu api is enabled, but the osuapi module was not found! Please run \"pip install osuapi\""
         )
         await self.bot.say(
             "Couldn't import the osu! api module, contact the bot developer!"
         )
         return
     await self.bot.send_typing(ctx.message.channel)
     api = osuapi.OsuApi(config._osuKey, connector=osuapi.AHConnector())
     try:
         user = await api.get_user(username)
     except osuapi.HTTPError as e:
         if e.code == 401:
             log.critical(
                 "An invalid osu! api key was set, please check the config for instructions on how to get a proper api key!"
             )
             await self.bot.say(
                 "An invalid osu! api key was set, contact the bot developer!"
             )
             return
         else:
             log.critical(
                 "An unknown error occured while trying to get an osu! profile."
             )
             await self.bot.say(
                 "An unknown error occured while trying to get that user's osu! profile, contact the bot developer!"
             )
             return
     try:
         user = user[0]
     except IndexError:
         await self.bot.say(
             "Could find any osu! profile named `{}`".format(username))
         return
     results = discord.Embed(description="\u200b")
     results.title = user.username + "'s osu! stats"
     results.add_field(name='ID', value=user.user_id)
     results.add_field(name='Country', value=user.country)
     results.add_field(name='Level', value=int(user.level))
     results.add_field(name='Total Hits', value=user.total_hits)
     results.add_field(name='Total Score', value=user.total_score)
     results.add_field(name='Accuracy',
                       value="{0:.2f}%".format(user.accuracy))
     results.add_field(name='Play Count', value=user.playcount)
     results.add_field(name='Ranked Score', value=user.ranked_score)
     results.add_field(name='A Rank Count/S Rank Count/SS Rank Count',
                       value="{}/{}/{}".format(user.ranked_score,
                                               user.count_rank_a,
                                               user.count_rank_s,
                                               user.count_rank_ss))
     await self.bot.say(embed=results)
Пример #4
0
    def __init__(self, config, attr):
        self.attr = attr
        self.api_key = config.register("api_key")
        self.osuapi = osuapi.OsuApi(
            self.api_key(),
            connector=osuapi.AHConnector(
                aiohttp.ClientSession(loop=asyncio.get_event_loop())))
        self._osu_presence_username_cache = LRU(4 << 10)

        self._beatmap_cache = LRU(256)
Пример #5
0
 async def osu(self, ctx, *, username: str):
     """Gets an osu! profile stats with the specified name"""
     if not config.enableOsu:
         await self.bot.say("The osu! command has been disabled.")
         return
     try:
         import osuapi
     except ImportError:
         log.critical(
             "The osu api is enabled, but the osuapi module was not found! Please run \"pip install osuapi\""
         )
         await self.bot.say(
             "Couldn't import the osu! api module, contact the bot developer!"
         )
         return
     await self.bot.send_typing(ctx.message.channel)
     api = osuapi.OsuApi(config._osuKey, connector=osuapi.AHConnector())
     try:
         user = await api.get_user(username)
     except osuapi.HTTPError as e:
         if e.code == 401:
             log.critical(
                 "An invalid osu! api key was set, please check the config for instructions on how to get a proper api key!"
             )
             await self.bot.say(
                 "An invalid osu! api key was set, contact the bot developer!"
             )
             return
         else:
             log.critical(
                 "An unknown error occured while trying to get an osu! profile."
             )
             await self.bot.say(
                 "An unknown error occured while trying to get that user's osu! profile, contact the bot developer!"
             )
             return
     try:
         user = user[0]
     except IndexError:
         await self.bot.say(
             "Could find any osu! profile named `{}`".format(username))
         return
     results = xl.format(
         "~~~~~~~~~~Osu! Stats~~~~~~~~~~\nUsername: {}\nID: {}\nCountry: {}\nLevel: {}\nTotal hits: {}\nTotal score: {}\nAccuracy: {}\nPlay count: {}\nRanked score: {}\nA rank: {}\nS rank: {}\nSS rank: {}\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
         .format("\"" + user.username + "\"", user.user_id,
                 "\"" + user.country + "\"", int(user.level),
                 user.total_hits, user.total_score,
                 "{0:.2f}%".format(user.accuracy), user.playcount,
                 user.ranked_score, user.count_rank_a, user.count_rank_s,
                 user.count_rank_ss))
     await self.bot.say(results)
Пример #6
0
  def __init__(self, bot):
    self.bot           = bot
    self.loop          = bot.loop
    self.conf          = Config('configs/osu.json')

    if 'api-key' not in self.conf:
      self.conf['api-key'] = input('enter osu api key: ')
    if 'watched-users' not in self.conf:
      self.conf['watched-users'] = {}
    self.conf.save()

    self.api=osuapi.OsuApi(self.conf['api-key'],connector=osuapi.AHConnector())

    self.loop.create_task(self.check_scores())
Пример #7
0
 def setUp(self):
     self.api = osuapi.OsuApi(
         key=os.environ['OSU_API_KEY'],
         connector=osuapi.AHConnector())
     # aiohttp can't decide if close() is a coro or not
     warnings.simplefilter("ignore")
Пример #8
0
 def setUp(self):
     self.api = osuapi.OsuApi(
         key=os.environ['OSU_API_KEY'],
         connector=osuapi.ReqConnector())
     warnings.simplefilter("error")
Пример #9
0
 def __init__(self, bot):
     self.bot = bot
     self.session = osuapi.AHConnector()
     self.osu = osuapi.OsuApi(bot.config['api_keys']['osu'],
                              connector=self.session)