micup

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 9 Imported by: 0

README

micup.go

micup.go is a standalone Go client for Micup bots, following the Fluxer API that Micup runs on. It covers:

  • Gateway: sessions that resume, replay unprocessed events and re-identify on the same socket; a shard manager for many shards in one process; optional zstd-stream compression; ignored events and presence; command pacing below Micup's limits.
  • State: guilds, channels with permission overwrites, roles, member roles and voice states, with permission computation.
  • REST: messages (send, edit, delete, bulk delete, list), buttons and click answers, reactions, pins, typing, DMs, files (multipart and presigned uploads), members, roles, moderation and webhooks, with Micup's error codes and rate limit rules.
  • Voice: the join handshake with fast refusal and permission checks, grant rotation, and Opus publishing to LiveKit.

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

Quick start

import micup "github.com/yestefir/micup.go"

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

s, err := b.NewSession(micup.SessionOptions{Handler: func(ctx context.Context, event micup.Event) error {
	if event.Name != micup.EventMessageCreate {
		return nil
	}
	var message micup.MessageCreate
	if err := event.Decode(&message); err != nil {
		return err
	}
	if message.Author.Bot || message.Content != "!ping" {
		return nil
	}
	_, err := b.REST.SendMessage(ctx, message.ChannelID, "pong", message.ID)
	return err
}})
if err != nil {
	log.Fatal(err)
}
err = s.Run(ctx)

Bots in many guilds use b.NewShardManager(micup.ShardOptions{ShardCount: 4, Session: options}) instead of b.NewSession. See Shards.

Public API

Applications import only two paths:

Import Contains
github.com/yestefir/micup.go Everything: bot setup, REST, Gateway events, sessions, shards, state cache, payload types, errors
github.com/yestefir/micup.go/voice LiveKit room and PCM→Opus publishing (separate so bots without voice skip LiveKit and WebRTC)

Both are thin facades over src/. Code under src/ can be moved or split without changing these import paths or names; a test fails if a facade gains logic of its own.

See the guides for setup, Gateway events, voice publishing, security boundaries, and the v0.3 → v0.4 migration.

Repository layout

The implementation lives under src/, one package per domain:

micup.go       Public facade: package micup
voice/         Public facade: package voice
src/
  bot/         Entry point: discovery, bot identity, wiring for sessions and shards
  discovery/   /.well-known endpoint discovery and origin checks
  rest/        Authenticated REST client: channels, messages, interactions, users
  gateway/     Opcodes, close codes, events, single-connection Gateway loop
  state/       Guild channel and voice state cache
  session/     Reconnecting, resuming session for one shard; voice join handshake
  shard/       Guild-to-shard mapping and multi-shard Manager
  model/       Plain Micup payload types
  voice/       LiveKit room and PCM-to-Opus publishing
  internal/    Version, HTTP safety, test fixtures, layer and facade rules
docs/          User, API, architecture, and contributor guides

Package dependencies point one way and are enforced by a test; see Architecture. Go source files intentionally contain no comments.

Run make check before sending a change. CI runs the same checks on Linux, macOS and Windows.

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.

The current release is v0.4.0. Release history is in CHANGELOG.md.

Documentation

Index

Constants

