Skip to content

Commit fdac862

Browse files
committed
feat: headings and instant messaging api
1 parent 72d78b4 commit fdac862

13 files changed

+180
-12
lines changed

docs/docusaurus.config.js

+16-11
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,18 @@ const config = {
3737
({
3838
docs: {
3939
sidebarPath: require.resolve('./sidebars.js'),
40-
// Please change this to your repo.
41-
// Remove this to remove the "edit this page" links.
42-
// editUrl:
43-
// 'https://github.com/facebook/docusaurus/tree/main/packages/create-docusaurus/templates/shared/',
4440
},
45-
// blog: {
46-
// showReadingTime: true,
47-
// // Please change this to your repo.
48-
// // Remove this to remove the "edit this page" links.
49-
// // editUrl:
50-
// // 'https://github.com/facebook/docusaurus/tree/main/packages/create-docusaurus/templates/shared/',
51-
// },
5241
theme: {
5342
customCss: [
5443
require.resolve('./src/css/custom.css'),
5544
],
5645
},
46+
sitemap: {
47+
changefreq: 'weekly',
48+
priority: 0.5,
49+
ignorePatterns: ['/tags/**'],
50+
filename: 'sitemap.xml',
51+
},
5752
}),
5853
],
5954
],
@@ -166,6 +161,16 @@ const config = {
166161
insights: true
167162
}
168163
}),
164+
165+
headTags: [
166+
{
167+
tagName: 'meta',
168+
attributes: {
169+
name: 'google-site-verification',
170+
content: 'yC1cNX1v5yzD_O87LDsebxnxy7KTEoe4-WE3OTQ6q80'
171+
}
172+
}
173+
],
169174
};
170175

171176
module.exports = config;

