コード例 #1
0
async def a_req(user: Player, args: list) -> str:
    """Accept a map status request"""
    if len(args) < 2:
        return "You must provide the request ID and status to set!"

    request = await glob.db.fetchrow(
        "SELECT * FROM requests WHERE id = %s",
        [int(args[0])],
    )
    _map = await Beatmap.bid_fetch(request["map"])
    ns = mapStatuses.from_str(args[1])

    # TODO: better management for ranking only certain difficulties
    _set = await glob.db.fetch("SELECT md5 FROM maps WHERE sid = %s",
                               [_map.sid])

    for m in _set:
        bm = await Beatmap.from_md5(m["md5"])
        bm.status = ns
        bm.frozen = True

        # reset lb cache in case of major status change
        bm.lb = None
        bm.lb_rx = None
        bm.lb_ap = None

        await bm.save()
        glob.cache["maps"][bm.md5] = bm

    if wh_url := glob.config.webhooks["maps"]:
        wh = Webhook(url=wh_url)
        embed = Embed(title="")

        embed.set_author(
            url=f"https://{glob.config.domain}/u/{user.id}",
            name=user.name,
            icon_url=f"https://a.{glob.config.domain}/{user.id}",
        )

        embed.set_image(
            url=f"https://assets.ppy.sh/beatmaps/{_map.sid}/covers/card.jpg", )

        embed.add_field(
            name=f"New {ns.name.lower()} map",
            value=f"[{_map.name}]({_map.url}) is now {ns.name.lower()}!",
            inline=True,
        )

        wh.add_embed(embed)
        await wh.post()
コード例 #2
0
ファイル: commands.py プロジェクト: cmyui/Asahi
async def _map(user: Player, args: list) -> str:
    """Update map statuses on the server"""
    if len(args) != 2:
        return 'Please provide the new status & whether we should update the map/set! (!map <rank/love/unrank> <map/set>)'

    status = args[0]
    _type = args[1]

    if status not in ('love', 'rank', 'unrank') or _type not in ('set', 'map'):
        return 'Invalid syntax! Command: !map <rank/love/unrank> <set/map>'

    bmap = user.np
    ns = mapStatuses.from_str(status)

    if _type == 'map':
        bmap.status = ns
        bmap.frozen = True

        # reset lb cache in case of major status change
        bmap.lb = None
        bmap.lb_rx = None
        bmap.lb_ap = None

        await bmap.save()
        glob.cache['maps'][bmap.md5] = bmap
    else:
        _set = await glob.db.fetch('SELECT md5 FROM maps WHERE sid = %s',
                                   [bmap.sid])

        for m in _set:
            md5 = m['md5']
            bm = await Beatmap.from_md5(md5)
            bm.status = ns
            bm.frozen = True

            # reset lb cache in case of major status change
            bm.lb = None
            bm.lb_rx = None
            bm.lb_ap = None

            await bm.save()
            glob.cache['maps'][bm.md5] = bm

    if (wh_url := glob.config.webhooks['maps']):
        wh = Webhook(url=wh_url)
        embed = Embed(title='')

        embed.set_author(url=f'https://{glob.config.domain}/u/{user.id}',
                         name=user.name,
                         icon_url=f'https://a.{glob.config.domain}/{user.id}')

        embed.set_image(
            url=f'https://assets.ppy.sh/beatmaps/{bmap.sid}/covers/card.jpg')

        embed.add_field(
            name=f'New {ns.name.lower()} map',
            value=f'[{bmap.name}]({bmap.url}) is now {ns.name.lower()}!',
            inline=True)

        wh.add_embed(embed)
        await wh.post()
コード例 #3
0
ファイル: commands.py プロジェクト: cmyui/Asahi
    ns = mapStatuses.from_str(args[0])

    await glob.db.execute(
        'INSERT IGNORE INTO requests (requester, map, status, mode) VALUES (%s, %s, %s, %s)',
        [user.name, user.np.id, int(ns), user.mode_vn])

    if (wh_url := glob.config.webhooks['requests']):
        wh = Webhook(url=wh_url)
        embed = Embed(title='')

        embed.set_author(url=f'https://{glob.config.domain}/u/{user.id}',
                         name=user.name,
                         icon_url=f'https://a.{glob.config.domain}/{user.id}')

        embed.set_image(
            url=f'https://assets.ppy.sh/beatmaps/{_map.sid}/covers/card.jpg')

        embed.add_field(
            name='New request',
            value=
            f'{user.name} requested [{_map.name}]({_map.url}) to be {ns.name.lower()}',
            inline=True)

        wh.add_embed(embed)
        await wh.post()

    return 'Request sent!'


@command(priv=Privileges.Admin, name='ban')
async def ban(user: Player, args: list) -> str:
コード例 #4
0
async def _map(user: Player, args: list) -> str:
    """Update map statuses on the server"""
    if len(args) != 2:
        return "Please provide the new status & whether we should update the map/set! (!map <rank/love/unrank> <map/set>)"

    status = args[0]
    _type = args[1]

    if status not in ("love", "rank", "unrank") or _type not in ("set", "map"):
        return "Invalid syntax! Command: !map <rank/love/unrank> <set/map>"

    bmap = user.np
    ns = mapStatuses.from_str(status)

    if _type == "map":
        bmap.status = ns
        bmap.frozen = True

        # reset lb cache in case of major status change
        bmap.lb = None
        bmap.lb_rx = None
        bmap.lb_ap = None

        await bmap.save()
        glob.cache["maps"][bmap.md5] = bmap
    else:
        _set = await glob.db.fetch("SELECT md5 FROM maps WHERE sid = %s",
                                   [bmap.sid])

        for m in _set:
            md5 = m["md5"]
            bm = await Beatmap.from_md5(md5)
            bm.status = ns
            bm.frozen = True

            # reset lb cache in case of major status change
            bm.lb = None
            bm.lb_rx = None
            bm.lb_ap = None

            await bm.save()
            glob.cache["maps"][bm.md5] = bm

    if wh_url := glob.config.webhooks["maps"]:
        wh = Webhook(url=wh_url)
        embed = Embed(title="")

        embed.set_author(
            url=f"https://{glob.config.domain}/u/{user.id}",
            name=user.name,
            icon_url=f"https://a.{glob.config.domain}/{user.id}",
        )

        embed.set_image(
            url=f"https://assets.ppy.sh/beatmaps/{bmap.sid}/covers/card.jpg", )

        embed.add_field(
            name=f"New {ns.name.lower()} map",
            value=f"[{bmap.name}]({bmap.url}) is now {ns.name.lower()}!",
            inline=True,
        )

        wh.add_embed(embed)
        await wh.post()