func FormShopCommands(db *d.MainDb, config *c.ShopConfig) *m.BotContext { var ShopRequestCommands = map[string]s.RequestCommandProcessor{ "commands": ShopCommandsProcessor{MainDb: *db}, } var ShopMessageCommands = map[string]s.MessageCommandProcessor{ "information": ShopInformationProcessor{Info: config.Info}, "authorise": ShopLogInMessageProcessor{MainDb: *db}, "log_out": ShopLogOutMessageProcessor{MainDb: *db}, "orders_state": ShopOrderStateProcessor{MainDb: *db}, "support_message": ShopSupportMessageProcessor{}, "balance": ShopBalanceProcessor{}, } context := m.BotContext{} context.MessageProcessors = ShopMessageCommands context.RequestProcessors = ShopRequestCommands context.Check = func() (string, bool) { if !db.Check() { return "Ошибка в подключении к БД попробуйте позже", false } return "All ok!", true } return &context }
func FormTaxiBotContext(im *ExternalApiMixin, db_handler *d.MainDb, cfgStore *d.ConfigurationStorage, tc c.TaxiConfig, ah AddressHandler, cc *CarsCache) *m.BotContext { context := m.BotContext{} context.Check = func() (detail string, ok bool) { ok = im.API.IsConnected() if !ok { detail = "Ошибка в подключении к сервису такси. Попробуйте позже." } else { return "", db_handler.Check() } return detail, ok } context.Commands = EnsureAvailableCommands(GetCommands(tc.DictUrl), tc.AvailableCommands) context.Name = tc.Name context.RequestProcessors = map[string]s.RequestCommandProcessor{ "commands": &TaxiCommandsProcessor{MainDb: *db_handler, context: &context}, } commandsGenerator := func(in *s.InPkg) (*[]s.OutCommand, error) { command, err := form_commands(in.From, *db_handler, &context) return command, err } context.MessageProcessors = map[string]s.MessageCommandProcessor{ "information": m.NewUpdatableInformationProcessor(cfgStore, commandsGenerator, tc.Chat.CompanyId), "new_order": &TaxiNewOrderProcessor{ExternalApiMixin: *im, MainDb: *db_handler, context: &context, AddressHandler: ah, Config: tc}, "cancel_order": &TaxiCancelOrderProcessor{ExternalApiMixin: *im, MainDb: *db_handler, context: &context, alert_phone: tc.Information.Phone}, "calculate_price": &TaxiCalculatePriceProcessor{ExternalApiMixin: *im, context: &context, AddressHandler: ah, Config: tc}, "feedback": &TaxiFeedbackProcessor{ExternalApiMixin: *im, MainDb: *db_handler, context: &context}, "write_dispatcher": &TaxiWriteDispatcherMessageProcessor{ExternalApiMixin: *im, MainDb: *db_handler}, "callback_request": &TaxiCallbackRequestMessageProcessor{ExternalApiMixin: *im}, "where_it": &TaxiWhereItMessageProcessor{ExternalApiMixin: *im, MainDb: *db_handler, context: &context}, "car_position": &TaxiCarPositionMessageProcessor{ExternalApiMixin: *im, MainDb: *db_handler, context: &context, Cars: NewCarInfoProvider(cc)}, "": &TaxiWriteDispatcherMessageProcessor{ExternalApiMixin: *im, MainDb: *db_handler}, } context.Settings = make(map[string]interface{}) context.Settings["not_send_price"] = tc.Api.NotSendPrice if tc.Markups != nil { context.Settings["markups"] = *tc.Markups } if tc.Api.Data.RefreshOrdersTimeStep != 0 { context.Settings["refresh_orders_time_step"] = time.Duration(tc.Api.Data.RefreshOrdersTimeStep) * time.Second } else { context.Settings["refresh_orders_time_step"] = 10 * time.Second } return &context }
func FormVoteBotContext(conf c.Configuration, db_handler *d.MainDb) *m.BotContext { context := m.BotContext{} vh, _ := NewVotingHandler(conf.Main.Database.ConnString, conf.Main.Database.Name) context.Check = func() (string, bool) { if vh.Check() { return "", true } return "", false } context.RequestProcessors = map[string]s.RequestCommandProcessor{ "commands": &VoteCommandProcessor{DictUrl: conf.Vote.DictUrl, Storage: vh}, } context.MessageProcessors = map[string]s.MessageCommandProcessor{ "add_company": &VoteConsiderCompanyProcessor{Storage: vh, DictUrl: conf.Vote.DictUrl, Answers: conf.Vote.Answers, MainStorage: db_handler}, "show_results": &VoteResultsProcessor{Storage: vh, DictUrl: conf.Vote.DictUrl}, "information": &VoteInformationProcessor{Storage: vh, DictUrl: conf.Vote.DictUrl}, } return &context }