예제 #1
0
        public override bool chatEvent(message m, chat c = null)
        {
            bool processed = false;

            if (c != null) //Needs to be done in a chat!
            {
                mod_birthday_data chatData = c.getPluginData <mod_birthday_data>();

                if (m.text_msg.StartsWith("/birthday_add"))
                {
                    TelegramAPI.GetExpectedReply(m.chatID, m.userID, "Whose birthday do you want to add?", true, this.GetType(), "ADD");
                    processed = true;
                }
                else if (m.text_msg.StartsWith("/birthday_remove"))
                {
                    TelegramAPI.GetExpectedReply(m.chatID, m.userID, "Whose birthday do you want to remove?", true, this.GetType(), "REMOVE");
                    processed = true;
                }

                else if (m.text_msg.StartsWith("/birthday_list"))
                {
                    chatData.listBirthdays();
                    processed = true;
                }
            }
            return(processed);
        }
예제 #2
0
        public static async void IniciarBot()
        {
            TelegramAPI.IniciarTelegram();
            var con = Consola.IniciarConsolaAsync();

            string cont = await con;
        }
예제 #3
0
        private void tsmiPublicate_ClickAsync(object sender, EventArgs e)
        {
            VkPublicationDTO publication = (VkPublicationDTO)dgvPosts.SelectedRows[0].Tag;

            TelegramPublicationDTO telegramPost = PublicationCreator.CreateTelegramPublication(publication);

            if (telegramPost == null)
            {
                MessageBox.Show("Ошибка публикации.");
                return;
            }
            else if (telegramPost.Error.Length > 0)
            {
                MessageBox.Show(telegramPost.Error);
                return;
            }
            else if (telegramPost.CanPublicate == false)
            {
                MessageBox.Show("Публикация отклонена. Не соответствует фильтру.");
                return;
            }

            bool ExistsImage = false;

            if (telegramPost.PhotoUrl != null && telegramPost.PhotoUrl != string.Empty)
            {
                ExistsImage = true;
            }

            TelegramAPI.SendPublicationAsync(telegramPost, ExistsImage);
        }
예제 #4
0
        private void TelegramMessage_Click(object sender, RoutedEventArgs e)
        {
            var message = "گزارش باشگاه، از " + Date1.Date + " تا " + Date2.Date + " \n\n";

            CostsList.ToList().ForEach(c => message +=
                                           c.Date + "عضو " + c.Member + " مبلغ " + c.Amount + " به روش " + c.Method + " بابت  " + c.Type + " اپراتور " + c.User + " مانده بدهی " + c.Debtor + " جزئیات " + c.Info + "\n");
            TelegramAPI.SendMessage(message);
        }
예제 #5
0
        public static void Main(string[] args)
        {
            _eventResetHandler = new AutoResetEvent(false);
            TelegramAPI telegramAPI = new TelegramAPI("278305922:AAEQmtHVWsJnbbWJ7PMZVDYxi2PKfRGI67M", null);

            telegramAPI.RunListener(HandleAction);
            _eventResetHandler.WaitOne();
        }
예제 #6
0
        /// <summary>
        /// Aplicando polimorfismo, EnviarReaccion para MensajeSalidaTelegram aplica su propio método para comunicarse
        /// mediante esta plataforma
        /// </summary>
        /// <returns></returns>
        public override async Task EnviarReaccion()
        {
            string url;
            var    random = new Random();
            int    indice = random.Next(confusion.Count);

            url = confusion[indice];

            await TelegramAPI.EnviarGif(this.Id, url);
        }
예제 #7
0
        public void listBirthdays()
        {
            String message = "I know about the following birthdays!";

            foreach (mod_birthday_birthday b in birthdays.OrderBy(x => x.birthday.Subtract(new DateTime(x.birthday.Year, 1, 1))))
            {
                message += b.birthday.ToString("\n\r" + "yyyy-MM-dd") + "\t\t - *" + b.name + "*";
            }
            TelegramAPI.SendMessage(chatID, message, null, true);
        }
