utils

package
v1.6.3 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2024 License: MIT Imports: 4 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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

func ComesFromDM(s *discordgo.Session, m *discordgo.MessageCreate) (bool, error)

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

func GetChannelName(s *discordgo.Session, channelID string) (string, error)

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

func GetGuildName(s *discordgo.Session, guildID string) (string, error)

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

func IsUserBot(session *discordgo.Session, userID string) (bool, error)

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

func SendDirectMessage(session *discordgo.Session, userID string, message string) error

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

func SetupLogger() *slog.Logger

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.

Jump to

Keyboard shortcuts

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