tranquility

package module
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2020 License: MIT Imports: 10 Imported by: 0

README

tranquility

Toolset for discord.go bots.

Documentation

Index

Constants

View Source
const VERSION = "0.6.2"

VERSION of tranquility, follows semantic versioning.

Variables

View Source
var ErrGuildIsUnavailable = errors.New("guild is unavailable")

ErrGuildIsUnavailable throws when a function is called on an unavailable guild

View Source
var ErrMemberNotFound = errors.New("member not found")

ErrMemberNotFound throws when a member isn't found

View Source
var ErrRoleNotFound = errors.New("role not found")

ErrRoleNotFound throws when a role is not found

View Source
var ErrTooManyRoles = errors.New("too many roles with one name")

ErrTooManyRoles throws when there are more than 1 role with the same name

Functions

This section is empty.

Types

type ChannelBasedPrompt added in v0.1.1

type ChannelBasedPrompt struct {
	ChannelID string

	// OutputChan is where messages can be received.
	// For sending reactions to this channel, use Send() instead.
	OutputChan  chan *discordgo.Message
	TimeoutChan <-chan time.Time
	// contains filtered or unexported fields
}

ChannelBasedPrompt is a channel-based prompt

func (*ChannelBasedPrompt) Dispose added in v0.1.1

func (c *ChannelBasedPrompt) Dispose()

Dispose disposes of the prompt gracefully

func (*ChannelBasedPrompt) Send added in v0.4.2

func (c *ChannelBasedPrompt) Send(m *discordgo.Message)

Send sends a message to the prompt

type ChannelBasedReactionPrompt added in v0.1.1

type ChannelBasedReactionPrompt struct {
	MessageID string

	// OutputChan is where reactions can be received.
	// For sending reactions to this channel, use Send() instead.
	OutputChan  chan *discordgo.MessageReaction
	TimeoutChan <-chan time.Time
	// contains filtered or unexported fields
}

ChannelBasedReactionPrompt is a channel-based reaction prompt

func (*ChannelBasedReactionPrompt) Dispose added in v0.1.1

func (c *ChannelBasedReactionPrompt) Dispose()

Dispose disposes of the prompt gracefully

func (*ChannelBasedReactionPrompt) Send added in v0.4.2

Send sends a reaction to the prompt

type ChannelBasedReactionTogglePrompt added in v0.1.1

type ChannelBasedReactionTogglePrompt struct {
	MessageID string

	// OutputChan is where reactions can be received.
	// For sending reactions to this channel, use Send() instead.
	OutputChan  chan *discordgo.MessageReaction
	TimeoutChan <-chan time.Time
	// contains filtered or unexported fields
}

ChannelBasedReactionTogglePrompt is a channel-based reaction toggle prompt

func (*ChannelBasedReactionTogglePrompt) Dispose added in v0.1.1

func (c *ChannelBasedReactionTogglePrompt) Dispose()

Dispose disposes of the prompt gracefully

func (*ChannelBasedReactionTogglePrompt) Send added in v0.4.2

Send sends a reaction to the prompt

type Command

type Command struct {
	// Names that can be used to get the command
	Names []string

	// Called when the bot first starts up.
	Init func(commands []*Command, commandsMap *map[string]*Command) error

	// Called when the bot has established a connection to Discord.
	Ready func(s *Session) error

	// Called when a user invokes this command.
	// This function assumes the length of args to be >= ArgCount, and as such
	// should only be called after checking len(*args).
	Run func(e *Event, m *discordgo.Message, args []string) *discordgo.MessageSend

	// Subcommands
	SubCmds []*Command

	// Minimum amount of arguments required
	ArgCount int

	// Argument names.
	// Only used for `help` command.
	// len(Args) must always >= ArgCount.
	Args []string

	Category int
	// Description of this command
	Desc string

	// Whether only the owner should be able to invoke this command
	Own bool
	// Whether this command is NSFW
	NSFW bool

	// Permission required for running the command
	Perms    []int
	BotPerms []int
}

Command represents a command

func (*Command) CheckExecution

func (command *Command) CheckExecution(e *Event, config Config, m *discordgo.Message, arguments []string) error

CheckExecution checks whether the command should be run in the specified environment

func (*Command) GetSubCmd

func (command *Command) GetSubCmd(name string) *Command

GetSubCmd gets a command's subcommand by name

type Config

type Config interface {
	GetOwnerID() string
	GetPrefix() string
	GetToken() string
}

Config holds configuration variables

type DMChannelCache added in v0.1.1

type DMChannelCache struct {
	// contains filtered or unexported fields
}

