Exemplo n.º 1
0
        private async static void MessageParse(object sender, Telegram.Bot.Args.MessageEventArgs e)
        {
            var x      = new Session(e.Message.Chat, null, Session.SessionType.Pass, null);
            var Sesion = x.ContatinSession(Sessions);

            if (Sesion != null)
            {
                switch (Sesion.Type)
                {
                case Session.SessionType.Pass:
                    Sessions.Remove(Sesion);
                    Sesion.Answers.Add(e.Message.Text);
                    Add add = new Add(Sesion.Poll);
                    add.AddResultsToDb(int.Parse(Sesion.Chat.Id.ToString()), int.Parse(e.Message.Text), null);
                    if (Sesion.Questions.Count == 0)
                    {
                        return;
                    }
                    SendQuestion(Sesion.Questions, Sesion.Chat);
                    Sessions.Add(Sesion);
                    break;

                case Session.SessionType.Create:
                    var file = await Bot.GetFileAsync(e.Message.Document.FileId);

                    Add AddPoll = new Add(new PollReader().ReadPoll(file));
                    AddPoll.AddPollsToDb();
                    Sessions.Remove(Sesion);

                    break;
                }
            }
            if (e.Message.Text != null)
            {
                string[] msg = e.Message.Text.Split(' ');
                switch (msg[0])
                {
                case "/join":
                    if (msg.Count() != 2)
                    {
                        DebugMessage.SendDebug("MainClient", "Wrong Arguments", DebugMessage.MessageLevel.Error);
                        Bot.SendTextMessageAsync(e.Message.Chat.Id, "Wrong Arguments");
                        break;
                    }
                    if (TokenContainer.Contains(msg[1]))
                    {
                        InitiateSesion(e.Message.Chat, msg[1], Session.SessionType.Pass);
                    }
                    break;

                case "/create":
                    Bot.SendTextMessageAsync(e.Message.Chat.Id, "Send *.txt file with your poll");
                    InitiateSesion(e.Message.Chat, "test", Session.SessionType.Create);
                    break;
                }
            }
        }