View Source
const (
	EventReady               = gateway.EventReady
	EventResumed             = gateway.EventResumed
	EventGuildCreate         = gateway.EventGuildCreate
	EventGuildSync           = gateway.EventGuildSync
	EventGuildUpdate         = gateway.EventGuildUpdate
	EventGuildDelete         = gateway.EventGuildDelete
	EventGuildRoleCreate     = gateway.EventGuildRoleCreate
	EventGuildRoleUpdate     = gateway.EventGuildRoleUpdate
	EventGuildRoleUpdateBulk = gateway.EventGuildRoleUpdateBulk
	EventGuildRoleDelete     = gateway.EventGuildRoleDelete
	EventGuildMemberAdd      = gateway.EventGuildMemberAdd
	EventGuildMemberUpdate   = gateway.EventGuildMemberUpdate
	EventGuildMemberRemove   = gateway.EventGuildMemberRemove
	EventGuildMembersChunk   = gateway.EventGuildMembersChunk
	EventGuildBanAdd         = gateway.EventGuildBanAdd
	EventGuildBanRemove      = gateway.EventGuildBanRemove
	EventChannelUpdateBulk   = gateway.EventChannelUpdateBulk
	EventChannelPinsUpdate   = gateway.EventChannelPinsUpdate
	EventMessageUpdate       = gateway.EventMessageUpdate
	EventMessageDelete       = gateway.EventMessageDelete
	EventMessageDeleteBulk   = gateway.EventMessageDeleteBulk
	EventReactionAdd         = gateway.EventReactionAdd
	EventReactionRemove      = gateway.EventReactionRemove
	EventReactionRemoveAll   = gateway.EventReactionRemoveAll
	EventReactionRemoveEmoji = gateway.EventReactionRemoveEmoji
	EventTypingStart         = gateway.EventTypingStart
	EventPresenceUpdate      = gateway.EventPresenceUpdate
	EventUserUpdate          = gateway.EventUserUpdate
	EventWebhooksUpdate      = gateway.EventWebhooksUpdate
	EventInviteCreate        = gateway.EventInviteCreate
	EventInviteDelete        = gateway.EventInviteDelete
	EventRateLimited         = gateway.EventRateLimited
	EventChannelCreate       = gateway.EventChannelCreate
	EventChannelUpdate       = gateway.EventChannelUpdate
	EventChannelDelete       = gateway.EventChannelDelete
	EventMessageCreate       = gateway.EventMessageCreate
	EventInteractionCreate   = gateway.EventInteractionCreate
	EventVoiceStateUpdate    = gateway.EventVoiceStateUpdate
	EventVoiceServerUpdate   = gateway.EventVoiceServerUpdate
)
View Source
const (
	OpDispatch                   = gateway.OpDispatch
	OpHeartbeat                  = gateway.OpHeartbeat
	OpIdentify                   = gateway.OpIdentify
	OpPresenceUpdate             = gateway.OpPresenceUpdate
	OpVoiceStateUpdate           = gateway.OpVoiceStateUpdate
	OpRequestGuildMembers        = gateway.OpRequestGuildMembers
	OpGatewayError               = gateway.OpGatewayError
	OpLazyRequest                = gateway.OpLazyRequest
	OpRequestGuildCounts         = gateway.OpRequestGuildCounts
	OpRequestChannelMemberCounts = gateway.OpRequestChannelMemberCounts
	OpResume                     = gateway.OpResume
	OpReconnect                  = gateway.OpReconnect
	OpInvalidSession             = gateway.OpInvalidSession
	OpHello                      = gateway.OpHello
	OpHeartbeatAck               = gateway.OpHeartbeatAck
)
View Source
const (
	FlagDebounceMessageReactions = gateway.FlagDebounceMessageReactions
	FlagChannelThreads           = gateway.FlagChannelThreads
	FlagGuildVisits              = gateway.FlagGuildVisits
)
View Source
const (
	StatusOnline    = model.StatusOnline
	StatusIdle      = model.StatusIdle
	StatusDND       = model.StatusDND
	StatusInvisible = model.StatusInvisible
	StatusOffline   = model.StatusOffline
)
View Source
const (
	VoiceChannelFull        = gateway.VoiceChannelFull
	VoiceP2PConsentRequired = gateway.VoiceP2PConsentRequired
	VoiceP2PUnavailable     = gateway.VoiceP2PUnavailable
)
View Source
const (
	DefaultMinBackoff = session.DefaultMinBackoff
	DefaultMaxBackoff = session.DefaultMaxBackoff
)
View Source
const (
	PermissionCreateInstantInvite   = model.PermissionCreateInstantInvite
	PermissionKickMembers           = model.PermissionKickMembers
	PermissionBanMembers            = model.PermissionBanMembers
	PermissionAdministrator         = model.PermissionAdministrator
	PermissionManageChannels        = model.PermissionManageChannels
	PermissionManageGuild           = model.PermissionManageGuild
	PermissionAddReactions          = model.PermissionAddReactions
	PermissionViewAuditLog          = model.PermissionViewAuditLog
	PermissionPrioritySpeaker       = model.PermissionPrioritySpeaker
	PermissionStream                = model.PermissionStream
	PermissionViewChannel           = model.PermissionViewChannel
	PermissionSendMessages          = model.PermissionSendMessages
	PermissionSendTTSMessages       = model.PermissionSendTTSMessages
	PermissionManageMessages        = model.PermissionManageMessages
	PermissionEmbedLinks            = model.PermissionEmbedLinks
	PermissionAttachFiles           = model.PermissionAttachFiles
	PermissionReadMessageHistory    = model.PermissionReadMessageHistory
	PermissionMentionEveryone       = model.PermissionMentionEveryone
	PermissionUseExternalEmojis     = model.PermissionUseExternalEmojis
	PermissionConnect               = model.PermissionConnect
	PermissionSpeak                 = model.PermissionSpeak
	PermissionMuteMembers           = model.PermissionMuteMembers
	PermissionDeafenMembers         = model.PermissionDeafenMembers
	PermissionMoveMembers           = model.PermissionMoveMembers
	PermissionUseVAD                = model.PermissionUseVAD
	PermissionChangeNickname        = model.PermissionChangeNickname
	PermissionManageNicknames       = model.PermissionManageNicknames
	PermissionManageRoles           = model.PermissionManageRoles
	PermissionManageWebhooks        = model.PermissionManageWebhooks
	PermissionManageExpressions     = model.PermissionManageExpressions
	PermissionManageThreads         = model.PermissionManageThreads
	PermissionCreatePublicThreads   = model.PermissionCreatePublicThreads
	PermissionCreatePrivateThreads  = model.PermissionCreatePrivateThreads
	PermissionUseExternalStickers   = model.PermissionUseExternalStickers
	PermissionSendMessagesInThreads = model.PermissionSendMessagesInThreads
	PermissionModerateMembers       = model.PermissionModerateMembers
	PermissionCreateExpressions     = model.PermissionCreateExpressions
	PermissionPinMessages           = model.PermissionPinMessages
	PermissionBypassSlowmode        = model.PermissionBypassSlowmode
	PermissionUpdateRTCRegion       = model.PermissionUpdateRTCRegion
	PermissionViewChannelMembers    = model.PermissionViewChannelMembers
	PermissionAll                   = model.PermissionAll
	OverwriteRole                   = model.OverwriteRole
	OverwriteMember                 = model.OverwriteMember
)
View Source
const (
	ChannelTypeGuildText          = model.ChannelTypeGuildText
	ChannelTypeDM                 = model.ChannelTypeDM
	ChannelTypeGuildVoice         = model.ChannelTypeGuildVoice
	ChannelTypeGroupDM            = model.ChannelTypeGroupDM
	ChannelTypeGuildCategory      = model.ChannelTypeGuildCategory
	ChannelTypeGuildAnnouncement  = model.ChannelTypeGuildAnnouncement
	ChannelTypeAnnouncementThread = model.ChannelTypeAnnouncementThread
	ChannelTypePublicThread       = model.ChannelTypePublicThread
	ChannelTypePrivateThread      = model.ChannelTypePrivateThread
	ChannelTypeGuildForum         = model.ChannelTypeGuildForum
	ChannelTypeGuildMedia         = model.ChannelTypeGuildMedia
	ChannelTypeGuildLink          = model.ChannelTypeGuildLink
	ChannelTypePersonalNotes      = model.ChannelTypePersonalNotes
)
View Source
const (
	MessageTypeDefault              = model.MessageTypeDefault
	MessageTypeRecipientAdd         = model.MessageTypeRecipientAdd
	MessageTypeRecipientRemove      = model.MessageTypeRecipientRemove
	MessageTypeCall                 = model.MessageTypeCall
	MessageTypeChannelNameChange    = model.MessageTypeChannelNameChange
	MessageTypeChannelIconChange    = model.MessageTypeChannelIconChange
	MessageTypeChannelPinnedMessage = model.MessageTypeChannelPinnedMessage
	MessageTypeUserJoin             = model.MessageTypeUserJoin
	MessageTypeChannelFollowAdd     = model.MessageTypeChannelFollowAdd
	MessageTypeThreadCreated        = model.MessageTypeThreadCreated
	MessageTypeReply                = model.MessageTypeReply
	MessageTypeThreadStarterMessage = model.MessageTypeThreadStarterMessage
)
View Source
const (
	MessageFlagCrossposted           = model.MessageFlagCrossposted
	MessageFlagIsCrosspost           = model.MessageFlagIsCrosspost
	MessageFlagSuppressEmbeds        = model.MessageFlagSuppressEmbeds
	MessageFlagSourceMessageDeleted  = model.MessageFlagSourceMessageDeleted
	MessageFlagHasThread             = model.MessageFlagHasThread
	MessageFlagEphemeral             = model.MessageFlagEphemeral
	MessageFlagSuppressNotifications = model.MessageFlagSuppressNotifications
	MessageFlagVoiceMessage          = model.MessageFlagVoiceMessage
)
View Source
const (
	MaxEmbeds          = model.MaxEmbeds
	MaxAttachments     = model.MaxAttachments
	MaxBulkDelete      = model.MaxBulkDelete
	MaxMessagesPerPage = model.MaxMessagesPerPage
	MentionUsers       = model.MentionUsers
	MentionRoles       = model.MentionRoles
	MentionEveryone    = model.MentionEveryone
)
View Source
const (
	ComponentTypeActionRow = model.ComponentTypeActionRow
	ComponentTypeButton    = model.ComponentTypeButton
	ButtonStylePrimary     = model.ButtonStylePrimary
	ButtonStyleSecondary   = model.ButtonStyleSecondary
	ButtonStyleSuccess     = model.ButtonStyleSuccess
	ButtonStyleDanger      = model.ButtonStyleDanger
	ButtonStyleLink        = model.ButtonStyleLink
	MaxActionRows          = model.MaxActionRows
	MaxButtonsPerRow       = model.MaxButtonsPerRow
	MaxCustomIDLength      = model.MaxCustomIDLength
	MaxButtonLabelLength   = model.MaxButtonLabelLength
)
View Source
const (
	InteractionTypePing               = model.InteractionTypePing
	InteractionTypeApplicationCommand = model.InteractionTypeApplicationCommand
	InteractionTypeMessageComponent   = model.InteractionTypeMessageComponent
	InteractionTypeAutocomplete       = model.InteractionTypeAutocomplete
	InteractionTypeModalSubmit        = model.InteractionTypeModalSubmit
)
View Source
const DefaultIdentifyInterval = shard.DefaultIdentifyInterval
View Source
const DefaultOrigin = discovery.DefaultOrigin
View Source
const Version = bot.Version

