Пример #1
0
        public override void initChatData(chat c)
        {
            mod_quote_data chatData = c.getPluginData <mod_quote_data>();

            if (chatData == null)
            {
                //Data doesnt exist, create, populate with sample data and register for saving
                chatData = new mod_quote_data();
                c.addChatData(chatData);
            }
            else
            {
                //migrate any old chats to multi_quotes
                //TODO - remove this once all migrated
                #pragma warning disable 612, 618
                foreach (mod_quote_quote q in chatData.quotes)
                {
                    //create a single line quote in multiquotes

                    mod_quote_multiquote mq = new mod_quote_multiquote(new List <mod_quote_quote_line>()
                    {
                        new mod_quote_quote_line(q.by, q.text)
                    });
                    mq.on = q.on;
                    chatData.multiquotes.Add(mq);
                    log("Migrated quote for chat " + chatData.chatID + " to multiquote");
                }
                if (chatData.quotes.Count > 0)
                {
                    log("Migrated " + chatData.quotes.Count + " quotes for chat " + chatData.chatID);
                    chatData.quotes.Clear();
                }
                #pragma warning restore 612, 618
            }
        }
Пример #2
0
        /// <summary>
        /// gets a FORMATTED string for the quote
        /// </summary>
        /// <returns></returns>
        private string getQuote(chat c)
        {
            mod_quote_data localData = c.getPluginData <mod_quote_data>();

            if (localData.multiquotes.Count > 0)
            {
                mod_quote_multiquote q = localData.multiquotes[settings.getRandom(localData.multiquotes.Count)];

                return(q.getText());
            }
            else
            {
                return("No quotes in DB");
            }
        }
Пример #3
0
        public override bool replyReceived(ExpectedReply e, message m, bool messageFailed = false)
        {
            chat           c        = Roboto.Settings.getChat(e.chatID);
            mod_quote_data chatData = (mod_quote_data)c.getPluginData(typeof(mod_quote_data));

            //Adding quotes
            if (e.messageData.StartsWith("WHO_M"))
            {
                if (m.text_msg.ToLower() == "cancel")
                {
                    TelegramAPI.SendMessage(m.userID, "Cancelled adding a new quote");
                }
                else if (m.text_msg.ToLower() == "done")
                {
                    List <mod_quote_quote_line> lines = new List <mod_quote_quote_line>();
                    //strip the "WHO_M" from the start
                    string message = e.messageData.TrimStart("WHO_M".ToCharArray());
                    //split out the text so we can put into a multiquote object
                    string[] delim    = new string[] { "<<#::#>>" };
                    string[] elements = message.Split(delim, StringSplitOptions.None);
                    string   last     = ""; //toggle between null string (populate with the name), and holding the previous value (add to the list)
                    foreach (string s in elements)
                    {
                        if (last == "")
                        {
                            last = s;
                        }
                        else
                        {
                            lines.Add(new mod_quote_quote_line(last, s));
                            last = "";
                        }
                    }

                    //now add the quote to the db
                    if (lines.Count > 0)
                    {
                        mod_quote_multiquote q = new mod_quote_multiquote(lines);
                        chatData.multiquotes.Add(q);
                        TelegramAPI.SendMessage(e.chatID, "Added quote \n\r" + q.getText(), m.userFullName, true);
                    }
                    else
                    {
                        TelegramAPI.SendMessage(m.userID, "Couldnt add quote - no lines to add?");
                    }
                }
                else
                {
                    //this should have a "\" in the middle of it to split the user from the text
                    int pos = m.text_msg.IndexOf("\\"[0]);
                    if (pos == -1)
                    {
                        TelegramAPI.SendMessage(m.userID, "Couldn't work out where the name and text were. Cancelled adding a new quote");
                    }
                    else
                    {
                        //need to store the whole set of messages in messagedata until we are finished
                        string newMsgData = e.messageData;
                        //replace the "\" with something less likely to come up accidentally
                        newMsgData = newMsgData + m.text_msg.Substring(0, pos) + "<<#::#>>" + m.text_msg.Substring(pos + 1) + "<<#::#>>";

                        TelegramAPI.GetExpectedReply(e.chatID, m.userID, "Enter the next line, 'cancel' or 'done'", true, typeof(mod_quote), newMsgData, m.userFullName, m.message_id, true);
                    }
                }


                return(true);
            }
            else if (e.messageData == "WHO")
            {
                if (m.text_msg.ToLower() == "cancel")
                {
                    TelegramAPI.SendMessage(m.userID, "Cancelled adding a new quote");
                }
                else
                {
                    TelegramAPI.GetExpectedReply(e.chatID, m.userID, "What was the quote from " + m.text_msg, true, typeof(mod_quote), "TEXT " + m.text_msg, m.userFullName, m.message_id, true, "", false, false, true);
                }
                return(true);
            }



            else if (e.messageData.StartsWith("TEXT"))
            {
                string quoteBy = e.messageData.Substring(5);    //.TrimStart("TEXT ".ToCharArray());
                bool   success = addQuote(new List <mod_quote_quote_line>()
                {
                    new mod_quote_quote_line(quoteBy, m.text_msg)
                }, c);
                TelegramAPI.SendMessage(e.chatID, "Added " + m.text_msg + " by " + quoteBy + " " + (success ? "successfully" : "but fell on my ass"));
                return(true);
            }

            //CONFIG
            else if (e.messageData.StartsWith("CONFIG"))
            {
                if (m.text_msg == "Set Duration")
                {
                    TelegramAPI.GetExpectedReply(e.chatID, m.userID, "How long between updates?" + m.text_msg, false, typeof(mod_quote), "DURATION" + m.text_msg, m.userFullName, m.message_id, true);
                    return(true);
                }
                else if (m.text_msg == "Toggle automatic quotes")
                {
                    chatData.autoQuoteEnabled = !chatData.autoQuoteEnabled;
                    TelegramAPI.SendMessage(c.chatID, "Quotes are now " + (chatData.autoQuoteEnabled == true ? "enabled" : "disabled"), m.userFullName, false, -1, true);
                    return(true);
                }
            }

            //DURATION
            else if (e.messageData.StartsWith("DURATION"))
            {
                int hours = -1;
                if (int.TryParse(m.text_msg, out hours) && hours >= -1)
                {
                    chatData.autoQuoteHours = hours;
                    TelegramAPI.SendMessage(c.chatID, "Quote schedule set to every " + hours.ToString() + " hours.", m.userFullName, false, -1, true);
                }
                else if (m.text_msg != "Cancel")
                {
                    TelegramAPI.GetExpectedReply(e.chatID, m.userID, "Not a number. How many hours between updates, or 'Cancel' to cancel" + m.text_msg, false, typeof(mod_quote), "DURATION" + m.text_msg, m.userFullName, m.message_id, true);
                }
                return(true);
            }
            return(false);
        }
