centauri

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2023 License: MIT Imports: 3 Imported by: 0

README

Centauri

Go Reference Badge CI Badge Discord Server Badge Last Commit Badge Conventional Commits Badge

Note Due to my military service from July 2023 until April 2024 I will not be able to work on this project a lot, most likely only during weekends if I have time and motivation ^-^

Warning This is a WIP library that may be very unstable and eventually not fully optimised, use at your own care! This README will also be reworked.

A Discord API wrapper written in Go with the goal of being easily understandable and simple to use, even for newcomers.

Features

The plan for Centauri would be for it to cover Discord's APIs in their entirety. A small list of features that will be, or are already in Centauri are:

  • ANSI Colors
  • Background Tasks
  • Caching
  • Easy Commands Creation
  • Gateway API
  • Interactions (Buttons, Modals, etc.)
  • OAuth 2.0
  • Rate Limiter
  • REST API
  • RPC
  • Sharding
  • Webhooks

Getting Started

Installation

To get started you will simply need to install the library in your project by executing the following command.

go get github.com/kkrypt0nn/centauri
Example Usage
REST Client

If you just want to interact with the REST API, you may use the following code.

package main

import (
	"fmt"

	"github.com/kkrypt0nn/centauri"
)

func main() {
	botClient := centauri.NewRestClient("Bot BOT_TOKEN")
	bot, err := botClient.GetCurrentUser()
	if err != nil {
		fmt.Println("err:", err)
	} else {
		fmt.Println(fmt.Sprintf("Got bot %s with ID %d", bot.Username, bot.ID))
	}
}
Gateway Client

If you want to handle events coming from Discord, you may use the following code.

package main

import (
	"fmt"
	"github.com/kkrypt0nn/centauri"
	"github.com/kkrypt0nn/centauri/discord"
	"github.com/kkrypt0nn/centauri/gateway"
	"log"
	"os"
	"os/signal"
	"syscall"
)

func main() {
	botClient := centauri.NewGatewayClient("Bot BOT_TOKEN", discord.IntentsGuildMessages|discord.IntentsMessageContent)

	botClient.On(gateway.EventTypeReady, func(c *gateway.Client, ready *gateway.Ready) {
		botClient.Logger.Info(fmt.Sprintf("We are now logged in as %s", ready.User.Username))
	})
	botClient.On(gateway.EventTypeMessageCreate, func(c *gateway.Client, message *gateway.MessageCreate) {
		botClient.Logger.Info(fmt.Sprintf("Got a new message from %s: %s", message.Author.Username, message.Content))
	})

	err := botClient.Login()
	if err != nil {
		botClient.Logger.Error(err.Error())
		botClient.Close()
		return
	}

	sc := make(chan os.Signal, 1)
	signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
	<-sc
	botClient.Close()
}

More examples are available here

Documentation

The documentation is available for reading here. There is also the Go reference page available here

Troubleshooting

Some troubleshooting articles and guides may be found in the documentation mentioned above.

Contributing

Before the version 1.0.0 of the project, contributions are mostly closed as I'd like to lay down the foundations of the library. Afterward contributions will be more than welcome if following the Contributing Guidelines.

License

This library was made with 💜 by Krypton and is under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewGatewayClient added in v0.6.0

func NewGatewayClient(token string, intents discord.Intents) *gateway.Client

NewGatewayClient returns a new Gateway API client (gateway.Client) to handle real-time events from Discord

func NewRestClient

func NewRestClient(token string) *rest.Client

NewRestClient returns a new REST client (rest.Client) to make REST API calls only, may be a bot or a user token

Types

This section is empty.

Directories

Path Synopsis
_examples
Package constants holds the constants used across the library
Package constants holds the constants used across the library
Package discord holds the different structures of Discord's API
Package discord holds the different structures of Discord's API
Package endpoints is a package that will facilitate getting Discord endpoints
Package endpoints is a package that will facilitate getting Discord endpoints
Package errors is a package where internal errors used across the library are stored
Package errors is a package where internal errors used across the library are stored
ext
tasks
Package tasks in an experimental package which serves as an extension that lets users run a function at a specified interval
Package tasks in an experimental package which serves as an extension that lets users run a function at a specified interval
Package gateway handles the Gateway API of Discord
Package gateway handles the Gateway API of Discord
Package oauth2 handle the OAuth 2.0 flow for Discord
Package oauth2 handle the OAuth 2.0 flow for Discord
Package ptr is a package to get a pointer for given types
Package ptr is a package to get a pointer for given types
Package rest handles the REST API of Discord
Package rest handles the REST API of Discord
utils
flags
Package flags is a package for helper functions related to bitwise flags
Package flags is a package for helper functions related to bitwise flags
timestamp
Package timestamp is a package for making it easier to send timestamps in Discord messages
Package timestamp is a package for making it easier to send timestamps in Discord messages

Jump to

Keyboard shortcuts

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