Exemplo n.º 1
0
async def osuStats(cls: "PhaazebotDiscord", _Command: DiscordCommand,
                   CommandContext: DiscordCommandContext) -> dict:

    search_mode: str = "0"
    if "--taiko" in CommandContext.parts:
        CommandContext.parts.remove("--taiko")
        search_mode = "1"
    elif "--ctb" in CommandContext.parts:
        CommandContext.parts.remove("--ctb")
        search_mode = "2"
    elif "--mania" in CommandContext.parts:
        CommandContext.parts.remove("--mania")
        search_mode = "3"

    content: str = " ".join(CommandContext.parts[1:])

    if not content:
        return {
            "content":
            ":warning: Please specify a query string to search a user"
        }

    search_by, is_id = extractUserInfo(content)
    User: OsuUser = await getOsuUser(cls.BASE,
                                     search=search_by,
                                     mode=search_mode,
                                     is_id=is_id)

    if not User:
        return {"content": ":warning: The given User could not found!"}

    emb_description: str = f":globe_with_meridians: #{prettifyNumbers(User.pp_rank, 0)}  |  :flag_{User.country.lower()}: #{prettifyNumbers(User.pp_country_rank, 0)}\n"
    emb_description += f":part_alternation_mark: {prettifyNumbers(User.pp_raw, 2)} pp\n"
    emb_description += f":dart: {prettifyNumbers(User.accuracy, 2)}% Accuracy\n"
    emb_description += f":military_medal: Level: {prettifyNumbers(User.level, 2)}\n"
    emb_description += f":timer: Playcount: {prettifyNumbers(User.playcount, 0)}\n"
    emb_description += f":chart_with_upwards_trend: Ranked Score: {prettifyNumbers(User.ranked_score, 0)}\n"
    emb_description += f":card_box: Total Score: {prettifyNumbers(User.total_score, 0)}\n"
    emb_description += f":id: {User.user_id}"

    Emb: discord.Embed = discord.Embed(
        title=User.username,
        color=0xFF69B4,
        description=emb_description,
        url=f"https://osu.ppy.sh/users/{User.user_id}")

    rank_table: list = [["A", prettifyNumbers(User.count_rank_a)],
                        ["S", prettifyNumbers(User.count_rank_s)],
                        ["SX", prettifyNumbers(User.count_rank_sh)],
                        ["SS", prettifyNumbers(User.count_rank_ss)],
                        ["SSX", prettifyNumbers(User.count_rank_ssh)]]

    Emb.add_field(name="Ranks:",
                  value=f"```{tabulate(rank_table, tablefmt='plain')}```")

    Emb.set_thumbnail(url=f"https://a.ppy.sh/{User.user_id}")
    Emb.set_footer(text="Provided by osu!", icon_url=cls.BASE.Vars.logo_osu)
    Emb.set_author(name=f"Stats for: {User.mode}")

    return {"embed": Emb}
Exemplo n.º 2
0
async def levelStatus(cls:"PhaazebotDiscord", Command:DiscordCommand, CommandContext:DiscordCommandContext) -> dict:

	# other than, normal, mod or regular commands that get blocked in commands.py
	# we can not tell if that command is a level command until now, so we end it now

	# owner disabled level commands serverwide
	if CommandContext.ServerSettings.owner_disable_level:
		return {}

	# same as above just for a a specific channel
	if CommandContext.Message.channel.id in CommandContext.ServerSettings.disabled_levelchannels:
		return {}

	search_from:str = " ".join([x for x in CommandContext.parts[1:]])
	# no search use author
	if not search_from:
		Member:discord.Member = CommandContext.Message.author
	# try a search
	else:
		Member:Optional[discord.Member] = getDiscordMemberFromString(cls, Guild=CommandContext.Message.guild, search=search_from, Message=CommandContext.Message)
		if not Member:
			return {"content": ":warning: Could not find a user with your query"}

	users:list = await getDiscordServerUsers(cls, guild_id=Command.server_id, member_id=Member.id)

	if not users:
		return {"content": f":warning: Seems like there are no statistics for `{Member.name}`\nMaybe the user never typed anything or got deleted."}

	LevelUser:DiscordUserStats = users.pop(0)

	exp_current:int = LevelUser.exp
	lvl_current:int = LevelCalc.getLevel(exp_current)
	exp_next:int = LevelCalc.getExp(lvl_current+1)
	rank:str = prettifyNumbers(LevelUser.rank) if LevelUser.rank else "[N/A]"
	avatar:str = Member.avatar_url if Member.avatar_url else Member.default_avatar_url

	Emb:discord.Embed = discord.Embed(color=0x00ffdd)
	Emb.set_author(name=Member.name, icon_url=avatar)

	Emb.add_field(name="Level:", value=f"{prettifyNumbers(lvl_current)}", inline=True)
	Emb.add_field(name="Exp:", value=f"{prettifyNumbers(exp_current)} / {prettifyNumbers(exp_next)}", inline=True)
	Emb.add_field(name="Rank:", value=f"# {rank}", inline=True)

	if LevelUser.edited:
		Emb.add_field(name=":warning: EDITED",value="Exp value got edited.", inline=False)

	if LevelUser.medals:
		Emb.add_field(name="Medals:",value="\n".join(m for m in LevelUser.medals), inline=False)

	return {"embed": Emb}
Exemplo n.º 3
0
async def levelLeaderboard(cls: "PhaazebotDiscord", Command: DiscordCommand,
                           CommandContext: DiscordCommandContext) -> dict:

    # other than, normal, mod or regular commands that get blocked in commands.py
    # we can not tell if that command is a level command until now, so we end it now

    # owner disabled level commands serverwide
    if CommandContext.ServerSettings.owner_disable_level:
        return {}

    # same as above just for a a specific channel
    if CommandContext.Message.channel.id in CommandContext.ServerSettings.disabled_levelchannels:
        return {}

    specific_len: Union[int, str] = CommandContext.part(1)
    if specific_len:
        if not specific_len.isdigit():
            specific_len = DEFAULT_LEADERBOARD_LEN
        else:
            specific_len = int(specific_len)

    else:
        specific_len = DEFAULT_LEADERBOARD_LEN

    if not specific_len or specific_len > MAX_LEADERBOARD_LEN:
        return {
            "content":
            f":warning: `{specific_len}` is unsupported, length must be between 1 and 15"
        }

    users: list = await getDiscordServerUsers(cls,
                                              guild_id=Command.server_id,
                                              limit=specific_len,
                                              order_str="ORDER BY exp DESC")

    if not users:
        return {
            "content":
            ":question: Seems like there are no member with level for a leaderboard :("
        }

    # there are less member ín the return than the limit requests, very rare
    if len(users) < specific_len:
        specific_len = len(users)

    return_table: list = [["#", "|", "LVL", "|", "EXP", "|", "Name"],
                          ["---", "|", "---", "|", "---", "|", "---"]]

    for LevelUser in users:

        e: str = " [EDITED]" if LevelUser.edited else ""
        lvl: str = prettifyNumbers(LevelCalc.getLevel(LevelUser.exp))
        exp: str = prettifyNumbers(LevelUser.exp)
        Member: discord.Member = CommandContext.Message.guild.get_member(
            int(LevelUser.member_id))
        if Member:
            user_name: str = Member.name
        else:
            user_name: str = "[N/A]"

        return_table.append(
            [f"#{LevelUser.rank}", "|", lvl, "|", f"{exp}{e}", "|", user_name])

    table: str = tabulate(return_table, tablefmt="plain")

    return {
        "content":
        f"**Top: {specific_len} leaderboard** :link: {cls.BASE.Vars.web_root}/discord/level/{Command.server_id} ```{table}```"
    }