Ejemplo n.º 1
0
def fuse_f(user, waifuID1, waifuID2, waifuID3):
    profile = UserProfile.load(user)

    # check if all of the 3 waifus are owned by the user
    waifuListCopy = profile.waifuList[:]
    try:
        waifuListCopy.remove(waifuID1)
        waifuListCopy.remove(waifuID2)
        waifuListCopy.remove(waifuID3)
    except:
        return -1

    # check if all of the 3 waifus are of the same rank
    waifu1 = waifu_fAux.getWaifu(waifuID1)
    waifu2 = waifu_fAux.getWaifu(waifuID2)
    waifu3 = waifu_fAux.getWaifu(waifuID3)
    if not (waifu1["rank"] == waifu2["rank"] == waifu3["rank"]):
        return -2

    # check if at least one is SSS
    if waifu1["rank"] == "SSS" or waifu2["rank"] == "SSS" or waifu3[
            "rank"] == "SSS":
        return -3

    # if all checks passed, get the a next-rank waifu
    nextRank = waifu_const.WAIFU_RANKS[
        waifu_const.WAIFU_RANKS.index(waifu1["rank"]) + 1]

    # Remove waifus from user profile
    profile.waifuRemove(waifu1)
    profile.waifuRemove(waifu2)
    profile.waifuRemove(waifu3)

    # Get random fused waifu
    fusedWaifu = waifu_fAux.getRandomWaifuByRank(nextRank)
    profile.waifuAdd(fusedWaifu)

    # Assemble embed
    embedTitle = "\U0001F9EC {}'s Waifu Fusion! \U0001F9EC".format(user)
    embedDescription = "You got a {}-tier Waifu!".format(fusedWaifu["rank"])
    embed = discord.Embed(title=embedTitle, description=embedDescription)

    infoValue1 = "Name: {}".format(fusedWaifu["name"])
    infoValue2 = ", alias {}".format(random.choice(
        fusedWaifu["aliases"])) if len(fusedWaifu["aliases"]) > 0 else ""
    infoValue3 = "From: {}".format(fusedWaifu["animeName"])
    embed.add_field(name="Basic Information",
                    value=infoValue1 + infoValue2 + "\n" + infoValue3)

    statsValue1 = "Value: {}".format(fusedWaifu["value"])
    statsValue2 = "Ranking: {}/{}".format(fusedWaifu["ranking"],
                                          waifu_fAux.waifuCount())
    embed.add_field(name="Stats", value=statsValue1 + "\n" + statsValue2)

    thumbnail_url = random.choice(fusedWaifu["pictures"])
    embed.set_thumbnail(url=thumbnail_url)

    return embed
Ejemplo n.º 2
0
def isSellable(seller, category, itemDict):
    if category == "waifu":
        profile = UserProfile.load(seller)
        waifu = waifu_fAux.getWaifu(itemDict["waifuID"])
        return profile.waifuCheck(waifu)
    else:
        return -1
Ejemplo n.º 3
0
def removeItem(seller, category, itemDict):
    if category == "waifu":
        waifu = waifu_fAux.getWaifu(itemDict["waifuID"])
        UserProfile.load(seller).waifuRemove(waifu)
        return 0
    else:
        raise ValueError("not a valid category: {}".format(category))
Ejemplo n.º 4
0
def retrieveItem(itemDoc):
    category = itemDoc["category"]
    if category == "waifu":
        waifuID = itemDoc["item"]["waifuID"]
        waifu = waifu_fAux.getWaifu(waifuID)
        return waifu
    else:
        raise ValueError("itemDoc with no valid category.\n{}".format(itemDoc))
Ejemplo n.º 5
0
def addItem(user, category, itemDict):
    print(user, category, itemDict)
    if category == "waifu":
        waifu = waifu_fAux.getWaifu(itemDict["waifuID"])
        print(waifu)
        UserProfile.load(user).waifuAdd(waifu)
    else:
        raise ValueError("not a valid category: {}".format(category))
    return 0
