micup

package module
v0.1.0 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 channel messages, 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

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 first release candidate is v0.1.0. Release history is in CHANGELOG.md. The public v0.1.0 release is available as a Go module.

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) Gateway

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

func (*Client) REST

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

func (*Client) SendMessage

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

type Config

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

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 Message

type Message struct {
	ID        string `json:"id"`
	ChannelID string `json:"channel_id"`
	GuildID   string `json:"guild_id,omitempty"`
	Content   string `json:"content"`
}

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 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