Skip to content

Commit aa6ea96

Browse files
committed
chore: refactor
1 parent 8ce255a commit aa6ea96

37 files changed

+240
-168
lines changed

swibots/api/auth/methods/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from .get_me import GetMe
22

33

4-
class AuthMethods(GetMe): ...
4+
class AuthMethods(GetMe): ...

swibots/api/auth/methods/get_me.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,5 @@ async def update_user_info(self: "swibots.ApiClient", user_info: User) -> bool:
3131
bool: Whether request was successful
3232
"""
3333
data = {x: y for x, y in user_info.to_json_request().items() if y is not None}
34-
response = await self.auth_service.post(
35-
"/api/update/bot", data=data
36-
)
37-
return response.data
34+
response = await self.auth_service.post("/api/update/bot", data=data)
35+
return response.data

swibots/api/auth/models/auth_result.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def __init__(
1111
user_id: Optional[int] = None,
1212
is_bot: Optional[bool] = False,
1313
roles: Optional[List[str]] = None,
14-
active: Optional[bool] = False
14+
active: Optional[bool] = False,
1515
):
1616
self.access_token = access_token
1717
self.refresh_token = refresh_token
@@ -29,4 +29,4 @@ def from_json(self, data: Optional[JSONDict]) -> "AuthResult":
2929
self.is_bot = data.get("is_bot")
3030
self.roles = data.get("roles")
3131
self.active = data.get("active")
32-
return self
32+
return self

swibots/api/bot/methods/answer_callback_query.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ async def answer_callback_query(
1212
message_id: Optional[int] = None,
1313
show_alert: Optional[bool] = False,
1414
cache_time: Optional[int] = None,
15-
app_session_id: Optional[str] = None
15+
app_session_id: Optional[str] = None,
1616
) -> bool:
1717
"""
1818
Answer Callback query from callback button
@@ -32,12 +32,15 @@ async def answer_callback_query(
3232
show_alert=show_alert,
3333
cache_time=cache_time,
3434
message_id=message_id,
35-
app_session_id=app_session_id
35+
app_session_id=app_session_id,
3636
)
3737

3838
async def answer_ui_query(
39-
self: "swibots.ApiClient", query_id: str, message_id: int, callback: AppPage,
40-
app_session_id: str
39+
self: "swibots.ApiClient",
40+
query_id: str,
41+
message_id: int,
42+
callback: AppPage,
43+
app_session_id: str,
4144
) -> bool:
4245
"""Answer UI Query
4346
@@ -50,6 +53,5 @@ async def answer_ui_query(
5053
Bool: whether callback was sent or not
5154
"""
5255
return await self.bots_service.bots.answer_ui_query(
53-
query_id, message_id, callback=callback,
54-
app_session_id=app_session_id
56+
query_id, message_id, callback=callback, app_session_id=app_session_id
5557
)

