Skip to content
This repository has been archived by the owner on May 5, 2024. It is now read-only.

Commit

Permalink
many updates
Browse files Browse the repository at this point in the history
  • Loading branch information
pixeldeee committed Aug 18, 2023
1 parent 720d1c7 commit c3974a8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
12 changes: 8 additions & 4 deletions pytecord/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .enums import ApplicationCommandType, GatewayIntents
from .guild import Guild, GuildChannel, Message, MessageDeleteEvent
from .user import User
from .utils import get_option_type
from .utils import get_option_type, rget
from .web import BaseWebhook

if TYPE_CHECKING:
Expand All @@ -17,21 +17,24 @@ def __init__(self, token: str, debug: bool = False) -> None:
self.webhook = BaseWebhook(token, debug)
self.token = token
self.__intents = GatewayIntents.GUILD_INTEGRATIONS
self.__user_id = None

@property
def user(self) -> User:
return User(self.webhook.get_user(self.__user_id), self.token)
return self.webhook.get_current_user()

@property
def guilds(self) -> list[Guild]:
return self.webhook.get_current_user_guilds()

def listen(self):
def decorator(func_to_decorate: Callable[..., Coroutine[Any, Any, Any]]):
event_name = func_to_decorate.__name__
match event_name:
case 'ready':
async def func(data: 'GatewayOutput'):
self.__user_id = data.d['user']['id']
await self.webhook.register_app_commands(data)
await func_to_decorate()

case 'message_create' | 'message_update':
self.__intents += GatewayIntents.GUILD_MESSAGES
self.__intents += GatewayIntents.MESSAGE_CONTENT
Expand All @@ -40,6 +43,7 @@ async def func(data: 'GatewayOutput'):
if not data.d['author'].get('bot', False):
message = Message(data.d, self.token)
await func_to_decorate(message)

case 'message_delete':
self.__intents += GatewayIntents.GUILD_MESSAGES
self.__intents += GatewayIntents.DIRECT_MESSAGES
Expand Down
18 changes: 1 addition & 17 deletions pytecord/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,11 @@ def __init__(self, data: dict[str, Any], token: str) -> None:
self.__data = data

def eval(self) -> dict[str, Any]:
"""
Returns a dict representation of user
```
>>> user = User()
>>> user.eval()
```
"""
return self.__data

def __int__(self) -> int:
"""
Returns an object id
```
>>> obj = Object()
>>> int(obj)
```
"""
return self.id


class GuildMember(Object):
def __init__(self, data: dict[str, Any], token: str) -> None:
Expand Down
14 changes: 14 additions & 0 deletions pytecord/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,14 @@ def get_guild(self, id: int) -> 'Guild':

data = rget(f'/guilds/{id}', self.token).json()
return Guild(data, self.token)

def get_current_user_guilds(self) -> 'list[Guild]':
data = rget('/users/@me/guilds', self.token).json()

result = []
for partial_guild in data:
result.append(self.get_guild(partial_guild['id']))
return result

def get_channel(self, id: int) -> 'GuildChannel':
from .guild import GuildChannel
Expand All @@ -267,3 +275,9 @@ def get_user(self, id: int) -> 'User':

data = rget(f'/users/{id}', self.token).json()
return User(data, self.token)

def get_current_user(self) -> 'User':
from .user import User

data = rget('/users/@me', self.token).json()
return User(data, self.token)

0 comments on commit c3974a8

Please sign in to comment.