Esempio n. 1
0
        static string ReceiveReply(ExpectedReply expectedReply)
        {
            int    n     = Control.Receive(buffer); // needed to convert the reply from the server
            string reply = Encoding.ASCII.GetString(buffer, 0, n);

            if (int.Parse(reply[0].ToString()) != (int)expectedReply)
            {
                throw new Exception(reply);
            }
            return(reply);
        }
Esempio n. 2
0
        public override bool replyReceived(ExpectedReply e, message m, bool messageFailed = false)
        {
            bool processed = false;
            chat c         = Roboto.Settings.getChat(e.chatID);
            mod_steam_chat_data chatData = c.getPluginData <mod_steam_chat_data>();

            //Adding a player to the chat. We should have a player ID in our message.
            if (e.messageData == "ADDPLAYER")
            {
                long playerID = -1;
                if (long.TryParse(m.text_msg, out playerID) && playerID >= -1)
                {
                    //get the steam profile
                    mod_steam_player player = mod_steam_steamapi.getPlayerInfo(playerID, c.chatID);

                    if (player.isPrivate)
                    {
                        TelegramAPI.SendMessage(c.chatID, "Couldn't add " + player.playerName + " as their profile is set to private", m.userFullName, false, m.message_id);
                    }
                    else
                    {
                        chatData.addPlayer(player);
                        TelegramAPI.SendMessage(c.chatID, "Added " + player.playerName + ". Any steam achievements will be announced.", m.userFullName, false, m.message_id);
                    }
                }
                else if (m.text_msg.ToUpper() != "CANCEL")
                {
                    TelegramAPI.GetExpectedReply(m.chatID, m.userID, m.text_msg + " is not a valid playerID. Enter a valid playerID or 'Cancel'", false, typeof(mod_steam), "ADDPLAYER", m.userFullName, m.message_id, true);
                }
                processed = true;
            }
            else if (e.messageData == "REMOVEPLAYER")
            {
                bool success = chatData.removePlayer(m.text_msg);

                if (success)
                {
                    TelegramAPI.SendMessage(c.chatID, "Player " + m.text_msg + " removed.", m.userFullName, false, m.message_id, true);
                }
                else
                {
                    TelegramAPI.SendMessage(c.chatID, "Sorry, something went wrong removing " + m.text_msg, m.userFullName, false, m.message_id, true);
                }
                processed = true;
            }
            return(processed);
        }
Esempio n. 3
0
        public override bool replyReceived(ExpectedReply e, message m, bool messageFailed = false)
        {
            if (e.messageData == "AddWord")
            {
                addCraftWord(m.text_msg);
                TelegramAPI.SendMessage(m.chatID, "Added " + m.text_msg + " for " + m.userFirstName);
                return(true);
            }

            else if (e.messageData == "RemWord")
            {
                bool success = removeCraftWord(m.text_msg);
                TelegramAPI.SendMessage(m.chatID, "Removed " + m.text_msg + " for " + m.userFirstName + " " + (success ? "successfully" : "but fell on my ass"));
                return(true);
            }

            return(false);
        }
Esempio n. 4
0
        public override bool replyReceived(ExpectedReply e, message m, bool messageFailed = false)
        {
            chat c = Roboto.Settings.getChat(e.chatID);
            mod_birthday_data chatData = c.getPluginData <mod_birthday_data>();

            if (e.messageData == "ADD")
            {
                //reply to add word
                TelegramAPI.GetExpectedReply(e.chatID, m.userID, "What is their Birthday? (DD-MON-YYYY format, e.g. 01-JAN-1900)", true, this.GetType(), "ADD2-" + m.text_msg);
                return(true);
            }

            else if (e.messageData.StartsWith("ADD2"))
            {
                string   uname = e.messageData.Substring(5);
                DateTime birthday;
                bool     success = DateTime.TryParse(m.text_msg, out birthday);
                if (success)
                {
                    mod_birthday_birthday data = new mod_birthday_birthday(uname, birthday);
                    addBirthday(data, c);
                    TelegramAPI.SendMessage(e.chatID, "Added " + uname + "'s Birthday (" + birthday.ToString("yyyy-MM-dd") + ")");
                }
                else
                {
                    Console.WriteLine("Failed to add birthday");
                    TelegramAPI.SendMessage(m.chatID, "Failed to add birthday");
                }
                return(true);
            }

            else if (e.messageData == "REMOVE")
            {
                bool success = removeBirthday(m.text_msg, c);
                TelegramAPI.SendMessage(m.chatID, "Removed birthday for " + m.text_msg + " " + (success ? "successfully" : "but fell on my ass"));
                return(true);
            }
            return(false);
        }