Variables

View Source
var (
	ErrReconnectRequested = gateway.ErrReconnectRequested
	ErrGatewayClosed      = gateway.ErrClosed
)
View Source
var (
	ErrNotReady           = session.ErrNotReady
	ErrVoiceJoinPending   = session.ErrVoiceJoinPending
	ErrVoiceGrant         = session.ErrVoiceGrant
	ErrVoiceMoved         = session.ErrVoiceMoved
	ErrVoiceRefused       = session.ErrVoiceRefused
	ErrVoicePermission    = session.ErrVoicePermission
	ErrMembersRateLimited = session.ErrMembersRateLimited
)
View Source
var (
	ErrShardNotOwned       = shard.ErrNotOwned
	ErrShardManagerRunning = shard.ErrRunning
)

Functions

func EmojiString added in v0.4.0

func EmojiString(emoji Emoji) string

func RunGateway added in v0.4.0

func RunGateway(ctx context.Context, options GatewayOptions, handler EventHandler) error

func ShardForGuild added in v0.3.0

func ShardForGuild(guildID string, shardCount int) (int, error)

Types

type APIError

type APIError = rest.APIError

type ActionRow added in v0.4.0

type ActionRow = model.ActionRow

func DisableButtons added in v0.4.0

func DisableButtons(rows []ActionRow) []ActionRow

