Пример #1
0
def is_player_check(member, channel=None):
    if isinstance(member, discord.Member):
        try:
            member = scores.getChannelPlayers(channel, columns=['shoots_fired'], match_id=member.id)[0]
        except IndexError:
            return False

    return member.get('shoots_fired', 0) or 0
Пример #2
0
Файл: api.py Проект: swhitt/DHV2
async def guild(ctx: HTTPRequestContext, server_id: str):
    await commons.bot.wait_until_ready()

    server = commons.bot.get_server(server_id)

    if server:
        player_count = 0
        channels = []

        global_scores = prefs.getPref(server, "global_scores")

        stats = defaultdict(int)

        if not global_scores:
            for channel in server.channels:
                activated = checks.is_activated_check(channel)
                if activated and channel.type == ChannelType.text:
                    table = scores.getChannelPlayers(channel,
                                                     columns=['shoots_fired'])
                    for member in table:
                        if checks.is_player_check(member):
                            channels.append({
                                "id": channel.id,
                                "name": channel.name
                            })
                            break

            channels.sort(key=lambda x: x['name'])

            resp = {
                "server": {
                    "name": server.name,
                    "channels": channels
                },
                "global_scores": global_scores
            }
        else:
            data = await list_members(server_id, server_id)

            if data:
                resp = {
                    "server": {
                        "id": data['server'].id,
                        "name": data['server'].name
                    },
                    "players": data['players'],
                    "global_scores": global_scores
                }
            else:
                return await prepare_resp(None, 404)  # Error

        return await prepare_resp(resp)
    else:
        return await prepare_resp(None, 404)  # Guild not found
Пример #3
0
Файл: api.py Проект: swhitt/DHV2
async def list_members(server_id, channel_id):
    server = commons.bot.get_server(server_id)

    if server:
        channel = server.get_channel(channel_id)
        if channel:
            activated = checks.is_activated_check(channel)

            if activated or prefs.getPref(server, "global_scores"):
                players = []
                table = scores.getChannelPlayers(channel,
                                                 columns=['shoots_fired'])

                for member in table:
                    if checks.is_player_check(member):
                        try:
                            player = server.get_member(str(member['id_']))

                            players.append({
                                "id":
                                player.id,
                                "name":
                                player.display_name,
                                "avatar":
                                player.avatar_url.replace('.webp', '.png')
                                or player.
                                default_avatar_url  # Tempfix pour le png
                            })
                        except:
                            pass
            else:
                return None  # Channel not activated
        else:
            return None  # Channel not found
    else:
        return None  # Guild not found

    players.sort(key=lambda x: x['name'])

    data = {"server": server, "channel": channel, "players": players}

    return data
Пример #4
0
Файл: api.py Проект: swhitt/DHV2
async def guild_channel_user(ctx: HTTPRequestContext, server_id: str,
                             channel_id: str, user_id: str):
    await commons.bot.wait_until_ready()
    server = commons.bot.get_server(server_id)

    if server:
        channel = server.get_channel(channel_id)
        if channel:
            activated = checks.is_activated_check(channel)
            if activated:
                player = server.get_member(user_id)

                resp = scores.getChannelPlayers(channel, match_id=user_id)[0]
                resp['avatar'] = player.avatar_url.replace(
                    '.webp', '.png') or player.default_avatar_url
            else:
                return await prepare_resp(None, 404)  # Channel not activated
        else:
            return await prepare_resp(None, 404)  # Channel not found
    else:
        return await prepare_resp(None, 404)  # Guild not found

    return await prepare_resp(resp)