예제 #8
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);
        }
예제 #9
0
        protected override void backgroundProcessing()
        {
            foreach (chat c in Roboto.Settings.chatData)
            {
                mod_quote_data localData = c.getPluginData <mod_quote_data>();

                if (localData != null && localData.autoQuoteEnabled && DateTime.Now > localData.nextAutoQuoteAfter && localData.multiquotes.Count > 0)
                {
                    TelegramAPI.SendMessage(c.chatID, getQuote(c), null, true);
                    int maxMins = localData.autoQuoteHours * 60;
                    //go back 1/8, then add rand 1/4 on
                    int randomMins = settings.getRandom((localData.autoQuoteHours * 60) / 4);
                    maxMins = maxMins - (maxMins / 8) + randomMins;
                    localData.nextAutoQuoteAfter = DateTime.Now.AddMinutes(maxMins);
                }
            }
        }
예제 #10
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);
        }
예제 #11
0
        public override bool chatEvent(message m, chat c = null)
        {
            bool processed = false;

            if (c != null)
            {
                mod_quote_data chatData = (mod_quote_data)c.getPluginData(typeof(mod_quote_data));

                if (m.text_msg.StartsWith("/quote_add"))
                {
                    TelegramAPI.GetExpectedReply(c.chatID, m.userID, "Who is the quote by? Or enter 'cancel'", true, typeof(mod_quote), "WHO", m.userFullName, -1, true);
                    processed = true;
                }
                else if (m.text_msg.StartsWith("/quote_conv"))
                {
                    TelegramAPI.GetExpectedReply(c.chatID, m.userID, "Enter the first speaker's name, a \\, then the text (e.g. Bob\\I like Bees).\n\rOr enter 'cancel' to cancel", true, typeof(mod_quote), "WHO_M", m.userFullName, -1, true);
                    processed = true;
                }

                else if (m.text_msg.StartsWith("/quote_config"))
                {
                    List <string> options = new List <string>();
                    options.Add("Set Duration");
                    options.Add("Toggle automatic quotes");
                    string keyboard = TelegramAPI.createKeyboard(options, 1);
                    TelegramAPI.GetExpectedReply(c.chatID, m.userID,
                                                 "Quotes are currently " + (chatData.autoQuoteEnabled == true? "enabled" : "disabled")
                                                 + " and set to announce every " + chatData.autoQuoteHours.ToString() + " hours"
                                                 , false, typeof(mod_quote), "CONFIG", m.userFullName, m.message_id, true, keyboard);
                }
                else if (m.text_msg.StartsWith("/quote"))
                {
                    TelegramAPI.SendMessage(m.chatID, getQuote(c), m.userFullName, true, m.message_id);
                    processed = true;
                }
            }

            //also accept forwarded messages



            return(processed);
        }
예제 #12
0
        protected override void backgroundProcessing()
        {
            foreach (chat c in Roboto.Settings.chatData)
            {
                mod_birthday_data localData = c.getPluginData <mod_birthday_data>();

                //have we already processed today?
                if (localData.lastDayProcessed.Month != DateTime.Now.Month || localData.lastDayProcessed.Day != DateTime.Now.Day)
                {
                    localData.lastDayProcessed = DateTime.Now;
                    foreach (mod_birthday_birthday b in localData.birthdays)
                    {
                        if (b.birthday.Day == DateTime.Now.Day && b.birthday.Month == DateTime.Now.Month)
                        {
                            TelegramAPI.SendMessage(c.chatID, "Happy Birthday to " + b.name + "!");
                        }
                    }
                }
            }
        }
예제 #13
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);
        }
