SwiBots Python Library

website·Indexed 29 days ago

https://switchcollab.github.io/Switch-Bots-Python-Library

A Python library for building bots and feature-rich mini-apps on Switch. It provides tools for creating user interfaces with components like Text, Button, Image, Grid, and Carousel, as well as handling inline queries, callback queries, and event filters.

Tokens
41.9K
Snippets
201
Records
306
Agent score
72%

What's inside SwiBots

  1. Organization object properties reference

    The Organization object contains detailed information about a specific organization within the chat application. It includes identification, contact details, social media handles, and metadata regarding its creation and updates.
    # The Organization object contains the following properties:
    
    # Core Application Context
    app: swibots.App  # The chat application instance
    
    # Identification & Basic Info
    id: str            # The ID of the organization (optional)
    name: str          # The name of the organization (optional)
    description: str   # A description of the organization (optional)
    profile_pic: str    # URL of the organization's profile picture (optional)
    thumbnail: str     # URL of the organization's thumbnail (optional)
    
    # Contact & Social Media
    email: str         # Email associated with the organization (optional)
    website: str       # URL of the organization's website (optional)
    twitter: str       # Twitter handle (optional)
    instagram: str     # Instagram handle (optional)
    telegram: str      # Telegram handle (optional)
    
    # Community & Social Metrics
    community_ids: List[str] # List of associated community IDs (optional)
    followers: int     # Number of followers (optional)
    follower: bool     # Whether the current user follows the organization (optional)
    
    # Metadata & Ownership
    created_by: int    # ID of the user who created the organization (optional)
    source_code_link: str # URL to the associated source code (optional)
    created_at: str    # Timestamp of creation (optional)
    updated_at: str    # Timestamp of last update (optional)
  2. Handle MessageEvent for chat messages

    The MessageEvent is triggered when a message is sent to a chat. In addition to base Event properties, it contains details about the message and the participants.
    # MessageEvent additional properties:
    - message: Message
    - message_id: str
    - user_id: str
    - user: User
    - receiver_id: str
    - receiver: User
  3. Message class properties reference

    The Message class represents a message sent to a chat. It contains metadata about the sender, receiver, content, and chat context (group, channel, or community).
    // Key properties of the Message class:
    id: int                 // The message's id
    user_id: int             // The message's sender's id
    user: User               // The message's sender object
    receiver_id: int         // The message's receiver's id
    receiver: User            // The message's receiver object
    message: str             // The message's text
    sent_date: int           // The message's sent date
    status: int              // The message's status
    request_id: int          // The message's request id
    channel_chat: bool       // Whether the message is a channel chat
    channel_id: int          // The message's channel's id
    channel: Channel         // The message's channel object
    community_id: int        // The message's community's id
    community: Community     // The message's community object
    group_chat: bool         // Whether the message is a group chat
    group_id: int            // The message's group's id
    group: Group             // The message's group object
    edit: bool               // Whether the message is an edit
    forward: bool            // Whether the message is a forward
    inline_markup: InlineMarkup // The message's inline markup
    is_read: bool            // Whether the message is read
    is_media: bool           // Whether message includes media
    is_embed_message: bool   // Whether message includes embedded content
    embed_message: EmbeddedMedia // The embedded message object
    media_link: str          // The message's media link
    replied_to_id: int       // The message's replied to id
    replied_to: Message      // The message's replied to object
    reply_count: int         // The message's reply count
    pinned: bool             // Whether the message is pinned
    reactions: List[str]     // The message's reactions
    media_id: int            // The message's media id (for media messages)
    media_info: Media        // The message's media object (for media messages)
    cached_media: Media      // Media already uploaded to the server (for media messages)
  4. Use the CommunityMember model to access community user data

    The swibots.api.community.models.CommunityMember class provides detailed information about a user linked to a specific community. It includes identity markers, administrative status, experience points (XP), notification settings, and mute configurations.
    # Example of properties available on a CommunityMember instance:
    member.id                  # (int) Unique ID
    member.admin                # (bool) Whether the user is an admin
    member.username             # (str) User's username
    member.user_id              # (int) User's unique ID
    member.community_id         # (str) The community ID
    member.user                 # (User) Linked User info object
    member.xp                   # (int) User's current XP
    member.xp_spend             # (int) XP spent by the user
    member.enable_notification  # (bool) Whether notifications are enabled
    member.role_info            # (dict) User's role information
    member.mute_period          # (str) The mute period duration
    member.mute_notification    # (bool) Whether notifications are muted
    member.mute_groups          # (List[str]) List of muted groups
    member.mute_channels        # (List[str]) List of muted channels
  5. Use the RestrictedUser model to access restricted user data

    The swibots.api.community.models.RestrictedUser class provides information about a user who has been restricted within a community. It contains the following properties:

    • restricted (bool): Indicates if the user is currently restricted.
    • user_id (int): The unique identifier of the user.
    • community_id (str): The identifier of the community where the restriction applies.
    • restricted_till (int | dict): Information regarding the expiration date of the restriction.
    • user (User): A reference to the full User info object.
  6. Use BotContext in handler functions

    The BotContext object is passed to handler functions and serves as the primary interface for interacting with the bot and the event that triggered the handler. It provides access to the bot instance and the event data, and allows developers to call any method available in the API to perform actions such as sending messages or retrieving user information.
  7. Access download progress data via DownloadProgress

    The DownloadProgress object provides real-time metadata about a file download operation. Its properties include:

    • downloaded (int): Number of bytes downloaded so far.
    • total (int): Total bytes to be downloaded.
    • url (str): The URL of the file.
    • file_name (str): The name of the file.
    • stared (bool): Indicates if the download has started.
    • client (IOClient): The client instance managing the download.