gtkcord

package
v0.0.24 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: GPL-3.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeaderHeight      = 42
	HeaderPadding     = 16
	GuildIconSize     = 48
	ChannelIconSize   = 32
	MessageAvatarSize = 42
	EmbedMaxWidth     = 250
	EmbedImgHeight    = 300
	InlineEmojiSize   = 22
	LargeEmojiSize    = 48
	StickerSize       = 92
	UserBarAvatarSize = 32
)

Constants for dimensions.

Variables

AllowedChannelTypes are the channel types that are shown.

View Source
var EmojiAttrs = textutil.Attrs(
	pango.NewAttrSize(32 * pango.SCALE),
)
View Source
var SnowflakeVariant = glib.NewVariantType("x")

SnowflakeVariant is the variant type for a discord.Snowflake.

Functions

func ChannelName

func ChannelName(ch *discord.Channel) string

ChannelName returns the channel's name in plain text.

func ChannelNameFromID

func ChannelNameFromID(ctx context.Context, id discord.ChannelID) string

ChannelNameFromID returns the channel's name in plain text from the channel with the given ID.

func EmojiURL

func EmojiURL(emojiID string, gif bool) string

EmojiURL returns a sized emoji URL.

func InjectAvatarSize

func InjectAvatarSize(urlstr string) string

InjectAvatarSize calls InjectSize with size being 64px.

func InjectSize

func InjectSize(urlstr string, size int) string

InjectSize injects the size query parameter into the URL. Size is automatically scaled up to 2x or more.

func InjectSizeUnscaled

func InjectSizeUnscaled(urlstr string, size int) string

InjectSizeUnscaled is like InjectSize, except the size is not scaled according to the scale factor.

func InjectState

func InjectState(ctx context.Context, state *State) context.Context

InjectState injects the given state to a new context.

func NewChannelIDVariant

func NewChannelIDVariant(id discord.ChannelID) *glib.Variant

NewChannelIDVariant creates a new ChannelID variant.

func NewGuildIDVariant

func NewGuildIDVariant(id discord.GuildID) *glib.Variant

NewGuildIDVariant creates a new GuildID variant.

func NewMessageIDVariant

func NewMessageIDVariant(id discord.MessageID) *glib.Variant

NewMessageIDVariant creates a new MessageID variant.

func NewSnowflakeVariant

func NewSnowflakeVariant(snowflake discord.Snowflake) *glib.Variant

NewSnowflakeVariant creates a new Snowflake variant.

func RecipientNames

func RecipientNames(ch *discord.Channel) string

RecipientNames formats the string for the list of recipients inside the given channel.

func SanitizeEmoji

func SanitizeEmoji(emoji string) string

SanitizeEmoji checks if provided emoji doesn't contain extraneous variation selector codepoint NOTE: This sanitizer covers ~70% of emojis

func WindowTitleFromID

func WindowTitleFromID(ctx context.Context, id discord.ChannelID) string

WindowTitleFromID returns the window title from the channel with the given ID.

Types

type MainThreadHandler

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

MainThreadHandler wraps a handler.Handler to run all events on the main thread.

func NewMainThreadHandler

func NewMainThreadHandler(h *handler.Handler) *MainThreadHandler

NewMainThreadHandler creates a new MainThreadHandler.

func (*MainThreadHandler) AddHandler

func (m *MainThreadHandler) AddHandler(handler any) func()

AddHandler adds a handler to the handler.Handler. The given handler will be called on the main thread. The returned function will remove the handler.

func (*MainThreadHandler) AddSyncHandler

func (m *MainThreadHandler) AddSyncHandler(handler any) func()

AddSyncHandler is the same as [AddHandler]. It exists for compatibility.

type State

type State struct {
	*MainThreadHandler
	*ningen.State
}

State extends the Discord state controller.

func FromContext

func FromContext(ctx context.Context) *State

FromContext gets the Discord state controller from the given context.

func Wrap

func Wrap(state *state.State) *State

Wrap wraps the given state.

func (*State) AddHandler

func (s *State) AddHandler(fns ...any) func()

AddHandler adds a handler to the state. The handler is removed when the returned function is called.

func (*State) AddHandlerForWidget

func (s *State) AddHandlerForWidget(w gtk.Widgetter, fns ...any) func()

AddHandlerForWidget replaces BindWidget and provides a way to bind a handler that only receives events as long as the widget is mapped. As soon as the widget is unmapped, the handler is unbound.

func (*State) AuthorMarkup

func (s *State) AuthorMarkup(m *gateway.MessageCreateEvent, mods ...author.MarkupMod) string

AuthorMarkup renders the markup for the message author's name. It makes no API calls.

func (*State) BindHandler

func (s *State) BindHandler(ctx gtkutil.Cancellable, fn func(gateway.Event), filters ...gateway.Event)

BindHandler is similar to BindWidgetHandler, except the lifetime of the handler is bound to the context.

func (*State) BindWidget

func (s *State) BindWidget(w gtk.Widgetter, fn func(gateway.Event), filters ...gateway.Event)

BindWidget is similar to BindHandler, except it doesn't rely on contexts.

func (*State) MemberMarkup

func (s *State) MemberMarkup(gID discord.GuildID, u *discord.GuildUser, mods ...author.MarkupMod) string

MemberMarkup is like AuthorMarkup but for any member inside a guild.

func (*State) MessagePreview

func (s *State) MessagePreview(msg *discord.Message) string

MessagePreview renders the message into a short content string.

func (*State) Offline

func (s *State) Offline() *State

Offline creates a copy of State with a new offline state.

func (*State) Online

func (s *State) Online() *State

Online creates a copy of State with a new online state.

func (*State) UserIDMarkup

func (s *State) UserIDMarkup(chID discord.ChannelID, uID discord.UserID, mods ...author.MarkupMod) string

UserIDMarkup gets the User markup from just the channel and user IDs.

func (*State) UserMarkup

func (s *State) UserMarkup(gID discord.GuildID, u *discord.User, mods ...author.MarkupMod) string

UserMarkup is like AuthorMarkup but for any user optionally inside a guild.

func (*State) WithContext

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

WithContext creates a copy of State with a new context.

Jump to

Keyboard shortcuts

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