Ejemplo n.º 1
0
 public void startBot()
 {
     botTelegram.OnMessage += BotTelegram_OnMessage;
     botTelegram.StartReceiving();
     Console.ReadLine();
     botTelegram.StopReceiving();
 }
Ejemplo n.º 2
0
 protected static void OnExit(object sender, ConsoleCancelEventArgs args)
 {
     BOT.StopReceiving();
     Json_Data.WriteData();
     logger.Info("Exit.");
     _closing.Set();
 }
Ejemplo n.º 3
0
        public Bottu(string Token, string baseApiAddress)
        {
            AutoResetEvent are = new AutoResetEvent(false);

            client       = new Telegram.Bot.TelegramBotClient(Token);
            MediaWikiApi = new HttpClient
            {
                BaseAddress = new Uri(baseApiAddress)
            };

            var InlineObservable = Observable.FromEventPattern <InlineQueryEventArgs>(c => client.OnInlineQuery += c, c => client.OnInlineQuery -= c);

            InlineObservable
            .Throttle(TimeSpan.FromMilliseconds(100))
            .Where(c => c?.EventArgs?.InlineQuery != null && !string.IsNullOrWhiteSpace(c.EventArgs.InlineQuery.Query))
            .Select(c => c.EventArgs.InlineQuery)
            .Select(c => Observable.FromAsync(async() => await ProcessInline(c)))
            .Concat()
            .Subscribe();

            client.StartReceiving(new[] { UpdateType.InlineQuery });

            Console.WriteLine("Started.");

            are.WaitOne();

            client.StopReceiving();
            Console.WriteLine("Stopped.");
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            Bot.OnMessage += BotOnTextReceived;
            var me = Bot.GetMeAsync().Result;

            Console.Title = me.Username;

            Bot.StartReceiving();
            Console.ReadLine();
            Bot.StopReceiving();
        }
Ejemplo n.º 5
0
        public static void Main()
        {
            var me = Bot.GetMeAsync().Result;

            Console.Title        = me.Username;
            Bot.OnMessage       += BotOnMessageReceived;
            Bot.OnMessageEdited += BotOnMessageReceived;
            Bot.OnCallbackQuery += BotOnCallbackQueryReceived;
            Bot.StartReceiving(Array.Empty <UpdateType>());
            Console.WriteLine($"Start listening for @{me.Username}");
            Console.ReadLine();
            Bot.StopReceiving();
        }
Ejemplo n.º 6
0
 private static void PrintReceiveScreenInteractive()
 {
     Console.Clear();
     WriteMessageSlowly("Switching to message view");
     Console.Clear();
     Console.WriteLine("Press <ESC> if you want to return to main menu");
     bot.StartReceiving();
     while (Console.ReadKey().Key != ConsoleKey.Escape)
     {
         Console.ReadKey();
     }
     bot.StopReceiving();
     Console.Clear();
     DrawMainMenue();
 }
Ejemplo n.º 7
0
        static void Main()
        {
            bot = new Telegram.Bot.TelegramBotClient("723889901:AAFSFuCmJI62q876qMXOnrZxjGssu6EhI00");

            // загрузка базы курьеров
            Courier.Load();
            Console.WriteLine("База загружена");

            // события TelegramAPI и их обработчики
            bot.OnMessage            += BotOnMessageReceived;
            bot.OnMessageEdited      += BotOnMessageReceived;
            bot.OnCallbackQuery      += BotOnCallbackQueryReceived;
            bot.OnInlineQuery        += BotOnInlineQueryReceived;
            bot.OnInlineResultChosen += BotOnChosenInlineResultReceived;
            bot.OnReceiveError       += BotOnReceiveError;

            bot.StartReceiving(Array.Empty <UpdateType>());


            while (true)
            {
                var input = Console.ReadLine().Trim().ToLower();
                switch (input)
                {
                case "cours":
                    Console.WriteLine(U.StrCol(Environment.NewLine, Courier.Couriers));
                    break;

                case "end":
                case "exit":
                    bot.StopReceiving();
                    return;

                default:
                    break;
                }
            }
        }
