Esempio n. 1
0
async def read(src, l_eval=True, decrypt=True, read_from_cache=True):
    is_cached = cache.check_cache(src)
    if is_cached and read_from_cache:
        data = cache.read_cache(src)

        if isinstance(data, str):
            try:
                data = ast.literal_eval(data)
            except ValueError:
                pass
            except SyntaxError:
                pass
        return data

    if decrypt:
        try:
            data = decode(key, ((await main_collection.find_one(
                {"_id": src}))['data'].decode("utf-8")))
        except AttributeError:
            data = decode(key, (await main_collection.find_one({"_id":
                                                                src}))['data'])
        except TypeError:
            await main_collection.insert_one({
                "_id": src,
                "data": encode(key, str({}))
            })
            data = {}

        if l_eval:
            value = ast.literal_eval(str(data))

        else:
            value = str(data)

        cache.cache(src, value)
        return value

    else:

        try:

            data = (await main_collection.find_one({"_id": src}))['data']

        except TypeError:

            await main_collection.insert_one({"_id": src, "data": str({})})
            data = {}

        if l_eval:
            value = ast.literal_eval(data)

        else:
            value = str(data)

        cache.cache(src, value)
        return value
Esempio n. 2
0
def submitcommands():
    data_raw = request.form['data']

    json_data = decode(key, data_raw)
    data = json.loads(json_data)

    cogs = [
        cog for cog in bot.cogs.values()
        if cog.qualified_name not in blacklisted_cogs
    ]
    commands = []
    for cog in cogs:
        for command in cog.get_commands():
            commands.append(command.name)
    guild = request.form['guild']
    print(request.form)
    if 'channel' in request.form:
        channel = request.form['channel']
    else:
        channel = None
    if 'role' in request.form:

        role = request.form['role']
    else:
        role = None
    print('ROLE', role)

    asyncio.run_coroutine_threadsafe(
        set_commands(bot, data, guild, channel, role), bot.loop).result()
    return 'done'
Esempio n. 3
0
async def read(src, lEval=True, decrypt=True):

	if decrypt:
		try:
			data = decode(key, (await client.retrieve(src)).decode("utf-8"))
		except AttributeError:
			data = decode(key, await client.retrieve(src))
		if lEval:
			value = ast.literal_eval(data)
		else:
			value = str(data)
		return value
	else:
		data = await client.retrieve(src)

		if lEval:
			value = ast.literal_eval(data)
		else:
			value = str(data)
		return value
Esempio n. 4
0
def submitperms():
    print('got a request')
    data_raw = request.form['data']

    json_data = decode(key, data_raw)
    guild = request.form['guild']
    data = json.loads(json_data)
    role = None
    channel = None
    if 'role' in request.form:
        role = request.form['role']
    if 'channel' in request.form:
        channel = request.form['channel']
    asyncio.run_coroutine_threadsafe(
        set_checks(data, int(guild), channel, role), bot.loop).result()
    return 'done'