Esempio n. 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(), 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);
        }
Esempio n. 6
0
        public override bool replyReceived(ExpectedReply e, message m, bool messageFailed = false)
        {
            chat c = Roboto.Settings.getChat(e.chatID);
            mod_standard_chatdata chatData = c.getPluginData <mod_standard_chatdata>();

            if (e.messageData == "setQuietHours")
            {
                if (m.text_msg.ToLower() == "cancel")
                {
                    //dont need to do anything else
                }
                else if (m.text_msg.ToLower() == "disable")
                {
                    chatData.quietHoursEndTime   = TimeSpan.MinValue;
                    chatData.quietHoursStartTime = TimeSpan.MinValue;
                    TelegramAPI.SendMessage(e.chatID, "Quiet hours have been disabled");
                }
                else
                {
                    //try parse it
                    TimeSpan s;
                    bool     success = TimeSpan.TryParse(m.text_msg, out s);
                    if (success && s > TimeSpan.Zero && s.TotalDays < 1)
                    {
                        chatData.quietHoursStartTime = s;
                        TelegramAPI.GetExpectedReply(e.chatID, m.userID, "Enter the wake time for the quiet hours, cancel, or disable. This should be in the format hh:mm:ss (e.g. 23:00:00)", true, this.GetType(), "setWakeHours", m.userFullName, -1, false, "", false, false, true);
                    }
                    else
                    {
                        TelegramAPI.GetExpectedReply(e.chatID, m.userID, "Invalid value. Enter the start time for the quiet hours, cancel, or disable. This should be in the format hh:mm:ss (e.g. 23:00:00)", true, this.GetType(), "setQuietHours", m.userFullName, -1, false, "", false, false, true);
                    }
                }
                return(true);
            }
            else if (e.messageData == "setWakeHours")
            {
                if (m.text_msg.ToLower() == "cancel")
                {
                    //dont need to do anything else
                }
                else if (m.text_msg.ToLower() == "disable")
                {
                    chatData.quietHoursEndTime   = TimeSpan.MinValue;
                    chatData.quietHoursStartTime = TimeSpan.MinValue;
                    TelegramAPI.SendMessage(e.chatID, "Quiet hours have been disabled");
                }
                else
                {
                    //try parse it
                    TimeSpan s;
                    bool     success = TimeSpan.TryParse(m.text_msg, out s);
                    if (success && s > TimeSpan.Zero && s.TotalDays < 1)
                    {
                        chatData.quietHoursEndTime = s;
                        TelegramAPI.SendMessage(e.chatID, "Quiet time set from " + chatData.quietHoursStartTime.ToString("c") + " to " + chatData.quietHoursEndTime.ToString("c"));
                    }
                    else
                    {
                        TelegramAPI.GetExpectedReply(e.chatID, m.userID, "Invalid value. Enter the start time for the quiet hours, cancel, or disable. This should be in the format hh:mm:ss (e.g. 23:00:00)", true, this.GetType(), "setQuietHours", m.userFullName, -1, false, "", false, false, true);
                    }
                }
                return(true);
            }
            else if (e.messageData == "ADDADMIN")
            {
                //try match against out presence list to get the userID
                List <chatPresence> members = c.getRecentChatUsers().Where(x => x.ToString() == m.text_msg).ToList();
                if (members.Count > 0)
                {
                    bool success = c.addAdmin(members[0].userID, m.userID);
                    TelegramAPI.SendMessage(m.chatID, success ? "Successfully added admin" : "Failed to add admin");
                }
                else
                {
                    TelegramAPI.SendMessage(m.chatID, "Failed to add admin");
                }
                return(true);
            }
            else if (e.messageData == "REMOVEADMIN")
            {
                //try match against out presence list to get the userID
                long playerID = -1;
                bool success  = long.TryParse(m.text_msg, out playerID);
                if (success)
                {
                    success = c.removeAdmin(playerID, m.userID);
                }

                TelegramAPI.SendMessage(m.chatID, success ? "Successfully removed admin" : "Failed to remove admin");
                return(true);
            }

            return(false);
        }
