Beispiel #1
0
 public void Unknown(Message msg)
 {
     if (msg.Text != null)
     {
         var ints   = 0;
         var parsed = int.TryParse(msg.Text, out ints);
         if (parsed)
         {
             Core.Config.woodlimit = ints;
         }
         else
         {
             TelegramBotController.SendMessage(this.Message, PrivateLocal.TELEGRAM_ERR_CANT_PARSE);
         }
     }
 }
Beispiel #2
0
        private void Bot_OnMessage(object sender, MessageEventArgs e)
        {
            var message = e.Message.Text ?? string.Empty;

            Logger.Debug($"Received a text message in chat {e.Message.Chat.Id}. Text: {message}");

            // THIS IS A NEW USER
            if (message.StartsWith("/start"))
            {
                var reg = new Regex(@"(\/start\s)(\d+)").Match(message);
                if (reg.Success)
                {
                    TelegramBotController.SendMessage(e.Message, "Hello! Please enter Startup Code from settings.");
                }
                else
                {
                    this.Parse(e.Message);
                }
            }
            else
            {
                this.Parse(e.Message);
            }
        }
Beispiel #3
0
        public async void Parse(Message msg)
        {
            var ser = Form1._teleconfig.users.Where(n => n.userid == msg.From.Id).FirstOrDefault();

            if (ser == null)
            {
                if (msg.Text != null)
                {
                    var mac  = TeleUtils.MacAdressCode;
                    var smac = mac.Substring(0, mac.Length / 2);
                    if (string.Compare(msg.Text, smac, true) == 0)
                    {
                        var men = GetMenuItems();

                        foreach (var mn in men)
                        {
                            try
                            {
                                var instance = Activator.CreateInstance(mn) as IMenu;
                                if (instance.ID == 0)
                                {
                                    await this.botClient.SendTextMessageAsync(
                                        msg.From.Id,
                                        "Redirecting..",
                                        replyMarkup : this.ParseReplyKeyboardMarkup(instance));
                                }
                            }
                            catch (Exception)
                            {
                                // ignored
                            }
                        }

                        Form1._teleconfig.users.Add(new User {
                            MenuID = 0, userid = msg.From.Id
                        });
                        TeleConfigSer.Save();
                    }
                    else
                    {
                        TelegramBotController.SendMessage(msg, "Wrong Code!\nPlease enter Startup Code from settings.");
                        return;
                    }
                }
                else
                {
                    return;
                }
            }

            ser = Form1._teleconfig.users.Where(n => n.userid == msg.From.Id).FirstOrDefault();
            var menus = GetMenuItems();

            var   menu  = ser.MenuID;
            IMenu first = null;

            foreach (var mn in menus)
            {
                try
                {
                    var instance = Activator.CreateInstance(mn) as IMenu;
                    if (instance.ID == menu)
                    {
                        first = instance;
                    }
                }
                catch (Exception)
                {
                    // ingored
                }
            }

            if (first == null)
            {
                await this.botClient.SendTextMessageAsync(msg.Chat, "Exeption, can't find menu item");
            }
            else
            {
                first.Message = msg;
                if (msg.Text != null)
                {
                    Button a = null;
                    foreach (var rowButton in first.buttons)
                    {
                        foreach (var n in rowButton)
                        {
                            if (string.Compare(n.name, msg.Text, true) == 0)
                            {
                                a = n;
                                break;
                            }
                        }
                    }

                    if (a == null)
                    {
                        await Task.Run(() => first.Unknown(msg));
                    }
                    else
                    {
                        if (a.redirect != -1)
                        {
                            await Task.Run(a.act);

                            Form1._teleconfig.users.Where(n => n.userid == msg.From.Id).First().MenuID = a.redirect;
                            TeleConfigSer.Save();
                            IMenu newinst = null;
                            foreach (var mn in menus)
                            {
                                try
                                {
                                    var instance = Activator.CreateInstance(mn) as IMenu;
                                    if (instance.ID == a.redirect)
                                    {
                                        newinst = instance;
                                    }
                                }
                                catch (Exception)
                                {
                                    // ignored
                                }
                            }

                            await this.botClient.SendTextMessageAsync(
                                msg.From.Id,
                                "Redirecting..",
                                replyMarkup : this.ParseReplyKeyboardMarkup(newinst));

                            newinst.Message = msg;
                            newinst.OnEnter();
                            return;
                        }

                        await Task.Run(a.act);
                    }
                }
                else
                {
                    await Task.Run(() => first.Unknown(msg));
                }
            }
        }
Beispiel #4
0
 public void OnEnter()
 {
     TelegramBotController.SendMessage(
         this.Message,
         PrivateLocal.TELEGRAM_INTERVAL_WOOD + Core.Config.woodlimit);
 }
Beispiel #5
0
 public void OnEnter()
 {
     TelegramBotController.SendMessage(
         this.Message,
         PrivateLocal.TELEGRAM_INTERVAL_HIBERNATION + Core.Config.hibernateinterval);
 }
Beispiel #6
0
 public void OnEnter()
 {
     TelegramBotController.SendMessage(
         this.Message,
         PrivateLocal.TELEGRAM_INTERVAL_BARREL + Core.Config.barrelinterval);
 }