Ejemplo n.º 1
0
        private bool TryRepeatReminder(Connection conn, InstantMessage im, User user)
        {
            int    iRemId = reminderMgr.RepeatReminder(DataManagerObj, user.UserID, msgParser);
            string strMsg;

            if (iRemId == -1)
            {
                strMsg = "No reminders have been recently delivered to you.";
            }
            else if (iRemId > 0)
            {
                strMsg = m_rm.GetString("reminder_scheduled");
                strMsg = strMsg.Replace("%d", msgParser.UserTimeString);
                strMsg = strMsg.Replace("%t", user.TimeZone);
                strMsg = strMsg.Replace("%r", iRemId.ToString());

                Log.Instance.WriteString("Reminder Repeat: ID (" + iRemId.ToString() + ") USER (" + user.UserID + ")", xCon.ConsoleColor.GreenForte, false);
                conn.SendMessage(im.User, strMsg);
                return(true);
            }
            else
            {
                strMsg = m_rm.GetString("create_reminder_failed");                 //0x03
            }
            conn.SendMessage(im.User, strMsg);
            return(false);
        }
Ejemplo n.º 2
0
        private bool TryCreateReminder(Connection conn, InstantMessage im, User user)
        {
            string strMsg = "";
            int    iNewId = 0;

            try
            {
                iNewId = reminderMgr.CreateReminder(DataManagerObj, user, msgParser, userMgr);

                strMsg = m_rm.GetString("reminder_scheduled");
                strMsg = strMsg.Replace("%d", msgParser.UserTimeString);
                strMsg = strMsg.Replace("%t", user.TimeZone);
                strMsg = strMsg.Replace("%r", iNewId.ToString());

                Log.Instance.WriteString("Reminder Created: ID (" + iNewId.ToString() + ") USER (" + user.UserID + ")", xCon.ConsoleColor.GreenForte, false);
                conn.SendMessage(im.User, strMsg + adMgr.GetNextAdText(user, conn.m_type));
                return(true);
            }
            catch (ReminderException re)
            {
                strMsg = re.Message;
            }
            catch (Exception e)
            {
                Log.Instance.WriteError("Exception in TryCreateReminder: " + e.Message);
                strMsg = "There has been an unknown error.";
            }

            conn.SendMessage(im.User, strMsg);
            return(false);            // assume failure
        }
Ejemplo n.º 3
0
 public void SendMessageHandler(Connection conn, InstantMessage im)
 {
     Log.Instance.WriteStatus("OUTMSG (" + conn.m_type.ToString() + ") >> " + im.User + " : " + im.Text);
 }
Ejemplo n.º 4
0
        private bool ProcessParse(Connection conn, InstantMessage im, User user, string strAction)
        {
            bool   bSendMessage = true;
            bool   bRetVal      = false;      // assume failure
            string strMsg       = "";

            if (!msgParser.SendParseRequest(im.Text, user.TimeZone, user.DLS, strAction))
            {
                strMsg = m_rm.GetString("mpserver_request_error");                 //0x01
            }
            else if (!msgParser.ProcessResponse())
            {
                strMsg = m_rm.GetString("mpserver_response_error");                 // 0x02
            }
            else
            {
                switch (msgParser.ParserErrorCode)
                {
                case "1":
                    strMsg = m_rm.GetString("mpserver_parser_error_1");
                    break;

                case "2":
                    strMsg = m_rm.GetString("mpserver_parser_error_2");
                    break;

                case "3":
                    strMsg = m_rm.GetString("mpserver_parser_error_3");
                    break;

                case "4":
                    strMsg = m_rm.GetString("mpserver_parser_error_4");
                    break;

                case "5":
                    strMsg = m_rm.GetString("mpserver_parser_error_5");
                    break;

                case "6":
                    strMsg = m_rm.GetString("mpserver_parser_error_6");
                    break;

                //case null:
                //	strMsg = "MPSERVER failure. If you are seeing this message, please report the problem to [email protected]. Thank you.";
                //break;

                default:                         // no error -- "0" ??
                    switch (strAction)
                    {
                    case @"creation_parse":
                        bRetVal      = TryCreateReminder(conn, im, user);
                        bSendMessage = false;
                        break;

                    case @"repeat_parse":
                        bRetVal      = TryRepeatReminder(conn, im, user);
                        bSendMessage = false;
                        break;

                    default:
                        break;
                    }
                    break;
                }
            }

            if (bSendMessage)
            {
                conn.SendMessage(im.User, strMsg);
            }

            return(bRetVal);
        }
Ejemplo n.º 5
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);
                }
            }
        }