Esempio n. 7
0
        public override bool replyReceived(ExpectedReply e, message m, bool messageFailed = false)
        {
            if (e.messageData == "AddWord")
            {
                addCraftWord(m.text_msg);
                TelegramAPI.SendMessage(m.chatID, "Added " + m.text_msg + " for " + m.userFirstName);
                return true;
            }

            else if (e.messageData == "RemWord")
            {
                bool success = removeCraftWord(m.text_msg);
                TelegramAPI.SendMessage(m.chatID, "Removed " + m.text_msg + " for " + m.userFirstName + " " + (success ? "successfully" : "but fell on my ass"));
                return true;
            }

            return false;
        }
 /// <summary>
 /// A reply that was expected from a call to getExpectedReply
 /// </summary>
 /// <param name="e"></param>
 /// <param name="m"></param>
 /// <returns>A boolean indicating whether the plugin dealt with the reply or not. </returns>
 public virtual bool replyReceived(ExpectedReply e, message m, bool messageFailed = false)
 {
     log("Plugin " + GetType().ToString() + " received a reply, but doesnt override replyReceived", logging.loglevel.critical);
     return(false);
 }
Esempio n. 9
0
        public override bool replyReceived(ExpectedReply e, message m, bool messageFailed = false)
        {
            bool processed = false;
            chat c = Roboto.Settings.getChat(e.chatID);
            mod_xyzzy_chatdata chatData = c.getPluginData<mod_xyzzy_chatdata>();

            //did one of our outbound messages fail?
            if (messageFailed)
            {
                //TODO - better handling of failed outbound messages. Timeout player or something depending on status?
                try
                {
                    string message = "Failed Incoming expected reply";
                    if (c != null) { message += " for chat " + c.ToString(); }
                    if (m != null) { message += " recieved from chatID " + m.chatID + " from userID " + m.userID + " in reply to " + e.outboundMessageID; }

                log(message, logging.loglevel.high);
                }
                catch (Exception ex)
                {
                    log("Error thrown during failed reply processing " + ex.ToString(), logging.loglevel.critical);
                }
                return true;
            }

            else
            {
                log("Incoming expected reply for chat " + c.ToString() + " recieved from chatID " + m.chatID + " from userID " + m.userID + " in reply to " + e.outboundMessageID, logging.loglevel.verbose);
            }

            //Set up the game, once we get a reply from the user.
            if (e.messageData == "Settings")
            {
                if (m.text_msg == "Cancel") { } //do nothing, should just end and go back
                else if (m.text_msg == "Change Packs") { chatData.sendPackFilterMessage(m, 1); }
                else if (m.text_msg == "Re-deal") { chatData.reDeal(); }
                else if (m.text_msg == "Extend") { chatData.extend(); }
                else if (m.text_msg == "Reset") { chatData.reset(); }
                else if (m.text_msg == "Force Question") { chatData.forceQuestion(); }
                else if (m.text_msg == "Timeout") { chatData.askMaxTimeout(m.userID); }
                else if (m.text_msg == "Delay") { chatData.askMinTimeout(m.userID); }
                else if (m.text_msg == "Kick") { chatData.askKickMessage(m); }
                else if (m.text_msg == "Abandon")
                {
                    TelegramAPI.GetExpectedReply(chatData.chatID, m.userID, "Are you sure you want to abandon the game?", true, typeof(mod_xyzzy), "Abandon", -1, true, TelegramAPI.createKeyboard(new List<string>() { "Yes", "No" },2));
                }
                return true;
            }

            else if (e.messageData == "useDefaults")
            {
                if (m.text_msg == "Use Defaults")
                {
                    //add all the q's and a's based on the previous settings / defaults if a new game.
                    chatData.addQuestions();
                    chatData.addAllAnswers();
                    string keyboard = TelegramAPI.createKeyboard(new List<string> { "Start", "Cancel" }, 2);
                    TelegramAPI.GetExpectedReply(chatData.chatID, m.userID, "To start the game once enough players have joined click the \"Start\" button below. You will need three or more players to start the game.", true, typeof(mod_xyzzy), "Invites", -1, true, keyboard);
                    chatData.setStatus(xyzzy_Statuses.Invites);
                }
                else if (m.text_msg == "Configure Game" )
                {
                    TelegramAPI.GetExpectedReply(c.chatID, m.userID, "How many questions do you want the round to last for (-1 for infinite)", true, typeof(mod_xyzzy), "SetGameLength");
                    chatData.setStatus(xyzzy_Statuses.SetGameLength);
                }
                else if (m.text_msg == "Cancel")
                {

                    TelegramAPI.SendMessage(m.userID, "Cancelled setup");
                    chatData.setStatus(xyzzy_Statuses.Stopped);
                }
                else
                {
                    string kb = TelegramAPI.createKeyboard(new List<string>() { "Use Defaults", "Configure Game", "Cancel" }, 2);
                    long messageID = TelegramAPI.GetExpectedReply(c.chatID, m.userID, "Not a valid answer. Do you want to start the game with the default settings, or set advanced optons first? You can change these options later with /xyzzy_settings", true, typeof(mod_xyzzy), "useDefaults", 01,false,kb);
                }
                processed = true;
            }

            else if (e.messageData == "SetGameLength")
            {
                int questions;

                if (int.TryParse(m.text_msg, out questions) && questions >= -1)
                {
                    chatData.enteredQuestionCount = questions;
                    //next, ask which packs they want:
                    chatData.sendPackFilterMessage(m,1);
                    chatData.setStatus(xyzzy_Statuses.setPackFilter);
                }
                else
                {
                    TelegramAPI.GetExpectedReply(c.chatID, m.userID, m.text_msg + " is not a valid number. How many questions do you want the round to last for? -1 for infinite", true, typeof(mod_xyzzy), "SetGameLength");
                }
                processed = true;
            }

            //Set up the game filter, once we get a reply from the user.
            else if (e.messageData.StartsWith( "setPackFilter"))
            {
                //figure out what page we are on. Should be in the message data
                int currentPage = 1;
                bool success = int.TryParse(e.messageData.Substring(14), out currentPage);
                if (!success)
                {
                    currentPage = 1;
                    log("Expected messagedata to contain a page number. Was " + e.messageData, logging.loglevel.high);
                }
                //import a cardcast pack
                if (m.text_msg == "Import CardCast Pack")
                {
                    TelegramAPI.GetExpectedReply(chatData.chatID, m.userID, Helpers.cardCast.boilerPlate + "\n\r"
                        + "To import a pack, enter the pack code. To cancel, type 'Cancel'", true, typeof(mod_xyzzy), "cardCastImport");
                    if (chatData.status == xyzzy_Statuses.setPackFilter) { chatData.setStatus(xyzzy_Statuses.cardCastImport); }
                }
                else if (m.text_msg == "Next")
                {
                    currentPage++;
                    chatData.sendPackFilterMessage(m, currentPage);

                }
                else if (m.text_msg == "Prev")
                {
                    currentPage--;
                    chatData.sendPackFilterMessage(m, currentPage);
                }

                //enable/disable an existing pack
                else if (m.text_msg != "Continue")
                {
                    chatData.setPackFilter(m);
                    chatData.sendPackFilterMessage(m,currentPage);
                }
                //no packs selected, retry
                else if (chatData.packFilter.Count == 0)
                {
                    chatData.sendPackFilterMessage(m,1);
                }
                //This is presumably a continue now...
                else
                {
                    //are we adding this as part of the setup process?
                    if (chatData.status == xyzzy_Statuses.setPackFilter)
                    {
                        chatData.addQuestions();
                        chatData.addAllAnswers();

                        chatData.askMaxTimeout(m.userID);
                        chatData.setStatus(xyzzy_Statuses.setMaxHours);
                    }
                    else
                    {
                        //adding as part of a /settings. return to main
                        chatData.sendSettingsMessage(m);
                        //TelegramAPI.SendMessage(chatData.chatID, "Updated the pack list. New cards won't get added to the game until you restart, or /xyzzy_reDeal" );
                    }
                }
                processed = true;
            }

            //Cardcast importing
            else if (e.messageData == "cardCastImport")
            {
                if (m.text_msg == "Cancel")
                {
                    //return to plugins
                    chatData.sendPackFilterMessage(m,1);
                    if (chatData.status == xyzzy_Statuses.cardCastImport) { chatData.setStatus(xyzzy_Statuses.setPackFilter); }
                }
                else
                {
                    string importMessage;
                    Helpers.cardcast_pack pack = new Helpers.cardcast_pack();
                    bool success = importCardCastPack(m.text_msg, out pack, out importMessage);
                    if (success == true)
                    {
                        //reply to user
                        TelegramAPI.SendMessage(m.userID, importMessage);
                        //enable the filter
                        chatData.setPackFilter(m, pack.name);
                        //return to plugin selection
                        chatData.sendPackFilterMessage(m,1);
                        if (chatData.status == xyzzy_Statuses.cardCastImport) { chatData.setStatus(xyzzy_Statuses.setPackFilter); }
                    }
                    else
                    {
                        TelegramAPI.GetExpectedReply(chatData.chatID, m.userID,
                        "Couldn't add the pack. " + importMessage + ". To import a pack, enter the pack code. To cancel, type 'Cancel'", true, typeof(mod_xyzzy), "cardCastImport");
                    }
                }
                processed = true;
            }

            //work out the maxWaitTime (timeout)
            else if (e.messageData == "setMaxHours")
            {
                //try parse
                bool success = chatData.setMaxTimeout(m.text_msg);
                if (success && chatData.status == xyzzy_Statuses.setMaxHours ) //could be at another status if being set mid-game
                {
                    //move to the throttle
                    chatData.setStatus(xyzzy_Statuses.setMinHours);
                    chatData.askMinTimeout(m.userID);

                }
                else if (success)
                {
                    //success, called inflite
                    //TelegramAPI.SendMessage(e.chatID, "Set timeouts to " + (chatData.maxWaitTimeHours == 0 ? "No Timeout" : chatData.maxWaitTimeHours.ToString() + " hours") );
                    //adding as part of a /settings. return to main
                    chatData.sendSettingsMessage(m);

                }
                else {
                    //send message, and retry
                    TelegramAPI.SendMessage(m.userID, "Not a valid value!");
                    chatData.askMaxTimeout(m.userID);
                }
                processed = true;
            }

            //work out the minWaitTime (throttle)
            else if (e.messageData == "setMinHours")
            {
                //try parse
                bool success = chatData.setMinTimeout(m.text_msg);
                if (success && chatData.status == xyzzy_Statuses.setMinHours)//could be at another status if being set mid-game
                {

                    //Ready to start game - tell the player they can start when they want
                    string keyboard = TelegramAPI.createKeyboard(new List<string> { "Start", "Cancel" }, 2);
                    TelegramAPI.GetExpectedReply(chatData.chatID, m.userID, "To start the game once enough players have joined click the \"Start\" button below. You will need three or more players to start the game.", true, typeof(mod_xyzzy), "Invites", -1, true, keyboard);
                    chatData.setStatus(xyzzy_Statuses.Invites);

                }
                else if (success)
                {
                    //adding as part of a /settings. return to main
                    chatData.sendSettingsMessage(m);
                    //success, called inflite
                    //TelegramAPI.SendMessage(e.chatID, (chatData.minWaitTimeHours == 0 ? "Game throttling disabled" :  "Set throttle to only allow one round every " + chatData.minWaitTimeHours.ToString() + " hours"));
                }

                else
                {
                    //send message, and retry
                    TelegramAPI.SendMessage(m.userID, "Not a valid number!");
                    chatData.askMinTimeout(m.userID);
                }
                processed = true;
            }

            //start the game proper
            else if (chatData.status == xyzzy_Statuses.Invites && e.messageData == "Invites")
                // TBH, dont care what they reply with. Its probably "start" as thats whats on the keyboard, but lets not bother checking,
                //as otherwise we would have to do some daft bounds checking
                // && m.text_msg == "start")
            {
                if (m.text_msg == "Cancel")
                {
                    //allow player to cancel, otherwise the message just keeps coming back.
                    chatData.setStatus(xyzzy_Statuses.Stopped);
                }
                else if (m.text_msg == "Override" && chatData.players.Count > 1)
                {
                    chatData.askQuestion(true);
                }
                else if (m.text_msg == "Start" && chatData.players.Count > 2)
                {
                    chatData.askQuestion(true);
                }
                else if (m.text_msg == "Start")
                {
                    string keyboard = TelegramAPI.createKeyboard(new List<string> { "Start", "Cancel" }, 2);
                    TelegramAPI.GetExpectedReply(chatData.chatID, m.userID, "Not enough players yet. You need three or more players to start the game. To start the game once enough players have joined click the \"Start\" button below.", true, typeof(mod_xyzzy), "Invites", -1, true, keyboard);
                }
                else
                {
                    string keyboard = TelegramAPI.createKeyboard(new List<string> { "Start", "Cancel" }, 2);
                    TelegramAPI.GetExpectedReply(chatData.chatID, m.userID, "To start the game once enough players have joined click the \"Start\" button below. You will need three or more players to start the game.", true, typeof(mod_xyzzy), "Invites", -1, true, keyboard);
                }

                processed = true;
            }

            //A player answering the question
            else if (chatData.status == xyzzy_Statuses.Question && e.messageData == "Question")
            {
                bool answerAccepted = chatData.logAnswer(m.userID, m.text_msg);
                processed = true;
                /*if (answerAccepted) - covered in the logAnswer step
                {
                    //no longer expecting a reply from this player
                    if (chatData.allPlayersAnswered())
                    {
                        chatData.beginJudging();
                    }
                }
                */
            }

            //A judges response
            else if (chatData.status == xyzzy_Statuses.Judging && e.messageData == "Judging" && m != null)
            {
                bool success = chatData.judgesResponse(m.text_msg);

                processed = true;
            }

            //abandon game
            else if (e.messageData == "Abandon")
            {
                chatData.setStatus(xyzzy_Statuses.Stopped);
                Roboto.Settings.clearExpectedReplies(c.chatID, typeof(mod_xyzzy));
                TelegramAPI.SendMessage(c.chatID, "Game abandoned. type /xyzzy_start to start a new game");
                processed = true;
            }

            //kicking a player
            else if (e.messageData == "kick")
            {
                mod_xyzzy_player p = chatData.getPlayer(m.text_msg);
                if (p != null)
                {
                    chatData.removePlayer(p.playerID);
                }
                chatData.check();
                //now return to the last settings page
                chatData.sendSettingsMessage(m);

                processed = true;
            }

            return processed;
        }
