Esempio n. 1
0
def bid_f(user, bidAmount):
    eventManager = EventManager.getEventManager()
    waifuAHEvent = eventManager.getEvent("waifuAH")

    if not waifuAHEvent.isRunning():
        return -1

    profile = UserProfile.load(user)
    if not profile.ecoCheckBalance(bidAmount):
        return -2

    if bidAmount <= waifuAHEvent.lastBid:
        return -3

    if abs(bidAmount - waifuAHEvent.lastBid) < waifuAHEvent.bidStepUp:
        return -4

    # If there is an event, check preliminary bidding info
    t = utcNow()
    extendedTime = False
    if (waifuAHEvent.timeEnd -
            t).total_seconds() < waifuAHEvent.timeThresholdToExtend:
        extendedTime = True

    # Eco unlock previous bidder and eco lock current one
    if waifuAHEvent.user is not None:
        UserProfile.load(waifuAHEvent.user).ecoUnlock()
    profile.ecoLock()

    # Set this user as current bidder in event
    waifuAHEvent.user = user
    waifuAHEvent.lastBid = bidAmount
    waifuAHEvent.lastBidTime = t

    # Assemble embed and return
    embed = discord.Embed(title="Bid Registered",
                          description="{} made the latest bid!".format(
                              user.name))
    embed.add_field(name="Bid Amount",
                    value="{}".format(economy_fAux.pMoney(bidAmount)))

    if extendedTime:
        newEndTime = utcToTZ(utcNow() + datetime.timedelta(
            seconds=waifuAHEvent.bidTimeExtension))
        tStr = "Auction will stop at {}.".format(
            newEndTime.strftime("%H:%M:%S"))
        embed.add_field(name="Time Extended!", value=tStr)

    return embed
Esempio n. 2
0
 def _save_waifuTimeSummoning(self):
     timeAware_usersColl = dbClient.getClient().DBot.users.with_options(
         codec_options=CodecOptions(tz_aware=True, tzinfo=TIMEZONE))
     timeAware_usersColl.update_one(
         {"user.id": self.user.id},
         {"$set": {
             "waifuDict.timeSummoning": utcNow()
         }})
     return timeAware_usersColl.find_one({"user.id": self.user.id
                                          })["waifuDict"]["timeSummoning"]
Esempio n. 3
0
    def load(user):
        matchingProfiles = [
            profile for profile in UserProfile.loadedProfiles
            if profile.user == user
        ]
        if len(matchingProfiles) == 1:
            return matchingProfiles[0]

        mongoClient = dbClient.getClient()
        timeAware_UsersColl = mongoClient.DBot.users.with_options(
            codec_options=CodecOptions(tz_aware=True, tzinfo=TIMEZONE))
        profileDoc = timeAware_UsersColl.find_one({"user.id": user.id})

        if profileDoc is None:
            user = user
            timeCreation = utcNow()
            ecoDict = {
                "balance": economy_const.STARTING_MONEY,
                "timeCollection": utcNow() - datetime.timedelta(days=1),
                "locked": False
            }
            waifuDict = {
                "waifuList": [],
                "waifuFavorite": None,
                "timeSummoning": utcNow() - datetime.timedelta(days=1)
            }
        else:
            user = Bot.getBot().get_user(profileDoc["user"]["id"])
            timeCreation = profileDoc["timeCreation"]
            ecoDict = profileDoc["ecoDict"]
            waifuDict = profileDoc["waifuDict"]

        userProfile = UserProfile(user, timeCreation, ecoDict, waifuDict)
        if profileDoc is None:
            userProfile._save()

        UserProfile.loadedProfiles.append(userProfile)
        return userProfile
Esempio n. 4
0
    def eventInit(self):
        self.status = True
        self.setTimeEnd(self.duration)

        self.waifu = waifu_fAux.getRandomWaifu()
        self.startingBid = max(
            1, int(self.waifu["value"] * random.uniform(0.65, 0.95)))
        self.buyoutPrize = random.randint(int(3.5 * self.waifu["value"]),
                                          int(5 * self.waifu["value"]))
        self.bidStepUp = max(1, int((self.lastBid / self.waifu["value"]))**2)

        self.user = None
        self.lastBid = self.startingBid
        self.lastBidTime = utcNow()
        self.lastBidTimeChecked = self.lastBidTime
Esempio n. 5
0
def addToMarketplace(seller, category, itemDict, price):
    itemDoc = {
        "itemID": generateItemID(),
        "seller": {
            "name": seller.name,
            "id": seller.id
        },
        "timeCreation": utcNow(),
        "price": price,
        "category": category,
        "item": itemDict
    }

    dbClient.getClient().DBot.marketplace.insert_one(itemDoc)
    return itemDoc
Esempio n. 6
0
    async def eventProcess(self):
        if self.lastBidTime != self.lastBidTimeChecked:
            if (self.timeEnd -
                    utcNow()).total_seconds() < self.timeThresholdToExtend:
                self.setTimeEnd(self.bidTimeExtension)
                self.lastBidTimeChecked = self.lastBidTime

        if self.lastBid > 0:
            newStepUp = max(1, int((self.lastBid / self.waifu["value"]))**2)
            if newStepUp > self.bidStepUp:
                self.bidStepUp = newStepUp
                embed = discord.Embed(
                    title="Waifu AH Bid STEP UP!",
                    description="New minimum bid Step-Up: {}".format(
                        economy_fAux.pMoney(self.bidStepUp)))
                await self.channel.send("", embed=embed)
Esempio n. 7
0
 def endCondition(self):
     return ((utcNow() > self.timeEnd)
             or (len(self.users) == self.maxUsers))
Esempio n. 8
0
 def endCondition(self):
     return ((utcNow() > self.timeEnd)
             or (self.lastBid >= self.buyoutPrize))
Esempio n. 9
0
 def endCondition(self):
     return ((utcNow() > self.timeEnd) or (self.winnerUser != None))