swibots/api/bot/models/bot_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def __init__(
5454
description: Optional[str] = None,
5555
welcome: BotWelcome = None,
5656
source_code: Optional[str] = None,
57-
preview: Optional[AppPage] = None
57+
preview: Optional[AppPage] = None,
5858
):
5959
super().__init__(
6060
id=id,

swibots/api/callback/AppPage.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def __init__(
8080
def to_json(self) -> JSONDict:
8181
components = []
8282
for component in self.components:
83-
83+
8484
if isinstance(component, ListView):
8585
if self.max_size != None:
8686
component.max_size = self.max_size
@@ -95,9 +95,7 @@ def to_json(self) -> JSONDict:
9595
componentJson["mainAxisSize"] = "max" if self.max_size else "min"
9696
components.append(componentJson)
9797
elif isinstance(component, str):
98-
components.append(
99-
Text(component)
100-
)
98+
components.append(Text(component))
10199

102100
data = {
103101
"type": self.type,
@@ -130,4 +128,4 @@ def from_json(self, data: dict) -> Any:
130128
Component.build_from_json(item) for item in data.get("components", [])
131129
]
132130

133-
return self
131+
return self

swibots/api/callback/BottomBar.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,13 @@ def __init__(
5353
self.options = options
5454
self.type = type
5555
self.theme_color = theme_color
56-
56+
5757
def from_json(self, data) -> Any:
5858
if "BottomBar" in data:
5959
self.type = BottomBarType(data.get("bottomBarStyle"))
60-
self.options = [BottomBarTile().from_json(option) for option in data.get("bottomBar")]
60+
self.options = [
61+
BottomBarTile().from_json(option) for option in data.get("bottomBar")
62+
]
6163
self.theme_color = data.get("bottomBarColour")
6264

6365
return self

swibots/api/callback/Button.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def to_json(self):
130130
"type": self.type,
131131
"buttons": [button.to_json() for button in self.buttons],
132132
"mainAxisSize": "max" if self.max_size else "min",
133-
"flexible": self.flexible
133+
"flexible": self.flexible,
134134
}
135135

136136

swibots/api/callback/Feed.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ def to_json(self) -> Dict[str, Any]:
4747
"feeds": [feed.to_json() for feed in self.feeds],
4848
"offsetCallbackData": self.next_callback,
4949
}
50-
return data
50+
return data

swibots/api/callback/ListView.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from typing import Union, List, Literal
55
from .Progress import ListTileProgress
66

7+
78
class ListViewType(Enum):
89
DEFAULT = "default"
910
SMALL = "small"
@@ -26,7 +27,7 @@ def __init__(
2627
thumb: Union[Image, str] = "",
2728
badges: List[Badge] = None,
2829
max_size: bool = None,
29-
progress: ListTileProgress = None
30+
progress: ListTileProgress = None,
3031
):
3132
self.title = title
3233
self.subtitle = subtitle

swibots/api/callback/Players.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def __init__(self, feeds, next_callback: str):
193193

194194
def to_json(self) -> Dict[str, Any]:
195195
data = {
196-
"type": self.type,
196+
"type": self.type,
197197
"feeds": [feed.to_json() for feed in self.feeds],
198198
"offsetCallbackData": self.next_callback,
199199
}

swibots/api/callback/Progress.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ class ListTileProgress(Progress):
4949
def __init__(
5050
self, color: str = None, progress: str = None, animation: bool = False
5151
):
52-
super().__init__(color, progress=progress, animation=animation)
52+
super().__init__(color, progress=progress, animation=animation)

swibots/api/callback/types.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,22 @@ class Component(SwitchObject):
3636
class Icon(Component):
3737
type = "icon"
3838

39-
def __init__(self, url: str, dark_url: str = None,
40-
text: str = "",
41-
callback_data: str = None):
39+
def __init__(
40+
self, url: str, dark_url: str = None, text: str = "", callback_data: str = None
41+
):
4242
self.url = url
4343
self.dark_url = dark_url or url
4444
self.text = text
4545
self.callback_data = callback_data
4646

4747
def to_json(self) -> Dict[str, Any]:
48-
return {"type": self.type, "name": self.url, "darkIcon": self.dark_url,
49-
"alt": self.text,
50-
"callbackData": self.callback_data}
48+
return {
49+
"type": self.type,
50+
"name": self.url,
51+
"darkIcon": self.dark_url,
52+
"alt": self.text,
53+
"callbackData": self.callback_data,
54+
}
5155

5256

5357
class Text(Component):

swibots/api/chat/controllers/ads_controller.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ def __init__(self, client: "ChatClient") -> None:
2020
self.client = client
2121

2222
async def get_all_ads(
23-
self, limit: int = 100, page: int = 0,
23+
self,
24+
limit: int = 100,
25+
page: int = 0,
2426
):
25-
param = urlencode(
26-
{"page": page, "limit": limit, "appId": self.client.user.id}
27-
)
27+
param = urlencode({"page": page, "limit": limit, "appId": self.client.user.id})
2828
response = await self.client.get(f"{BASE_PATH}/byAppId?{param}")
2929
return self.client.build_list(ADInfo, response.data)
3030

swibots/api/chat/controllers/chat_controller.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import logging
22
from typing import TYPE_CHECKING, List, Optional
33

4-
from swibots.api.chat.models import (
5-
Message, SessionInfo
6-
)
4+
from swibots.api.chat.models import Message, SessionInfo
75

86
if TYPE_CHECKING:
97
from swibots.api.chat import ChatClient

swibots/api/chat/controllers/heading_controller.py

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,53 +9,71 @@
99

1010
log = logging.getLogger(__name__)
1111

12+
1213
class HeadingsController:
1314
def __init__(self, client: "CommunityClient"):
1415
self.client = client
1516

16-
async def get_headings(self, community_id: str, additional: bool = False) -> List[CommunityHeading]:
17+
async def get_headings(
18+
self, community_id: str, additional: bool = False
19+
) -> List[CommunityHeading]:
1720
"""
1821
:param community_id: The ID of the community
1922
:return: The Heading object
2023
"""
21-
query = urlencode({"additional": additional,
22-
"communityId": community_id,
23-
})
24+
query = urlencode(
25+
{
26+
"additional": additional,
27+
"communityId": community_id,
28+
}
29+
)
2430
response = await self.client.get(f"/headings?{query}")
2531
return self.client.build_list(CommunityHeading, response.data)
2632

27-
28-
async def create_heading(self, community_id: str, name: str,
29-
chat_id: str,
30-
heading_for: Literal["CHANNEL", "GROUP"] = "CHANNEL",
31-
heading_type: Literal['BLANK', "VALUE"] = "VALUE",
32-
):
33-
query = urlencode({
34-
"communityId": community_id,
35-
"heading": name,
36-
"id": chat_id,
37-
"headingFor": heading_for,
38-
"headingType": heading_type,
39-
})
33+
async def create_heading(
34+
self,
35+
community_id: str,
36+
name: str,
37+
chat_id: str,
38+
heading_for: Literal["CHANNEL", "GROUP"] = "CHANNEL",
39+
heading_type: Literal["BLANK", "VALUE"] = "VALUE",
40+
):
41+
query = urlencode(
42+
{
43+
"communityId": community_id,
44+
"heading": name,
45+
"id": chat_id,
46+
"headingFor": heading_for,
47+
"headingType": heading_type,
48+
}
49+
)
4050
response = await self.client.post(f"/headings?{query}")
4151
return response.data
4252

4353
async def delete_heading(self, community_id: str, heading_name: str):
44-
query = urlencode({
45-
"communityId": community_id,
46-
"headingName": heading_name,
47-
})
54+
query = urlencode(
55+
{
56+
"communityId": community_id,
57+
"headingName": heading_name,
58+
}
59+
)
4860
response = await self.client.post(f"/headings/delete-headings?{query}")
4961
return response.data
5062

51-
async def edit_heading(self, community_id: str, heading_name: str, new_heading_name: str,
52-
heading_type: Literal['BLANK', "VALUE"] = "VALUE"):
53-
query = urlencode({
54-
"communityId": community_id,
55-
"headingName": heading_name,
56-
"newHeadingName": new_heading_name,
57-
"headingType": heading_type,
58-
})
63+
async def edit_heading(
64+
self,
65+
community_id: str,
66+
heading_name: str,
67+
new_heading_name: str,
68+
heading_type: Literal["BLANK", "VALUE"] = "VALUE",
69+
):
70+
query = urlencode(
71+
{
72+
"communityId": community_id,
73+
"headingName": heading_name,
74+
"newHeadingName": new_heading_name,
75+
"headingType": heading_type,
76+
}
77+
)
5978
response = await self.client.post(f"/headings/edit-headings?{query}")
6079
return response.data
61-

swibots/api/chat/controllers/message_controller.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@
1616
)
1717
from swibots.utils import isUrl
1818
from swibots.api.common.models import User, EmbeddedMedia, Media
19-
from swibots.api.community.models import Channel, Group, CommunityMember, SearchResultUser
19+
from swibots.api.community.models import (
20+
Channel,
21+
Group,
22+
CommunityMember,
23+
SearchResultUser,
24+
)
2025