Esempio n. 10
0
 static readonly byte[] buffer = new byte[1024];                                                              //buffer for data from the server
 static string SendCommand(string Command, ExpectedReply expectedReply)                                       // sends the commands to the server
 {
     Control.Send(Encoding.ASCII.GetBytes(Command + "\r\n"));                                                 // sends the needed command
     return(ReceiveReply(expectedReply));
 }
Esempio n. 11
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;
        }
Esempio n. 12
0
        public override bool replyReceived(ExpectedReply e, message m, bool messageFailed = false)
        {
            chat c = Roboto.Settings.getChat(e.chatID);
            mod_birthday_data chatData = c.getPluginData<mod_birthday_data>();

            if (e.messageData == "ADD")
            {
                //reply to add word
                TelegramAPI.GetExpectedReply(e.chatID, m.userID, "What is their Birthday? (DD-MON-YYYY format, e.g. 01-JAN-1900)", true, this.GetType(), "ADD2-" + m.text_msg);
                return true;
            }

            else if (e.messageData.StartsWith("ADD2"))
            {
                string uname = e.messageData.Substring(5);
                DateTime birthday;
                bool success = DateTime.TryParse(m.text_msg, out birthday);
                if (success)
                {
                    mod_birthday_birthday data = new mod_birthday_birthday(uname, birthday);
                    addBirthday(data, c );
                    TelegramAPI.SendMessage(e.chatID, "Added " + uname + "'s Birthday (" + birthday.ToString("yyyy-MM-dd") + ")");
                }
                else
                {
                    Console.WriteLine("Failed to add birthday");
                    TelegramAPI.SendMessage(m.chatID, "Failed to add birthday");
                }
                return true;
            }

            else if (e.messageData == "REMOVE")
            {

                bool success = removeBirthday(m.text_msg, c);
                TelegramAPI.SendMessage(m.chatID, "Removed birthday for " + m.text_msg + " " + (success ? "successfully" : "but fell on my ass"));
                return true;
            }
            return false;
        }