예제 #14
0
        public override bool chatEvent(message m, chat c = null)
        {
            bool processed = false;

            if (m.text_msg.StartsWith("/craft_add"))
            {
                TelegramAPI.GetExpectedReply(m.chatID, m.userID, "Enter the word to add", true, GetType(), "AddWord");
                processed = true;
            }
            else if (m.text_msg.StartsWith("/craft_remove"))
            {
                TelegramAPI.GetExpectedReply(m.chatID, m.userID, "Enter the word to remove", true, GetType(), "RemWord");
                processed = true;
            }
            else if (m.text_msg.StartsWith("/craft"))
            {
                TelegramAPI.SendMessage(m.chatID, craftWord());
                processed = true;
            }

            return(processed);
        }
예제 #15
0
 /// <summary>
 /// Aplicando polimorfismo, EnviarTexto para MensajeSalidaTelegram aplica su propio método para comunicarse
 /// mediante esta plataforma
 /// </summary>
 /// <returns></returns>
 public async override Task EnviarTexto()
 {
     await TelegramAPI.Contestar(this.Id, this.Contenido);
 }
예제 #16
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);
        }
예제 #17
0
        public override bool chatEvent(message m, chat c = null)
        {
            bool processed = false;

            if (m.text_msg.StartsWith("/help") && c != null && c.muted == false)
            {
                mod_standard_chatdata chatData = c.getPluginData <mod_standard_chatdata>();
                string openingMessage          = "This is chat " + (c.chatTitle == null ? "" : c.chatTitle) + " (" + c.chatID + "). " + "\n\r";
                if (chatData.quietHoursStartTime != TimeSpan.MinValue && chatData.quietHoursEndTime != TimeSpan.MinValue)
                {
                    openingMessage += "Quiet time set between " + chatData.quietHoursStartTime.ToString("c") + " and " + chatData.quietHoursEndTime.ToString("c") + ". \n\r";
                }

                TelegramAPI.SendMessage(m.chatID, openingMessage + getAllMethodDescriptions());
                processed = true;
            }
            else if (m.text_msg.StartsWith("/save"))
            {
                Roboto.Settings.save();
                TelegramAPI.SendMessage(m.chatID, "Saved settings");
                processed = true;
            }
            else if (m.text_msg.StartsWith("/stop") && c != null)
            {
                c.muted = true;
                TelegramAPI.SendMessage(m.chatID, "I am now ignoring all messages in this chat until I get a /start command. ");
                //TODO - make sure we abandon any games

                processed = true;
            }
            else if (m.text_msg.StartsWith("/start") && c != null && c.muted == true)
            {
                c.muted = false;
                TelegramAPI.SendMessage(m.chatID, "I am listening for messages again. Type /help for a list of commands." + "\n\r" + getAllWelcomeDescriptions());
                processed = true;
            }
            else if (m.text_msg.StartsWith("/start"))
            {
                //a default /start message where we arent on pause. Might be in group or private chat.
                TelegramAPI.SendMessage(m.chatID, getAllWelcomeDescriptions());
            }


            else if (m.text_msg.StartsWith("/background"))
            {
                //kick off the background loop.
                Roboto.Settings.backgroundProcessing(true);
            }

            else if (m.text_msg.StartsWith("/setquiethours") && c != null)
            {
                TelegramAPI.GetExpectedReply(m.chatID, m.userID, "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");
                processed = true;
            }

            else if (m.text_msg.StartsWith("/stats"))
            {
                TimeSpan uptime = DateTime.Now.Subtract(Roboto.startTime);

                String statstxt = "I is *@" + Roboto.Settings.botUserName + "*" + "\n\r" +
                                  "Uptime: " + uptime.Days.ToString() + " days, " + uptime.Hours.ToString() + " hours and " + uptime.Minutes.ToString() + " minutes." + "\n\r" +
                                  "I currently know about " + Roboto.Settings.chatData.Count().ToString() + " chats." + "\n\r" +
                                  "The following plugins are currently loaded:" + "\n\r";

                foreach (RobotoModuleTemplate plugin in settings.plugins)
                {
                    statstxt += "*" + plugin.GetType().ToString() + "*" + "\n\r";
                    statstxt += plugin.getStats() + "\n\r";
                }

                TelegramAPI.SendMessage(m.chatID, statstxt, m.userFullName, true);
                processed = true;
            }
            else if (m.text_msg.StartsWith("/addadmin") && c != null)
            {
                //check if we have privs. This will send a fail if not.
                if (c.checkAdminPrivs(m.userID, c.chatID))
                {
                    //if there is no admin, add player
                    if (!c.chatHasAdmins())
                    {
                        bool added = c.addAdmin(m.userID, m.userID);
                        if (added)
                        {
                            TelegramAPI.SendMessage(m.chatID, "Added " + m.userFullName + " as admin.");
                        }
                        else
                        {
                            TelegramAPI.SendMessage(m.chatID, "Something went wrong! ");
                            log("Error adding user as an admin", logging.loglevel.high);
                        }
                    }
                    else
                    {
                        //create a keyboard with the recent chat members
                        List <string> members = new List <string>();
                        foreach (chatPresence p in c.getRecentChatUsers())
                        {
                            members.Add(p.ToString());
                        }
                        //send keyboard to player requesting admin.
                        TelegramAPI.GetExpectedReply(m.chatID, m.userID, "Who do you want to add as admin?", true, typeof(mod_standard), "ADDADMIN", m.userFullName, -1, false, TelegramAPI.createKeyboard(members, 2));
                    }
                }
                else
                {
                    log("User tried to add admin, but insufficient privs", logging.loglevel.high);
                }
                processed = true;
            }
            else if (m.text_msg.StartsWith("/removeadmin") && c != null)
            {
                //check if we have privs. This will send a fail if not.
                if (c.checkAdminPrivs(m.userID, c.chatID))
                {
                    //if there is no admin, add player
                    if (!c.chatHasAdmins())
                    {
                        TelegramAPI.SendMessage(m.chatID, "Group currently doesnt have any admins!");
                    }
                    else
                    {
                        //create a keyboard with the recent chat members
                        List <string> members = new List <string>();
                        foreach (long userID in c.chatAdmins)
                        {
                            members.Add(userID.ToString());
                        }
                        //send keyboard to player requesting admin.
                        TelegramAPI.GetExpectedReply(m.chatID, m.userID, "Who do you want to remove as admin?", true, typeof(mod_standard), "REMOVEADMIN", m.userFullName, -1, false, TelegramAPI.createKeyboard(members, 2));
                    }
                }
                else
                {
                    log("User tried to remove admin, but insufficient privs", logging.loglevel.high);
                }
                processed = true;
            }



            else if (m.text_msg.StartsWith("/statgraph"))
            {
                string[] argsList = m.text_msg.Split(" ".ToCharArray(), 2);
                Stream   image;
                //Work out args and get our image
                if (argsList.Length > 1)
                {
                    string args = argsList[1];
                    image = Roboto.Settings.stats.generateImage(argsList[1].Split("|"[0]).ToList());
                }
                else
                {
                    image = Roboto.Settings.stats.generateImage(new List <string>());
                }

                //Sending image...
                if (image != null)
                {
                    TelegramAPI.SendPhoto(m.chatID, "Stats", image, "StatsGraph.jpg", "application/octet-stream", m.message_id, false);
                }
                else
                {
                    TelegramAPI.SendMessage(m.chatID, "No statistics were found that matched your input, sorry!");
                }
                processed = true;

                //TODO - keyboard for stats?
            }

            return(processed);
        }
