Ejemplo n.º 1
0
 def getAllUsers():
     userDocs = dbClient.getClient().DBot.users.find({})
     userList = [
         UserProfile.load(Bot.getBot().get_user(userDoc["user"]["id"]))
         for userDoc in userDocs
     ]
     return userList
Ejemplo n.º 2
0
def buy_f(buyer, itemID):
    if not itemID.isdigit():
        return -1
    else:
        itemID = int(itemID)

    itemDoc = dbClient.getClient().DBot.marketplace.find_one({"itemID": itemID})
    if itemDoc is None:
        return -2
    
    if itemDoc["seller"]["id"] == buyer.id:
        return -3

    # check if buyer has enough money
    buyerProfile = UserProfile.load(buyer)
    if not buyerProfile.ecoCheckBalance(itemDoc["price"]):
        return -4

    # Remove from marketplace listing and add to buyer
    print(buyer)
    marketplace_fAux.addItem(buyer, itemDoc["category"], itemDoc["item"])
    marketplace_fAux.removeFromMarketplace(itemDoc["itemID"])

    # Remove money from buyer, and add to seller
    UserProfile.load(buyer).ecoChangeBalance(-itemDoc["price"], forced=True)
    
    seller = Bot.getBot().get_user(itemDoc["seller"]["id"])
    sellerProfile = UserProfile.load(seller)
    sellerProfile.ecoChangeBalance(itemDoc["price"], forced=True)

    # Assemble embed
    embed = marketplace_fAux.makeBuyEmbed(buyer, seller, itemDoc["category"], itemDoc["item"], itemDoc["price"], itemID)
    return embed
Ejemplo n.º 3
0
def letter_moment_f(message):
    if len(message.content) == 2:
        if message.content[0] == Bot.getBot(
        ).command_prefix and message.content[1] in string.ascii_uppercase:
            msgDict = autism_fAux.letterMoment(message)
            return msgDict
    else:
        return -1
Ejemplo n.º 4
0
def ranking_f():
    embed = discord.Embed(title="Economy Ranking",
                          description="Top 5 based on total Balance.")

    mongoClient = dbClient.getClient()
    userDocs = list(
        mongoClient.DBot.users.find({}).sort("ecoDict.balance",
                                             pymongo.DESCENDING))

    selectedDocs = userDocs[:5]
    for userDoc in selectedDocs:
        profile = UserProfile.load(Bot.getBot().get_user(
            userDoc["user"]["id"]))
        fieldName = "{}/{}: {}".format(
            selectedDocs.index(userDoc) + 1, len(selectedDocs),
            profile.user.name)
        fieldValue = "Balance: {}".format(
            economy_fAux.pMoney(profile.ecoBalance))
        embed.add_field(name=fieldName, value=fieldValue, inline=False)

    return embed
Ejemplo n.º 5
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
Ejemplo n.º 6
0
Archivo: DBot.py Proyecto: drizak/DBot
from scripts.helpers.singletons import Bot

# Check if this is not the main file
if __name__ != "__main__":
    raise Exception("DBot.py should be the main executable!")

# Change current working directory to this file's directory
os.chdir(os.path.split(os.path.abspath(__file__))[0])

# Set prefix and load token
COMMAND_PREFIX = ">"
with io.open(os.path.join(os.getcwd(), "keys", "token.secret"), "r", encoding="utf-8") as f:
    TOKEN = f.read()

# Init bot and cogs
bot = Bot.getBot(COMMAND_PREFIX)

# Bot events
# When ready, load cogs
@bot.event
async def on_ready():
    log("Removing Help Command")
    bot.remove_command("help")

    log("Loading Event Channel")
    eventChannel = getEventChannel()

    log("Loading cogs")
    bot.add_cog(random_commands.Random(eventChannel))
    bot.add_cog(google_commands.Google(eventChannel))
    bot.add_cog(basic_commands.Basic(eventChannel))
Ejemplo n.º 7
0
def autism_f(author, phrase):
    allowedCharacters = string.ascii_lowercase + " "
    phrase = phrase.lower()

    # Check length
    if len(phrase) < 1:
        return -1
    if len(phrase) > 20:
        return -2

    # Check for invalid characters
    for c in phrase:
        if not (c in allowedCharacters):
            return -3

    # Collect source letters
    letterDict = dict()
    for char in set(phrase):
        if char != " ":
            letterDict[char] = Image.open(
                os.path.join(os.getcwd(), "resources", "letters",
                             "{}.gif".format(char)))

    # Calculate size of resulting image
    sizeX = letterDict[phrase[0]].size[0] * len(phrase)
    sizeY = letterDict[phrase[0]].size[1]
    imgSize = (sizeX, sizeY)

    # Start making frames
    frames = []
    frameCount = letterDict[phrase[0]].n_frames
    for frameIndex in range(frameCount):
        imgWordFrame = Image.new("P", imgSize, color=7)
        imgWordFrame.putpalette(letterDict[phrase[0]].getpalette())

        xIndex = 0
        for char in phrase:
            if char == " ":
                xIndex += 1
                continue
            else:
                letterImg = letterDict[char]
                letterImg.seek(frameIndex)

            imgWordFrame.paste(letterImg.copy(),
                               box=(letterDict[phrase[0]].size[0] * xIndex, 0))
            xIndex += 1

        frames.append(imgWordFrame.copy())

    autismFolder = os.path.join(os.getcwd(), "resources", "autism")
    imageFileName = "{}_{}.gif".format(time.time(), author.id)
    imageFinalPath = os.path.join(autismFolder, imageFileName)

    frames[0].save(imageFinalPath,
                   format="GIF",
                   append_images=frames[1:],
                   save_all=True,
                   duration=170,
                   loop=0,
                   version="GIF89a",
                   background=0,
                   transparency=7,
                   disposal=2)

    # Schedule for deletion in the minute and return path
    Bot.getBot().loop.create_task(scheduleDeleteFile(imageFinalPath, 15))
    return discord.File(imageFinalPath)
Ejemplo n.º 8
0
Archivo: aux_f.py Proyecto: drizak/DBot
def getEventChannel():
    mongoClient = dbClient.getClient()
    channelRegistryDoc = mongoClient.DBot.config.find_one(
        {"type": "channelRegistry"})
    channel = Bot.getBot().get_channel(channelRegistryDoc["channelID"])
    return channel