Esempio n. 13
0
        public override bool replyReceived(ExpectedReply e, message m, bool messageFailed = false)
        {
            chat c = Roboto.Settings.getChat(e.chatID);
            mod_standard_chatdata chatData = c.getPluginData<mod_standard_chatdata>();

            if (e.messageData == "setQuietHours")
            {
                if (m.text_msg.ToLower() == "cancel")
                {
                    //dont need to do anything else
                }
                else if (m.text_msg.ToLower() == "disable")
                {
                    chatData.quietHoursEndTime = TimeSpan.MinValue;
                    chatData.quietHoursStartTime = TimeSpan.MinValue;
                    TelegramAPI.SendMessage(e.chatID, "Quiet hours have been disabled");
                }
                else
                {
                    //try parse it
                    TimeSpan s;
                    bool success = TimeSpan.TryParse(m.text_msg, out s);
                    if (success && s > TimeSpan.Zero && s.TotalDays < 1)
                    {
                        chatData.quietHoursStartTime = s;
                        TelegramAPI.GetExpectedReply(e.chatID, m.userID, "Enter the wake time for the quiet hours, cancel, or disable. This should be in the format hh:mm:ss (e.g. 23:00:00)", true, this.GetType(), "setWakeHours", -1, false, "", false, false, true);
                    }
                    else
                    {
                        TelegramAPI.GetExpectedReply(e.chatID, m.userID, "Invalid value. Enter the start time for the quiet hours, cancel, or disable. This should be in the format hh:mm:ss (e.g. 23:00:00)", true, this.GetType(), "setQuietHours", -1, false, "", false, false, true);
                    }

                }
                return true;

            }
            else if (e.messageData == "setWakeHours")
            {
                if (m.text_msg.ToLower() == "cancel")
                {
                    //dont need to do anything else
                }
                else if (m.text_msg.ToLower() == "disable")
                {
                    chatData.quietHoursEndTime = TimeSpan.MinValue;
                    chatData.quietHoursStartTime = TimeSpan.MinValue;
                    TelegramAPI.SendMessage(e.chatID, "Quiet hours have been disabled");
                }
                else
                {
                    //try parse it
                    TimeSpan s;
                    bool success = TimeSpan.TryParse(m.text_msg, out s);
                    if (success && s > TimeSpan.Zero && s.TotalDays < 1)
                    {
                        chatData.quietHoursEndTime = s;
                        TelegramAPI.SendMessage(e.chatID, "Quiet time set from " + chatData.quietHoursStartTime.ToString("c") + " to " + chatData.quietHoursEndTime.ToString("c"));
                    }
                    else
                    {
                        TelegramAPI.GetExpectedReply(e.chatID, m.userID, "Invalid value. Enter the start time for the quiet hours, cancel, or disable. This should be in the format hh:mm:ss (e.g. 23:00:00)", true, this.GetType(), "setQuietHours", -1, false, "", false, false, true);
                    }
                }
                return true;
            }
            return false;
        }