DMChannelCache represents a user cache

func NewDMChannelCache added in v0.1.1

func NewDMChannelCache(s *Session) *DMChannelCache

NewDMChannelCache returns a new UserCache instance

func (*DMChannelCache) CreateDMChannel added in v0.1.1

func (cc *DMChannelCache) CreateDMChannel(userID string) (string, error)

CreateDMChannel returns the DM channel ID of the user

type Database

type Database struct {
	*bolt.DB
	// contains filtered or unexported fields
}

Database is a Bolt database with utilities

func NewDatabase

func NewDatabase() *Database

NewDatabase creates a new database

func (*Database) AddBucket

func (db *Database) AddBucket(bucketName string) []byte

AddBucket adds a bucket

func (*Database) ListBuckets

func (db *Database) ListBuckets() [][]byte

ListBuckets returns a list of all buckets

func (*Database) Open

func (db *Database) Open(path string) (err error)

Open opens the database

type ErrInsufficientBotPermissions

type ErrInsufficientBotPermissions struct {
	ErrInsufficientPermissions
}

ErrInsufficientBotPermissions throws when the bot does not have sufficient permissions

func (*ErrInsufficientBotPermissions) Error

type ErrInsufficientPermissions

type ErrInsufficientPermissions struct{}

ErrInsufficientPermissions throws when the user does not have sufficient permissions

func (*ErrInsufficientPermissions) Error

type ErrMissingArgs

type ErrMissingArgs struct {
	Wanted int
	Got    int
	Usage  []string
}

ErrMissingArgs throws when not enough arguments are supplied

func (*ErrMissingArgs) Error

func (*ErrMissingArgs) Error() string

type ErrNeedsNSFWChannel

type ErrNeedsNSFWChannel struct{}

ErrNeedsNSFWChannel throws when a NSFW command is used inside a non-NSFW channel

func (*ErrNeedsNSFWChannel) Error

func (*ErrNeedsNSFWChannel) Error() string

type ErrNotOwner

type ErrNotOwner struct{}

ErrNotOwner throws when an owner-only command is used by a non-owner

func (*ErrNotOwner) Error

func (*ErrNotOwner) Error() string

type Event

type Event struct {
	// The discordgo session
	Session *Session
	// The prefix in the context of the message that ran the command
	Prefix string
	// The command name used to identify the command
	CommandName []string
}

Event represents an event sent to a command function

type PromptStatus

type PromptStatus int

PromptStatus represents the prompt's finish status

const (
	// Success means the prompt is successful
	Success PromptStatus = iota
	// Timeout means the prompt timed out
	Timeout
	// Fail means the prompt was overriden and you should cancel the command
	Fail
)

func (PromptStatus) IsSuccess

func (s PromptStatus) IsSuccess() bool

IsSuccess returns whether the prompt was successful

type Session

type Session struct {
	*discordgo.Session

	StartTime time.Time

	SelfMentions []string
	// contains filtered or unexported fields
}

Session is a discordgo session with utilities

func NewSession

func NewSession(args ...interface{}) (s *Session, err error)

NewSession returns a session

func (*Session) CheckChannelPermission

func (s *Session) CheckChannelPermission(userID string, channelID string, permission int) bool

CheckChannelPermission checks if a member has a permission in a channel

func (*Session) CheckMemberPermission

func (s *Session) CheckMemberPermission(userID string, guildID string, permission int) bool

CheckMemberPermission checks if a member has a permission

func (*Session) CreateDMChannelCached added in v0.1.1

func (s *Session) CreateDMChannelCached(userID string) (string, error)

CreateDMChannelCached fetches a DM channel by user ID, using a cache to reduce network traffic.

func (*Session) DownloadMembers added in v0.5.0

func (s *Session) DownloadMembers(guildID string, onReceivePage func(st []*discordgo.Member) (shouldStop bool)) error

DownloadMembers downloads all members from the guild

func (*Session) FetchChannel

func (s *Session) FetchChannel(id string) (*discordgo.Channel, error)

FetchChannel fetches a channel by ID

func (*Session) FetchEmoji

func (s *Session) FetchEmoji(emojiID string) (*discordgo.Emoji, bool)

FetchEmoji returns an emoji under the specified ID

func (*Session) FetchGuild

func (s *Session) FetchGuild(id string) (*discordgo.Guild, error)

FetchGuild gets a guild by ID

func (*Session) FetchGuildUser

func (s *Session) FetchGuildUser(guildID string, id string) (*discordgo.User, error)