Пример #5
0
Файл: api.py Проект: swhitt/DHV2
async def guilds(ctx: HTTPRequestContext):
    await commons.bot.wait_until_ready()

    servers = []
    server_count = 0

    for server in commons.bot.servers:
        global_scores = prefs.getPref(server, "global_scores")
        channel_count = 0
        hasPlayers = False

        for channel in server.channels:
            activated = checks.is_activated_check(channel)
            if activated and channel.type == ChannelType.text:
                channel_count += 1
                if not hasPlayers:
                    table = scores.getChannelPlayers(channel,
                                                     columns=['shoots_fired'])
                    for member in table:
                        if checks.is_player_check(member):
                            hasPlayers = True
                            break

        if channel_count > 0 and hasPlayers:
            server_count += 1
            servers.append({
                "id": server.id,
                "name": server.name,
                "icon": server.icon_url
            })

    servers.sort(key=lambda x: x['name'])

    resp = {"servers": servers, "server_count": server_count}

    return await prepare_resp(resp)
Пример #6
0
    async def bang(self, ctx):
        now = time.time()
        message = ctx.message
        channel = message.channel
        author = message.author

        language = prefs.getPref(message.server, "language")
        await self.giveBackIfNeeded(message)

        if scores.getStat(channel, author, "mouille") > int(now):  # Water
            await comm.message_user(
                message,
                _(
                    "Your clothes are wet, you can't go hunting! Wait {temps_restant} minutes.",
                    language).format(
                        **{
                            "temps_restant":
                            int((scores.getStat(channel, author, "mouille") -
                                 int(time.time())) / 60)
                        }))
            scores.addToStat(channel, author, "shoots_tried_while_wet", 1)
            return

        if scores.getStat(channel, author, "confisque",
                          default=False):  # No weapon
            await comm.message_user(message,
                                    _("You don't have a weapon.", language))
            scores.addToStat(channel, author, "shoots_without_weapon", 1)
            return

        if scores.getStat(channel, author, "enrayee", default=False):  # Jammed
            await comm.message_user(
                message,
                _("Your weapon is jammed, it must be reloaded to unjam it.",
                  language))
            scores.addToStat(channel, author, "shoots_with_jammed_weapon", 1)
            return

        if scores.getStat(channel, author, "sabotee",
                          default="-") is not "-":  # Sabotaged
            await comm.message_user(
                message,
                _(
                    "Your weapon is sabotaged, thank {assaillant} for this bad joke.",
                    language).format(
                        **{
                            "assaillant":
                            scores.getStat(
                                channel, author, "sabotee", default="-")
                        }))
            scores.addToStat(channel, author, "shoots_sabotaged", 1)
            scores.setStat(channel, author, "enrayee", True)
            scores.setStat(channel, author, "sabotee", "-")
            return

        if scores.getStat(
                channel,
                author,
                "balles",
                default=scores.getPlayerLevel(
                    channel,
                    author)["balles"]) <= 0:  # No more bullets in charger
            await comm.message_user(
                message,
                _(
                    "** CHARGER EMPTY ** | Ammunition in the weapon: {balles_actuelles} / {balles_max} | Magazines remaining: {chargeurs_actuels} / {chargeurs_max}",
                    language).format(
                        **{
                            "balles_actuelles":
                            scores.getStat(channel,
                                           author,
                                           "balles",
                                           default=scores.getPlayerLevel(
                                               channel, author)["balles"]),
                            "balles_max":
                            scores.getPlayerLevel(channel, author)["balles"],
                            "chargeurs_actuels":
                            scores.getStat(channel,
                                           author,
                                           "chargeurs",
                                           default=scores.getPlayerLevel(
                                               channel, author)["chargeurs"]),
                            "chargeurs_max":
                            scores.getPlayerLevel(channel, author)["chargeurs"]
                        }))
            scores.addToStat(channel, author, "shoots_without_bullets", 1)
            return

        fiabilite = scores.getPlayerLevel(channel, author)["fiabilitee"]

        if scores.getStat(channel, author, "sand", default=False):
            fiabilite /= 2
            scores.setStat(channel, author, "sand", False)

        if not random.randint(1, 100) <= fiabilite and not (scores.getStat(
                channel, author,
                "graisse") > int(now)):  # Weapon jammed just now
            await comm.message_user(
                message,
                _("Your weapon just jammed, reload it to unjam it.", language))
            scores.addToStat(channel, author, "shoots_jamming_weapon", 1)
            scores.setStat(channel, author, "enrayee", True)
            return

        current_duck = None

        if commons.ducks_spawned:
            for duck in commons.ducks_spawned:
                if duck["channel"] == channel:
                    current_duck = duck
                    break

        if not current_duck and scores.getStat(
                channel, author,
                "detecteurInfra") > int(now) and scores.getStat(
                    channel, author, "detecteur_infra_shots_left"
                ) > 0:  # No ducks but infrared detector
            await comm.message_user(
                message,
                _(
                    "There isn't any duck in here, but the bullet wasn't fired because the infrared detector you added to your weapon is doing its job!",
                    language))
            scores.addToStat(channel, author, "shoots_infrared_detector", 1)
            scores.addToStat(channel, author, "detecteur_infra_shots_left", -1)
            return

        scores.addToStat(channel, author, "balles", -1)
        scores.addToStat(channel, author, "shoots_fired", 1)

        if not current_duck:  # No duck
            await self.sendBangMessage(
                message,
                _(
                    "Luckily you missed, but what were you aiming at exactly? There isn't any duck in here... [missed: -1 xp] [wild shot: -1 xp]",
                    language))
            scores.addToStat(channel, author, "exp", -2)
            scores.addToStat(channel, author, "shoots_no_duck", 1)
            return

        if random.randint(1, 100) <= prefs.getPref(
                message.server, "duck_frighten_chance") and scores.getStat(
                    channel, author,
                    "silencieux") < int(now):  # Duck frightened
            try:
                commons.ducks_spawned.remove(current_duck)
                commons.n_ducks_flew += 1
                scores.addToStat(channel, author, "exp", -1)
                await self.sendBangMessage(
                    message,
                    _(
                        "**FLAPP**\tFrightened by so much noise, the duck fled! CONGRATS! [missed: -1 xp]",
                        language))
                scores.addToStat(channel, author, "shoots_frightened", 1)
            except ValueError:
                await self.sendBangMessage(
                    message,
                    _("**PIEWW**\tYou missed the duck! [missed: -1 xp]",
                      language))
                scores.addToStat(channel, author, "shoots_missed", 1)
            return

        if scores.getStat(channel, author, "dazzled", True):
            accuracy = 200  # 50% moins de chance de toucher
            scores.setStat(channel, author, "dazzled", False)
        else:
            accuracy = 100

        precision = scores.getPlayerLevel(channel, author)["precision"]
        sight = scores.getStat(channel, author, "sight")
        if sight:
            precision += (100 - precision) / 3
            scores.setStat(channel, author, "sight", sight - 1)

        if random.randint(1, accuracy) > precision * prefs.getPref(
                message.server, "multiplier_miss_chance"):
            if random.randint(1, 100) <= prefs.getPref(
                    message.server,
                    "chance_to_kill_on_missed"):  # Missed and shot someone
                scores.addToStat(channel, author, "exp", -3)
                scores.addToStat(channel, author, "shoots_missed", 1)
                scores.addToStat(channel, author, "killed_players", 1)
                scores.setStat(channel, author, "confisque", True)

                memberlist = scores.getChannelPlayers(channel,
                                                      columns=['shoots_fired'])
                victim = None
                while not victim:
                    victim = random.choice(memberlist)
                    while not checks.is_player_check(victim):
                        memberlist.remove(victim)
                        victim = random.choice(memberlist)

                    victim = message.server.get_member(str(victim['id_']))

                if victim is not author:
                    await self.sendBangMessage(
                        message,
                        _(
                            "**BANG**\tYou missed the duck... and shot {player}! [missed: -1 xp] [hunting accident: -2 xp] [weapon confiscated]",
                            language).format(
                                **{
                                    "player":
                                    victim.mention if prefs.
                                    getPref(message.server, "killed_mentions"
                                            ) else victim.name
                                }))
                else:
                    await self.sendBangMessage(
                        message,
                        _(
                            "**BANG**\tYou missed the duck... and shot yourself! Maybe you should turn your weapon a little before shooting the next time? [missed: -1 xp] [hunting accident: -2 xp] [weapon confiscated]",
                            language))
                    scores.addToStat(channel, author, "self_killing_shoots", 1)

                if scores.getStat(channel, victim,
                                  "life_insurance") > int(now):
                    exp = int(
                        scores.getPlayerLevel(channel, author)["niveau"] / 2)
                    scores.addToStat(channel, victim, "exp", exp)
                    await self.bot.send_message(
                        channel,
                        str(victim.mention) +
                        _(" > You won {exp} with your life insurance !",
                          language).format(**{"exp": exp}))
                    scores.addToStat(channel, victim, "life_insurence_rewards",
                                     1)
            else:  # Missed and none was shot
                scores.addToStat(channel, author, "exp", -1)
                scores.addToStat(channel, author, "shoots_missed", 1)
                await self.sendBangMessage(
                    message,
                    _("**PIEWW**\tYou missed the duck! [missed: -1 xp]",
                      language))
            return

        if scores.getStat(channel, author, "explosive_ammo") > int(now):
            current_duck["SCvie"] -= 3
            vieenmoins = 3
            ono = _("BPAM", language)
        elif scores.getStat(channel, author, "ap_ammo") > int(now):
            current_duck["SCvie"] -= 2
            vieenmoins = 2
            ono = _("BAAM", language)
        else:
            current_duck["SCvie"] -= 1
            vieenmoins = 1
            ono = random.choice([_("BOUM", language), _("SPROTCH", language)])

        if current_duck["SCvie"] <= 0:  # Duck killed
            try:
                commons.ducks_spawned.remove(current_duck)
                commons.n_ducks_killed += 1
            except ValueError:
                await self.sendBangMessage(
                    message,
                    _(
                        "That was close, you almost killed the duck, but the other hunter got it first! [missed: -1 xp]",
                        language))
                scores.addToStat(channel, author, "exp", -1)
                scores.addToStat(channel, author, "shoots_missed", 1)
                scores.addToStat(channel, author, "shoots_almost_killed", 1)
                return

            exp = prefs.getPref(message.server, "exp_won_per_duck_killed")
            exp += prefs.getPref(
                message.server, "super_ducks_exp_multiplier") * (
                    current_duck["level"] - 1) * prefs.getPref(
                        message.server, "exp_won_per_duck_killed")
            if scores.getStat(channel, author, "trefle") >= time.time():
                toadd = scores.getStat(channel, author, "trefle_exp")
                exp += toadd
                scores.addToStat(channel, author, "exp_won_with_clover", toadd)

            exp = int(exp)

            scores.addToStat(channel, author, "exp", exp)
            scores.addToStat(channel, author, "killed_ducks", 1)
            if current_duck["level"] > 1:
                scores.addToStat(channel, author, "killed_super_ducks", 1)

            await self.sendBangMessage(
                message,
                _(
                    ":skull_crossbones: **{onomatopoeia}**\tYou killed the duck in {time} seconds, you are now at a grand total of {total} ducks (of which {supercanards} were super-ducks) killed on #{channel}.     \_X<   *COUAC*   [{exp} exp]",
                    language).format(
                        **{
                            "time":
                            round(now - current_duck["time"], 4),
                            "total":
                            scores.getStat(channel, author, "killed_ducks"),
                            "channel":
                            channel,
                            "exp":
                            exp,
                            "supercanards":
                            scores.getStat(channel, author,
                                           "killed_super_ducks"),
                            "onomatopoeia":
                            ono
                        }))
            if scores.getStat(channel,
                              author,
                              "best_time",
                              default=prefs.getPref(message.server,
                                                    "time_before_ducks_leave")
                              ) > float(now - current_duck["time"]):
                scores.setStat(channel, author, "best_time",
                               round(now - current_duck["time"], 6))
            if prefs.getPref(message.server, "users_can_find_objects"):
                rand = random.randint(0, 1000)
                HOUR = 3600
                DAY = 86400

                if rand <= 50:
                    scores.addToStat(channel, author, "trashFound", 1)
                    await comm.message_user(
                        message,
                        _(
                            "While searching in the bushes around the duck, you found **{inutilite}**.",
                            language).format(
                                **{
                                    "inutilite":
                                    _(random.choice(commons.inutilite),
                                      language)
                                }))

                elif rand <= 54:
                    c = scores.getStat(message.channel, message.author,
                                       "explosive_ammo")
                    if c > time.time():
                        scores.setStat(message.channel, message.author,
                                       "explosive_ammo", int(c + DAY))
                    else:
                        scores.setStat(message.channel,
                                       message.author, "explosive_ammo",
                                       int(time.time() + DAY))
                    scores.addToStat(message.channel, message.author,
                                     "found_explosive_ammo", 1)
                    await comm.message_user(
                        message,
                        _(
                            "While searching in the bushes around the duck, you found **a box of explosive ammo**.",
                            language))

                elif rand <= 60:
                    c = scores.getStat(message.channel, message.author,
                                       "explosive_ammo")
                    if c > time.time():
                        scores.setStat(message.channel, message.author,
                                       "explosive_ammo", int(c + DAY / 4))
                    else:
                        scores.setStat(message.channel, message.author,
                                       "explosive_ammo",
                                       int(time.time() + DAY / 4))
                    scores.addToStat(message.channel, message.author,
                                     "found_almost_empty_explosive_ammo", 1)
                    await comm.message_user(
                        message,
                        _(
                            "While searching in the bushes around the duck, you found **an almost empty box of explosive ammo**.",
                            language))

                elif rand <= 63:
                    scores.addToStat(message.channel, message.author,
                                     "found_chargers", 1)

                    if scores.getStat(message.channel,
                                      message.author,
                                      "chargeurs",
                                      default=scores.getPlayerLevel(
                                          message.channel, message.author)
                                      ["chargeurs"]) < scores.getPlayerLevel(
                                          message.channel,
                                          message.author)["chargeurs"]:
                        scores.addToStat(message.channel, message.author,
                                         "chargeurs", 1)
                        await comm.message_user(
                            message,
                            _(
                                "While searching in the bushes around the duck, you found **a full charger**.",
                                language))
                    else:
                        scores.addToStat(message.channel, message.author,
                                         "found_chargers_not_taken", 1)
                        await comm.message_user(
                            message,
                            _(
                                "While searching in the bushes around the duck, you found **a full charger**. You left it there, because your backpack is full.",
                                language))
                elif rand <= 70:
                    scores.addToStat(message.channel, message.author,
                                     "found_bullets", 1)
                    if scores.getStat(message.channel,
                                      message.author,
                                      "balles",
                                      default=scores.getPlayerLevel(
                                          message.channel, message.author)
                                      ["balles"]) < scores.getPlayerLevel(
                                          message.channel,
                                          message.author)["balles"]:
                        scores.addToStat(message.channel, message.author,
                                         "balles", 1)
                        await comm.message_user(
                            message,
                            _(
                                "While searching in the bushes around the duck, you found **a bullet**.",
                                language))

                    else:  # Shouldn't happen but we never know...
                        await comm.message_user(
                            message,
                            _(
                                "While searching in the bushes around the duck, you found **a bullet**. You left it there, because you have enough in your charger.",
                                language))
                        scores.addToStat(message.channel, message.author,
                                         "found_bullets_not_taken", 1)

        else:  # Duck harmed
            await self.sendBangMessage(
                message,
                _(
                    ":gun: The duck survived, try again! *SUPER DUCK DETECTED* [life: -{vie}]",
                    language).format(**{"vie": vieenmoins}))
            current_duck["SCvie"] -= vieenmoins
            scores.addToStat(channel, author, "shoots_harmed_duck", 1)