docs/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"dependencies": {
1717
"@docusaurus/core": "^3.1.0",
1818
"@docusaurus/preset-classic": "^3.1.0",
19+
"@docusaurus/plugin-sitemap": "^3.1.0",
1920
"@mdx-js/react": "^3.0.0",
2021
"clsx": "^1.2.1",
2122
"prism-react-renderer": "^1.3.5",

swibots/api/chat/controllers/heading_controller.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,15 @@ async def rearrange_headings(self,
9191
}
9292
response = await self.client.post("/headings/rearrange-headings",
9393
data=body)
94-
94+
return response.data
95+
96+
async def move_heading_content(self, request_dto: dict):
97+
"""
98+
Move content from one heading to another
99+
100+
:param request_dto: Dictionary containing move heading content details
101+
:return: Response data from the API
102+
"""
103+
response = await self.client.post("/headings/move-heading-content",
104+
data=request_dto)
105+
return response.data

swibots/api/chat/methods/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from .upload_media import UploadMedia
2525
from .sticker_methods import StickerMethods
2626
from .organization_methods import OrganizationMethods
27+
from .heading_methods import HeadingMethods
2728

2829

2930
class ChatMethods(
@@ -52,5 +53,6 @@ class ChatMethods(
5253
GetUser,
5354
StickerMethods,
5455
OrganizationMethods,
56+
HeadingMethods,
5557
):
5658
pass

swibots/api/chat/methods/heading_methods.py

+44
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,47 @@ async def edit_heading(
6666
return await self.chat_service.headings.edit_heading(
6767
community_id, heading_name, new_heading_name, heading_type
6868
)
69+
70+
async def rearrange_headings(
71+
self: "swibots.ApiClient",
72+
community_id: str,
73+
heading_names: List[str],
74+
subheading: str = ''
75+
):
76+
"""
77+
Rearrange headings in a community
78+
79+
:param community_id: The ID of the community
80+
:param heading_names: List of heading names in the desired order
81+
:param subheading: Optional subheading name
82+
"""
83+
return await self.chat_service.headings.rearrange_headings(
84+
community_id, heading_names, subheading
85+
)
86+
87+
async def move_heading_content(
88+
self,
89+
community_id: str,
90+
heading_for: Literal["GROUP", "CHANNEL", "STORE", "WIDGET"],
91+
heading_type: Literal["BLANK", "VALUE"],
92+
type_id: str,
93+
updated_heading: str
94+
):
95+
"""
96+
Move content from one heading to another
97+
98+
:param community_id: The ID of the community
99+
:param heading_for: The type of content being moved
100+
:param heading_type: The type of heading
101+
:param type_id: The ID of the content being moved
102+
:param updated_heading: The name of the heading to move content to
103+
"""
104+
move_dto = {
105+
"communityId": community_id,
106+
"headingFor": heading_for,
107+
"headingType": heading_type,
108+
"typeId": type_id,
109+
"updatedHeading": updated_heading
110+
}
111+
request_dto = {"moveHeadingContentDto": [move_dto]}
112+
return await self.chat_service.headings.move_heading_content(request_dto)

swibots/api/community/community_client.py

+8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
RoleMemberController,
1919
RestrictController,
2020
BanController,
21+
InstantMessagingController,
2122
QuestsController,
2223
)
2324

@@ -45,6 +46,7 @@ def __init__(
4546
self._restrict = None
4647
self._ws: SwitchWSAsyncClient = None
4748
self._started = False
49+
self._instant_messaging = None
4850

4951
@property
5052
def quests(self) -> QuestsController:
@@ -59,6 +61,12 @@ def channels(self) -> ChannelController:
5961
self._channels = ChannelController(self)
6062
return self._channels
6163

64+
@property
65+
def instant_messaging(self) -> InstantMessagingController:
66+
if self._instant_messaging is None:
67+
self._instant_messaging = InstantMessagingController(self)
68+
return self._instant_messaging
69+
6270
@property
6371
def groups(self) -> GroupController:
6472
"""Get the channels controller"""

swibots/api/community/controllers/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
from .restrict_controller import *
88
from .ban_controller import *
99
from .quest_controller import *
10+
from .messaging_controller import InstantMessagingController
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import logging
2+
from typing import TYPE_CHECKING, List
3+
from swibots.api.community.models import InstantMessaging
4+
5+
if TYPE_CHECKING:
6+
from swibots.api.community import CommunityClient
7+
8+
log = logging.getLogger(__name__)
9+
10+
BASE_PATH = "/v1/community/instant/messaging"
11+
12+
13+
class InstantMessagingController:
14+
def __init__(self, client: "CommunityClient"):
15+
self.client = client
16+
17+
async def enable_messages(
18+
self, community_id: str, group_id: str, bot_id: str | int = None
19+
) -> InstantMessaging:
20+
if not bot_id:
21+
bot_id = self.client.user.id
22+
response = await self.client.get(
23+
f"{BASE_PATH}/enable",
24+
data={"communityId": community_id, "groupId": group_id, "botId": bot_id},
25+
)
26+
return self.client.build_object(InstantMessaging, response.data.get("result"))
27+
28+
async def disable_messages(
29+
self, community_id: str, group_id: str, bot_id: str | int = None
30+
) -> InstantMessaging:
31+
if not bot_id:
32+
bot_id = self.client.user.id
33+
response = await self.client.get(
34+
f"{BASE_PATH}/disable",
35+
data={"communityId": community_id, "groupId": group_id, "botId": bot_id},
36+
)
37+
return self.client.build_object(InstantMessaging, response.data.get("result"))
38+
39+
async def get_messaging_enabled(self, community_id: str, group_id: str) -> List[InstantMessaging]:
40+
resp = await self.client.get(f"{BASE_PATH}/bots?communityId={community_id}&groupId={group_id}")
41+
return self.client.build_list(InstantMessaging, resp.data.get("result"))

swibots/api/community/methods/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from .community_methods import CommunityMethods
99
from .restrict_user import RestrictUser
1010
from .deduct_xp import DeductXP
11+
from .instant_messaging import InstantMessagingMethods
1112
from .quest_methods import QuestsMethods
1213

1314

@@ -23,5 +24,6 @@ class CommunityMethods(
2324
RestrictUser,
2425
DeductXP,
2526
QuestsMethods,
27+
InstantMessagingMethods,
2628
):
2729
pass
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import swibots
2+
from typing import Optional
3+
4+
from swibots.api.community.models import InstantMessaging
5+
6+
7+
class InstantMessagingMethods:
8+
async def enable_messages(
9+
self: "swibots.ApiClient",
10+
community_id: str,
11+
group_id: str,
12+
bot_id: Optional[str] = None,
13+
) -> InstantMessaging:
14+
"""Enable messaging in group"""
15+
return await self.community_service.instant_messaging.enable_messages(
16+
community_id, group_id, bot_id
17+
)
18+
19+
async def disable_messages(
20+
self: "swibots.ApiClient",
21+
community_id: str,
22+
group_id: str,
23+
bot_id: Optional[str] = None,
24+
) -> InstantMessaging:
25+
"""Disable messaging in group"""
26+
return await self.community_service.instant_messaging.disable_messages(
27+
community_id, group_id, bot_id
28+
)
29+
30+
async def get_messaging_enabled(
31+
self: "swibots.ApiClient", community_id: str, group_id: str
32+
) -> InstantMessaging:
33+
"""Get bot with messaging enable in the community"""
34+
return await self.community_service.instant_messaging.get_messaging_enabled(
35+
community_id, group_id
36+
)

swibots/api/community/models/channel.py

+9
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ def __init__(
2525
link: Optional[str] = None,
2626
muted: Optional[bool] = None,
2727
bot_id: Optional[str] = None,
28+
mini_app_link: Optional[str] = None,
29+
linked_group_id: Optional[str] = None,
2830
):
2931
super().__init__(app)
3032
self.id = id
@@ -46,6 +48,8 @@ def __init__(
4648
self.link_based = bool(self.link)
4749
self.muted = muted
4850
self.bot_id = bot_id
51+
self.mini_app_link = mini_app_link
52+
self.linked_group_id = linked_group_id
4953

5054
def to_json(self) -> JSONDict:
5155
return {
@@ -68,6 +72,8 @@ def to_json(self) -> JSONDict:
6872
"twitterUsername": self.twitter,
6973
"muted": self.muted,
7074
"linkBased": self.link_based,
75+
"miniAppLink": self.mini_app_link,
76+
"linkedGroupId": self.linked_group_id,
7177
}
7278

7379
def from_json(self, data: JSONDict) -> "Channel":
@@ -90,4 +96,7 @@ def from_json(self, data: JSONDict) -> "Channel":
9096
self.muted = data.get("muted")
9197
self.is_twitter = data.get("isTwitter")
9298
self.twitter = data.get("twitterUsername")
99+
self.mini_app_link = data.get("miniAppLink")
100+
self.linked_group_id = data.get("linkedGroupId")
93101
return self
102+

swibots/api/community/models/community.py

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def __init__(
3131
channels_count: Optional[int] = None,
3232
default_channel: Optional[Channel] = None,
3333
visible: Optional[bool] = True,
34+
ai_data: Optional[dict] = None,
3435
):
3536
super().__init__(app)
3637
self.id = id
@@ -54,6 +55,7 @@ def __init__(
5455
self.channels_count = channels_count
5556
self.default_channel = default_channel
5657
self.visible = visible
58+
self.ai_data = ai_data
5759

5860
def to_json(self) -> JSONDict:
5961
return {
@@ -80,6 +82,7 @@ def to_json(self) -> JSONDict:
8082
"defaultChannel": (
8183
self.default_channel.to_json() if self.default_channel else None
8284
),
85+
"aiData": self.ai_data,
8386
}
8487

8588
def from_json(self, data: Optional[JSONDict]) -> Optional["Community"]:
@@ -104,6 +107,7 @@ def from_json(self, data: Optional[JSONDict]) -> Optional["Community"]:
104107
self.link = data.get("link")
105108
self.icon = data.get("icon")
106109
self.visible = data.get("visible")
110+
self.ai_data = data.get("aiData")
107111

108112
if data.get("defaultChannel"):
109113
self.default_channel = Channel().from_json(data.get("defaultChannel"))

swibots/api/community/models/group.py

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def __init__(
2121
allowed_content: Optional[str] = None,
2222
created_at: Optional[str] = None,
2323
updated_at: Optional[str] = None,
24+
is_linked_chat: Optional[bool] = None,
2425
):
2526
super().__init__(app)
2627
self.id = id
@@ -36,6 +37,7 @@ def __init__(
3637
self.allowed_content = allowed_content
3738
self.created_at = created_at
3839
self.updated_at = updated_at
40+
self.is_linked_chat = is_linked_chat
3941

4042
def to_json(self) -> JSONDict:
4143
return {
@@ -52,6 +54,7 @@ def to_json(self) -> JSONDict:
5254
"allowedContent": self.allowed_content,
5355
"createdAt": self.created_at,
5456
"updatedAt": self.updated_at,
57+
"linkedChat": self.is_linked_chat,
5558
}
5659

5760
def from_json(self, data: JSONDict) -> "Group":
@@ -69,6 +72,7 @@ def from_json(self, data: JSONDict) -> "Group":
6972
self.allowed_content = data.get("allowedContent")
7073
self.created_at = data.get("createdAt")
7174
self.updated_at = data.get("updatedAt")
75+
self.is_linked_chat = data.get("linkedChat")
7276
return self
7377

7478
async def m_enabled(self) -> bool:

0 commit comments

Comments
 (0)