Ejemplo n.º 8
0
        public async void BotOnMessageReceived(object sender, MessageEventArgs messageEventArgs)
        {
            Message message = messageEventArgs.Message;

            if (message == null || message.Type != MessageType.TextMessage)
            {
                return;
            }
            _chatid = message.Chat.Id;
            try
            {
                Logger.ColoredConsoleWrite(ConsoleColor.Red, "[TelegramAPI] Got Request from " + message.From.Username + " | " + message.Text);
                string username       = _botSettings.TelegramName;
                string telegramAnswer = string.Empty;

                if (username != message.From.Username)
                {
                    using (System.IO.Stream stream = new System.IO.MemoryStream())
                    {
                        PokemonGo.RocketAPI.Logic.Properties.Resources.norights.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
                        stream.Position = 0;
                        await _telegram.SendPhotoAsync(_chatid, new FileToSend("norights.jpg", stream), replyMarkup : new ReplyKeyboardHide()).ConfigureAwait(false);
                    }
                    return;
                }

                // [0]-Commando; [1+]-Argument
                var              msgText = message.Text;
                string[]         textCMD = msgText.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                TelegramUtilTask cmd     = getTask(textCMD[0]);
                switch (cmd)
                {
                case TelegramUtilTask.UNKNOWN:
                    telegramAnswer = string.Format("Usage:\r\n{0}\r\n{1}\r\n{2}\r\n{3}\r\n{4}\r\n{5}\r\n{6}\r\n{7}\r\n{8}\r\n{9}",
                                                   @"/stats - Get Current Stats",
                                                   @"/livestats - Enable/Disable Live Stats",
                                                   @"/information <topic> - Enable/Disable Information topics",
                                                   @"/top <HowMany?> - Outputs Top (?) Pokemons",
                                                   @"/transfer pokemon cp - transfer pokemons that matches with the given data",
                                                   @"/items  - Outputs Items List",
                                                   @"/drop item amount  - Throws the amount of items given",
                                                   @"/forceevolve - Forces Evolve",
                                                   @"/snipe pokemon latitude, longitude - snipe desired pokemon",
                                                   @"/stopbot - stop running bot");
                    break;

                case TelegramUtilTask.GET_STATS:
                    var ps = _client.Inventory.GetPlayerStats();

                    int    l             = ps.First().Level;
                    long   expneeded     = ((ps.First().NextLevelXp - ps.First().PrevLevelXp) - StringUtils.getExpDiff(ps.First().Level));
                    long   curexp        = ((ps.First().Experience - ps.First().PrevLevelXp) - StringUtils.getExpDiff(ps.First().Level));
                    double curexppercent = (Convert.ToDouble(curexp) / Convert.ToDouble(expneeded)) * 100;
                    string curloc        = _client.CurrentLatitude + "%20" + _client.CurrentLongitude;
                    curloc = curloc.Replace(",", ".");
                    string curlochtml = "https://www.google.com/maps/search/" + curloc + "/";
                    double shortenLng = Math.Round(_client.CurrentLongitude, 3);
                    double shortenLat = Math.Round(_client.CurrentLatitude, 3);
                    var    player     = _client.Player.GetPlayer();
                    telegramAnswer += "\nNickname: " + player.PlayerData.Username;
                    telegramAnswer += "\nLevel: " + ps.First().Level;
                    telegramAnswer += "\nEXP Needed: " + ((ps.First().NextLevelXp - ps.First().PrevLevelXp) - StringUtils.getExpDiff(ps.First().Level));
                    telegramAnswer += $"\nCurrent EXP: {curexp} ({Math.Round(curexppercent)}%)";
                    telegramAnswer += "\nEXP to Level up: " + ((ps.First().NextLevelXp) - (ps.First().Experience));
                    telegramAnswer += "\nKM walked: " + ps.First().KmWalked;
                    telegramAnswer += "\nPokeStops visited: " + ps.First().PokeStopVisits;
                    telegramAnswer += "\nStardust: " + player.PlayerData.Currencies.ToArray()[1].Amount;
                    telegramAnswer += "\nPokemons: " + (_client.Inventory.GetPokemons()).Count() + "/" + player.PlayerData.MaxPokemonStorage;
                    telegramAnswer += "\nItems: " + _client.Inventory.GetItems().Count() + " / " + player.PlayerData.MaxItemStorage;
                    telegramAnswer += "\nCurentLocation:\n" + curlochtml;
                    break;

                case TelegramUtilTask.GET_TOPLIST:
                    int shows = 10;
                    if (textCMD.Length > 1 && !int.TryParse(textCMD[1], out shows))
                    {
                        telegramAnswer += $"Error! This is not a Number: {textCMD[1]}\nNevermind...\n";
                        shows           = 10; //TryParse error will reset to 0
                    }
                    telegramAnswer += "Showing " + shows + " Pokemons...\nSorting...";
                    await _telegram.SendTextMessageAsync(_chatid, telegramAnswer, replyMarkup : new ReplyKeyboardHide()).ConfigureAwait(false);

                    var myPokemons = _client.Inventory.GetPokemons();
                    myPokemons = myPokemons.OrderByDescending(x => x.Cp);
                    var PogoUsername = _client.Player.GetPlayer().PlayerData.Username;
                    telegramAnswer = $"Top {shows} Pokemons of {PogoUsername}:";

                    IEnumerable <PokemonData> topPokemon = myPokemons.Take(shows);
                    foreach (PokemonData pokemon in topPokemon)
                    {
                        telegramAnswer += string.Format("\n{0} |  CP: {1} ({2}% perfect)",
                                                        pokemon.PokemonId,
                                                        pokemon.Cp,
                                                        Math.Round(PokemonInfo.CalculatePokemonPerfection(pokemon), 2));
                    }
                    break;

                case TelegramUtilTask.SWITCH_LIVESTATS:
                    _livestats = SwitchAndGetAnswer(_livestats, out telegramAnswer, "Live Stats");
                    break;

                case TelegramUtilTask.SWITCH_INFORMATION:
                    //_informations = SwitchAndGetAnswer(_informations, out telegramAnswer, "Information");
                    Array topics = Enum.GetValues(typeof(TelegramUtilInformationTopics));
                    if (textCMD.Length > 1)
                    {
                        if (textCMD[1] == "all-enable")
                        {
                            foreach (TelegramUtilInformationTopics topic in topics)
                            {
                                String niceName = topic.ToString().Substring(0, 1).ToUpper() + topic.ToString().Substring(1).ToLower();
                                telegramAnswer     += "Enabled information topic " + niceName + "\n";
                                _information[topic] = true;
                            }
                            break;
                        }
                        else if (textCMD[1] == "all-disable")
                        {
                            foreach (TelegramUtilInformationTopics topic in topics)
                            {
                                String niceName = topic.ToString().Substring(0, 1).ToUpper() + topic.ToString().Substring(1).ToLower();
                                telegramAnswer     += "Disabled information topic " + niceName + "\n";
                                _information[topic] = false;
                            }
                            break;
                        }
                        else
                        {
                            foreach (TelegramUtilInformationTopics topic in topics)
                            {
                                if (textCMD[1].ToLower() == topic.ToString().ToLower())
                                {
                                    String niceName = topic.ToString().Substring(0, 1).ToUpper() + topic.ToString().Substring(1).ToLower();
                                    _information[topic] = !_information[topic];
                                    telegramAnswer      = (_information[topic] ? "En" : "Dis") + "abled information topic " + niceName + "\n";
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        foreach (TelegramUtilInformationTopics topic in topics)
                        {
                            String niceName = topic.ToString().Substring(0, 1).ToUpper() + topic.ToString().Substring(1).ToLower();
                            telegramAnswer += " - " + niceName + "\n";
                            telegramAnswer += " -     " + _informationDescription[topic] + "\n";
                            telegramAnswer += " -     Currently " + (_information[topic] ? "enabled" : "disabled") + "\n";
                            telegramAnswer += "\n";
                        }

                        telegramAnswer += " - all-disable\n";
                        telegramAnswer += " -     " + TranslationHandler.GetString("telegram-disable-all", "Disable all topics") + "\n";
                        telegramAnswer += "\n";

                        telegramAnswer += " - all-enable\n";
                        telegramAnswer += " -     " + TranslationHandler.GetString("telegram-enable-all", "Enable all topics") + "\n";
                        telegramAnswer += "\n";
                        break;
                    }

                    break;

                case TelegramUtilTask.RUN_FORCEEVOLVE:
                    IEnumerable <PokemonData> pokemonToEvolve = Setout.GetPokemonToEvolve(true);
                    if (pokemonToEvolve.Count() > 3)
                    {
                        Setout.UseLuckyEgg(_client);
                    }
                    foreach (PokemonData pokemon in pokemonToEvolve)
                    {
                        if (_botSettings.pokemonsToEvolve.Contains(pokemon.PokemonId))
                        {
                            var evolvePokemonOutProto = _client.Inventory.EvolvePokemon((ulong)pokemon.Id);
                            if (evolvePokemonOutProto.Result == POGOProtos.Networking.Responses.EvolvePokemonResponse.Types.Result.Success)
                            {
                                await _telegram.SendTextMessageAsync(_chatid, $"Evolved {pokemon.PokemonId} successfully for {evolvePokemonOutProto.ExperienceAwarded}xp", replyMarkup : new ReplyKeyboardHide()).ConfigureAwait(false);
                            }
                            else
                            {
                                await _telegram.SendTextMessageAsync(_chatid, $"Failed to evolve {pokemon.PokemonId}. EvolvePokemonOutProto.Result was {evolvePokemonOutProto.Result}, stopping evolving {pokemon.PokemonId}", replyMarkup : new ReplyKeyboardHide()).ConfigureAwait(false);
                            }
                            RandomHelper.RandomSleep(2000);
                        }
                    }
                    telegramAnswer = "Done.";
                    break;

                case TelegramUtilTask.RUN_SNIPE:
                    telegramAnswer = ProcessSnipeCommand(msgText.Replace(textCMD[0], "").Trim());
                    break;

                case TelegramUtilTask.FORCE_STOP:
                    var secs = 1;
                    if (textCMD.Length > 1)
                    {
                        int.TryParse(textCMD[1].Trim(), out secs);
                    }
                    telegramAnswer = $"Stopping bot in {secs} seconds";
                    await _telegram.SendTextMessageAsync(_chatid, telegramAnswer, replyMarkup : new ReplyKeyboardHide()).ConfigureAwait(false);

                    _telegram.StopReceiving();
                    RandomHelper.RandomSleep(secs * 1000);
                    Environment.Exit(0);
                    break;

                case TelegramUtilTask.TRANSFER_POKEMON:
                    telegramAnswer = ProcessTransferPokemon(msgText.Replace(textCMD[0], "").Trim());
                    break;

                case TelegramUtilTask.GET_ITEMSLIST:
                    telegramAnswer = ProcessGetItemList();
                    break;

                case TelegramUtilTask.DROP_ITEM:
                    telegramAnswer = ProcessDropItem(msgText.Replace(textCMD[0], "").Trim());
                    break;
                }

                await _telegram.SendTextMessageAsync(_chatid, telegramAnswer, replyMarkup : new ReplyKeyboardHide()).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                Logger.Debug(ex.ToString());
                var apiRequestException = ex as ApiRequestException;
                if (apiRequestException != null)
                {
                    await _telegram.SendTextMessageAsync(_chatid, apiRequestException.Message, replyMarkup : new ReplyKeyboardHide()).ConfigureAwait(false);
                }
            }
        }
Ejemplo n.º 9
0
 public void Stop()
 {
     botClient.StopReceiving();
 }