Exemple #1
0
        public static async void OnMessage(object sender, MessageEventArgs args)
        {
            Message msg = args.Message;
            BotUser us  = handler.users.Find(x => x.chatId == msg.Chat.Id);

            if (us == null)
            {
                us = new BotUser()
                {
                    chatId        = msg.Chat.Id,
                    username      = msg.From.Username,
                    step          = 0,
                    targetCommand = "",
                    currentGame   = null,
                };
                handler.users.Add(us);
                using (FileStream fs = new FileStream("users.dat", FileMode.OpenOrCreate))
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    bf.Serialize(fs, handler.users);
                }
            }
            //update username if user change it
            us.username = msg.From.Username;
            try
            {
                await Task.Factory.StartNew(() => handler.ExecuteCommandAsync(msg, us));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }