from enum import Enum from typing import TypedDict from breadtube_bot.objects import Overwrite class ApiVersion(Enum): V10 = 10 V9 = 9 V8 = 8 V7 = 7 V6 = 6 class ApiAction(Enum): DELETE = 'DELETE' GET = 'GET' POST = 'POST' class Api: class Guild: @staticmethod def create_channel(guild_id: int) -> tuple[ApiAction, str]: return ApiAction.POST, f'/guilds/{guild_id}/channels' class CreateChannelParams(TypedDict, total=False): # All # channel name (1-100 characters) name: str # All # the type of channel type: int # Text, Announcement, Forum, Media # channel topic (0-1024 characters) topic: str # Voice, Stage # the bitrate (in bits) of the voice or stage channel; min 8000 bitrate: int # Voice, Stage # the user limit of the voice channel user_limit: int # Text, Voice, Stage, Forum, Media # amount of seconds a user has to wait before sending another message (0-21600); # bots, as well as users with the permission manage_messages or manage_channel, are unaffected rate_limit_per_user: int # All # sorting position of the channel (channels with the same position are sorted by id) position: int # All # the channel's permission overwrites permission_overwrites: list[dict] # Text, Voice, Announcement, Stage, Forum, Media # id of the parent category for a channel parent_id: int # Text, Voice, Announcement, Stage, Forum # whether the channel is nsfw nsfw: bool # Voice, Stage # channel voice region id of the voice or stage channel, automatic when set to null rtc_region: str # Voice, Stage # the camera video quality mode of the voice channel video_quality_mode: int # Text, Announcement, Forum, Media # the default duration that the clients use (not the API) for newly created threads in the channel, # in minutes, to automatically archive the thread after recent activity default_auto_archive_duration: int # Forum, Media # emoji to show in the add reaction button on a thread in a GUILD_FORUM or a GUILD_MEDIA channel default_reaction_emoji: dict # Forum, Media # set of tags that can be used in a GUILD_FORUM or a GUILD_MEDIA channel available_tags: list[dict] # Forum, Media # the default sort order type used to order posts in GUILD_FORUM and GUILD_MEDIA channels default_sort_order: int # Forum # the default forum layout view used to display posts in GUILD_FORUM channels default_forum_layout: int # Text, Announcement, Forum, Media # the initial rate_limit_per_user to set on newly created threads in a channel. # this field is copied to the thread at creation time and does not live update. default_thread_rate_limit_per_user: int class CreateTextChannelParams(TypedDict, total=False): name: str type: int topic: str rate_limit_per_user: int position: int permission_overwrites: list[Overwrite] parent_id: int nsfw: bool default_auto_archive_duration: int default_thread_rate_limit_per_user: int @staticmethod def list_guilds(guild_id: int) -> tuple[ApiAction, str]: return ApiAction.GET, f'/guilds/{guild_id}/channels' @staticmethod def list_roles(guild_id: int) -> tuple[ApiAction, str]: return ApiAction.GET, f'/guilds/{guild_id}/roles' class Message: @staticmethod def create(channel_id: int) -> tuple[ApiAction, str]: return ApiAction.POST, f'/channels/{channel_id}/messages' class CreateParams(TypedDict, total=False): content: str # Message contents (up to 2000 characters) # Can be used to verify a message was sent (up to 25 characters). # Value will appear in the Message Create event. nonce: int | str tts: bool # true if this is a TTS message # embeds: list[Embeded] # Up to 10 rich embeds (up to 6000 characters) # allowed_mentions: MentionObject # Allowed mentions for the message # message_reference: MessageReference # Include to make your message a reply or a forward # components: list[MessageComponent] # Components to include with the message sticker_ids: list[int] # IDs of up to 3 stickers in the server to send in the message # files[n]: FileContents # Contents of the file being sent. See Uploading Files # payload_json: str # JSON-encoded body of non-file params, only for multipart/form-data requests # attachments: list[Attachment] # Attachment objects with filename and description. See Uploading Files # Message flags combined as a bitfield # (only SUPPRESS_EMBEDS, SUPPRESS_NOTIFICATIONS, IS_VOICE_MESSAGE, and IS_COMPONENTS_V2 can be set) # flags: MessageFlags # If true and nonce is present, it will be checked for uniqueness in the past few minutes. # If another message was created by the same author with the same nonce, that message will be returned # and no new message will be created. # enforce_nonce: bool # poll: PollRequest # A poll! @staticmethod def delete(channel_id: int, message_id: int) -> tuple[ApiAction, str]: return ApiAction.DELETE, f'/channels/{channel_id}/messages/{message_id}' @staticmethod def list_by_channel(channel_id: int, limit: int | None = None) -> tuple[ApiAction, str]: if limit is not None and not (0 < limit <= 100): # noqa: PLR2004 raise RuntimeError('Cannot list messages by channel with limit outside [0, 100] range') return ApiAction.GET, f'/channels/{channel_id}/messages'