Browse Source

Added an args param to context that strips out the command value itself

Thisnthat 4 years ago
parent
commit
aabd6798f5
2 changed files with 7 additions and 5 deletions
  1. 2 1
      bot/event/mux/message.go
  2. 5 4
      bot/event/mux/router.go

+ 2 - 1
bot/event/mux/message.go

@@ -84,9 +84,10 @@ func (r *Router) OnMessageCreate(s *discordgo.Session, m *discordgo.MessageCreat
 		return
 		return
 	}
 	}
 
 
-	route, fields := r.findRoute(ctx.Content, MessageRoute)
+	route, fields, args := r.findRoute(ctx.Content, MessageRoute)
 	if route != nil {
 	if route != nil {
 		ctx.Fields = fields
 		ctx.Fields = fields
+		ctx.Args = args
 		route.Run(s, m.Message, ctx)
 		route.Run(s, m.Message, ctx)
 		return
 		return
 	}
 	}

+ 5 - 4
bot/event/mux/router.go

@@ -49,6 +49,7 @@ type Handler func(*discordgo.Session, *discordgo.Message, *Context)
 // This way processing some of this only needs to happen once.
 // This way processing some of this only needs to happen once.
 type Context struct {
 type Context struct {
 	Fields          []string
 	Fields          []string
+	Args            []string
 	Content         string
 	Content         string
 	isDirectMessage bool // Indicates the message was sent via direct message
 	isDirectMessage bool // Indicates the message was sent via direct message
 	Method          Method
 	Method          Method
@@ -166,13 +167,13 @@ func isValidRouteType(routeType RouteType) bool {
 	return false
 	return false
 }
 }
 
 
-func (r *Router) findRoute(searchString string, routeType RouteType) (*route, []string) {
+func (r *Router) findRoute(searchString string, routeType RouteType) (*route, []string, []string) {
 	logrus.Printf("Find Route: %s", searchString)
 	logrus.Printf("Find Route: %s", searchString)
 	fields := strings.Fields(searchString)
 	fields := strings.Fields(searchString)
 
 
 	if len(fields) == 0 {
 	if len(fields) == 0 {
 		logrus.Printf("No route Found")
 		logrus.Printf("No route Found")
-		return nil, nil
+		return nil, nil, nil
 	}
 	}
 
 
 	commandKey := fields[0]
 	commandKey := fields[0]
@@ -184,9 +185,9 @@ func (r *Router) findRoute(searchString string, routeType RouteType) (*route, []
 
 
 		if strings.ToLower(commandKey) == strings.ToLower(route.Name) {
 		if strings.ToLower(commandKey) == strings.ToLower(route.Name) {
 			logrus.Printf("Route Found: %s", route.Name)
 			logrus.Printf("Route Found: %s", route.Name)
-			return route, fields[0:]
+			return route, fields[0:], fields[1:]
 		}
 		}
 	}
 	}
 
 
-	return nil, nil
+	return nil, nil, nil
 }
 }