예제 #18
0
        public override bool chatEvent(message m, chat c = null)
        {
            bool processed = false;

            if (c != null)
            {
                mod_steam_chat_data chatData = (mod_steam_chat_data)c.getPluginData(typeof(mod_steam_chat_data));


                if (m.text_msg.StartsWith("/steam_addplayer"))
                {
                    TelegramAPI.GetExpectedReply(c.chatID, m.userID
                                                 , "Enter the steamID of the player you want to add. /steam_help to find out how to get this."
                                                 , false
                                                 , typeof(mod_steam)
                                                 , "ADDPLAYER", m.userFullName, m.message_id, true);
                    processed = true;
                }
                else if (m.text_msg.StartsWith("/steam_help"))
                {
                    TelegramAPI.SendMessage(m.chatID, "You are looking for an ID from the Steam Community site, try http://steamcommunity.com/ and find your profile. You should have something like http://steamcommunity.com/profiles/01234567890132456 . Take this number on the end of the URL."
                                            , m.userFullName, false, m.message_id);
                    processed = true;
                }
                else if (m.text_msg.StartsWith("/steam_check"))
                {
                    checkChat(c);

                    processed = true;
                }
                else if (m.text_msg.StartsWith("/steam_stats"))
                {
                    string announce = "Currently watching achievements from the following players: " + "\n\r";
                    foreach (mod_steam_player p in chatData.players)
                    {
                        announce += "*" + p.playerName + "* - " + p.chievs.Count().ToString() + " known achievements" + "\n\r";
                    }
                    int achievements = 0;
                    foreach (mod_steam_game g in localData.games)
                    {
                        achievements += g.chievs.Count();
                    }
                    announce += "Tracking " + achievements.ToString() + " achievements across " + localData.games.Count().ToString() + " games";

                    TelegramAPI.SendMessage(m.chatID, announce, m.userFullName, true, m.message_id);
                }


                else if (m.text_msg.StartsWith("/steam_remove"))
                {
                    List <string> playerKeyboard = new List <string>();
                    foreach (mod_steam_player p in chatData.players)
                    {
                        playerKeyboard.Add(p.playerName);
                    }
                    playerKeyboard.Add("Cancel");
                    string playerKeyboardText = TelegramAPI.createKeyboard(playerKeyboard, 2);
                    TelegramAPI.GetExpectedReply(c.chatID, m.userID, "Which player do you want to stop tracking?", false, typeof(mod_steam), "REMOVEPLAYER", m.userFullName, m.message_id, true, playerKeyboardText);
                }
            }
            return(processed);
        }
