Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

166 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Important

The API coverage is currently quite low, and reliability is not guaranteed. The library is also subject to making breaking changes since a release has not yet been made!

Flo

A cute Go library for making Fluxer bots/self-bots aiming to be simple in implementation and usage! More user-API specific things may be considered in the future, but that is likely more useful for custom clients which is not the current focus.

Join our Fluxer Community to get help or just hang out!

Features

  • Rate limiting
  • Caching
  • Sharding support (in theory)
  • Cache and REST methods on objects for slightly more type safety
    • Another approach is typed IDs, but this has its downsides - at least taking the approach of arikawa which duplicates code and uses codegen.

See also

  • FluxerGo - Port of DisGo to Fluxer
    • Split up into several packages which may be more your style
    • Still has a lot of Discord stuff that needs to removed/changed :(

Example

package main

import (
	"context"
	"fmt"
	"log/slog"
	"os"

	"github.com/fluxer-flo/flo"
)

func main() {
	token := os.Getenv("FLUXER_TOKEN")
	if token == "" {
		slog.Error("please provide the token as FLUXER_TOKEN")
		os.Exit(1)
	}
	// you need this prefix for bot tokens!
	token = "Bot " + token

	cache := flo.NewCacheDefault()
	// if you want to change the limit or avoid caching something entirely:
	// cache.Guilds = flo.NewCollection[Guild](0)

	// REST is used to perform actions through Fluxer's REST HTTP API
	rest := flo.REST{
        // Auth can be omitted, for example if you're just using webhooks
        // Note that this will cause ratelimits to be done based on IP instead
        // Cache is also optional, omitting it will simply stop requests populating the cache
		Auth:  token, 
		Cache: &cache,
        // Recommended - disable all mentions unless AllowedMentions is explicitly specified for a message
        DefaultAllowedMentions: &flo.AllowedMentionsNone,
	}

	// Gateway is used to receive events through a persistent websocket connection to Fluxer's gateway
	gateway := flo.Gateway{
        // Auth is required, but cache can be omitted to stop events from populating the cache (not recommended)
		Auth:  token,
		Cache: &cache,
	}
    gateway.SetPresence(flo.PresenceOpts{
        Status: flo.UserStatusIdle,
        CustomStatus: flo.CustomStatusOpts{
            EmojiName: "💤",
            Text: "chillin'",
        },
    })

	gateway.ShardReady.OnceSync(func(r flo.ShardReadyEvent) {
		fmt.Println("ready as " + r.User.Tag())
	})

	gateway.MessageCreate.On(func(m flo.MessageCreateEvent) {
		var resp string
		switch m.Content {
		case "!ping":
			resp = "Pong!"
		case "!pong":
			resp = "Ping!"
		default:
			return
		}

		_, err := rest.CreateMessage(context.TODO(), m.ChannelID, flo.CreateMessageOpts{
			Content: resp,
			// reply to the original message
			MessageReference: flo.MessageReferenceOpts{
				MessageID: m.ID,
			},
		})
		if err != nil {
			slog.Warn("couldn't reply to command :/", slog.Any("err", err))
		}
	})

	gateway.Start()

	stopped, _ := gateway.ShardStopped.OnceChan()
	event := <-stopped
	if event.Err != nil {
		slog.Error("stopped with error", slog.Any("err", event.Err))
	}
}

About

Go library for Fluxer

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages