common

package
v2.0.0-...-e570596 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2023 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ColourPurple = 0x9b59b6
	ColourGreen  = 0x2ecc71
	ColourRed    = 0xe74c3c
	ColourOrange = 0xe67e22
	ColourBlue   = 0x3498db
	ColourGold   = 0xf1c40f
)
View Source
const (
	PermissionViewServerInsights = 1 << 19
	PermissionModerateMembers    = 1 << 40
)

Permission constants that Arikawa is missing

Variables

View Source
var (
	MajorPerms = []Perm{
		{discord.PermissionAdministrator, "Administrator"},
		{discord.PermissionManageGuild, "Manage Server"},
		{discord.PermissionManageWebhooks, "Manage Webhooks"},
		{discord.PermissionManageChannels, "Manage Channels"},

		{discord.PermissionBanMembers, "Ban Members"},
		{discord.PermissionKickMembers, "Kick Members"},

		{discord.PermissionManageRoles, "Manage Roles"},
		{discord.PermissionManageNicknames, "Manage Nicknames"},
		{discord.PermissionManageEmojisAndStickers, "Manage Emojis and Stickers"},
		{discord.PermissionManageThreads, "Manage Threads"},
		{discord.PermissionManageMessages, "Manage Messages"},
		{PermissionModerateMembers, "Moderate Members"},

		{discord.PermissionMentionEveryone, "Mention Everyone"},

		{discord.PermissionModerateMembers, "Timeout Members"},
		{discord.PermissionMuteMembers, "Voice Mute Members"},
		{discord.PermissionDeafenMembers, "Voice Deafen Members"},
		{discord.PermissionMoveMembers, "Voice Move Members"},
	}

	NotablePerms = []Perm{
		{discord.PermissionViewAuditLog, "View Audit Log"},
		{PermissionViewServerInsights, "View Server Insights"},

		{discord.PermissionPrioritySpeaker, "Priority Speaker"},
		{discord.PermissionSendTTSMessages, "Send TTS Messages"},

		{discord.PermissionCreateInstantInvite, "Create Invite"},
		{discord.PermissionCreatePublicThreads, "Create Public Threads"},
		{discord.PermissionCreatePrivateThreads, "Create Private Threads"},
	}

	MinorPerms = []Perm{
		{discord.PermissionStream, "Video"},
		{discord.PermissionUseVAD, "Use Voice Activity"},
		{discord.PermissionSpeak, "Speak"},
		{discord.PermissionConnect, "Connect"},
		{discord.PermissionRequestToSpeak, "Request to Speak"},

		{discord.PermissionAttachFiles, "Attach Files"},
		{discord.PermissionEmbedLinks, "Embed Links"},
		{discord.PermissionStartEmbeddedActivities, "Start Embedded Activities"},

		{discord.PermissionAddReactions, "Add Reactions"},
		{discord.PermissionSendMessages, "Send Messages"},
		{discord.PermissionSendMessagesInThreads, "Send Messages in Threads"},

		{discord.PermissionReadMessageHistory, "Read Message History"},
		{discord.PermissionViewChannel, "View Channel"},

		{discord.PermissionUseSlashCommands, "Use Slash Commands"},

		{discord.PermissionChangeNickname, "Change Nickname"},
		{discord.PermissionUseExternalEmojis, "Use External Emojis"},
	}

	AllPerms = append(MajorPerms, append(NotablePerms, MinorPerms...)...)
)

All permissions

View Source
var Commands = []api.CreateCommandData{
	{
		Name:        "catalogger",
		Description: "Meta commands",
		Options: discord.CommandOptions{
			&discord.SubcommandOption{
				OptionName:  "help",
				Description: "Show help!",
			},
			&discord.SubcommandOption{
				OptionName:  "invite",
				Description: "Get an invite for Catalogger",
			},
			&discord.SubcommandOption{
				OptionName:  "dashboard",
				Description: "Get a link to the Catalogger dashboard",
			},
		},
	},
	{
		Name:                     "config",
		Description:              "Configure Catalogger",
		DefaultMemberPermissions: discord.NewPermissions(discord.PermissionManageGuild),
		Options: discord.CommandOptions{
			&discord.SubcommandOption{
				OptionName:  "channels",
				Description: "Configure logging channels",
			},
		},
	},
}

