|
| 1 | +import logging |
| 2 | +from typing import TYPE_CHECKING, Optional, List, Literal |
| 3 | +from swibots.api.community.models import CommunityHeading |
| 4 | +from swibots.api.common.models import User |
| 5 | +from urllib.parse import urlencode |
| 6 | + |
| 7 | +if TYPE_CHECKING: |
| 8 | + from swibots.api.community import CommunityClient |
| 9 | + |
| 10 | +log = logging.getLogger(__name__) |
| 11 | + |
| 12 | +class HeadingsController: |
| 13 | + def __init__(self, client: "CommunityClient"): |
| 14 | + self.client = client |
| 15 | + |
| 16 | + async def get_headings(self, community_id: str, additional: bool = False) -> List[CommunityHeading]: |
| 17 | + """ |
| 18 | + :param community_id: The ID of the community |
| 19 | + :return: The Heading object |
| 20 | + """ |
| 21 | + query = urlencode({"additional": additional, |
| 22 | + "communityId": community_id, |
| 23 | + }) |
| 24 | + response = await self.client.get(f"/headings?{query}") |
| 25 | + return self.client.build_list(CommunityHeading, response.data) |
| 26 | + |
| 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 | + }) |
| 40 | + response = await self.client.post(f"/headings?{query}") |
| 41 | + return response.data |
| 42 | + |
| 43 | + async def delete_heading(self, community_id: str, heading_name: str): |
| 44 | + query = urlencode({ |
| 45 | + "communityId": community_id, |
| 46 | + "headingName": heading_name, |
| 47 | + }) |
| 48 | + response = await self.client.post(f"/headings/delete-headings?{query}") |
| 49 | + return response.data |
| 50 | + |
| 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 | + }) |
| 59 | + response = await self.client.post(f"/headings/edit-headings?{query}") |
| 60 | + return response.data |
| 61 | + |
0 commit comments