Esempio n. 14
0
        public override bool replyReceived(ExpectedReply e, message m, bool messageFailed = false)
        {
            bool processed = false;
            chat c = Roboto.Settings.getChat(e.chatID);
            mod_steam_chat_data chatData = c.getPluginData<mod_steam_chat_data>();

            //Adding a player to the chat. We should have a player ID in our message.
            if (e.messageData == "ADDPLAYER")
            {

                long playerID = -1;
                if (long.TryParse(m.text_msg, out playerID) && playerID >= -1)
                {
                    //get the steam profile
                    mod_steam_player player = mod_steam_steamapi.getPlayerInfo(playerID, c.chatID);

                    if (player.isPrivate)
                    {
                        TelegramAPI.SendMessage(c.chatID, "Couldn't add " + player.playerName + " as their profile is set to private", false, m.message_id);
                    }
                    else
                    {
                        chatData.addPlayer(player);
                        TelegramAPI.SendMessage(c.chatID, "Added " + player.playerName + ". Any steam achievements will be announced.", false, m.message_id);

                    }

                }
                else if (m.text_msg.ToUpper() != "CANCEL")
                {
                    TelegramAPI.GetExpectedReply(m.chatID, m.userID, m.text_msg + " is not a valid playerID. Enter a valid playerID or 'Cancel'", false, typeof(mod_steam), "ADDPLAYER", m.message_id, true);
                }
                processed = true;
            }
            else if (e.messageData == "REMOVEPLAYER")
            {
                bool success = chatData.removePlayer(m.text_msg);

                if (success)
                {
                    TelegramAPI.SendMessage(c.chatID, "Player " + m.text_msg + " removed.", false, m.message_id, true);
                }
                else
                {
                    TelegramAPI.SendMessage(c.chatID, "Sorry, something went wrong removing " + m.text_msg, false, m.message_id,true);
                }
                processed = true;
            }
            return processed;
        }