コード例 #1
0
        private void UpdateClient(Client client, ref Message message)
        {
            {
                Bot.UpdateClient(client);

                Bot.AddCommand(client);
                Bot.AddMessage(client, message);
                message.Text    = null;
                message.Contact = null;
            }
        }
コード例 #2
0
        // public async Task<OkResult> Post([FromBody]Update update)
        //    public async Task<OkResult> Post([FromBody]Update update)
        public async Task <OkResult> Post([FromBody] Update update)

        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            try
            {
                var botClient = await Bot.GetBotClientAsync();

                if (update.CallbackQuery != null)
                {
                    try
                    {
                        var callbackQuery = update.CallbackQuery;

                        await ExecuteCallbackMessage(callbackQuery, botClient);

                        return(Ok());
                    }
                    catch (Exception ex)
                    {
                        Bot.MyLogger(ex.Message);
                        Bot.MyLogger(ex.StackTrace);
                        return(Ok());
                    }
                }
                else if (update == null)
                {
                    Bot.MyLogger("Какая то херня =(");

                    return(Ok());
                }

                var    message     = update.Message;
                string copymessage = null;
                if (update.Message.Text != null)
                {
                    copymessage = (string)update.Message.Text.Clone();
                }

                client        = new Client();
                client.ChatId = (long)message.Chat.Id;

                if (!Bot.Contains(client))
                {
                    if (message.Text.Contains("/start") && message.Text.Length > 8)
                    {
                        client.Metrica = message.Text.Substring(8);
                    }
                    Bot.AddClient(client);
                    Kitchen kitchen = new Kitchen();
                    kitchen.ChatId = client.ChatId;
                    Bot.AddKitchen(kitchen);
                    Bot.AddMessage(client, message);
                }
                else
                {
                    client = Bot.GetClient(client);
                    if (!DBHelper.ChekKitchen(client))
                    {
                        Kitchen kitchen = new Kitchen();
                        kitchen.ChatId = client.ChatId;
                        Bot.AddKitchen(kitchen);
                    }
                }



                Bot.AddCommand(client);


                //Bot.AddMessage(client, message);



                //return Ok();
                await ExecuteCommand(message, botClient, copymessage);

                return(Ok());
            }
            catch (Exception ex)
            {
                Bot.MyLogger(ex.Message);
                Bot.MyLogger(ex.StackTrace);
                return(Ok());
            }
        }