예제 #1
0
파일: Pack.py 프로젝트: ttrnecka/imperium
    async def genpack(self, ctx, pack_type:str, subtype:str=None):
        """Generates packs"""
        if not check_gen_command(pack_type, subtype):
          raise discord.ext.commands.CommandError("Invalid usage!")

        coach = CoachService.discord_user_to_coach(ctx.author)
        if coach is None:
          await ctx.send(f"Coach {ctx.author.mention} does not exist. Use !newcoach to create coach first.")
          return

        pp_count = db.session.query(Pck.id).filter_by(coach_id=coach.id, pack_type="player").count()

        if pack_type == "player":
          first = True if pp_count == 0 else False
          pack = PackService.generate(pack_type, team=subtype, first=first, coach=coach)
        elif pack_type in ["training","special", "hc"]:
          pack = PackService.generate(pack_type, coach=coach)
        elif pack_type == "booster":
          pack_type = "booster_budget" if not subtype else f"booster_{subtype}"
          pack = PackService.generate(pack_type, coach=coach)

        duster = coach.duster
        duster_on = False
        duster_txt = ""
        if pp_count > 0 and duster and duster.status == "COMMITTED":
          if (pack_type == "player" and duster.type == "Tryouts" or
                pack_type == "training" and duster.type == "Drills" or
                pack_type == "special" and duster.type == "Drills"):
            duster_on = True
            duster_txt = f" ({duster.type})"
            db.session.delete(duster)

        free_packs = coach.get_freepacks()

        if pack_type in ["player"] and not duster_on:
          if pack_type in free_packs:
            pack.price = 0
            coach.remove_from_freepacks(pack_type)
          else:
            raise TransactionError(
              "You need to commit Tryouts or earn the pack through" +
              " Achievements to be able to generate this pack!"
            )

        if pack_type in ["training", "special"] and not duster_on:
          raise TransactionError(
            "You need to commit Drills to be able to generate this pack!"
          )

        if pack_type in ["booster_budget", "booster_premium"]:
          if pack_type in free_packs:
            pack.price = 0
            coach.remove_from_freepacks(pack_type)

        tran = Transaction(pack=pack, price=pack.price, description=PackService.description(pack))
        coach.make_transaction(tran)

        title = f"**{PackService.description(pack)}** for **{ctx.message.author.name}** - **{pack.price}** coins{duster_txt}"
        description = f"**Bank:** {coach.account.amount} coins"
        pieces = PackHelper.format_pack_to_pieces(pack.cards)

        await self.auto_cards(pack, ctx)
        CoachService.check_collect_three_legends_quest(coach)

        efs = []
        efs.append({
            'name': "Cards:",
            'value': pieces['cards'],
            'inline': False,
        })
        for desc in pieces['descriptions']:
          efs.append({
            'name': desc['name'],
            'value': desc['description'],
            'inline': False,
          })
        embed = {
          'embed_title': title,
          'embed_desc': description,
          'thumbnail_url': 'https://cdn2.rebbl.net/images/cards/dice_small.png',
          'embed_fields': efs,
        }
        await self.send_embed(embed, ctx)
예제 #2
0
파일: Admin.py 프로젝트: ttrnecka/imperium
    async def admincard(self,
                        ctx,
                        action: str,
                        coach_name: str = None,
                        *cards):
        """Adds or removes cards from coach, or updates card database
      USAGE 1:
      Add or remove cards from coach
      !admincard <action> <coach> <card>;...;<card>
        <action>: add or remove
        <coach>: coach discord name or its part, must be unique
        <card>: Exact card name as is in the All Cards list, if mutliple cards are specified separate them by **;**
      USAGE 2:
      Updates card database from the master sheet
      !admincard update
      """
        if action not in ["add", "remove", "update"]:
            raise ValueError("Incorrect action")

        if not cards and not coach_name and action in ["add", "remove"]:
            raise ValueError("Missing arguments")

        if action == "update":
            await ctx.send(f"Updating...")
            CardService.update()
            await ctx.send(f"Cards updated!!!")
            return
        else:
            coach = await coach_unique(coach_name, ctx)
            if coach is None:
                return
            card_names = [card.strip() for card in " ".join(cards).split(";")]

        if action == "add":
            pack = PackService.admin_pack(0, card_names, coach)
            # situation when some of the cards could not be found
            if len(card_names) != len(pack.cards):
                msg = []
                msg.append(f"Not all cards were found, check the names!!!\n")
                for card in card_names:
                    if card in [
                            card.get('name').lower() for card in pack.cards
                    ]:
                        found = True
                    else:
                        found = False
                    found_msg = "**not found**" if not found else "found"
                    msg.append(f"{card}: {found_msg}")
                await self.send_message(ctx.channel, msg)
                return

            reason = f"{action.capitalize()} {';'.join([str(card.get('name')) for card in pack.cards])} - by " + str(
                ctx.author.name)
            tran = Transaction(pack=pack, description=reason, price=0)
            coach.make_transaction(tran)

            msg = []
            msg.append(
                f"**{PackService.description(pack)}** for @{coach.name} - **{pack.price}** coins:\n"
            )
            # message sent to admin so display the hidden cards
            msg.append(
                f"{PackHelper.format_pack(pack.cards, show_hidden=True)}")
            msg.append(f"**Bank:** {coach.account.amount} coins")
            await self.send_message(ctx.channel, msg)
            # message sent to discord so hide the names
            await self.bank_notification(
                ctx,
                f"Card(s) **{', '.join([card.get('name', show_hidden=False) for card in pack.cards])}** added to your collection by {str(ctx.author.name)}",
                coach)
            await self.auto_cards(pack, ctx)
            CoachService.check_collect_three_legends_quest(coach)
            return

        if action == "remove":
            removed_cards = []
            unknown_cards = []

            for name in card_names:
                card = CardService.get_card_from_coach(coach, name)
                if card:
                    removed_cards.append(card)
                    db.session.delete(card)
                    db.session.expire(coach, ['cards'])
                else:
                    unknown_cards.append(name)
            reason = f"{action.capitalize()} {';'.join([card.get('name') for card in removed_cards])} - by " + str(
                ctx.author.name)
            tran = Transaction(description=reason, price=0)
            coach.make_transaction(tran)

            if removed_cards:
                msg = []
                msg.append(f"Cards removed from @{coach.name} collection:\n")
                msg.append(
                    f"{PackHelper.format_pack(removed_cards, show_hidden=True)}"
                )
                await self.send_message(ctx.channel, msg)
                await self.bank_notification(
                    ctx,
                    f"Card(s) **{', '.join([card.get('name') for card in removed_cards])}** removed from your collection by {str(ctx.author.name)}",
                    coach)

            if unknown_cards:
                msg = ["**Warning** - these cards have been skipped:"]
                for name in unknown_cards:
                    msg.append(f"{name}: **not found**")
                await self.send_message(ctx.channel, msg)
            return