Functions

func Contains

func Contains[T comparable](slice []T, v T) bool

Contains returns whether `v` is in `slice`.

func IsThread

func IsThread(ch discord.Channel) bool

func PermStrings

func PermStrings(p discord.Permissions) []string

PermStrings gives permission strings for all Discord permissions

func PermStringsFor

func PermStringsFor(m []Perm, p discord.Permissions) []string

PermStringsFor gives permission strings for the given Perm slice

func Version

func Version() string

Version returns the version

func WaitFor

func WaitFor[T any](ctx context.Context, s StateWaiter, filter func(t T) bool) (t T, ok bool)

WaitFor is a wrapper around s.WaitFor that checks for a specific type and accepts a filter function based on that, avoiding type casting in the filter function.

Types

type Map

type Map[K comparable, V any] struct {
	// contains filtered or unexported fields
}

Map is a concurrent map. It wraps the standard library's map with a mutex for concurrent access.

func NewMap

func NewMap[K comparable, V any]() *Map[K, V]

NewMap returns a new Map.

func (*Map[K, V]) Exists

func (m *Map[K, V]) Exists(k K) (exists bool)

Exists returns true if key exists in the map, false otherwise.

func (*Map[K, V]) Get

func (m *Map[K, V]) Get(k K) (v V, ok bool)

Get gets the value at key k, or the zero value if not set.

func (*Map[K, V]) Length

func (m *Map[K, V]) Length() int

Length returns the size of m.

func (*Map[K, V]) ReadFunc

func (m *Map[K, V]) ReadFunc(fn func(map[K]V))

ReadFunc runs fn with the mutex locked for reading. The raw map is passed to fn.

func (*Map[K, V]) Remove

func (m *Map[K, V]) Remove(k K) (exists bool)

Remove removes a key from the map. It returns true if the key existed in the map, false otherwise.

func (*Map[K, V]) Set

func (m *Map[K, V]) Set(k K, v V)

Set sets the key k to the value v.

func (*Map[K, V]) Values

func (m *Map[K, V]) Values() []V

Values returns all values in m. The returned slice is unordered.

func (*Map[K, V]) WriteFunc

func (m *Map[K, V]) WriteFunc(fn func(map[K]V))

WriteFunc runs fn with the mutex locked for writing. The raw map is passed to fn.

type Perm

type Perm struct {
	Permission discord.Permissions
	Name       string
}

Perm is a single permission

type Set

type Set[T comparable] struct {
	// contains filtered or unexported fields
}

Set is a concurrent set. It is not ordered.

func NewSet

func NewSet[T comparable](initial ...T) *Set[T]

NewSet returns a new Set.

func (*Set[T]) Add

func (s *Set[T]) Add(v T) bool

Add adds a value to the set. It returns true if the value doesn't already exist, false otherwise.

func (*Set[T]) Append

func (s *Set[T]) Append(values ...T)

Append adds a slice of values to the set.

func (*Set[T]) Exists

func (s *Set[T]) Exists(v T) (exists bool)

Exists returns true if v exists in the set, false otherwise.

func (*Set[T]) Length

func (s *Set[T]) Length() int

Length returns the length of the set.

func (*Set[T]) Remove

func (s *Set[T]) Remove(v T) (exists bool)

Remove removes a value from the set. It returns true if the value existed in the set, false otherwise.

func (*Set[T]) Values

func (s *Set[T]) Values() []T

Values returns all values in the set. The return slice is unordered.

type StateWaiter

type StateWaiter interface {
	WaitFor(context.Context, func(any) bool) any
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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