コード例 #1
0
ファイル: Gator.cs プロジェクト: Trikos/D2TelegramBot
        private async void BotOnCallbackQueryReceived(object sender, CallbackQueryEventArgs callbackQueryEventArgs)
        {
            var    callbackQuery = callbackQueryEventArgs.CallbackQuery;
            string currentTimer  = "Current timer: ";

            // When Click on Inline Keyboard this method will get call
            switch (callbackQuery.Data)
            {
            //TODO Fix start and stop for different cd keys
            case "/stopbot":
                //InitializeBotShutdownProcedure();
                Console.WriteLine("Bot Shutdown");
                break;

            case "/startbot":
                Console.WriteLine("Bot Starting...");
                //InitializeBotResumeProcedure();
                Console.WriteLine("Bot Started");
                break;

            case "/time":
                await bot.EditMessageTextAsync(
                    callbackQuery.Message.Chat.Id,
                    callbackQuery.Message.MessageId,
                    "Choose how often to receive updates (minutes)",
                    replyMarkup : keyboards.TimeIK());

                break;

            case "/5min":
                seconds *= 5;
                await bot.AnswerCallbackQueryAsync(callbackQuery.Id, $"5 minutes set", true);

                Console.WriteLine(currentTimer + seconds);
                break;

            case "/10min":
                seconds *= 10;
                await bot.AnswerCallbackQueryAsync(callbackQuery.Id, $"10 minutes set", true);

                Console.WriteLine(currentTimer + seconds);
                break;

            case "/15min":
                seconds *= 15;
                await bot.AnswerCallbackQueryAsync(callbackQuery.Id, $"15 minutes set", true);

                Console.WriteLine(currentTimer + seconds);
                break;

            case "/20min":
                seconds *= 20;
                await bot.AnswerCallbackQueryAsync(callbackQuery.Id, $"20 minutes set", true);

                Console.WriteLine(currentTimer + seconds);
                break;

            case "/30min":
                seconds *= 30;
                await bot.AnswerCallbackQueryAsync(callbackQuery.Id, $"30 minutes set", true);

                Console.WriteLine(currentTimer + seconds);
                break;

            case "/60min":
                seconds *= 60;
                await bot.AnswerCallbackQueryAsync(callbackQuery.Id, $"60 minutes set", true);

                Console.WriteLine(currentTimer + seconds);
                break;

            case "/options":
                //await bot.EditMessageReplyMarkupAsync(
                //    callbackQuery.Message.Chat.Id,
                //    callbackQuery.Message.MessageId,
                //    keyboards.OptionsIK());
                await bot.EditMessageTextAsync(
                    callbackQuery.Message.Chat.Id,
                    callbackQuery.Message.MessageId,
                    "Options menu",
                    replyMarkup : keyboards.OptionsIK());

                break;

            case "/clearconsole":
                Console.Clear();
                Console.WriteLine("Running...");
                await bot.AnswerCallbackQueryAsync(callbackQuery.Id, $"WIN PROMPT CLEARED");

                break;

            case "/screenshot":
                //TODO Bot will send a screen of your desktop
                //Could be not safe so im not sure If I will implement it
                break;

            case "/mainmenu":
                await bot.EditMessageTextAsync(
                    callbackQuery.Message.Chat.Id,
                    callbackQuery.Message.MessageId,
                    "Main Menu",
                    replyMarkup : keyboards.MainMenuIK());

                break;

            case "/difficulty":
                NotImplementedYet(callbackQuery);
                break;

            case "/realm":
                NotImplementedYet(callbackQuery);
                break;

            case "/gameinfo":
                NotImplementedYet(callbackQuery);
                break;

            case "/param":
                NotImplementedYet(callbackQuery);
                break;

            case "/entryscript":
                NotImplementedYet(callbackQuery);
                break;

            case "/character":
                NotImplementedYet(callbackQuery);
                break;

            case "/status":
                Console.WriteLine("Button Bot Status pressed, reading status now...");
                diabloChecker.ReadStatus();
                Console.WriteLine("Editing message with new keyboard with status updated");
                await bot.EditMessageTextAsync(
                    callbackQuery.Message.Chat.Id,
                    callbackQuery.Message.MessageId,
                    "*STATUS*",
                    parseMode : ParseMode.Markdown,
                    replyMarkup : keyboards.BotStatusIK(diabloChecker.botStatus));

                break;

            default:
                data.UserChatId = callbackQuery.From.Id;
                await bot.AnswerCallbackQueryAsync(callbackQuery.Id, $"NO COMMAND FOUND");

                break;
            }
        }
コード例 #2
0
ファイル: Gator.cs プロジェクト: Trikos/D2TelegramBot
        private void Update()
        {
            diabloChecker = new DiabloChecker(data);
            Dictionary <string, long> levels = GetAllLevels();

            //Get number of picked up objects lines
            int currentLine = File.ReadLines(data.PathToItemLog).Count();

            //Get number of picked up objects images
            int fileInFolder = Directory.GetFiles(data.PathImages).Length;

            //Start Task and every minutes read and update the status
            Task task = new Task(async() =>
            {
                //Leggo stato prima volta per inizializzare
                diabloChecker.ReadStatus();
                //Loop for item, exp, death
                while (true)
                {
                    //Controllo se ci sono aggiornamenti
                    Tuple <string, bool> WasUpdated = diabloChecker.IsUpdated();
                    if (WasUpdated.Item2)
                    {
                        switch (WasUpdated.Item1)
                        {
                        case "EXP":
                            Experience(diabloChecker, levels);
                            break;

                        case "DEATH":
                            Death(diabloChecker);
                            break;

                        case "LVLUP":
                            LevelUp(diabloChecker);
                            break;
                        }
                    }
                    int readLine = File.ReadLines(data.PathToItemLog).Count();
                    //Se si son aggiunte righe
                    if (currentLine < readLine)
                    {
                        currentLine     = readLine;
                        string lastLine = File.ReadLines(data.PathToItemLog).Last();
                        string message  = "I picked an object:\n" + lastLine;
                        //Invio il messaggio assieme alla foto usando il bot
                        await bot.SendTextMessageAsync(data.UserChatId, message);

                        var directory = new DirectoryInfo(data.PathImages);
                        //var myFile = (from f in directory.GetFiles() orderby f.LastWriteTime descending select f).First();
                        var myFile       = directory.GetFiles().OrderByDescending(f => f.LastWriteTime).First();
                        string imagePath = myFile.Directory.ToString() + "\\" + myFile.ToString();

                        //Send image of object found
                        using (Stream stream = System.IO.File.OpenRead(imagePath))
                        {
                            if (stream != null && stream.Length > 0)
                            {
                                await bot.SendPhotoAsync(
                                    chatId: data.UserChatId,
                                    photo: stream
                                    );
                            }
                            else
                            {
                                await bot.SendTextMessageAsync(data.UserChatId, "Corrupted image");
                            }
                        }
                        Console.WriteLine("Item Drop/Pick");
                    }
                    else if (currentLine > readLine)
                    {
                        currentLine = readLine;
                    }
                    Thread.Sleep(seconds);
                    Console.WriteLine("Current timer: " + seconds);
                }
            });

            task.Start();
            Console.Clear();
            Console.WriteLine("Running...");
            Console.ReadLine();
        }