コード例 #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);
            }
        }
コード例 #2
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")));
 }
コード例 #3
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;
 }