Ejemplo n.º 1
0
        //TODO make delta time message related, and not use local time!
        public void MessageInput(Update update)
        {
            lastUpdate = update.message.message_id;
            switch (activity)
            {
            case activity.WaitingResponse:
                activity = activity.WaitingSend;
                TimeSpan delta = DateTime.Now - lastMessageSent;
                ServerMethods.sendMessage(chat.id, "Got it! You took " + delta.TotalSeconds.ToString("#0.000") + " seconds.");
                if (delta.TotalSeconds < localUsersData.appInfo.minResponseTime_s)
                {
                    ServerMethods.sendMessage(chat.id, "That's a new record!\nWould you like to share it with other users? (They will know your username and your record; if you did not set an username, your first name will be used instead)\nWrite <i>yes</i> for yes (case insensitive).\nWrite anything else for no.\nbtw: You will not receive other messagges until you answer me.");
                    activity = activity.PrivacyConsent;
                    localUsersData.appInfo.minResponseTime_s = delta.TotalSeconds;
                }
                else if (delta.TotalSeconds < response.Min())
                {
                    ServerMethods.sendMessage(chat.id, "That's a new personal record!\nYour previous record was " + response.Min().ToString("#0.000") + " seconds.");
                }
                _response.Add(delta.TotalSeconds);
                break;

            case activity.WaitingSend:
                ServerMethods.sendMessage(chat.id, "What do you mean?\nUse commands or wait my next message", reply_to_message_id: update.message.message_id);
                break;

            case activity.Inactive:
                ServerMethods.sendMessage(chat.id, "Currently I am not sending you messagges. Use \\write to receive messagges");
                break;

            case activity.PrivacyConsent:
                if (update.message.text.ToLower() == "yes")
                {
                    if (response.Min() <= localUsersData.appInfo.minResponseTime_s)
                    {
                        ShareRecord();
                    }
                    else
                    {
                        ServerMethods.sendMessage(chat.id, "You took too long to answer. Strange right?\nThere is a new record now...");
                    }
                }
                else
                {
                    ServerMethods.sendMessage(chat.id, "Ok. I'll keep your secret.");
                }
                activity = activity.Inactive;
                ServerMethods.sendMessage(chat.id, "Use command /write to receive messagges.\nBy now I'm idle.");
                break;
            }
            //user update
            if (DateTime.Now - lastUserUpdate > new TimeSpan(Settings.Default.userUpdatePeriod_day, 0, 0, 0))
            {
                Update(update.message);
            }
        }
Ejemplo n.º 2
0
        void ShareRecord()
        {
            string name = user.first_name;

            if (user.username != null)
            {
                name = user.username;
            }
            ServerMethods.sendBroadMessage("The user " + name + " just answered a message in " + response.Min().ToString("#.000") + " seconds!");
        }
Ejemplo n.º 3
0
        public static void Main(string[] args)
        {
            localUsersData.LoadData();
            localUsersData.DeleteOld();

            if (ServerMethods.GetMe().ok)
            {
                new Thread(Updater).Start();
                ServerMethods.sendBroadMessage("I am back on\n<b>MV</b>", true);
            }
        }
Ejemplo n.º 4
0
        /*//use this to START the Updarer loop*/
        static void Updater()
        {
            long cycle = 0;
            int  block = Convert.ToInt16(Settings.Default.SavePeriod_s / (Settings.Default.updateLoopSleepDuration_ms / 1000f));

            while (run)
            {
                ServerMethods.GetUnreadUpdates();
                Thread.Sleep(Settings.Default.updateLoopSleepDuration_ms);
                cycle++;
                if (cycle % block == 0)
                {
                    localUsersData.SaveData();
                }
            }
        }
Ejemplo n.º 5
0
        public static void Main(string[] args)
        {
            /*
             * Thread formThread = new Thread(RunForm);
             * formThread.Name = "Form Thread";
             * formThread.Start();
             * formCreated.WaitOne();
             * formCreated = null; //this is not supposed to be used anymore
             */

            localUsersData.LoadData();
            localUsersData.DeleteOld();

            if (ServerMethods.GetMe().ok)
            {
                new Thread(Updater).Start();
                ServerMethods.sendBroadMessage("I am back on\n<b>MV</b>", true);
            }
        }
Ejemplo n.º 6
0
 public void SendStats()
 {
     ServerMethods.sendMessage(chat.id, string.Format("Here are your stats:\nNumber of responses: {0}\nAverage response time: <b>{1}</b>\nJoin Date: {2}\nSpeed: {3}\nActivity: {4}\nNotification active?: {5}\nLast message I sent: {6}", response.Count, response.Average(), joinDate.ToLongDateString(), speed, activity.ToString(), notificate, lastMessageSent.ToString("HH:mm.ss.fff - ddd dd MMMM yyyy")));
 }
Ejemplo n.º 7
0
 void Send(object sender, ElapsedEventArgs e)
 {
     ServerMethods.sendMessage(chat.id, "Answer this!\nI sent this: " + DateTime.Now.ToString("H:mm:ss.fff"), !notificate);
     lastMessageSent = DateTime.Now;
     activity        = activity.WaitingResponse;
 }
Ejemplo n.º 8
0
 /*
  * static void RunForm() {
  *  form = new Form(formCreated);
  *  try {
  *             Application.Run(form);
  *  } catch ( Exception exception ) {
  *      File.AppendAllLines(localUsersData.LogFilepath, exception.ToString().Split(new string[] { "\n" }, StringSplitOptions.None).ToArray());
  *      throw;
  *  }
  *  //code after Application.Run is not executed!
  * }
  */
 public static void Close(object sender, FormClosingEventArgs e)
 {
     ServerMethods.sendBroadMessage("I will be off for a while\n<b>MV</b>", true);
     localUsersData.SaveData();
     Environment.Exit(0);
 }