Beispiel #1
0
        private static async Task LightSelect(int idlamp, Telegram.Bot.Types.CallbackQuery callbackQuery)
        {
            TcpClient newClient = new TcpClient();

            byte[] lightChange = new byte[2] {
                0x01, 0x00
            };

            newClient.Connect(Ipadress, Port);
            byte bt = InterfaceMK.ViaTCP.SendCMD(newClient, lightStatus);

            bt            ^= (byte)(1 << idlamp);
            lightChange[1] = bt;
            byte btget = InterfaceMK.ViaTCP.SendCMD(newClient, lightChange);

            newClient.Close();
            if (bt == btget)
            {
                if (Model.SmartHouseDbFill.lamps[idlamp].Status == 0)
                {
                    Model.SmartHouseDbFill.lamps[idlamp].Status = 1;
                }
                else
                {
                    Model.SmartHouseDbFill.lamps[idlamp].Status = 0;
                }
            }
            var inlineLight = Views.ViewLightBot.KeyLightInit(Model.SmartHouseDbFill.lamps);
            await Views.ViewLightBot.EditMessageToChat(Bot, InfoMesage.Lighcontol, callbackQuery.Message, inlineLight);
        }
        public IAnswer GetAnswer(Telegram.Bot.Types.CallbackQuery callbackQuery)
        {
            foreach (var answer in answers)
            {
                if (answer.CanExecute(callbackQuery))
                {
                    return(answer);
                }
            }

            return(null);
        }
Beispiel #3
0
        private static async Task EditLightinNight(Telegram.Bot.Types.CallbackQuery callbackQuery)
        {
            if (lightintight.Status == false)
            {
                lightintight.Status = true;
            }
            else
            {
                lightintight.Status = false;
            }

            //var inlineLightSetting = Views.ViewLightBot.KeyLightMode(presenceeffect, autooff, lightintight);
            //await Views.ViewLightBot.EditMessageToChat(Bot, InfoMesage.Lightmode, callbackQuery.Message, inlineLightSetting);
        }
Beispiel #4
0
        private static async Task EditAutoShut(Telegram.Bot.Types.CallbackQuery callbackQuery)
        {
            var inlineLightSetting = Views.ViewLightBot.KeyboardLightModeAutoOff(Model.SmartHouseDbFill.lamps, Model.SmartHouseDbFill.autooff);

            Views.ViewLightBot.SendMessageToChat(Bot, InfoMesage.Lightmode, callbackQuery.Message, inlineLightSetting);

            //if (autooff.Status == false)
            //    {
            //    autooff.Status = true;
            //    timer.Elapsed +=new ElapsedEventHandler(LightAutoOff);
            //    }
            //else autooff.Status = false;
            //var inlineLightSetting = Views.ViewLightBot.KeyLightMode(presenceeffect,autooff,lightintight);
            //await Views.ViewLightBot.EditMessageToChat(Bot, InfoMesage.Lightmode, callbackQuery.Message, inlineLightSetting);
        }
Beispiel #5
0
        private static void LightSettings(Telegram.Bot.Types.CallbackQuery callbackQuery)
        {
            var inlineLightSetting = Views.ViewLightBot.KeyLightMode(presenceeffect, lightintight);

            Views.ViewLightBot.SendMessageToChat(Bot, InfoMesage.Lightmode, callbackQuery.Message, inlineLightSetting);
        }
Beispiel #6
0
 public async void RemoveKeyboard(Telegram.Bot.Types.CallbackQuery cquery)
 {
     await this.Instance.EditMessageReplyMarkupAsync(cquery.Message.Chat.Id, cquery.Message.MessageId, replyMarkup : null);
 }
Beispiel #7
0
 private async void NotImplementedYet(Telegram.Bot.Types.CallbackQuery callbackQuery)
 {
     await bot.AnswerCallbackQueryAsync(callbackQuery.Id, $"NOT IMPLEMENTED YET");
 }
Beispiel #8
0
        private async void CreatingProfileLoop(User currentUser, Telegram.Bot.Types.Message message = null, Telegram.Bot.Types.CallbackQuery cquery = null)
        {
            AskAction currentAsk = this.FindAskAction(currentUser.ProfileCreatingState.Value);

            if (currentAsk is IGotCallbackQuery)
            {
                if (cquery == null)
                {
                    return;
                }
            }
            else
            {
                if (message == null)
                {
                    return;
                }
            }

            bool isValid = currentAsk.Validate(currentUser, cquery: cquery, message: message);

            if (!isValid)
            {
                currentAsk.OnValidationFail(currentUser);
                return;
            }

            if (cquery != null)
            {
                currentUser.SetInfo(cquery.Data);
            }
            else if (message != null)
            {
                if (message.Type == MessageType.Text)
                {
                    if (currentAsk is AskPicture)
                    {
                        try
                        {
                            Telegram.Bot.Types.Message messageWithPhoto = await this.Instance.SendPhotoAsync(currentUser.UserId, message.Text);

                            currentUser.SetInfo(messageWithPhoto.Photo.Last());
                        }
                        catch
                        {
                            await this.Instance.SendTextMessageAsync(currentUser.UserId, "Что-то пошло не так. Кажется, ссылка битая.");
                        }

                        return;
                    }

                    currentUser.SetInfo(message.Text);
                }
                else if (message.Type == MessageType.Photo && currentAsk is AskPicture)
                {
                    currentUser.SetInfo(message.Photo.Last());
                }
            }

            currentAsk.OnSuccess(currentUser, message: message, cquery: cquery);

            AskAction nextAsk = this.GetNextAskAction(currentUser.ProfileCreatingState.Value);

            if (nextAsk != null)
            {
                currentUser.ProfileCreatingState = (ProfileCreatingEnum?)nextAsk.Id;
                nextAsk.Ask(currentUser);
            }
            else
            {
                await this.Instance.SendTextMessageAsync(currentUser.UserId,
                                                         "Ура, ты зарегистрировался! Теперь мы попробуем найти кого-нибудь для тебя.");

                this.TrySendNextProfile(currentUser);
                currentUser.ProfileCreatingState = null;
            }

            this.UserContext.SaveChanges();
        }