Exemple #1
0
        public override Reminder GetReminder(int iRemID)
        {
            try
            {
                string s =
                    @"<?xml version=""1.0"" encoding=""utf-8""?>
<request version=""2.71828"">
  <function name=""GetReminder"">
      <argument>" + iRemID.ToString() + @"</argument>
  </function>
</request>
";
                XmlDocument dataDoc = GetDataDocument(s);

                Hashtable reminderInfo = new Hashtable();
                foreach (XmlNode remElementNode in dataDoc.DocumentElement.ChildNodes)
                {
                    reminderInfo[remElementNode.Name.ToLower()] = remElementNode.InnerText;
                }

                DateTime datime = DateTime.ParseExact(reminderInfo[@"servertime"].ToString(), @"yyyy-MM-dd HH:mm:ss", null);

                Reminder retVal = new Reminder(
                    reminderInfo[@"id"].ToString(),
                    int.Parse(reminderInfo[@"userid"].ToString()),
                    int.Parse(reminderInfo[@"creatorid"].ToString()),
                    reminderInfo[@"msg"].ToString(),
                    datime,
                    reminderInfo[@"datetime"].ToString(),
                    null);

                return(retVal);
            }
            catch (Exception ex)
            {
            }

            return(null);
        }
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);
                }
            }
        }
Exemple #4
0
        public override ArrayList GetReminders()
        {
            ArrayList retList    = new ArrayList();
            string    strPattern = "yyyy-MM-dd HH:mm:ss";

            try
            {
                string s =
                    @"<?xml version=""1.0"" encoding=""utf-8""?>
<request version=""2.71828"">
  <function name=""GetReminders"">
      <argument>" + BotName + @"</argument>
  </function>
</request>
";
                XmlDocument dataDoc = GetDataDocument(s);

                XmlNodeList reminderList = dataDoc.SelectNodes(@"/reminders/reminder");
                if (reminderList == null)
                {
                    // yeah, we neeed exceptions
                    return(retList);
                }

                foreach (XmlNode reminderNode in reminderList)
                {
                    Hashtable reminderInfo = new Hashtable();
                    ArrayList contacts     = new ArrayList();

                    foreach (XmlNode remElementNode in reminderNode.ChildNodes)
                    {
                        reminderInfo[remElementNode.Name.ToLower()] = remElementNode.InnerText;
                    }

                    DateTime datime = DateTime.ParseExact(reminderInfo[@"servertime"].ToString(), strPattern, null);

                    RepeaterClass newRepeater = null;
                    if (reminderInfo[@"repid"] != null)
                    {
                        newRepeater = new RepeaterClass(
                            reminderInfo["repid"].ToString(),
                            reminderInfo["pattern"].ToString(),
                            int.Parse(reminderInfo["count"].ToString()),
                            reminderInfo["disabled"].ToString() != "0",
                            reminderInfo["expiration"].ToString());
                    }

                    Reminder rem = new Reminder(
                        reminderInfo[@"id"].ToString(),
                        int.Parse(reminderInfo[@"userid"].ToString()),
                        int.Parse(reminderInfo[@"creatorid"].ToString()),
                        reminderInfo[@"msg"].ToString(),
                        datime,
                        reminderInfo[@"datetime"].ToString(),
                        newRepeater);

                    retList.Add(rem);
                }
            }
            catch (Exception ex)
            {
            }

            return(retList);
        }
Exemple #5
0
 abstract public bool SaveReminderDeliveryInfo(Reminder rem);
Exemple #6
0
 abstract public bool SaveReminder(Reminder rem);
Exemple #7
0
 abstract public int CreateReminder(ref Reminder rem, string strBotName);
Exemple #8
0
        public int CreateReminder(DataManager dbMgr, User user, MessageParser msgPar, UserManager userMgr)
        {
            // TODO: add exception handling
            string   strPattern;
            DateTime dt;

            try
            {
                strPattern = "yyyy-MM-dd HH:mm:ss";
                dt         = DateTime.ParseExact(msgPar.ServerTimeString, strPattern, null);
            }
            catch (Exception e)
            {
                throw e;
            }


            Reminder rmdr = null;
            User     toUser;

            if (msgPar.ToUser.ToLower().Trim() == @"me" || msgPar.ToUser.ToLower().Trim() == user.Username.ToLower().Trim())
            {
                toUser = userMgr.GetUserByID(user.UserID);                 // this saves precious calls to the db
            }
            else
            {
                toUser = dbMgr.GetUserByUsername(msgPar.ToUser);
            }
            //toUser = dbMgr.GetUser(msgPar.ToUser);

            if (toUser == null)
            {
                throw new ReminderException("(" + msgPar.ToUser + ") is not a valid RemindMe username.");
            }


            if (msgPar.ToUser.ToLower().Trim() == @"me" || msgPar.ToUser.ToLower().Trim() == user.Username.ToLower().Trim())
            {
                //if (reminderMgr.UserReminderCount(user.UserID) >= user.MaxNumReminders)
                if (dbMgr.GetUserReminderCount(user.UserID) >= user.MaxNumReminders)
                {
                    ResourceManager rm     = new ResourceManager("server.botMsgs", this.GetType().Assembly);
                    string          strMsg = rm.GetString("max_reminder_error");
                    strMsg = strMsg.Replace("%d", user.MaxNumReminders.ToString());
                    throw new ReminderException(strMsg);
                }

                // create a reminder for the user
                rmdr = new Reminder(user.UserID, user.UserID, msgPar.MessageText, dt, msgPar.UserTimeString);
            }
            else if (msgPar.ToUser.Trim().Length >= 3)
            {
                // create a person-to-person reminder

                // TODO: somewhere here you would do a check for commas to check for
                // something like: remind amy,bob,frank in 10 minutes to meet in conference room b

                // TODO: Change this to user.UserID
                if (toUser.Buddies.IndexOf(user.Username.ToLower()) < 0 && user.Class != UserClassType.ADMIN)
                {
                    throw new ReminderException(@"This user has not added you to his or her allow list to receive reminders.");
                }

                // see if the touser has any ptp reminders left
                if (toUser.MaxNumPTPReminders <= dbMgr.GetUserPTPReminderCount(toUser.UserID))
                {
                    throw new ReminderException(@"That user's reminder inbox is full!");
                }

                rmdr = new Reminder(toUser.UserID, user.UserID, msgPar.MessageText, dt, msgPar.UserTimeString);
            }

            if (rmdr == null)
            {
                throw new Exception(@"ReminderManager.CreateReminder(): rmdr = null");
            }

            // pass it a reference, dbMgr will assign the ID
            int wId = dbMgr.CreateReminder(ref rmdr, toUser.BotName);

            if (wId == 0)
            {
                throw new ReminderException(@"There has been an internal error. Please report error code 0x19 to [email protected]");
            }

            if (m_strBotName == toUser.BotName)
            {
                reminders.Add(rmdr);
            }

            return(wId);
        }