Пример #4
0
        public override void initChatData(chat c)
        {
            mod_quote_data chatData = c.getPluginData<mod_quote_data>();

            if (chatData == null)
            {
                //Data doesnt exist, create, populate with sample data and register for saving
                chatData = new mod_quote_data();
                c.addChatData(chatData);
            }
            else
            {
                //migrate any old chats to multi_quotes
                //TODO - remove this once all migrated
                #pragma warning disable 612, 618
                foreach (mod_quote_quote q in chatData.quotes)
                {
                    //create a single line quote in multiquotes

                    mod_quote_multiquote mq = new mod_quote_multiquote(new List<mod_quote_quote_line>() { new mod_quote_quote_line(q.by, q.text) });
                    mq.on = q.on;
                    chatData.multiquotes.Add(mq);
                    log("Migrated quote for chat " + chatData.chatID + " to multiquote");
                }
                if (chatData.quotes.Count > 0)
                {
                    log("Migrated " + chatData.quotes.Count + " quotes for chat " + chatData.chatID);
                    chatData.quotes.Clear();
                }
                #pragma warning restore 612, 618

            }
        }
Пример #5
0
        public override bool replyReceived(ExpectedReply e, message m, bool messageFailed = false)
        {
            chat c = Roboto.Settings.getChat(e.chatID);
            mod_quote_data chatData = (mod_quote_data)c.getPluginData(typeof(mod_quote_data));

            //Adding quotes
            if (e.messageData.StartsWith("WHO_M"))
            {
                if (m.text_msg.ToLower() == "cancel")
                {
                    TelegramAPI.SendMessage(m.userID, "Cancelled adding a new quote");
                }
                else if (m.text_msg.ToLower() == "done")
                {

                    List<mod_quote_quote_line> lines = new List<mod_quote_quote_line>();
                    //strip the "WHO_M" from the start
                    string message = e.messageData.TrimStart("WHO_M".ToCharArray());
                    //split out the text so we can put into a multiquote object
                    string[] delim = new string[] { "<<#::#>>" };
                    string[] elements = message.Split(delim, StringSplitOptions.None);
                    string last = ""; //toggle between null string (populate with the name), and holding the previous value (add to the list)
                    foreach (string s in elements)
                    {
                        if (last == "") { last = s; }
                        else
                        {
                            lines.Add(new mod_quote_quote_line(last, s));
                            last = "";
                        }
                    }

                    //now add the quote to the db
                    if (lines.Count > 0)
                    {
                        mod_quote_multiquote q = new mod_quote_multiquote(lines);
                        chatData.multiquotes.Add(q);
                        TelegramAPI.SendMessage(e.chatID, "Added quote \n\r" + q.getText(),true);

                    }
                    else
                    {
                        TelegramAPI.SendMessage(m.userID, "Couldnt add quote - no lines to add?");
                    }

                }
                else
                {
                    //this should have a "\" in the middle of it to split the user from the text
                    int pos = m.text_msg.IndexOf("\\"[0]);
                    if (pos == -1) { TelegramAPI.SendMessage(m.userID, "Couldn't work out where the name and text were. Cancelled adding a new quote"); }
                    else
                    {
                        //need to store the whole set of messages in messagedata until we are finished
                        string newMsgData = e.messageData;
                        //replace the "\" with something less likely to come up accidentally
                        newMsgData = newMsgData + m.text_msg.Substring(0, pos) + "<<#::#>>" + m.text_msg.Substring(pos+1) + "<<#::#>>";

                        TelegramAPI.GetExpectedReply(e.chatID, m.userID, "Enter the next line, 'cancel' or 'done'", true, typeof(mod_quote), newMsgData, m.message_id, true);

                    }

                }

                return true;
            }
            else if (e.messageData == "WHO")
            {
                if (m.text_msg.ToLower() == "cancel")
                {
                    TelegramAPI.SendMessage(m.userID, "Cancelled adding a new quote");
                }
                else
                {
                    TelegramAPI.GetExpectedReply(e.chatID, m.userID, "What was the quote from " + m.text_msg, true, typeof(mod_quote), "TEXT " + m.text_msg, m.message_id, true, "", false,false,true);
                }
                return true;
            }

            else if (e.messageData.StartsWith("TEXT"))
            {
                string quoteBy = e.messageData.Substring(5);    //.TrimStart("TEXT ".ToCharArray());
                bool success = addQuote(new List<mod_quote_quote_line>() { new mod_quote_quote_line(quoteBy, m.text_msg) }, c);
                TelegramAPI.SendMessage(e.chatID, "Added " + m.text_msg + " by " + quoteBy + " " + (success ? "successfully" : "but fell on my ass"));
                return true;
            }

            //CONFIG
            else if (e.messageData.StartsWith("CONFIG"))
            {
                if (m.text_msg == "Set Duration")
                {
                    TelegramAPI.GetExpectedReply(e.chatID, m.userID, "How long between updates?" + m.text_msg, false, typeof(mod_quote), "DURATION" + m.text_msg, m.message_id, true);
                    return true;
                }
                else if (m.text_msg == "Toggle automatic quotes")
                {
                    chatData.autoQuoteEnabled = !chatData.autoQuoteEnabled;
                    TelegramAPI.SendMessage(c.chatID, "Quotes are now " + (chatData.autoQuoteEnabled == true ? "enabled" : "disabled"), false, -1, true);
                    return true;
                }
            }

            //DURATION
            else if (e.messageData.StartsWith("DURATION"))
            {
                int hours = -1;
                if (int.TryParse(m.text_msg, out hours) && hours >= -1)
                {
                    chatData.autoQuoteHours = hours;
                    TelegramAPI.SendMessage(c.chatID, "Quote schedule set to every " + hours.ToString() + " hours.", false, -1, true);
                }
                else if (m.text_msg != "Cancel")
                {
                    TelegramAPI.GetExpectedReply(e.chatID, m.userID, "Not a number. How many hours between updates, or 'Cancel' to cancel" + m.text_msg, false, typeof(mod_quote), "DURATION" + m.text_msg, m.message_id, true);
                }
                return true;

            }
            return false;
        }