瀏覽代碼

refactor: cleanup

ayntgl 4 年之前
父節點
當前提交
78f75db905
共有 2 個文件被更改,包括 6 次插入2 次删除
  1. 3 0
      util/discord.go
  2. 3 2
      util/ui.go

+ 3 - 0
util/discord.go

@@ -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 {

+ 3 - 2
util/ui.go

@@ -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