Skip to content

Commit 57f5421

Browse files
committed
Made an enum for room include values
1 parent 4e9d524 commit 57f5421

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

src/recnetpy/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
from .client import Client
1+
from .client import Client
2+
from .managers.room_manager import RoomInclude

src/recnetpy/managers/room_manager.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from typing import TYPE_CHECKING, List, Optional
22

3+
from enum import Enum
34
from . import BaseManager
45
from ..dataclasses import Room
56
from ..misc import stringify_bulk
@@ -8,12 +9,35 @@
89
from ..misc.api_responses import RoomResponse, RoomSearchResponse
910
from ..rest import Response
1011

12+
class RoomInclude(Enum):
13+
"""
14+
Enum which corresponds to the room include parameter values
15+
"""
16+
SUBROOMS = 2
17+
ROLES = 4
18+
TAGS = 8
19+
PROMO_CONTENT = 32
20+
SCORES = 64
21+
LOADING_SCREENS = 256
22+
23+
def sum_enum_list(enums: List[Enum]) -> int:
24+
"""
25+
Sums a list of integer enums
26+
27+
:param enums: A list of enums that have integer values
28+
:return: Sum of the enums' values
29+
"""
30+
sum = 0
31+
for i in enums:
32+
sum += i.value
33+
return sum
34+
1135
class RoomManager(BaseManager['Room', 'RoomResponse']):
1236
"""
1337
This is a factory object for creating room objects. Its the
1438
main interface for fetching room related data.
1539
"""
16-
async def get(self, name: str, include: int = 0) -> 'Room':
40+
async def get(self, name: str, include: int | List[RoomInclude] = 0) -> 'Room':
1741
"""
1842
Gets room data by their name, and returns it as an room object.
1943
Returns nothing if the room doesn't exist or is private.
@@ -35,11 +59,14 @@ async def get(self, name: str, include: int = 0) -> 'Room':
3559
:param include: An integer that add additional information to the response.
3660
:return: An room object representing the data or nothing if not found.
3761
"""
62+
63+
if isinstance(include, list):
64+
include = sum_enum_list(include)
3865
data: 'Response[RoomResponse]' = await self.rec_net.rooms.rooms.make_request('get', params = {'name': name, 'include': include})
3966
if data.data: return self.create_dataclass(data.data['RoomId'], data.data)
4067
return None
4168

42-
async def fetch(self, id: int, include: int = 0) -> 'Room':
69+
async def fetch(self, id: int, include: int | List[RoomInclude] = 0) -> 'Room':
4370
"""
4471
Gets room data by their id, and returns it as an room object.
4572
Returns nothing if the room doesn't exist or is private.
@@ -61,6 +88,8 @@ async def fetch(self, id: int, include: int = 0) -> 'Room':
6188
:param include: An integer that add additional information to the response.
6289
:return: An room object representing the data.
6390
"""
91+
if isinstance(include, list):
92+
include = sum_enum_list(include)
6493
data: 'Response[RoomResponse]' = await self.rec_net.rooms.rooms(id).make_request('get', params = {'include': include})
6594
if data.data: return self.create_dataclass(data.data['RoomId'], data.data)
6695
return None

0 commit comments

Comments
 (0)