micup

package module
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 13 Imported by: 0

README

micup.go

micup.go is a standalone Go client for Micup bots. It discovers the public REST and Gateway endpoints, authenticates bot requests, delivers native Gateway events, sends messages with embeds, responds privately to interactions, and can publish stereo PCM to a LiveKit voice room.

The module keeps platform transport separate from application behavior. It does not implement music search, queues, command syntax, persistence, or worker coordination.

Requirements

  • Go 1.26.8 or newer
  • A Micup bot token
  • FFmpeg with libopus enabled when publishing voice audio

Install

go get github.com/yestefir/micup.go@v0.2.1

The public repository is yestefir/micup.go. The Go module path matches that repository.

Quick start

client, err := micup.New(ctx, micup.Config{Token: os.Getenv("MICUP_BOT_TOKEN")})
if err != nil {
	log.Fatal(err)
}

err = client.Gateway(ctx, func(ctx context.Context, event micup.Event) error {
	if event.Name != "MESSAGE_CREATE" {
		return nil
	}
	var message micup.MessageCreate
	if err := json.Unmarshal(event.Data, &message); err != nil {
		return err
	}
	if message.Author.Bot || message.Content != "!ping" {
		return nil
	}
	_, err := client.SendMessage(ctx, message.ChannelID, "pong", message.ID)
	return err
})

See the guides for setup, Gateway events, voice publishing, security boundaries, and examples.

License

This project is free to use under the MIT License, including in commercial projects. Keep the copyright and license notice with copies or substantial portions of the software.

Repository layout

client.go          Discovery, bot authentication, and REST requests
gateway.go         Native Gateway connection and event delivery
types.go           Micup REST and Gateway payload types
voice/             LiveKit room and PCM-to-Opus publishing
docs/              User, API, architecture, and contributor guides

Go source files intentionally contain no comments. The documentation site is the source of user and API guidance.

Current scope

The first release target is the public REST/Gateway transport and the LiveKit PCM publishing helper. The Gateway runner holds one connection and returns on a disconnect; reconnect and resume policy belongs to the calling application. Identify uses the configured shard ID and count. It does not discover shard counts or redistribute shards.

The current public release is v0.2.1. Release history is in CHANGELOG.md.

Documentation

Index

Constants

View Source
const DefaultOrigin = "https://micup.gg"

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct{ StatusCode int }

func (*APIError) Error

func (e *APIError) Error() string

type Channel

type Channel struct {
	ID      string `json:"id"`
	GuildID string `json:"guild_id"`
	Name    string `json:"name"`
	Type    int    `json:"type"`
}

type Client

type Client struct {
	BotID                 string
	MessageContentEnabled *bool
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, config Config) (*Client, error)

func (*Client) DeferInteraction added in v0.2.0

func (c *Client) DeferInteraction(ctx context.Context, interaction Interaction, ephemeral bool) error

func (*Client) Gateway

func (c *Client) Gateway(ctx context.Context, handler EventHandler) error

func (*Client) GatewayEndpoint added in v0.2.0

func (c *Client) GatewayEndpoint() string

func (*Client) REST

func (c *Client) REST(ctx context.Context, method, path string, body, dest any) error

func (*Client) RespondToInteraction added in v0.2.0

func (c *Client) RespondToInteraction(ctx context.Context, interaction Interaction, options MessageOptions, ephemeral bool) error

func (*Client) SendInteractionFollowup added in v0.2.0

func (c *Client) SendInteractionFollowup(ctx context.Context, interaction Interaction, options MessageOptions, ephemeral bool) (Message, error)

func (*Client) SendMessage

func (c *Client) SendMessage(ctx context.Context, channelID, content, replyTo string) (Message, error)

func (*Client) SendMessageWithOptions added in v0.2.0

func (c *Client) SendMessageWithOptions(ctx context.Context, channelID string, options MessageOptions) (Message, error)

type Config

