ningen

package module
v2.0.0-...-9d96e6b Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2021 License: ISC Imports: 13 Imported by: 19

README

ningen

ningen provides abstractions that override Arikawa's existing state to provide behaviors more similar to the official client with more aggressive caching.

Usage

Using ningen is similar to using *state.State, but you'd be handling around *ningen.State instead. Typically, it might look like this:

s, err := state.New(os.Getenv("TOKEN"))
if err != nil {
	return errors.Wrap(err, "failed to create state")
}

n, err := ningen.FromState(s)
if err != nil {
	return errors.Wrap(err, "failed to wrap state")
}

if err := n.Open(); err != nil {
	return errors.Wrap(err, "failed to open connection to Discord")
}

return startApp(n)

Afterwards, *ningen.State can be used as if it is *state.State. The new state will transparently behave more similarly to the official client.

Extras

In addition to wrapping, *ningen.State also adds a few more stores that the client can use:

  • n.NoteState keeps track of known user notes, which can be seen on the client by clicking the profile picture of a user.
  • n.ReadState allows seeing which channels are not read as well as allowing the client to asynchronously mark a channel as read.
  • n.MutedState keeps track of which channels, categories and guilds are muted.
  • n.EmojiState keeps track of the user's emojis; it returns the appropriate guild emojis depending on whether or not the user has Nitro.
  • n.MemberState provides a way to lazily fetch the right-hand side member list seen in the official client. It also provides an asynchronous guild subscription API for listening to typing events.
    • Sometimes, in large guilds, messages may not be received from the gateway. This might mean that a guild subscription is required.
  • n.RelationshipState keeps track of which users are blocked or are friends.

For detailed documentation of each state, see the reference documentation.

Markdown

ningen also provides a built-in Discord Markdown parser using goldmark. For an example on how to implement a custom Markdown renderer that is compatible with ningen, see md/renderer.go.

Documentation

Overview

Package ningen contains a set of helpful functions and packages to aid in making a Discord client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Connected

type Connected struct {
	Event gateway.Event
}

Connected is an event that's sent on Ready or Resumed. The event arrives before all ningen's handlers are called.

type State

type State struct {
	*state.State
	*handler.Handler

	// PreHandler is the handler that is given to states; it is always
	// synchronous.
	PreHandler *handler.Handler

	// Custom Cabinet values.
	MemberStore   *nstore.MemberStore
	PresenceStore *nstore.PresenceStore

	// Custom State values.
	NoteState         *note.State
	ReadState         *read.State
	MutedState        *mute.State
	EmojiState        *emoji.State
	MemberState       *member.State
	RelationshipState *relationship.State
	// contains filtered or unexported fields
}

func FromState

func FromState(s *state.State) (*State, error)

FromState wraps a normal state.

func (*State) MessageMentions

func (s *State) MessageMentions(msg discord.Message) bool

MessageMentions returns true if the given message mentions the current user.

func (*State) Offline

func (s *State) Offline() *State

Offline returns an offline version of the state.

func (*State) Online

func (s *State) Online() *State

Online returns an online state. If the state is already online, then it returns itself.

func (*State) Open

func (s *State) Open() error

func (*State) PrivateChannels

func (s *State) PrivateChannels() ([]discord.Channel, error)

PrivateChannels returns the sorted list of private channels from the state.

func (*State) WithContext

func (s *State) WithContext(ctx context.Context) *State

WithContext returns State with the given context.

Directories

Path Synopsis
states
mute
Package mute implements a channel/guild muted state.
Package mute implements a channel/guild muted state.
read
Package read implements a read state with an event handler API.
Package read implements a read state with an event handler API.

Jump to

Keyboard shortcuts

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