Exemple #1
0
        private string ReminderMsgText(Reminder rem, User user, ConnectionType ct)
        {
            string retVal = "";

            // get the from user string
            string strFromString = "";

            // if this reminder was not created by the person it's being delivered to
            // then tag along who it is from
            if (rem.UserID != rem.CreatorID)
            {
                User creatorObj = DataManagerObj.GetUser(rem.CreatorID);
                strFromString = " from " + creatorObj.Username;
            }



            switch (ct)
            {
            case ConnectionType.AIM:
                retVal = "Reminder (<a href=\"http://www.remindme.cc/viewreminder?remid=" + rem.ID + "\">" + rem.ID + "</a>)" + strFromString + ": " + rem.Message;
                break;

            case ConnectionType.EMAIL:
                retVal  = "Reminder (" + rem.ID + ")" + strFromString + ": " + rem.Message;
                retVal += "\r\n\r\nThis email is an automated response to a message sent to RemindMe from your account. You can change your account settings by logging in at www.remindme.cc";
                break;

            default:
                retVal = "Reminder (" + rem.ID + ")" + strFromString + ": " + rem.Message;
                break;
            }

            return(retVal + adMgr.GetNextAdText(user, ct));
        }
Exemple #2
0
        public void OnDeliverReminder(Reminder rem)
        {
            // very smiliar to the perl server's functionality here
            // should change this to thread delivery to a deliverymanager object

            User user = userMgr.GetUserByID(rem.UserID);

            if (user == null)
            {
                // TODO: not sure what I was doing with the code below, this should throw an error or something

                rem.Delivered = true;
                goto quit;

                //if (rem.Creator.ToLower().Trim() == "admin")
                //{
                //    rem.ServerDeliveryTime += new TimeSpan(1,0,0);
                //    DataManagerObj.SaveReminder(rem);
                //    goto quit;
                //}
                //else
                //{
                //    Log.Instance.WriteError("INTERNAL ERROR 1x01: GetUserByID returned null rem.User = ("+rem.UserID+")");
                //    rem.Delivered = true; // to prevent the error from reoccuring into infinity
                //    goto quit;
                //}
            }

            ArrayList userContacts = user.Contacts;

            TimeSpan ts = (TimeSpan)(DateTime.Now - rem.ServerDeliveryTime);

            if (ts.TotalHours >= 2 && !rem.Delivered)
            {
                userContacts.Add(new IMContact(user.Email, ConnectionType.EMAIL, 4));               // max number of users needs to globalized and const'd!
            }
            foreach (IMContact ct in userContacts)
            {
                ct.UserName.Trim();
                if (conMgr.IsBuddyOnline(ct.ConnectionType, ct.UserName) && ct.UserName.Length > 0)
                {
                    Connection cntn = conMgr.GetConnection(ct.ConnectionType);

                    if (cntn == null)
                    {
                        Log.Instance.WriteError("INTERNAL ERROR 1x02: GetConnection return NULL cntn.m_type = (" + cntn.m_type.ToString() + ")");
                        rem.Delivered = true;                         // to prevent the error from reoccuring into infinity
                        goto quit;
                    }

                    try
                    {
                        cntn.SendMessage(ct.UserName, ReminderMsgText(rem, user, ct.ConnectionType));
                        Log.Instance.WriteString("Reminder Reciept: ID (" + rem.ID + ") USER (" + user.Username + ")", xCon.ConsoleColor.GreenForte, false);

                        rem.DeliveredName     = ct.UserName;
                        rem.DeliveredConnType = ct.ConnectionType;
                        rem.Delivered         = true;
                    }
                    catch (Exception ex)
                    {
                        Log.Instance.WriteError("SendEmail ERROR: " + ex.Message);
                        rem.DeliveredName = "SendEmail ERROR";
                        rem.Delivered     = true;                     // // to prevent the error from reoccuring into infinity
                    }
                    break;
                }
            }

            if (!rem.Delivered)
            {
                rem.InDeliveryQue = false;
            }
            else
            {
                rem.DeliveredTime = System.DateTime.Now.ToString("u");
            }

            quit : {}

            // only save it to the db if it's been delivered
            if (rem.Delivered)
            {
                // check to see if the reminder contains a repeater
                if (rem.Repeater != null && !rem.Repeater.HasExpired())
                {
                    RepeatPattern patt         = new RepeatPattern(rem.Repeater.Pattern);
                    DateTime      UserNextTime = patt.GetNextDate(DateTime.ParseExact(rem.UserTimeString, @"yyyy-MM-dd HH:mm:ss", null));

                    string userTimeString = UserNextTime.ToString("u");
                    userTimeString = userTimeString.Replace("Z", null);
                    if (msgParser.SendParseRequest(userTimeString, user.TimeZone, user.DLS, "getservertime") && msgParser.ProcessResponse())
                    {
                        string strTemp = msgParser.ServerTimeString;
                        strTemp = strTemp.Replace("Z", null);

                        rem.ServerDeliveryTimeString = strTemp;                        //msgParser.ServerTimeString;
                        rem.UserTimeString           = userTimeString;
                        rem.Delivered = false;
                    }

                    //Log.Instance.WriteStatus("REPEATER: NEWUSERDATE IS ["+UserNextTime.ToString("u")+"]");
                    //Log.Instance.WriteStatus("REPEATER: NEWSERVERDATE IS ["+msgParser.ServerTimeString+"]");
                }

                DataManagerObj.SaveReminder(rem);
            }

            // move below the if (rem.Delivered)...
            // save the change to the reminderQue
            reminderMgr.SaveReminderToQue(rem);
        }
