Exemple #1
0
    async def from_ctx(cls, ctx, ignore_guild: bool = False):
        owner_id = str(ctx.author.id)
        active_character = None
        if ctx.guild is not None and not ignore_guild:
            guild_id = str(ctx.guild.id)
            active_character = await ctx.bot.mdb.characters.find_one({
                "owner":
                owner_id,
                "active_guilds":
                guild_id
            })
        if active_character is None:
            active_character = await ctx.bot.mdb.characters.find_one({
                "owner":
                owner_id,
                "active":
                True
            })
        if active_character is None:
            raise NoCharacter()

        try:
            # return from cache if available
            return cls._cache[owner_id, active_character['upstream']]
        except KeyError:
            # otherwise deserialize and write to cache
            inst = cls.from_dict(active_character)
            cls._cache[owner_id, active_character['upstream']] = inst
            return inst
 async def from_bot_and_ids(cls, bot, author_id, character_id):
     character = await bot.mdb.characters.find_one({
         "owner": author_id,
         "upstream": character_id
     })
     if character is None:
         raise NoCharacter()
     return cls(character, character_id)
Exemple #3
0
 def from_ctx(cls, ctx):
     user_characters = ctx.bot.db.not_json_get(
         ctx.message.author.id + '.characters', {})
     active_character = ctx.bot.db.not_json_get(
         'active_characters', {}).get(ctx.message.author.id)
     if active_character is None:
         raise NoCharacter()
     character = user_characters[active_character]
     return cls(character, active_character)
Exemple #4
0
 async def _get_character(self):
     if self._character is not _sentinel:
         return self._character
     elif self._character is None:
         raise NoCharacter()
     ctx = await self.bot.get_context(self.message)
     character = await ctx.get_character()
     self._character = character
     return character
 async def from_ctx(cls, ctx):
     active_character = await ctx.bot.mdb.characters.find_one({
         "owner":
         ctx.message.author.id,
         "active":
         True
     })
     if active_character is None:
         raise NoCharacter()
     return cls(active_character, active_character['upstream'])
Exemple #6
0
 async def from_ctx(cls, ctx):
     active_character = await ctx.bot.mdb.characters.find_one({
         "owner":
         str(ctx.author.id),
         "active":
         True
     })
     if active_character is None:
         raise NoCharacter()
     return cls.from_dict(active_character)
Exemple #7
0
 def from_bot_and_ids_sync(cls, bot, owner_id, character_id):
     if (owner_id, character_id) in cls._cache:
         # read from cache
         return cls._cache[owner_id, character_id]
     character = bot.mdb.characters.delegate.find_one({"owner": owner_id, "upstream": character_id})
     if character is None:
         raise NoCharacter()
     # write to cache
     inst = cls.from_dict(character)
     cls._cache[owner_id, character_id] = inst
     return inst
Exemple #8
0
    async def from_ctx(cls, ctx):
        owner_id = str(ctx.author.id)
        active_character = await ctx.bot.mdb.characters.find_one({"owner": owner_id, "active": True})
        if active_character is None:
            raise NoCharacter()

        if (owner_id, active_character['upstream']) in cls._cache:
            # return from cache
            return cls._cache[owner_id, active_character['upstream']]
        else:
            # write to cache
            inst = cls.from_dict(active_character)
            cls._cache[owner_id, active_character['upstream']] = inst
            return inst
 async def from_bot_and_ids(cls, bot, owner_id: str, character_id: str):
     owner_id = str(owner_id)
     if (owner_id, character_id) in cls._cache:
         # read from cache
         return cls._cache[owner_id, character_id]
     character = await bot.mdb.characters.find_one({
         "owner": owner_id,
         "upstream": character_id
     })
     if character is None:
         raise NoCharacter()
     # write to cache
     inst = cls.from_dict(character)
     cls._cache[owner_id, character_id] = inst
     return inst
Exemple #10
0
    def from_bot_and_ids_sync(cls, bot, owner_id: str, character_id: str):
        owner_id = str(owner_id)

        try:
            # read from cache if available
            return cls._cache[owner_id, character_id]
        except KeyError:
            pass

        character = bot.mdb.characters.delegate.find_one({"owner": owner_id, "upstream": character_id})
        if character is None:
            raise NoCharacter()
        # write to cache
        inst = cls.from_dict(character)
        cls._cache[owner_id, character_id] = inst
        return inst
Exemple #11
0
 def from_bot_and_ids(cls, bot, author_id, character_id):
     user_characters = bot.db.not_json_get(author_id + '.characters', {})
     character = user_characters.get(character_id)
     if character is None: raise NoCharacter()
     return cls(character, character_id)