Skip to content
This repository has been archived by the owner on Jul 24, 2020. It is now read-only.

Commit

Permalink
This finally fixes #6
Browse files Browse the repository at this point in the history
  • Loading branch information
Rivalo committed Mar 3, 2016
1 parent 114ed8b commit 2fabb88
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
25 changes: 25 additions & 0 deletions commands.go
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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
Expand Down
12 changes: 7 additions & 5 deletions helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
}

0 comments on commit 2fabb88

Please sign in to comment.