Ejemplo n.º 6
0
def makeSellEmbed(seller, category, itemDict, price, itemID):
    embedTitle = "Marketplace Item Added \U0001F4E8 | ID: {}".format(itemID)
    embedThumbnail = None
    if category == "waifu":
        waifu = waifu_fAux.getWaifu(itemDict["waifuID"])
        embedThumbnail = random.choice(waifu["pictures"])

    embedDescription = makeSellEmbedItemDescription(seller, category, itemDict, price)
    embed = discord.Embed(title=embedTitle, description=embedDescription)

    if embedThumbnail is not None:
        embed.set_thumbnail(url=embedThumbnail)

    return embed
Ejemplo n.º 7
0
def makeBuyEmbed(buyer, seller, category, itemDict, price, itemID):
    embedTitle = "Successful Purchase \U0001F4B3"
    embedThumbnail = None
    if category == "waifu":
        waifu = waifu_fAux.getWaifu(itemDict["waifuID"])
        embedThumbnail = random.choice(waifu["pictures"])

    embedDescription = makeBuyEmbedItemDescription(buyer, seller, category, itemDict, price)
    embed = discord.Embed(title=embedTitle, description=embedDescription)

    if embedThumbnail is not None:
        embed.set_thumbnail(url=embedThumbnail)
    
    return embed
Ejemplo n.º 8
0
def makeBuyEmbedItemDescription(buyer, seller, category, itemDict, price):
    embedDescription0 = "{} just purchased an item from {} for {}!".format(
        buyer.name, 
        seller.name,
        economy_fAux.pMoney(price))
    
    if category == "waifu":
        waifu = waifu_fAux.getWaifu(itemDict["waifuID"])
        embedDescription1_part1 = "{}{}".format(marketplace_const.ITEM_VALUENAME, waifu["name"])
        embedDescription1_part2 = "{}Source: {}".format(marketplace_const.ITEM_VALUESPACE, waifu["animeName"])
        embedDescription1_part3 = "{}Rank: {}".format(marketplace_const.ITEM_VALUESPACE, waifu["rank"])
        embedDescription1_part4 = "{}Value: {}".format(marketplace_const.ITEM_VALUESPACE, waifu["value"])
        embedDescription1List = [embedDescription1_part1, embedDescription1_part2, embedDescription1_part3, embedDescription1_part4]
        embedDescription1 = "\n".join(embedDescription1List)
    else:
        raise ValueError("Not a valid category: {}".format(category))

    embedDescriptionList = [embedDescription0, "", embedDescription1]
    embedDescription = "\n".join(embedDescriptionList)
    return embedDescription
Ejemplo n.º 9
0
def makeSellEmbedItemDescription(seller, category, itemDict, price):
    embedDescription0 = "Seller: {}".format(seller.name)
    embedDescription1 = "Category: {}".format(category)

    if category == "waifu":
        waifu = waifu_fAux.getWaifu(itemDict["waifuID"])
        embedDescription2_part1 = "{}{}".format(marketplace_const.ITEM_VALUENAME, waifu["name"])
        embedDescription2_part2 = "{}Source: {}".format(marketplace_const.ITEM_VALUESPACE, waifu["animeName"])
        embedDescription2_part3 = "{}Rank: {}".format(marketplace_const.ITEM_VALUESPACE, waifu["rank"])
        embedDescription2_part4 = "{}Value: {}".format(marketplace_const.ITEM_VALUESPACE, waifu["value"])
        embedDescription2List = [embedDescription2_part1, embedDescription2_part2, embedDescription2_part3, embedDescription2_part4]
        embedDescription2 = "\n".join(embedDescription2List)
    else:
        return ValueError("Not valid category: {}".format(category))
    
    embedDescriptionValue3 = "Price: {}".format(economy_fAux.pMoney(price))
    
    embedValueList = [embedDescription0, embedDescription1, embedDescription2, embedDescriptionValue3]
    embedDescription = "\n".join(embedValueList)
    return embedDescription
