func process_car_state(taxiContext *TaxiContext, botContext *m.BotContext, api_order Order, db_order *d.OrderWrapper) {
	var result s.OutPkg

	result.To = db_order.Whom
	car_info := taxiContext.Cars.GetCarInfo(api_order.IDCar)
	if car_info == nil {
		log.Printf("ALERT! CAR CHANGED TO NOT RECOGNIZED ID")
		return
	}
	result.Message = &s.OutMessage{Body: fmt.Sprintf("Ваша машина изменилась на %v", car_info)}
	taxiContext.Notifier.Notify(result)
}
Пример #2
0
func process_request_pkg(buff *s.OutPkg, in *s.InPkg, context *BotContext) (*s.OutPkg, error) {
	if in.Request.Type == "error" {
		log.Printf("error because type of request is error:\n %+v", in.Request)
		return buff, errors.New("error because request type is error")
	}
	action := in.Request.Query.Action
	buff.Request = &s.OutRequest{ID: u.GenStringId(), Type: "result"}
	buff.Request.Query.Action = action
	buff.Request.Type = "result"

	if commandProcessor, ok := context.RequestProcessors[action]; ok {
		requestResult := commandProcessor.ProcessRequest(in)
		if requestResult.Error != nil {
			err := requestResult.Error
			return buff, err
		} else {
			//normal our request forming
			buff.Request.Query.Result = *requestResult.Commands
			if requestResult.Type != "" {
				buff.Request.Type = requestResult.Type
			}
		}
	} else {
		err := errors.New("Команда не поддерживается.")
		return buff, err
	}
	return buff, nil
}
Пример #3
0
func process_message_pkg(buff *s.OutPkg, in *s.InPkg, context *BotContext) (*s.OutPkg, bool, error) {
	var err error
	var isDeferred bool

	if in.Message.Type == "error" {
		log.Printf("error because type of message is error:\n %+v", in.Message.Error)
		return buff, false, errors.New(fmt.Sprintf("Error because type of message id: %+v is error", in.Message.ID))
	}

	in_commands := in.Message.Commands
	for _, command := range *in_commands {
		action := command.Action
		if commandProcessor, ok := context.MessageProcessors[action]; ok {
			log.Printf("BOT found [%v] action", action)
			buff, isDeferred, err = process_message(commandProcessor, buff, in)
		} else {
			err = errors.New("Команда не поддерживается.")
			buff.Message = &s.OutMessage{
				Thread: in.Message.Thread,
				ID:     u.GenStringId(),
				Type:   "chat",
				Body:   err.Error(),
			}
		}
	}
	return buff, isDeferred, err
}
Пример #4
0
func process_message(commandProcessor s.MessageCommandProcessor, buff *s.OutPkg, in *s.InPkg) (*s.OutPkg, bool, error) {
	messageResult := commandProcessor.ProcessMessage(in)
	buff.Message = &s.OutMessage{
		Thread: in.Message.Thread,
		ID:     u.GenStringId(),
		Type:   "chat",
	}
	if messageResult.Type != "" {
		buff.Message.Type = messageResult.Type
	}
	buff.Message.Body = messageResult.Body
	buff.Message.Commands = messageResult.Commands

	log.Printf("message result\ntype: %+v \nbody:%+v\ncommands:%+v\ndeffered?: %+v", messageResult.Type, buff.Message.Body, buff.Message.Commands, messageResult.IsDeferred)

	return buff, messageResult.IsDeferred, messageResult.Error
}