Sleepy Discord

website·Indexed 32 days ago

https://yourwaifu.dev/sleepy-discord/

A C++ library for interacting with the Discord API. The documentation covers setup using CMake, Visual Studio, and CLI, as well as implementing slash commands, voice channel connectivity, event handling, and managing Discord objects like Snowflakes and Embeds.

Tokens
12.9K
Snippets
56
Records
98
Agent score
60%

What's inside Sleepy Discord

  1. Overview of Sleepy Discord C++ Library

    Sleepy Discord is a library that allows developers to use the Discord API within software written in C++. It is designed to be portable and modular, allowing for customization of core components such as WebSockets, HTTPS, and I/O objects.
  2. Overview of Graphics APIs and Rendering Libraries

    Graphics Processing Units (GPUs) are specialized processors for drawing graphics. To interact with them, developers use Graphics APIs (Application Programming Interfaces) which translate high-level instructions into GPU-understandable commands. Common examples include OpenGL, Vulkan, and DirectX. To avoid direct API complexity, developers often use rendering libraries like BGFX, three.js, and Filament, or full game engines like Unity.
  3. Understand Snowflake uniqueness and type safety

    The library uses a template class SleepyDiscord::Snowflake<T> to differentiate IDs of different types. While two objects of the same type must have unique IDs, objects of different types (e.g., a Server, its general channel, and its default role) may share the same ID value. Using the template class prevents logic errors when handling these overlapping IDs.
  4. Understand object relationships in SleepyDiscord

    Discord objects often maintain relationships with one another. For example, the ServerMember class acts as a bridge between a Server and a User, containing specific data relevant to that user's presence on that specific server, such as their nickname.
  5. Voice support implementation in Sleepy Discord

    Voice support is available in the develop branch. To support voice, the library was extended to handle multiple WebSocket connections simultaneously: one for general text channel information and one specifically for the voice connection. Note that voice receiving is still under development and undocumented, meaning its implementation may change.
  6. Use JSX and React components in Markdown with MDX

    The documentation system supports MDX, which allows developers to write JSX and embed React components directly within Markdown files. This enables a mix of standard Markdown formatting (like bold and italics) and interactive React elements in the same document.
  7. Manage voice states

    Voice states provide information about users in a voice chat, such as joining/leaving channels, muting, or deafening. This can be tracked using:

    • The onEditVoiceState event on the Discord Client.
    • The server.voiceStates data available during the onServer event.
  8. Fundamental Graphics Concepts: Meshes, Textures, and Shaders

    Graphics are typically built using triangles, which connect to form complex shapes called polygon meshes. Texture mapping is used to apply images to these surfaces, requiring a UV map to define how the image coordinates align with the mesh vertices. Materials define how light reacts to a surface and can be customized using shaders (code executed on the GPU).
  9. Implement an Entity Component System (ECS) for game engine architecture

    To improve performance and flexibility over a type-based list system (e.g., list<NPC>), use an Entity Component System (ECS). In this pattern, entities are containers for components (data), and systems contain the logic that operates on those components. This allows for easier multithreading by scheduling systems as parallel jobs.
    // Example of querying entities with specific components and running a parallel job
    Entities
      .WithAll<Body, Health>() // Require these components
      .ForEach(
        (Entity entity, ref Body body, ref Health health) =>
        {
          // Logic for entities having both Body and Health components
        }
      )
      .ScheduleParallel(); // Schedule as a parallel job
  10. Build a 3D website with React Three Fiber and Blender

    To create a 3D website with models, lighting, and materials, use the following stack:

    • Blender: For creating and exporting 3D models.
    • Three.js: The core WebGL library for rendering 3D content.
    • React Three Fiber (R3F): A React renderer for Three.js that allows managing 3D scenes as React components.
    • Drei: A helper library for React Three Fiber that provides useful utilities like HTML overlays.
  11. Retrieve values from command options

    Option values are retrieved from the interaction.data.options list. You can use the .get<T>() method (which may throw an exception) or the .get(T&) method (which returns a boolean indicating success) to parse the JSON data into the desired type.
    void onInteraction(SleepyDiscord::Interaction interaction) override {
        if (interaction.data.name != "add") return;
    
        for (auto& option : interaction.data.options) {
            if (option.name == "left" || option.name == "right") {
                double num;
                if (option.get(num)) {
                    answer += num;
                } else {
                    return; // fail
                }
            }
        }
    }
  12. Implement fixed choices for command options

    Choices allow users to select from a predefined list. Create SleepyDiscord::AppCommand::Option::Choice objects, set their display name and value using .set<T>(), and add them to the option's choices vector. Note that there is a limit of 25 choices per option; for larger lists, use autocomplete.
    SleepyDiscord::AppCommand::Option iceCream;
    iceCream.name = "ice-cream";
    iceCream.description = "Which ice-cream would you like";
    iceCream.type = SleepyDiscord::AppCommand::Option::TypeHelper<std::string>::getType();
    
    SleepyDiscord::AppCommand::Option::Choice vanilla;
    vanilla.name = "Vanilla";
    vanilla.set<std::string>("vanilla");
    iceCream.choices.push_back(std::move(vanilla));