diff --git a/swibots/api/community/controllers/channel_controller.py b/swibots/api/community/controllers/channel_controller.py index f845db0d..f39a78d6 100644 --- a/swibots/api/community/controllers/channel_controller.py +++ b/swibots/api/community/controllers/channel_controller.py @@ -2,7 +2,7 @@ from typing import TYPE_CHECKING, List from swibots.api.community.models import Channel - +from swibots.errors import SwitchError if TYPE_CHECKING: from swibots.api.community import CommunityClient @@ -25,6 +25,15 @@ async def create_channel(self, channel: Channel) -> str: response = await self.client.post(BASE_PATH, data=channel.to_json_request()) return response.data.get("result", {}).get("channelId") + async def delete_channel(self, channel_id: str) -> bool: + response = await self.client.delete(f"{BASE_PATH}/{channel_id}") + if response.status_code == 200: + return True + logging.debug(response.data) + if err:= response.data.get("errorMessage"): + raise SwitchError(err) + return False + async def update_channel(self, channel: Channel) -> str: response = await self.client.put(BASE_PATH, data=channel.to_json_request()) return response.data.get("result", {}).get("channelId") diff --git a/swibots/api/community/methods/channel_methods.py b/swibots/api/community/methods/channel_methods.py index 3729d237..15ef887a 100644 --- a/swibots/api/community/methods/channel_methods.py +++ b/swibots/api/community/methods/channel_methods.py @@ -37,6 +37,22 @@ async def update_channel(self: "swibots.ApiClient", channel: Channel) -> str: """ return await self.community_service.channels.update_channel(channel) + async def delete_channel(self: "swibots.ApiClient", id: str) -> bool: + """Delete channel + + Args: + :obj:`swibots.api.community.models.Channel`: The channel object. + + Returns: + bool: Whether the channel was deleted! + + Raises: + :obj:`switch.error.SwitchError`: If the channel could not be retrieved + + This method does the same as :meth:`switch.api.community.controllers.ChannelController.delete_channel`. + """ + return await self.community_service.channels.delete_channel(id) + async def get_all_channels( self: "swibots.ApiClient", community_id: str ) -> List[Channel]: