diff -r 98d8850e0551 commands.go --- a/commands.go Thu Dec 13 15:05:57 2018 -0600 +++ b/commands.go Fri Dec 14 12:25:13 2018 -0700 @@ -3,27 +3,58 @@ import ( "strconv" "strings" + "github.com/bwmarrin/discordgo" ) //ParseForCommands parses input for Commands, returns message if no command specified, else return is empty func ParseForCommands(line string) string { - //One Key Commands - switch line { + if len(line) < 2 { + return line + } + switch line[:2] { case ":g": SelectGuild() - line = "" - case ":c": - SelectChannel() - line = "" + return "" case ":p": SelectPrivate() - line = "" - default: - // Nothing - } - - //Argument Commands - if strings.HasPrefix(line, ":m") { + return "" + case ":c": + opts := strings.Split(line, " ") + if len(opts) == 1 { + SelectChannel() + return "" + } + selectID := 0 + if opts[1] == "?" { + for _, channel := range State.Channels { + if channel.Type == 0 { + Msg(TextMsg, "[%d] %s\n", selectID, channel.Name) + selectID++ + } + } + return "" + } + selectMap := make(map[int]*discordgo.Channel) + for _, channel := range State.Channels { + if channel.Type == 0 { + selectMap[selectID] = channel + selectID++ + } + } + selection, err := strconv.Atoi(opts[1]) + if err != nil { + Msg(ErrorMsg, "[:c] Argument Error: %s\n", err) + return "" + } + if len(State.Channels) < selection || selection < 0 { + Msg(ErrorMsg, "[:c] Argument Error: Out of bounds\n") + return "" + } + channel := selectMap[selection] + State.SetChannel(channel.ID) + ShowContent() + return "" + case ":m": AmountStr := strings.Split(line, " ") if len(AmountStr) < 2 { Msg(ErrorMsg, "[:m] No Arguments \n") @@ -39,9 +70,8 @@ Msg(InfoMsg, "Printing last %d messages!\n", Amount) State.RetrieveMessages(Amount) PrintMessages(Amount) - line = "" - } - if strings.HasPrefix(line, ":u") { + return line + case ":u": session := State.Session user := session.User newName := strings.TrimPrefix(line, ":u ") @@ -49,9 +79,8 @@ if err != nil { Msg(ErrorMsg, "[:u] Argument Error: %s\n", err) } - line = "" - } - + return line + } return line } diff -r 98d8850e0551 helper.go --- a/helper.go Thu Dec 13 15:05:57 2018 -0600 +++ b/helper.go Fri Dec 14 12:25:13 2018 -0700 @@ -5,6 +5,7 @@ "fmt" "github.com/bwmarrin/discordgo" "io" + "io/ioutil" "log" "os" "os/exec" @@ -60,11 +61,16 @@ //PrintMessages prints amount of Messages to CLI func PrintMessages(Amount int) { for Key, m := range State.Messages { + name := m.Author.Username + if member, ok := State.Members[m.Author.Username]; ok { + if member.Nick != "" { + name = member.Nick + } + } if Key >= len(State.Messages)-Amount { Messages := ReceivingMessageParser(m) for _, Msg := range Messages { - //log.Printf("> %s > %s\n", UserName(m.Author.Username), Msg) - MessagePrint(string(m.Timestamp), m.Author.Username, Msg) + MessagePrint(string(m.Timestamp), name, Msg) } } @@ -94,7 +100,7 @@ switch runtime.GOOS { case "plan9": pr, pw := io.Pipe() - cmd := exec.Command("/bin/aux/statusmsg", "-k", *notifyFlag, Title) + cmd := exec.Command("/bin/aux/statusmsg", *notifyFlag, Title) cmd.Stdin = pr go func() { defer pw.Close() @@ -105,7 +111,7 @@ if err != nil { Msg(ErrorMsg, "%s\n", err) } - + ioutil.WriteFile("/dev/wctl", []byte("current"), 0644) default: cmd := exec.Command("notify-send", Title, m.ContentWithMentionsReplaced()) err := cmd.Start() diff -r 98d8850e0551 main.go --- a/main.go Thu Dec 13 15:05:57 2018 -0600 +++ b/main.go Fri Dec 14 12:25:13 2018 -0700 @@ -141,9 +141,8 @@ //ReplaceMentions replaces mentions to ID func ReplaceMentions(input string) string { // Check for guild members that match - channel := State.Guild.Members - for _, member := range channel { - if member.Nick == input[1:] { + for _, member := range State.Guild.Members { + if strings.HasPrefix(member.Nick, input[1:]) { return member.User.Mention() } if strings.HasPrefix(member.User.Username, input[1:]) { @@ -158,7 +157,6 @@ for _, channel := range userChannels { for _, recipient := range channel.Recipients { if strings.HasPrefix(input[1:], recipient.Username) { - fmt.Println("usermatch") return recipient.Mention() } }