func NewActionRow added in v0.4.0

func NewActionRow(buttons ...Button) ActionRow

type AllowedMentions added in v0.4.0

type AllowedMentions = model.AllowedMentions

type Application added in v0.4.0

type Application = rest.Application

type Attachment added in v0.4.0

type Attachment = model.Attachment

type Ban added in v0.4.0

type Ban = model.Ban

type Bot added in v0.4.0

type Bot = bot.Bot

func New

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

type Button added in v0.4.0

type Button = model.Button

func DangerButton added in v0.4.0

func DangerButton(customID, label string) Button

func LinkButton added in v0.4.0

func LinkButton(url, label string) Button

func PrimaryButton added in v0.4.0

func PrimaryButton(customID, label string) Button

func SecondaryButton added in v0.4.0

func SecondaryButton(customID, label string) Button

func SuccessButton added in v0.4.0

func SuccessButton(customID, label string) Button

type Channel

type Channel = model.Channel

type ChannelLookup added in v0.4.0

type ChannelLookup = session.ChannelLookup

type CloseError added in v0.3.0

type CloseError = gateway.CloseError

type ComponentData added in v0.4.0

type ComponentData = model.ComponentData

type Config

type Config = bot.Config

type CustomStatus added in v0.4.0

type CustomStatus = model.CustomStatus

