diff --git a/commands.go b/commands.go index 4d08d23..b496007 100644 --- a/commands.go +++ b/commands.go @@ -1,7 +1,13 @@ package main +import ( + "strconv" + "strings" +) + //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 { case ":g": SelectGuild() @@ -11,7 +17,26 @@ func ParseForCommands(line string) string { line = "" default: // Nothing + } + + //Argument Commands + if strings.HasPrefix(line, ":m") { + AmountStr := strings.Split(line, " ") + if len(AmountStr) < 2 { + Msg(ErrorMsg, "[:m] No Arguments \n") + return "" + } + Amount, err := strconv.Atoi(AmountStr[1]) + if err != nil { + Msg(ErrorMsg, "[:m] Argument Error: %s \n", err) + return "" + } + + Msg(InfoMsg, "Printing last %d messages!\n", Amount) + State.RetrieveMessages(Amount) + PrintMessages(Amount) + line = "" } return line diff --git a/helper.go b/helper.go index 36b04f2..1351c12 100644 --- a/helper.go +++ b/helper.go @@ -69,11 +69,13 @@ func ReceivingMessageParser(m *discordgo.Message) []string { //PrintMessages prints amount of Messages to CLI func PrintMessages(Amount int) { UserName := color.New(color.FgGreen).SprintFunc() - for _, m := range State.Messages { - Messages := ReceivingMessageParser(m) - - for _, Msg := range Messages { - log.Printf("> %s > %s\n", UserName(m.Author.Username), Msg) + for Key, m := range State.Messages { + if Key >= len(State.Messages)-Amount { + Messages := ReceivingMessageParser(m) + + for _, Msg := range Messages { + log.Printf("> %s > %s\n", UserName(m.Author.Username), Msg) + } } } }