Documentation
¶
Overview ¶
Package utils provides utility functions to assist with tasks common in the commandler package, especially those involving interactions with the Discord API.
Package utils provides utility functions and configurations used by the commandler package, particularly for logging and other common tasks.
Index ¶
- Variables
- func ComesFromDM(s *discordgo.Session, m *discordgo.MessageCreate) (bool, error)
- func GetChannelName(s *discordgo.Session, channelID string) (string, error)
- func GetGuildName(s *discordgo.Session, guildID string) (string, error)
- func IsUserBot(session *discordgo.Session, userID string) (bool, error)
- func SendDirectMessage(session *discordgo.Session, userID string, message string) error
- func SetupLogger() *slog.Logger
Constants ¶
This section is empty.
Variables ¶
var Logger = SetupLogger()
Logger is a global slog.Logger instance used for logging throughout the commandler package. It is initialized with a handler that outputs logs in a structured text format.
Functions ¶
func ComesFromDM ¶
ComesFromDM checks if a message was sent from a direct message channel. It returns true if the message originates from a DM, or false and an error if the channel details could not be confirmed.
func GetChannelName ¶
GetChannelName retrieves the name of a channel from its ID, utilizing cached data if available. It returns the channel name or an empty string and an error if the channel details could not be retrieved.
func GetGuildName ¶
GetGuildName retrieves the name of a guild from its ID, using cached data if available. It returns the guild name or an empty string and an error if the guild details could not be retrieved.
func IsUserBot ¶
IsUserBot checks whether the user identified by userID is a bot. It returns true if the user is a bot, or false along with an error if the user information could not be retrieved.
func SendDirectMessage ¶
SendDirectMessage sends a message to the direct message channel of the specified user. It first checks whether the user is a bot, to avoid unnecessary messages to bots.
func SetupLogger ¶
SetupLogger configures and returns a new slog.Logger configured for structured logging. The logger outputs key=value pairs in text format to the standard error stream.
Types ¶
This section is empty.