type Embed added in v0.2.0

type Embed = model.Embed

type EmbedAuthor added in v0.2.0

type EmbedAuthor = model.EmbedAuthor

type EmbedField added in v0.2.0

type EmbedField = model.EmbedField

type EmbedFooter added in v0.2.0

type EmbedFooter = model.EmbedFooter

type EmbedMedia added in v0.2.0

type EmbedMedia = model.EmbedMedia

type Emoji added in v0.4.0

type Emoji = model.Emoji

type Endpoints added in v0.4.0

type Endpoints = discovery.Endpoints

type Event

type Event = gateway.Event

type EventHandler

type EventHandler = gateway.Handler

type FieldError added in v0.4.0

type FieldError = rest.FieldError

type File added in v0.4.0

type File = rest.File

type GatewayConn added in v0.4.0

type GatewayConn = gateway.Conn

type GatewayError added in v0.4.0

type GatewayError = gateway.GatewayError

type GatewayOptions added in v0.4.0

type GatewayOptions = gateway.Options

type Guild

type Guild = model.Guild

type GuildMember added in v0.4.0

type GuildMember = model.GuildMember

type GuildMemberRemove added in v0.4.0

type GuildMemberRemove = model.GuildMemberRemove

type Interaction added in v0.2.0

type Interaction = model.Interaction

type Member added in v0.4.0

type Member = model.Member

type MemberEdit added in v0.4.0

type MemberEdit = model.MemberEdit

type MemberQuery added in v0.4.0

type MemberQuery = model.MemberQuery

type MembersRateLimitedError added in v0.4.0

type MembersRateLimitedError = session.MembersRateLimitedError

type MembersRequest added in v0.4.0

