discordutil

package
v0.0.0-...-17efaa7 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2021 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AcknowledgeChannel

func AcknowledgeChannel(session *discordgo.Session, channelID string) error

AcknowledgeChannel acknowledges all messages in the given channel. If the channel is a category, all children will be acknowledged.

func CompareChannels

func CompareChannels(a, b *discordgo.Channel) bool

CompareChannels checks which channel is smaller. Smaller meaning it is the one with the more recent message.

func FindDMChannelWithUser

func FindDMChannelWithUser(state *discordgo.State, userID string) *discordgo.Channel

FindDMChannelWithUser tries to find a DM channel with the specified user as one of its two recipients. If no channel is found, nil is returned.

func FindEmojiInGuild

func FindEmojiInGuild(session *discordgo.Session, guild *discordgo.Guild, omitGWCheck bool, emojiSequence string) string

FindEmojiInGuild searches for a fitting emoji. Fitting means the correct name (case insensitive), not animated and the correct permissions. If the result is an empty string, it means no result was found.

func GenerateQuote

func GenerateQuote(message, author string, time discordgo.Timestamp, attachments []*discordgo.MessageAttachment, messageAfterQuote string) (string, error)

GenerateQuote formats a message quote using the given Input. The `messageAfterQuote` will be appended after the quote in case it is not empty.

func GetMemberColor

func GetMemberColor(state *discordgo.State, member *discordgo.Member) string

GetMemberColor gets the members color according the members role. If role colors aren't enabled, or the member is a bot, we fallthrough to GetUserColor.

func GetMemberName

func GetMemberName(member *discordgo.Member) string

GetMemberName returns the name to use for representing this user. This is either the username or the nickname. In case the member is a bot, the bot prefix will be prepended.

func GetPrivateChannelName

func GetPrivateChannelName(channel *discordgo.Channel) string

GetPrivateChannelName generates a name for a private channel.

func GetPrivateChannelNameUnescaped

func GetPrivateChannelNameUnescaped(channel *discordgo.Channel) string

GetPrivateChannelNameUnescaped generates a name for a private channel. The name won't be escaped view tviewutil and therefore shouldn't be used for displaying it in tview components.

func GetRoleColor

func GetRoleColor(role *discordgo.Role) string

GetRoleColor returns the roles color in the format #RRGGBB or an empty string if there's no color.

func GetUserColor

func GetUserColor(user *discordgo.User) string

GetUserColor gers a user color according to the configuration. If "random" is the setting, then a new random color is retrieved and cached for this session and this user.

func GetUserName

func GetUserName(user *discordgo.User) string

GetUserName returns the users username, prepending the bot prefix in case he is a bot.

func HandleReactionAdd

func HandleReactionAdd(state *discordgo.State,
	message *discordgo.Message,
	newReaction *discordgo.MessageReactionAdd)

HandleReactionAdd adds a new reaction to a message or updates the count if that message already has a reaction with that same emoji.

func HandleReactionRemove

func HandleReactionRemove(state *discordgo.State,
	message *discordgo.Message,
	newReaction *discordgo.MessageReactionRemove)

HandleReactionRemove removes an existing reaction to a message or updates the count if the same message still has reactions with the same emoji left.

func HandleReactionRemoveAll

func HandleReactionRemoveAll(state *discordgo.State,
	message *discordgo.Message)

HandleReactionRemoveAll removes all reactions from all users in a message.

func HasReadMessagesPermission

func HasReadMessagesPermission(channelID string, state *discordgo.State) bool

HasReadMessagesPermission checks if the user has permission to view a specific channel.

func IsBlocked

func IsBlocked(state *discordgo.State, user *discordgo.User) bool

IsBlocked checks whether the state contains any relationship that says the given user has been blocked.

func LoadGuilds

func LoadGuilds(guildLoader GuildLoader) ([]*discordgo.UserGuild, error)

LoadGuilds loads all guilds the current user is part of.

func MentionsCurrentUserExplicitly

func MentionsCurrentUserExplicitly(state *discordgo.State, message *discordgo.Message) bool

MentionsCurrentUserExplicitly checks whether the message contains any explicit mentions for the user associated with the currently logged in user.

func MessageToPlainText

func MessageToPlainText(message *discordgo.Message) string

MessageToPlainText converts a discord message to a human readable text. Markdown characters are reserved and file attachments are added as URLs. Embeds are currently not being handled, nor are other special elements.

func ReplaceMentions

func ReplaceMentions(message *discordgo.Message) string

ReplaceMentions replaces both user mentions and global mentions like @here and @everyone.

func ResolveFilePathAndSendFile

func ResolveFilePathAndSendFile(session *discordgo.Session, message, targetChannelID string) error

ResolveFilePathAndSendFile will attempt to resolve the message and see if it points to a file on the users harddrive. If so, it's sent to the given channel using it's basename as the discord filename.

func SendMessageAsFile

func SendMessageAsFile(session *discordgo.Session, message string, channel string, onFailure func(error))

SendMessageAsFile sends the given message into the given channel using the passed discord Session. If an error occurs, onFailure gets called.

func SortGuilds

func SortGuilds(settings *discordgo.Settings, guilds []*discordgo.Guild)

SortGuilds sorts the guilds according to the users settings.

func SortMessagesByTimestamp

func SortMessagesByTimestamp(messages []*discordgo.Message)

SortMessagesByTimestamp sorts all messages in the given array according to their creation date.

func SortPrivateChannels

func SortPrivateChannels(channels []*discordgo.Channel)

SortPrivateChannels sorts private channels depending on their last message.

func SortUserRoles

func SortUserRoles(roles []string, guildRoles []*discordgo.Role)

SortUserRoles sorts an array of roleIDs according to the guilds roles.

Types

type GuildLoader

type GuildLoader interface {
	UserGuilds(int, string, string) ([]*discordgo.UserGuild, error)
}

GuildLoader reflects an instance that allows loading guilds from a discord backend.

type MessageDataSupplier

type MessageDataSupplier interface {
	// ChannelMessages fetches up to 100 messages for a channel.
	// The parameter beforeID defines whether message only older than
	// a specific message should be returned. The parameter afterID does
	// the same but for newer messages. The parameter aroundID is a mix of
	// both.
	ChannelMessages(channelID string, limit int, beforeID string, afterID string, aroundID string) ([]*discordgo.Message, error)
}

MessageDataSupplier defines the method that is necessary for requesting channels. This is satisfied by the discordgo.Session struct and can be used in order to make testing easier.

type MessageLoader

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

MessageLoader represents a util object that remember which channels have already been cached and which not.

func CreateMessageLoader

func CreateMessageLoader(messageDataSupplier MessageDataSupplier) *MessageLoader

CreateMessageLoader creates a MessageLoader using the given MessageDataSupplier. It is empty and can be used right away.

func (*MessageLoader) DeleteFromCache

func (l *MessageLoader) DeleteFromCache(channelID string)

DeleteFromCache deletes the entry that indicates the channel has been cached. The next call to LoadMessages with the same ID will ask for data from the MessageDataSupplier.

func (*MessageLoader) IsCached

func (l *MessageLoader) IsCached(channelID string) bool

IsCached checks whether the channel has already been requested from the backend once.

func (*MessageLoader) LoadMessages

func (l *MessageLoader) LoadMessages(channel *discordgo.Channel) ([]*discordgo.Message, error)

LoadMessages returns the last 100 messages for a channel. If less messages were sent, less will be returned. As soon as a channel has been loaded once it won't ever be loaded again, instead a global cache will be accessed.

Jump to

Keyboard shortcuts

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