FetchGuildUser fetches a user by ID in the specified guild's presences and falls back to FetchUser.

func (*Session) FetchGuildUserCached

func (s *Session) FetchGuildUserCached(guildID string, id string) (*discordgo.User, error)

FetchGuildUserCached fetches a user by ID in the specified guild's presences and falls back to FetchUser, using a cache to reduce network traffic.

func (*Session) FetchMember

func (s *Session) FetchMember(guildID string, id string) (*discordgo.Member, error)

FetchMember gets a guild member by ID

func (*Session) FetchRole

func (s *Session) FetchRole(guildID string, id string) (*discordgo.Role, error)

FetchRole gets a role by ID

func (*Session) FetchUser

func (s *Session) FetchUser(id string) (*discordgo.User, error)

FetchUser fetches a user by ID

func (*Session) GetMember

func (s *Session) GetMember(query string, guildID string) (*discordgo.Member, error)

GetMember gets a member by ID, mention, nickname or tag

func (*Session) GetMemberStrict

func (s *Session) GetMemberStrict(query string, guildID string) (*discordgo.Member, error)

GetMemberStrict gets a member by ID or mention

func (*Session) GetPrompt

func (s *Session) GetPrompt(userID string) (prompt *ChannelBasedPrompt, ok bool)

GetPrompt gets the prompt channel of the specified user ID

func (*Session) GetReactionPrompt added in v0.1.1

func (s *Session) GetReactionPrompt(userID string) (prompt *ChannelBasedReactionPrompt, ok bool)

GetReactionPrompt gets the prompt channel of the specified user ID

func (*Session) GetReactionTogglePrompt added in v0.1.1

func (s *Session) GetReactionTogglePrompt(userID string) (prompt *ChannelBasedReactionTogglePrompt, ok bool)

GetReactionTogglePrompt gets the prompt channel of the specified user ID

func (*Session) GetRole

func (s *Session) GetRole(query string, guild *discordgo.Guild, allowNames bool) (*discordgo.Role, error)

GetRole gets a role by ID allowNames allows also getting a role by name

func (*Session) GetRoles

func (s *Session) GetRoles(query string, guild *discordgo.Guild) ([]*discordgo.Role, error)

GetRoles gets a role by ID allowNames allows also getting roles by name

func (*Session) GuildRoleEditMentionable

func (s *Session) GuildRoleEditMentionable(guildID string, roleID string, mention bool) (st *discordgo.Role, err error)

GuildRoleEditMentionable updates whether an existing Guild Role is mentionable

func (*Session) Open

func (s *Session) Open() (err error)

Open opens the discordgo session and initialises self

func (*Session) Prompt

func (s *Session) Prompt(timeout time.Duration, userID string, channelID string) (PromptStatus, *discordgo.Message)

Prompt prompts the user. The returned Message is nil unless the returned status is Success.

func (*Session) PromptChannel added in v0.1.1

func (s *Session) PromptChannel(timeout time.Duration, userID string, channelID string) *ChannelBasedPrompt

PromptChannel creates a channel-based prompt

func (*Session) PromptReaction added in v0.1.1

func (s *Session) PromptReaction(timeout time.Duration, userID string, messageID string) (PromptStatus, *discordgo.MessageReaction)

PromptReaction prompts the user's reaction. The returned MessageReaction is nil unless the returned status is Success.

func (*Session) PromptReactionChannel added in v0.1.1

func (s *Session) PromptReactionChannel(timeout time.Duration, userID string, messageID string) *ChannelBasedReactionPrompt

PromptReactionChannel creates a channel-based reaction prompt

func (*Session) PromptReactionToggle added in v0.1.1

func (s *Session) PromptReactionToggle(timeout time.Duration, userID string, messageID string) (PromptStatus, *discordgo.MessageReaction)

PromptReactionToggle prompts the user's reaction toggle. The returned MessageReaction is nil unless the returned status is Success.

func (*Session) PromptReactionToggleChannel added in v0.1.1

func (s *Session) PromptReactionToggleChannel(timeout time.Duration, userID string, messageID string) *ChannelBasedReactionTogglePrompt

PromptReactionToggleChannel creates a channel-based reaction toggle prompt

type UserCache

type UserCache struct {
	// contains filtered or unexported fields
}

UserCache represents a user cache

func NewUserCache

func NewUserCache(s *Session) *UserCache

NewUserCache returns a new UserCache instance

func (*UserCache) FetchGuildUser

func (uc *UserCache) FetchGuildUser(guildID string, id string) (*discordgo.User, error)

FetchGuildUser fetches a guild user by ID

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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