Ejemplo n.º 10
0
def list_f(ctx, args):
    # parse args
    # parse page number
    numbers = [int(arg) for arg in args if arg.isdigit()]
    if len(numbers) > 1:
        return -1
    page = numbers[0] if len(numbers) == 1 else 1

    # parse ranks
    ranksInArgs = [
        arg for arg in args if (arg.upper() in waifu_const.WAIFU_RANKS)
    ]
    ranksQuery = ranksInArgs if len(
        ranksInArgs) > 0 else waifu_const.WAIFU_RANKS

    # parse target user
    mentions = ctx.message.mentions
    if len(mentions) != 0:
        if not isAdmin(ctx.author):
            return -2
        if len(mentions) > 1:
            return -3

        targetUser = mentions[0]
    else:
        targetUser = ctx.author

    # Parse duplicate mode
    duplicateMode = False
    if ("-d" in args) or ("-D" in args) or ("duplicates" in args):
        duplicateMode = True

    # Get waifu profile
    profile = UserProfile.load(ctx.author)

    if len(profile.waifuList) == 0:
        if targetUser == ctx.author:
            return -4
        else:
            return -5

    # Query waifus from DB
    if duplicateMode:
        duplicateIDs = list(profile.waifuGetDuplicateWaifuDict().keys())
        query = {
            "$and": [{
                "MAL_data.charID": {
                    "$in": duplicateIDs
                }
            }, {
                "rank": {
                    "$in": ranksQuery
                }
            }]
        }
    else:
        query = {
            "$and": [{
                "MAL_data.charID": {
                    "$in": list(set(profile.waifuList))
                }
            }, {
                "rank": {
                    "$in": ranksQuery
                }
            }]
        }

    waifuList = list(dbClient.getClient().DBot.waifus.find(query).sort(
        "value", pymongo.DESCENDING))

    if len(waifuList) == 0:
        return -6

    if profile.waifuFavorite is not None:
        waifuFav = waifu_fAux.getWaifu(profile.waifuFavorite)
        embedDescription = "Favorite Waifu: {}{}\nFrom: {}".format(
            waifuFav["name"],
            "" if waifuFav["aliases"] == [] else ", alias {}".format(
                random.choice(waifuFav["aliases"])), waifuFav["animeName"])
        thumbnail_url = random.choice(waifuFav["pictures"])
    else:
        embedDescription = discord.Embed.Empty
        thumbnail_url = random.choice(waifu_const.NO_FAV_WAIFU_URLS)

    embed = discord.Embed(title="{}'s Harem".format(profile.user.name),
                          description=embedDescription)
    waifuStart = waifu_const.WAIFU_LIST_WAIFUS_PER_PAGE * (page - 1)
    waifuEnd = waifuStart + waifu_const.WAIFU_LIST_WAIFUS_PER_PAGE
    for waifu in waifuList[waifuStart:waifuEnd]:
        fieldName = "{}/{} \U0000300C{}\U0000300D: {} [{}]".format(
            waifuList.index(waifu) + 1, len(waifuList), waifu["rank"],
            waifu["name"], waifu["MAL_data"]["charID"])

        fieldValue1 = "Source: {}".format(waifu["animeName"])
        fieldValue2 = "Ranking: {}/{}\nValue: {}".format(
            waifu["ranking"], waifu_fAux.waifuCount(), waifu["value"])
        fieldValues = [fieldValue1, fieldValue2]

        if duplicateMode:
            fieldValue4 = "Count: {}".format(
                profile.waifuList.count(waifu["MAL_data"]["charID"]))
            fieldValues.append(fieldValue4)
        elif profile.waifuList.count(waifu["MAL_data"]["charID"]) > 1:
            fieldValue4 = "Count: {}".format(
                profile.waifuList.count(waifu["MAL_data"]["charID"]))
            fieldValues.append(fieldValue4)

        embed.add_field(name=fieldName,
                        value="\n".join(fieldValues),
                        inline=False)

    embed.add_field(name="Total Waifu Value",
                    value="{}".format(
                        economy_fAux.pMoney(profile.waifuGetTotalValue())),
                    inline=False)

    embed.set_thumbnail(url=thumbnail_url)
    footerText1 = "Waifu Harem page: {} of {}.".format(
        page,
        math.ceil(len(waifuList) / waifu_const.WAIFU_LIST_WAIFUS_PER_PAGE))
    footerText2 = "Search other pages using `>waifu list <page>`"
    embed.set_footer(text=footerText1 + "\n" + footerText2)

    return embed