예제 #1
0
    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
예제 #2
0
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,
        },
    )
예제 #3
0
 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]
예제 #4
0
def create_fake_user(user_id):
    return User(
        state=None,
        data={
            "username": "",
            "id": str(user_id),
            "discriminator": "",
            "avatar": "",
        },
    )
예제 #5
0
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)
예제 #6
0
파일: webhook.py 프로젝트: pvffyn/wakeful
    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)
예제 #7
0
 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
예제 #8
0
 def store_user(self, data):
     return User(state=self, data=data)
예제 #9
0
 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)
예제 #10
0
 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)
     ]