type MembersRequest = model.MembersRequest

type Message

type Message = model.Message

type MessageCreate

type MessageCreate = model.MessageCreate

type MessageDelete added in v0.4.0

type MessageDelete = model.MessageDelete

type MessageDeleteBulk added in v0.4.0

type MessageDeleteBulk = model.MessageDeleteBulk

type MessageEdit added in v0.4.0

type MessageEdit = model.MessageEdit

type MessageOptions added in v0.2.0

type MessageOptions = model.MessageOptions

type MessageQuery added in v0.4.0

type MessageQuery = model.MessageQuery

type MessageReference added in v0.4.0

type MessageReference = model.MessageReference

type MessageUpdate added in v0.4.0

type MessageUpdate = model.MessageUpdate

type PermissionOverwrite added in v0.4.0

type PermissionOverwrite = model.PermissionOverwrite

type Permissions added in v0.4.0

type Permissions = model.Permissions

func ComputePermissions added in v0.4.0

func ComputePermissions(guildID, ownerID, userID string, roles map[string]Role, memberRoles []string, overwrites []PermissionOverwrite) Permissions

type Pin added in v0.4.0

type Pin = model.Pin

type PinQuery added in v0.4.0

type PinQuery = model.PinQuery

type PinsPage added in v0.4.0

type PinsPage = model.PinsPage

type Presence added in v0.4.0

type Presence = model.Presence

type RESTClient added in v0.4.0

type RESTClient = rest.Client

func NewREST added in v0.4.0

func NewREST(config RESTConfig) (*RESTClient, error)

type RESTConfig added in v0.4.0

type RESTConfig = rest.Config

type Reaction added in v0.4.0

type Reaction = model.Reaction

type ReactionEvent added in v0.4.0

type ReactionEvent = model.ReactionEvent

type RequestOption added in v0.4.0

type RequestOption = rest.RequestOption

func WithReason added in v0.4.0

func WithReason(reason string) RequestOption

type Resume added in v0.4.0

type Resume = gateway.Resume

type Role added in v0.4.0

type Role = model.Role

type RoleDelete added in v0.4.0

type RoleDelete = model.RoleDelete

type RoleEvent added in v0.4.0

type RoleEvent = model.RoleEvent

type Session added in v0.3.0

type Session = session.Session

func NewSession added in v0.4.0

func NewSession(config SessionConfig, options SessionOptions) (*Session, error)

type SessionConfig added in v0.4.0

type SessionConfig = session.Config

type SessionOptions added in v0.3.0

type SessionOptions = session.Options

type ShardManager added in v0.3.0

type ShardManager = shard.Manager

func NewShardManager added in v0.4.0

func NewShardManager(config SessionConfig, options ShardOptions) (*ShardManager, error)

type ShardOptions added in v0.4.0

type ShardOptions = shard.Options

type State added in v0.3.0

type State = state.Cache

func NewState added in v0.3.0

func NewState(botID string) *State

type TypingStart added in v0.4.0

type TypingStart = model.TypingStart

type Upload added in v0.4.0

type Upload = rest.Upload

type UploadedAttachment added in v0.4.0

type UploadedAttachment = model.UploadedAttachment

type User

type User = model.User

type VoiceJoin added in v0.3.0

type VoiceJoin = session.VoiceJoin

type VoiceMove added in v0.4.0

type VoiceMove = state.VoiceMove

type VoiceRefusedError added in v0.4.0

type VoiceRefusedError = session.VoiceRefusedError

type VoiceServerUpdate

type VoiceServerUpdate = model.VoiceServerUpdate

type VoiceState

type VoiceState = model.VoiceState

type Webhook added in v0.4.0

type Webhook = model.Webhook

type WebhookMessage added in v0.4.0

type WebhookMessage = model.WebhookMessage

Directories

Path Synopsis
src
bot

Jump to

Keyboard shortcuts

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