Exemple #3
0
        public void MessageHandler(Connection conn, InstantMessage im)
        {
            Log.Instance.WriteStatus("INMSG (" + conn.m_type.ToString() + ") << " + im.User + " : " + im.Text);

            string strUniqueID = im.User + conn.m_type.ToString();

            if (m_bLoadingUsers || m_bLoadingReminders)
            {
                conn.SendMessage(im.User, "RemindMe is performing maintenance. Please try again in a few minutes. If the problem persists, please contact [email protected]");

                // TODO: fiond out why the bot gets stuck with one of these two being true all the time
                Log.Instance.WriteLine("m_bLoadingUsers = {0} , m_bLoadingReminders = {1}", m_bLoadingUsers.ToString(), m_bLoadingReminders.ToString());
                return;
            }

            User user = userMgr.GetUserByService(conn.m_type, im.User);

            // unknown user? Then get out ohere quickly
            if (user == null)
            {
                // we don't want to send email back to spammers
                if ((m_imers[strUniqueID] == null || (int)m_imers[strUniqueID] < 1))                // && conn.m_type != ConnectionType.EMAIL)
                {
                    conn.SendMessage(im.User, m_rm.GetString("unknown_user") + adMgr.GetNextAdText(null, conn.m_type));
                }

                // protect against spamming the bot, max of 1 im
                if (m_imers[strUniqueID] == null)
                {
                    m_imers[strUniqueID] = 1;
                }
                else
                {
                    m_imers[strUniqueID] = (int)m_imers[strUniqueID] + 1;
                }

                return;
            }

            if ((im.Text.ToLower() == @"/reset aim" || im.Text.ToLower() == @"/reset icq" ||
                 im.Text.ToLower() == @"/reset yahoo" || im.Text.ToLower() == @"/reset msn") &&
                user.Class == UserClassType.ADMIN)
            {
                string []      strList = im.Text.Split(' ');
                ConnectionType ct      = (ConnectionType)Enum.Parse(typeof(ConnectionType), strList[1], true);

                Connection resetcon = conMgr.GetConnection(ct);
                if (resetcon != null)
                {
                    resetcon.Disconnect();
                    Thread.Sleep(1000);
                    resetcon.Connect();
                }

                return;
            }

            if (im.Text.ToLower() == @"/whoami")
            {
                conn.SendMessage(im.User, "\r\nUser: "******"(" + user.UserID + ")" +
                                 "\r\nClass: " + user.Class.ToString() +
                                 "\r\nEmail: " + user.Email +
                                 "\r\nPlanNumber: " + user.PlanNumber);
                return;
            }

            Regex reg = new Regex(@"^f**k\s+you", RegexOptions.IgnoreCase);
            Match m   = reg.Match(im.Text);

            if (m.Success)
            {
                conn.SendMessage(im.User, "That's really not nice!");
                m_fuers[im.User] = 1;
                return;
            }

            // /help commands
            reg = new Regex(@"^[\/\-\:]+help\s*[\w\s]*$", RegexOptions.IgnoreCase);
            m   = reg.Match(im.Text);
            if (m.Success)
            {
                string strResponse = helpMgr.GetResponse(im.Text);

                if (strResponse.Length > 1)
                {
                    conn.SendMessage(im.User, strResponse);
                }

                return;
            }

            // /list
            reg = new Regex(@"^\/list", RegexOptions.IgnoreCase);
            m   = reg.Match(im.Text);
            if (m.Success)
            {
                string strResponse = "\nCurrent Pending Reminders:\n";

                foreach (Reminder aRem in DataManagerObj.GetUsersReminders(user.UserID))
                {
                    strResponse += aRem.ID + "   " + aRem.UserTimeString + "\n";
                }

                conn.SendMessage(im.User, strResponse);
                return;
            }

            // /cancel 1234 -- show a reminder
            reg = new Regex(@"^/cancel\s+(\d+)\s*$", RegexOptions.IgnoreCase);
            m   = reg.Match(im.Text);
            if (m.Success)
            {
                string   remId  = m.Groups[1].Captures[0].ToString();
                int      iRemID = int.Parse(remId);
                Reminder aRem   = DataManagerObj.GetReminder(iRemID);

                if (aRem != null && aRem.UserID == user.UserID)
                {
                    aRem.Delivered = true;
                    DataManagerObj.SaveReminder(aRem);

                    string strResponse = m_rm.GetString("cancel_reminder_conf");
                    strResponse = strResponse.Replace("%d", aRem.ID);

                    conn.SendMessage(im.User, strResponse);
                }

                return;
            }

            // /show 1234 - display the details of reminder 1234
            reg = new Regex(@"^/show\s+(\d+)\s*$", RegexOptions.IgnoreCase);
            m   = reg.Match(im.Text);
            if (m.Success)
            {
                string   remId  = m.Groups[1].Captures[0].ToString();
                int      iRemID = int.Parse(remId);
                Reminder aRem   = DataManagerObj.GetReminder(iRemID);

                if (aRem != null && aRem.UserID == user.UserID)
                {
                    string strResponse = m_rm.GetString(@"reminder_info_IM");
                    User   creatorObj  = _dataManager.GetUser(aRem.CreatorID);

                    strResponse = strResponse.Replace("%d", aRem.ID.ToString());
                    strResponse = strResponse.Replace("%a", creatorObj.Username);
                    strResponse = strResponse.Replace("%b", aRem.UserTimeString);
                    strResponse = strResponse.Replace("%c", aRem.Message);

                    conn.SendMessage(im.User, strResponse);
                }
                return;
            }

            // remind me .......
            reg = new Regex(@"^remind\s+\w+\s+\w+", RegexOptions.IgnoreCase);
            m   = reg.Match(im.Text);

            if (m.Success)
            {
                ProcessParse(conn, im, user, @"creation_parse");
                return;
            }

            // in 20 minutes remind me to transfer
            reg = new Regex(@"^.*?\s+remind\s+[\w_,]+\s+.*", RegexOptions.IgnoreCase);
            m   = reg.Match(im.Text);

            if (m.Success)
            {
                ProcessParse(conn, im, user, @"creation_parse");
                return;
            }

            reg = new Regex(@"^repeat\s+\w+", RegexOptions.IgnoreCase);
            m   = reg.Match(im.Text);

            if (m.Success)
            {
                ProcessParse(conn, im, user, @"repeat_parse");
                return;
            }

            if (user != null && conn.m_type != ConnectionType.EMAIL)
            {
                if (_aliceBotReady)
                {
                    cResponse reply = _aliceBot.chat(im.Text, user.Username);
                    conn.SendMessage(im.User, reply.getOutput());
                }
                else
                {
                    string strMsg = m_rm.GetString("known_user_default");
                    strMsg = strMsg.Replace("%u", user.Username);
                    conn.SendMessage(im.User, strMsg);
                }
            }
        }