예제 #19
0
        public void checkAchievements()
        {
            List <string>       announce  = new List <string>();
            mod_steam_core_data localData = Roboto.Settings.getPluginData <mod_steam_core_data>();

            //get a list of what the player has been playing
            try
            {
                List <mod_steam_game> playerGames = mod_steam_steamapi.getRecentGames(playerID);

                foreach (mod_steam_game g in playerGames)
                {
                    //get the local data object
                    mod_steam_game gameData = localData.getGame(g.gameID);

                    //get the achievement list for each game
                    try
                    {
                        List <string> gainedAchievements = mod_steam_steamapi.getAchievements(playerID, g.gameID);

                        //make a list of any that we havent recorded yet
                        List <string> newAchievements = new List <string>();
                        foreach (string achievementCode in gainedAchievements)
                        {
                            if (chievs.Where(x => x.chievName == achievementCode && x.appID == g.gameID).Count() == 0)
                            {
                                newAchievements.Add(achievementCode);
                            }
                        }

                        if (newAchievements.Count() > 0)
                        {
                            List <string> failedAchieves = new List <string>();
                            //try get the cached friendly text for each achievement, and add them to our player's stash.
                            foreach (string s in newAchievements)
                            {
                                chievs.Add(new mod_steam_chiev(s, g.gameID));
                                mod_steam_achievement chiev = gameData.getAchievement(s);
                                if (chiev == null)
                                {
                                    Console.WriteLine("Failed to get friendly data for " + s + " from cache, will refresh");
                                    failedAchieves.Add(s);
                                }
                                else
                                {
                                    announce.Add(chiev.ToString() + " in " + g.displayName);
                                }
                            }

                            //if we failed, refresh the cache and try again.
                            if (failedAchieves.Count() > 0)
                            {
                                gameData.refreshAchievs();
                            }
                            //add any that failed originally.
                            foreach (string s in failedAchieves)
                            {
                                mod_steam_achievement chiev = gameData.getAchievement(s);
                                if (chiev == null)
                                {
                                    Console.WriteLine("Failed to get friendly data for " + s + " even after refresh. Will add default text instead");
                                    announce.Add(s.Replace("_", " ") + " in " + g.displayName);
                                }
                                else
                                {
                                    announce.Add(chiev.ToString() + " in " + g.displayName);
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        //probably failed to call the web service.
                        Console.WriteLine("Failed during update of player achievements for game" + e.ToString());
                    }
                }
            }
            catch (Exception e)
            {
                //probably failed to call the web service.
                Console.WriteLine("Failed during update of player achievements " + e.ToString());
            }
            //send a message (first few per game)
            if (announce.Count() > 0)
            {
                string message = playerName + " got the following achievements:" + "\n\r";
                int    max     = 5;
                if (announce.Count < 5)
                {
                    max = announce.Count;
                }

                for (int i = 0; i < max; i++)
                {
                    message += "- " + announce[i] + "\n\r";
                }
                if (announce.Count > 5)
                {
                    message += "And (" + (announce.Count - 5).ToString() + ") others";
                }
                TelegramAPI.SendMessage(this.chatID, message, null, true, -1, true);
            }
        }
예제 #20
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);
        }
예제 #21
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public string ToTechnologyGroup()
        {
            log4net.ILog logger = log4net.LogManager.GetLogger(typeof(string));  //Declaring Log4Net

            string telegramPublishPath         = System.Configuration.ConfigurationManager.AppSettings["TelegramPublishPath"].ToString();
            string telegramTechnologyGroupID   = System.Configuration.ConfigurationManager.AppSettings["TelegramTechnologyGroupID"].ToString();
            string telegramTechnologyGroupName = System.Configuration.ConfigurationManager.AppSettings["TelegramTechnologyGroupName"].ToString();

            //string telegramLoggerPath = System.Configuration.ConfigurationManager.AppSettings["telegramLoggerPath"].ToString();
            try
            {
                // Send Post Queue To Telegram Technology Channel
                var telegramQueuePath = telegramPublishPath + "TechnologyPostQueue.json";
                var telegramJsonData  = System.IO.File.ReadAllText(telegramQueuePath);
                // Check Telegram Queue is not Empty
                if (telegramJsonData == null || telegramJsonData == "[]")
                {
                    logger.Error("List is Empty.");
                    return("OK");
                }

                var telegramPostList = Newtonsoft.Json.JsonConvert.DeserializeObject <System.Collections.Generic.List <PostModel> >(telegramJsonData) ?? new System.Collections.Generic.List <PostModel>();

                // First Selection Method : Max Article Length
                PostModel post = telegramPostList.OrderByDescending(x => x.ArticleLength).FirstOrDefault();

                // Two Selection Method : High Post Priority
                if (post == null)
                {
                }

                // Three Selection Method : Max Caption White Word Count
                if (post == null)
                {
                }

                // Four Selection Method : Max Article Image Count
                if (post == null)
                {
                }

                // Anyway : First Post in Queue
                if (post == null)
                {
                    post = telegramPostList.FirstOrDefault();
                }

                TelegramAPI telegram = new TelegramAPI();
                // Send Photo Post
                if (post.Content == PostContentType.Photo)
                {
                    var caption = post.Caption + "\n\n" + post.ShortArticle + "\n\n🔗 " + post.ShortLink.Replace("http://", "") + "\n\n" + telegramTechnologyGroupName;
                    telegram.SendPhoto(telegramTechnologyGroupID, post.Photo, caption);
                }

                // Delete Post
                telegramPostList.Remove(post);
                telegramJsonData = Newtonsoft.Json.JsonConvert.SerializeObject(telegramPostList);
                System.IO.File.WriteAllText(telegramQueuePath, telegramJsonData);

                return("OK");
            }
            catch (System.Exception ex)
            {
                logger.Error(ex.ToString());
                return("BAD");
            }
        }