async def get_user(self, user_id): result = await self._members_get("member", second=user_id) if result: return User(state=self, data=result["user"]) return None
def mock_discord_user( username: str = "sevo", discriminator: int = 4375, user_id: int = 383854815186518016, ) -> User: """ Returns a mock `User` object to test with Args: username (str): the discord username (name shown on discord profile) discriminator (int): the number after the `#` in discord profile name user_id (int): the numeric id for each discord user (can be found via developer controls `copy id`) Returns: User: the user object defined by the discord API. NOTE: this object is incomplete and does not support all features """ return User( state=None, data={ "username": username, "discriminator": discriminator, "avatar": "", # currently not needed for testing "id": user_id, }, )
async def _users(self): results = [] user_ids = [] for match in await self._members("member"): user_id = match.split(":")[2] if user_id not in user_ids: results.append(await self._get(match)) user_ids.append(user_id) return [User(state=self, data=x["user"]) for x in results]
def create_fake_user(user_id): return User( state=None, data={ "username": "", "id": str(user_id), "discriminator": "", "avatar": "", }, )
def create_discord_user(**kwargs): global _user_id default_params = { 'id': _user_id, 'discriminator': None, 'avatar': None, 'username': '******' % _user_id } _user_id += 1 default_params.update(kwargs) return User(state=FakeState(), data=default_params)
def __init__(self, data, *, adapter, state=None): self.id = int(data['id']) self.type = try_enum(WebhookType, int(data['type'])) self.channel_id = utils._get_as_snowflake(data, 'channel_id') self.guild_id = utils._get_as_snowflake(data, 'guild_id') self.name = data.get('name') self.avatar = data.get('avatar') self.token = data.get('token') self._state = state or _PartialWebhookState(adapter, self, parent=state) self._adapter = adapter self._adapter._prepare(self) user = data.get('user') if user is None: self.user = None elif state is None: self.user = BaseUser(state=None, data=user) else: self.user = User(state=state, data=user)
def __init__(self, uid, author_id, message, at_time): self.uid = uid self.author = User(id=author_id) self.message = message self.at_time = at_time
def store_user(self, data): return User(state=self, data=data)
def __init__(self, uid, notification_message, notification_time, user_id): self.uid = uid self.notification_message = notification_message self.notification_time = notification_time self.user = User(id=user_id)
async def _users(self): user_ids = set( [x.split(":")[2] for x in await self._members("member")]) return [ User(state=self, data=x["user"]) for x in await self.get(user_ids) ]