diff --git a/plugins/sed/sed.go b/plugins/sed/sed.go index 29a38ab..72094af 100644 --- a/plugins/sed/sed.go +++ b/plugins/sed/sed.go @@ -1,6 +1,7 @@ package sed import ( + "strconv" "strings" "github.com/godwhoa/oodle/oodle" @@ -17,8 +18,8 @@ func SedHelp() oodle.Command { return oodle.Command{ Prefix: ".", Name: "sed", - Description: "Simple sed-like find and replace. Since it is simple you can't replace '/'", - Usage: "s/{find}/{replace}/ ending '/' is optional", + Description: "Simple sed-like find and replace. Since it is simple you can't replace '/' or do escaping", + Usage: "s/{find}/{replace}/{replace limit} replace limit defaults to all", Fn: func(nick string, args []string) (reply string, err error) { return ".sed is not an actual command. Do s/{find}/{replace} to use it. This exists since murii might do .help sed", nil }, @@ -40,13 +41,20 @@ func Sed(sender oodle.Sender) oodle.Trigger { if len(args) < 3 { return } + rlimit := -1 + if len(args) > 3 { + i, err := strconv.Atoi(args[3]) + if err == nil { + rlimit = i + } + } // apply find n replace on user's last msg. lastmsg, ok := usermsgs[nick] if !ok { sender.Sendf("Your last message was not found.") return } - newmsg := strings.Replace(lastmsg, args[1], args[2], -1) + newmsg := strings.Replace(lastmsg, args[1], args[2], rlimit) sender.Sendf("<%s> %s", nick, newmsg) } else { // store it as user's last msg.