2126
if TYPE_CHECKING:
2227
from swibots.api.chat import ChatClient
@@ -772,14 +777,15 @@ async def get_user(self, user_id: int | str = None, username: str = None) -> Use
772777
raise ValueError("Either provide 'user_id' or 'username' to get user info.")
773778
return self.client.build_object(User, response.data)
774779

775-
776780
async def search_community_data(
777-
self,
778-
query: str,
779-
community_id: str,
780-
filter: Literal["MESSAGES", "MEDIA", "LINK", "GROUP", "CHANNEL", "MEMBER"] = "MESSAGES",
781-
limit: int = 10,
782-
page: int = 0,
781+
self,
782+
query: str,
783+
community_id: str,
784+
filter: Literal[
785+
"MESSAGES", "MEDIA", "LINK", "GROUP", "CHANNEL", "MEMBER"
786+
] = "MESSAGES",
787+
limit: int = 10,
788+
page: int = 0,
783789
) -> Union[List[Message], List[Group], List[Channel], List[SearchResultUser]]:
784790
"""Search community data
785791
@@ -793,7 +799,7 @@ async def search_community_data(
793799
Returns:
794800
Union[List[Message], List[Group], List[Channel], List[SearchResultUser]]: The search results
795801
796-
"""
802+
"""
797803
data = {
798804
"searchString": query,
799805
"item": filter,
@@ -812,4 +818,4 @@ async def search_community_data(
812818
return self.client.build_list(Channel, response.data)
813819
elif filter == "MEMBER":
814820
return self.client.build_list(SearchResultUser, response.data)
815-
return response.data
821+
return response.data

0 commit comments

Comments
 (0)