refactor: cleanup

This commit is contained in:
ayntgl 2021-10-29 13:31:38 +04:00
parent 207a4d43bd
commit 78f75db905
2 changed files with 6 additions and 2 deletions

View file

@ -6,6 +6,7 @@ import (
"github.com/ayntgl/discordgo"
)
// ChannelToString constructs a string representation of the given channel. The string representation may vary for different channel types.
func ChannelToString(c *discordgo.Channel) string {
var repr string
if c.Name != "" {
@ -25,6 +26,7 @@ func ChannelToString(c *discordgo.Channel) string {
return repr
}
// ChannelIsUnread returns `true` if the given channel is marked as read by the client user, otherwise `false`.
func ChannelIsUnread(s *discordgo.State, c *discordgo.Channel) bool {
if c.LastMessageID == "" {
return false
@ -39,6 +41,7 @@ func ChannelIsUnread(s *discordgo.State, c *discordgo.Channel) bool {
return false
}
// FindMessageByID returns the index and the `*Message` struct of the current message if the given message ID *mID* is equal to the current message ID. If the given message ID *mID* is not found in the given slice *ms*, `-1` and `nil` are returned instead.
func FindMessageByID(ms []*discordgo.Message, mID string) (int, *discordgo.Message) {
for i, m := range ms {
if m.ID == mID {

View file

@ -2,8 +2,9 @@ package util
import "github.com/rivo/tview"
func GetTreeNodeByReference(tv *tview.TreeView, r interface{}) (mn *tview.TreeNode) {
tv.GetRoot().Walk(func(n, _ *tview.TreeNode) bool {
// GetTreeNodeByReference walks the root `*TreeNode` of the given `*TreeView` *treeView* and returns the TreeNode whose reference is equal to the given reference *r*. If the `*TreeNode` is not found, `nil` is returned instead.
func GetTreeNodeByReference(treeView *tview.TreeView, r interface{}) (mn *tview.TreeNode) {
treeView.GetRoot().Walk(func(n, _ *tview.TreeNode) bool {
if n.GetReference() == r {
mn = n
return false