Browse Source

Linting code

bugs/edit-cursor
Gregory Rudolph 5 years ago
parent
commit
2dd635669c
Signed by: rudi
GPG Key ID: EF64F3CBD1A1EBDD
  1. 20
      cmdEdit.go
  2. 2
      cmdHelp.go
  3. 12
      cmdReact.go
  4. 43
      main.go

20
cmdEdit.go

@ -11,7 +11,7 @@ import ( @@ -11,7 +11,7 @@ import (
func init() {
command := Command{
Cmd: []string{"edit", "e"},
Description: "$messageId - Edit a message (messageID is optional)",
Description: "$messageID - Edit a message (messageID is optional)",
Help: "",
Exec: cmdEdit,
}
@ -20,22 +20,22 @@ func init() { @@ -20,22 +20,22 @@ func init() {
}
func cmdEdit(cmd []string) {
var messageId int
var messageID int
chat := k.NewChat(channel)
if len(cmd) == 2 || len(cmd) == 1 {
if len(cmd) == 2 {
messageId, _ = strconv.Atoi(cmd[1])
messageID, _ = strconv.Atoi(cmd[1])
} else if lastMessage.ID != 0 {
if lastMessage.Type != "text" {
printToView("Feed", "Last message isn't editable (is it an edit?)")
return
}
messageId = lastMessage.ID
messageID = lastMessage.ID
} else {
printToView("Feed", "No message to edit")
return
}
origMessage, _ := chat.ReadMessage(messageId)
origMessage, _ := chat.ReadMessage(messageID)
if origMessage.Result.Messages[0].Msg.Content.Type != "text" {
printToView("Feed", fmt.Sprintf("%+v", origMessage))
return
@ -47,19 +47,19 @@ func cmdEdit(cmd []string) { @@ -47,19 +47,19 @@ func cmdEdit(cmd []string) {
editString := origMessage.Result.Messages[0].Msg.Content.Text.Body
clearView("Edit")
popupView("Edit")
printToView("Edit", fmt.Sprintf("/e %d %s", messageId, editString))
setViewTitle("Edit", fmt.Sprintf(" Editing message %d ", messageId))
printToView("Edit", fmt.Sprintf("/e %d %s", messageID, editString))
setViewTitle("Edit", fmt.Sprintf(" Editing message %d ", messageID))
return
}
if len(cmd) < 3 {
printToView("Feed", "Not enough options for Edit")
return
}
messageId, _ = strconv.Atoi(cmd[1])
messageID, _ = strconv.Atoi(cmd[1])
newMessage := strings.Join(cmd[2:], " ")
_, err := chat.Edit(messageId, newMessage)
_, err := chat.Edit(messageID, newMessage)
if err != nil {
printToView("Feed", fmt.Sprintf("Error editing message %d, %+v", messageId, err))
printToView("Feed", fmt.Sprintf("Error editing message %d, %+v", messageID, err))
}
}

2
cmdHelp.go

@ -28,7 +28,7 @@ func cmdHelp(cmd []string) { @@ -28,7 +28,7 @@ func cmdHelp(cmd []string) {
helpText = fmt.Sprintf("%s%s%s\t\t%s\n", helpText, cmdPrefix, c, commands[c].Description)
}
if len(typeCommands) > 0 {
for c, _ := range typeCommands {
for c := range typeCommands {
tCommands = append(tCommands, typeCommands[c].Name)
}
sort.Strings(tCommands)

12
cmdReact.go

@ -10,7 +10,7 @@ import ( @@ -10,7 +10,7 @@ import (
func init() {
command := Command{
Cmd: []string{"react", "r", "+"},
Description: "$messageId $reaction - React to a message (messageID is optional)",
Description: "$messageID $reaction - React to a message (messageID is optional)",
Help: "",
Exec: cmdReact,
}
@ -20,7 +20,7 @@ func init() { @@ -20,7 +20,7 @@ func init() {
func cmdReact(cmd []string) {
if len(cmd) > 2 {
reactToMessageId(cmd[1], strings.Join(cmd[2:], " "))
reactToMessageID(cmd[1], strings.Join(cmd[2:], " "))
} else if len(cmd) == 2 {
reactToMessage(cmd[1])
}
@ -30,13 +30,13 @@ func cmdReact(cmd []string) { @@ -30,13 +30,13 @@ func cmdReact(cmd []string) {
func reactToMessage(reaction string) {
doReact(lastMessage.ID, reaction)
}
func reactToMessageId(messageId string, reaction string) {
ID, _ := strconv.Atoi(messageId)
func reactToMessageID(messageID string, reaction string) {
ID, _ := strconv.Atoi(messageID)
doReact(ID, reaction)
}
func doReact(messageId int, reaction string) {
func doReact(messageID int, reaction string) {
chat := k.NewChat(channel)
_, err := chat.React(messageId, reaction)
_, err := chat.React(messageID, reaction)
if err != nil {
printToView("Feed", "There was an error reacting to the message.")
}

43
main.go

@ -114,9 +114,8 @@ func initKeybindings() error { @@ -114,9 +114,8 @@ func initKeybindings() error {
if input != "" {
clearView("Input")
return nil
} else {
return gocui.ErrQuit
}
return gocui.ErrQuit
}); err != nil {
return err
}
@ -168,9 +167,8 @@ func setViewTitle(viewName string, title string) { @@ -168,9 +167,8 @@ func setViewTitle(viewName string, title string) {
updatingView, err := g.View(viewName)
if err != nil {
return err
} else {
updatingView.Title = title
}
updatingView.Title = title
return nil
})
}
@ -180,9 +178,9 @@ func getViewTitle(viewName string) string { @@ -180,9 +178,9 @@ func getViewTitle(viewName string) string {
// in case there is active tab completion, filter that to just the view title and not the completion options.
printToView("Feed", fmt.Sprintf("Error getting view title: %s", err))
return ""
} else {
return strings.Split(view.Title, "||")[0]
}
return strings.Split(view.Title, "||")[0]
}
func popupView(viewName string) {
_, err := g.SetCurrentView(viewName)
@ -197,10 +195,10 @@ func popupView(viewName string) { @@ -197,10 +195,10 @@ func popupView(viewName string) {
updatingView, err := g.View(viewName)
if err != nil {
return err
} else {
viewX, viewY := updatingView.Size()
updatingView.MoveCursor(viewX, viewY, true)
}
viewX, viewY := updatingView.Size()
updatingView.MoveCursor(viewX, viewY, true)
return nil
})
@ -210,11 +208,11 @@ func clearView(viewName string) { @@ -210,11 +208,11 @@ func clearView(viewName string) {
inputView, err := g.View(viewName)
if err != nil {
return err
} else {
inputView.Clear()
inputView.SetCursor(0, 0)
inputView.SetOrigin(0, 0)
}
inputView.Clear()
inputView.SetCursor(0, 0)
inputView.SetOrigin(0, 0)
return nil
})
@ -224,11 +222,11 @@ func writeToView(viewName string, message string) { @@ -224,11 +222,11 @@ func writeToView(viewName string, message string) {
updatingView, err := g.View(viewName)
if err != nil {
return err
} else {
for _, c := range message {
updatingView.EditWrite(c)
}
}
for _, c := range message {
updatingView.EditWrite(c)
}
return nil
})
}
@ -237,9 +235,8 @@ func printToView(viewName string, message string) { @@ -237,9 +235,8 @@ func printToView(viewName string, message string) {
updatingView, err := g.View(viewName)
if err != nil {
return err
} else {
fmt.Fprintf(updatingView, "%s\n", message)
}
fmt.Fprintf(updatingView, "%s\n", message)
return nil
})
}
@ -275,11 +272,11 @@ func populateChat() { @@ -275,11 +272,11 @@ func populateChat() {
if err2 != nil {
printToView("Feed", fmt.Sprintf("%+v", err))
return
} else {
go populateChat()
go generateChannelTabCompletionSlice()
return
}
go populateChat()
go generateChannelTabCompletionSlice()
return
}
var printMe []string
var actuallyPrintMe string

Loading…
Cancel
Save