type Config struct {
	Token      string
	Origin     string
	HTTP       *http.Client
	ShardID    int
	ShardCount int
}

type Embed added in v0.2.0

type Embed struct {
	Title       string       `json:"title,omitempty"`
	Type        string       `json:"type,omitempty"`
	Description string       `json:"description,omitempty"`
	URL         string       `json:"url,omitempty"`
	Timestamp   string       `json:"timestamp,omitempty"`
	Color       int          `json:"color,omitempty"`
	Footer      *EmbedFooter `json:"footer,omitempty"`
	Image       *EmbedMedia  `json:"image,omitempty"`
	Thumbnail   *EmbedMedia  `json:"thumbnail,omitempty"`
	Author      *EmbedAuthor `json:"author,omitempty"`
	Fields      []EmbedField `json:"fields,omitempty"`
}

type EmbedAuthor added in v0.2.0

type EmbedAuthor struct {
	Name    string `json:"name"`
	URL     string `json:"url,omitempty"`
	IconURL string `json:"icon_url,omitempty"`
}

type EmbedField added in v0.2.0

type EmbedField struct {
	Name   string `json:"name"`
	Value  string `json:"value"`
	Inline bool   `json:"inline,omitempty"`
}

type EmbedFooter added in v0.2.0

type EmbedFooter struct {
	Text    string `json:"text"`
	IconURL string `json:"icon_url,omitempty"`
}

type EmbedMedia added in v0.2.0

type EmbedMedia struct {
	URL string `json:"url"`
}

type Event

type Event struct {
	Name     string
	Sequence *int64
	Data     json.RawMessage
	// contains filtered or unexported fields
}

func (Event) Send

func (e Event) Send(ctx context.Context, opcode int, data any) error

type EventHandler

type EventHandler func(context.Context, Event) error

type Guild

type Guild struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

type Interaction added in v0.2.0

type Interaction struct {
	ID            string          `json:"id"`
	ApplicationID string          `json:"application_id"`
	Type          int             `json:"type"`
	Data          json.RawMessage `json:"data,omitempty"`
	GuildID       string          `json:"guild_id,omitempty"`
	ChannelID     string          `json:"channel_id,omitempty"`
	Token         string          `json:"token"`
	Version       int             `json:"version,omitempty"`
	Member        json.RawMessage `json:"member,omitempty"`
	User          json.RawMessage `json:"user,omitempty"`
}

type Message

type Message struct {
	ID        string  `json:"id"`
	ChannelID string  `json:"channel_id"`
	GuildID   string  `json:"guild_id,omitempty"`
	Content   string  `json:"content"`
	Embeds    []Embed `json:"embeds,omitempty"`
	Flags     int     `json:"flags,omitempty"`
}

type MessageCreate

type MessageCreate struct {
	ID        string          `json:"id"`
	GuildID   string          `json:"guild_id"`
	ChannelID string          `json:"channel_id"`
	Content   string          `json:"content"`
	Author    User            `json:"author"`
	Mentions  []User          `json:"mentions"`
	Raw       json.RawMessage `json:"-"`
}

type MessageOptions added in v0.2.0

type MessageOptions struct {
	Content      string  `json:"content,omitempty"`
	Embeds       []Embed `json:"embeds,omitempty"`
	ReplyTo      string  `json:"-"`
	Nonce        string  `json:"nonce,omitempty"`
	EnforceNonce bool    `json:"enforce_nonce,omitempty"`
}

type User

type User struct {
	ID       string `json:"id"`
	Username string `json:"username"`
	Bot      bool   `json:"bot"`
}

type VoiceServerUpdate

type VoiceServerUpdate struct {
	GuildID      string `json:"guild_id"`
	Endpoint     string `json:"endpoint"`
	Token        string `json:"token"`
	ConnectionID string `json:"connection_id"`
}

type VoiceState

type VoiceState struct {
	GuildID   string `json:"guild_id"`
	UserID    string `json:"user_id"`
	ChannelID string `json:"channel_id"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL