def __init__(self, prefix, formatter=None, description=None, pm_help=False, testing=False, **options): super(Avrae, self).__init__(prefix, formatter, description, pm_help, **options) self.remove_command("help") self.testing = testing self.state = "init" self.credentials = Credentials() if TESTING: self.rdb = RedisIO(testing=True, database_url=self.credentials.test_redis_url) self.mclient = motor.motor_asyncio.AsyncIOMotorClient( self.credentials.test_mongo_url) else: self.rdb = RedisIO(database_url=os.getenv('REDIS_URL', '')) self.mclient = motor.motor_asyncio.AsyncIOMotorClient( os.getenv('MONGO_URL', "mongodb://localhost:27017")) self.mdb = self.mclient.avrae # let's just use the avrae db self.dynamic_cog_list = DYNAMIC_COGS self.owner = None self.prefixes = self.rdb.not_json_get("prefixes", {}) self.muted = set()
def __init__(self, prefix, description=None, testing=False, **options): super(Avrae, self).__init__(prefix, help_command=help_command, description=description, **options) self.testing = testing self.state = "init" self.credentials = Credentials() if TESTING: self.rdb = RedisIO(testing=True, database_url=self.credentials.test_redis_url) self.mclient = motor.motor_asyncio.AsyncIOMotorClient( self.credentials.test_mongo_url) else: self.rdb = RedisIO(database_url=os.getenv('REDIS_URL', '')) self.mclient = motor.motor_asyncio.AsyncIOMotorClient( os.getenv('MONGO_URL', "mongodb://localhost:27017")) self.mdb = self.mclient.avrae # let's just use the avrae db self.dynamic_cog_list = DYNAMIC_COGS self.prefixes = dict() self.muted = set() if SENTRY_DSN is not None: sentry_sdk.init( dsn=SENTRY_DSN, environment="Development" if TESTING else "Production")
def __init__(self, command_prefix, formatter=None, description=None, pm_help=False, testing=False, **options): super(Avrae, self).__init__(command_prefix, formatter, description, pm_help, **options) self.prefix = prefix self.remove_command("help") self.testing = testing self.state = "init" self.credentials = Credentials() if TESTING: self.rdb = RedisIO( testing=True, test_database_url=self.credentials.test_redis_url) self.mclient = motor.motor_asyncio.AsyncIOMotorClient( self.credentials.test_mongo_url) else: self.rdb = RedisIO() self.mclient = motor.motor_asyncio.AsyncIOMotorClient( "mongodb://localhost:27017") self.mdb = self.mclient.avrae # let's just use the avrae db self.dynamic_cog_list = DYNAMIC_COGS
def __init__(self, prefix, description=None, testing=False, **options): super(Avrae, self).__init__(prefix, help_command=help_command, description=description, **options) self.testing = testing self.state = "init" self.credentials = Credentials() if TESTING: self.rdb = RedisIO(testing=True, database_url=self.credentials.test_redis_url, db=REDIS_DB_NUM) self.mclient = motor.motor_asyncio.AsyncIOMotorClient( self.credentials.test_mongo_url) else: self.rdb = RedisIO(database_url=os.getenv('REDIS_URL', ''), db=REDIS_DB_NUM) self.mclient = motor.motor_asyncio.AsyncIOMotorClient( os.getenv('MONGO_URL', "mongodb://*****:*****@{GIT_COMMIT_SHA}" sentry_sdk.init(dsn=SENTRY_DSN, environment=ENVIRONMENT.title(), release=release)
class Avrae(commands.AutoShardedBot): def __init__(self, prefix, formatter=None, description=None, pm_help=False, testing=False, **options): super(Avrae, self).__init__(prefix, formatter, description, **options) self.remove_command("help") self.testing = testing self.state = "init" self.credentials = Credentials() if TESTING: self.rdb = RedisIO(testing=True, test_database_url=self.credentials.test_redis_url) self.mclient = motor.motor_asyncio.AsyncIOMotorClient(self.credentials.test_mongo_url) else: self.rdb = RedisIO() self.mclient = motor.motor_asyncio.AsyncIOMotorClient("mongodb://127.0.0.1:27017") self.mdb = self.mclient.avrae # let's just use the avrae db self.dynamic_cog_list = DYNAMIC_COGS self.owner = None self.prefixes = self.rdb.not_json_get("prefixes", {}) def get_server_prefix(self, msg): return get_prefix(self, msg)[-1] async def launch_shards(self): if self.shard_count is None: recommended_shards, _ = await self.http.get_bot_gateway() if recommended_shards >= 96 and not recommended_shards % 16: # half, round up to nearest 16 self.shard_count = recommended_shards // 2 + (16 - (recommended_shards // 2) % 16) else: self.shard_count = recommended_shards // 2 log.info(f"Launching {self.shard_count} shards!") await super(Avrae, self).launch_shards()
async def setup_rdb(self): if config.TESTING: redis_url = self.credentials.test_redis_url else: redis_url = config.REDIS_URL return RedisIO(await aioredis.create_redis_pool(redis_url, db=config.REDIS_DB_NUM))
import asyncio import motor.motor_asyncio from migrators import bestiary, character, combat, customization, lookupsettings from utils.redisIO import RedisIO async def run(rdb, mdb): await bestiary.run(rdb, mdb) await character.run(rdb, mdb) await combat.run(rdb, mdb) await customization.run(rdb, mdb) await lookupsettings.run(rdb, mdb) if __name__ == '__main__': rdb = RedisIO() mdb = motor.motor_asyncio.AsyncIOMotorClient( "mongodb://localhost:27017").avrae asyncio.get_event_loop().run_until_complete(run(rdb, mdb))
def __init__(self): self.db = RedisIO(TESTING, credentials.test_redis_url) self.shards = {}
num_bestiaries += 1 print(f"Found bestiary: {bestiary['name']} ({_id})") owner_id = key[:-11] print(f"Adding owner, id, active keys: {owner_id}, {_id}") bestiary['owner'] = owner_id bestiary['critterdb_id'] = _id bestiary['active'] = False print("Inserting into MongoDB...") result = await mdb.bestiaries.insert_one(bestiary) print(result.inserted_id) print("Creating compound index on owner|critterdb_id...") await mdb.bestiaries.create_index([("owner", pymongo.ASCENDING), ("critterdb_id", pymongo.ASCENDING)], unique=True) print(f"Done! Migrated {num_bestiaries} bestiaries for {num_users} users.") if __name__ == '__main__': from utils.redisIO import RedisIO import credentials import motor.motor_asyncio import asyncio rdb = RedisIO(True, credentials.test_redis_url) # production should run main script mdb = motor.motor_asyncio.AsyncIOMotorClient(credentials.test_mongo_url).avrae asyncio.get_event_loop().run_until_complete(run(rdb, mdb))
async def setup_rdb(self): return RedisIO(await aioredis.create_redis_pool(config.REDIS_URL, db=config.REDIS_DB_NUM))