discord

package
v0.10.5 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2022 License: MPL-2.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

View Source
const (
	RelayJoinsSay = 1 << iota
	RelayJoinsList

	RelayJoinsBoth = RelayJoinsSay | RelayJoinsList
)

RelayJoins

Variables

View Source
var (
	ErrSayBufferFull = errors.New("gw-discord: Say buffer full")
	ErrInvalidGuild  = errors.New("gw-discord: Invalid guild ID")
)

Errors

Functions

This section is empty.

Types

type Channel

type Channel struct {
	gateway.Common
	network.EventEmitter

	// Set once before Run(), read-only after that
	*ChannelConfig
	// contains filtered or unexported fields
}

Channel manages a Discord channel

func NewChannel added in v0.9.1

func NewChannel(s *discordgo.Session, conf *ChannelConfig) (*Channel, error)

NewChannel initializes a new Channel struct

func (*Channel) Ban added in v0.9.0

func (c *Channel) Ban(uid string) error

Ban user from channel

func (*Channel) Channel added in v0.9.0

func (c *Channel) Channel() *gateway.Channel

Channel residing in

func (*Channel) ChannelUsers added in v0.9.0

func (c *Channel) ChannelUsers() []gateway.User

ChannelUsers online

func (*Channel) FindTrigger added in v0.9.0

func (c *Channel) FindTrigger(s string) *gateway.Trigger

FindTrigger checks if s starts with trigger, return Trigger{} if true

func (*Channel) Kick added in v0.9.0

func (c *Channel) Kick(uid string) error

Kick user from channel

func (*Channel) Ping added in v0.9.0

func (c *Channel) Ping(uid string) (time.Duration, error)

Ping user to calculate RTT in milliseconds

func (*Channel) Relay

func (c *Channel) Relay(ev *network.Event, from gateway.Gateway) error

Relay dumps the event content in channel

func (*Channel) Run

func (c *Channel) Run(ctx context.Context) error

Run placeholder to implement Gateway interface

func (*Channel) Say

func (c *Channel) Say(s string) error

Say sends a chat message

func (*Channel) SayPrivate added in v0.9.0

func (c *Channel) SayPrivate(uid string, s string) error

SayPrivate sends a private chat message to uid

func (*Channel) SetUserAccess added in v0.9.0

func (c *Channel) SetUserAccess(uid string, a gateway.AccessLevel) (*gateway.AccessLevel, error)

SetUserAccess overrides accesslevel for a specific user

func (*Channel) Unban added in v0.9.0

func (c *Channel) Unban(uid string) error

Unban user from channel

func (*Channel) User added in v0.9.0

func (c *Channel) User(uid string) (*gateway.User, error)

User by ID

func (*Channel) Users added in v0.9.0

func (c *Channel) Users() map[string]gateway.AccessLevel

Users with non-default access level

func (*Channel) WebhookOrSay

func (c *Channel) WebhookOrSay(p *discordgo.WebhookParams) error

WebhookOrSay sends a chat message preferably via webhook

type ChannelConfig

type ChannelConfig struct {
	gateway.Config
	ChannelID      string
	Webhook        string
	OnlineListID   string
	BufSize        uint8
	RelayJoins     RelayJoinMode
	AccessMentions gateway.AccessLevel
	AccessTalk     gateway.AccessLevel
	AccessRole     map[string]gateway.AccessLevel
	AccessUser     map[string]gateway.AccessLevel
}

ChannelConfig stores the configuration of a single Discord channel

type Config

type Config struct {
	gateway.Config
	AuthToken  string
	Channels   map[string]*ChannelConfig
	Presence   string
	AccessDM   gateway.AccessLevel
	AccessUser map[string]gateway.AccessLevel
}

Config stores the configuration of a Discord session

type Gateway

type Gateway struct {
	gateway.Common
	network.EventEmitter
	*discordgo.Session

	// Set once before Run(), read-only after that
	*Config
	Channels map[string]*Channel
	// contains filtered or unexported fields
}

Gateway manages a Discord connection

func New

func New(conf *Config) (*Gateway, error)

New initializes a new Gateway struct

func (*Gateway) Ban added in v0.9.0

func (d *Gateway) Ban(uid string) error

Ban user from channel

func (*Gateway) Channel added in v0.9.0

func (d *Gateway) Channel() *gateway.Channel

Channel residing in

func (*Gateway) ChannelUsers added in v0.9.0

func (d *Gateway) ChannelUsers() []gateway.User

ChannelUsers online

func (*Gateway) InitDefaultHandlers

func (d *Gateway) InitDefaultHandlers()

InitDefaultHandlers adds the default callbacks for relevant packets

func (*Gateway) Kick added in v0.9.0

func (d *Gateway) Kick(uid string) error

Kick user from channel

func (*Gateway) Ping added in v0.9.0

func (d *Gateway) Ping(uid string) (time.Duration, error)

Ping user to calculate RTT in milliseconds

func (*Gateway) Relay

func (d *Gateway) Relay(ev *network.Event, from gateway.Gateway) error

Relay placeholder to implement Gateway interface Events should instead be relayed directly to a Channel

func (*Gateway) Run

func (d *Gateway) Run(ctx context.Context) error

Run reads packets and emits an event for each received packet

func (*Gateway) Say added in v0.9.0

func (d *Gateway) Say(s string) error

Say sends a chat message

func (*Gateway) SayPrivate added in v0.9.0

func (d *Gateway) SayPrivate(uid string, s string) error

SayPrivate sends a private chat message to uid

func (*Gateway) SetUserAccess added in v0.9.0

func (d *Gateway) SetUserAccess(uid string, a gateway.AccessLevel) (*gateway.AccessLevel, error)

SetUserAccess overrides accesslevel for a specific user

func (*Gateway) Unban added in v0.9.0

func (d *Gateway) Unban(uid string) error

Unban user from channel

func (*Gateway) User added in v0.9.0

func (d *Gateway) User(uid string) (*gateway.User, error)

User by ID

func (*Gateway) Users added in v0.9.0

func (d *Gateway) Users() map[string]gateway.AccessLevel

Users with non-default access level

type RelayJoinMode

type RelayJoinMode int32

RelayJoinMode enum

func (RelayJoinMode) MarshalText added in v0.9.0

func (r RelayJoinMode) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler

func (RelayJoinMode) String added in v0.9.0

func (r RelayJoinMode) String() string

func (*RelayJoinMode) UnmarshalText added in v0.9.0

func (r *RelayJoinMode) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler

Jump to

Keyboard shortcuts

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