Пример #1
0
        public static async void Command_SearchForMusic(ITelegramBotClient telegramBot, long cid)
        {
            #region SearchAreaSession
            if (SearchArea.All(x => x.chatId != cid))
            {
                Console.WriteLine("For someone in ChatId " + cid + " new session has been created");
                SearchArea.Add(new _SearchArea(1, cid));
            }
            else
            {
                SearchArea.Single(x => x.chatId == cid).area = 1;
            }
            #endregion

            #region markup settings
            Markup.ResizeKeyboard = true;
            Markup.Keyboard       = new[]
            {
                new[]
                {
                    new KeyboardButton(SearchForMusic),
                    new KeyboardButton(Back)
                }
            };
            #endregion

            await telegramBot.SendTextMessageAsync(cid, "Enter song name, sir! 🎵",
                                                   ParseMode.Default, false, false, 0, Markup);
        }
Пример #2
0
        public static async void Command_Back(ITelegramBotClient telegramBot, long cid)
        {
            #region SearchAreaSession
            if (SearchArea.All(x => x.chatId != cid))
            {
                Console.WriteLine("For someone in ChatId " + cid + " new session has been created");
                SearchArea.Add(new _SearchArea(0, cid));
            }
            else
            {
                SearchArea.Single(x => x.chatId == cid).area = 0;
            }
            #endregion

            #region markup settings
            Markup.ResizeKeyboard = true;
            Markup.Keyboard       = new[]
            {
                new[]
                {
                    new KeyboardButton(SearchForMusic),
                    new KeyboardButton(SearchForAlbums)
                },
                new[]
                {
                    new KeyboardButton(SearchForArtists),
                    new KeyboardButton(GetRandomMusic)
                }
            };
            #endregion

            await telegramBot.SendTextMessageAsync(cid, "I'm ready to serve you 😉",
                                                   ParseMode.Default, false, false, 0, Markup);
        }
Пример #3
0
        public static async void Response_Album(ITelegramBotClient telegramBot, long cid, string extension)
        {
            try
            {
                await telegramBot.SendTextMessageAsync
                    (cid, "Wait a bit, we're doing some magic ✨🔮");

                var albums = JsonConvert.DeserializeObject <List <Album> >
                                 (new WebClient().DownloadString(BaseLink + "albums"));

                var fittingAlbums = albums
                                    .Where(a => a.name.ToLower().Contains(extension.ToLower()))
                                    .ToList();

                var botResponse = new List <string>();

                foreach (var fittingAlbum in fittingAlbums)
                {
                    botResponse.Add($"Album Name: {fittingAlbum.name}\n" +
                                    $"Genre: {fittingAlbum.genre}\n" +
                                    $"Date of Release: {fittingAlbum.releaseDate}\n" +
                                    $"Description: {fittingAlbum.description}\n" +
                                    $"Artist Name: {fittingAlbum.artist.nickName}\n" +
                                    $"{fittingAlbum.albumCoverUrl}\n");
                }

                if (botResponse.Count > 0)
                {
                    var paginationNumeric = "<b>[1/" + fittingAlbums.Count + "] </b>";

                    var respondMsg = await telegramBot.SendTextMessageAsync(cid, paginationNumeric + botResponse[0],
                                                                            ParseMode.Html, false, false, 0, Inline);

                    Program.paginationHistory.AddInList(new HistoryObject(respondMsg.Chat.Id, respondMsg.MessageId, botResponse));
                }
                else
                {
                    await telegramBot.SendTextMessageAsync
                        (cid, "Sorry, we didn't find at least one album with such name in our database 😱");
                }

                #region SearchAreaSession
                if (SearchArea.All(x => x.chatId != cid))
                {
                    Console.WriteLine("For someone in ChatId " + cid + " new session has been created");
                    SearchArea.Add(new _SearchArea(0, cid));
                }
                else
                {
                    SearchArea.Single(x => x.chatId == cid).area = 0;
                }
                #endregion
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: ({0}) - {1}", DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString(), e.Message);

                await telegramBot.SendTextMessageAsync
                    (cid, "Something went wrong, please, try again later 😔");
            }
        }
Пример #4
0
        public static async void Response_RandomMusic(TelegramBotClient telegramBot, long cid, string extension)
        {
            try
            {
                await telegramBot.SendTextMessageAsync
                    (cid, "Wait a bit, we're doing some magic ✨🔮");

                var songs = JsonConvert.DeserializeObject <List <Song> >
                                (new WebClient().DownloadString(BaseLink + "songs"));

                var fittingSongs = songs
                                   .Where(a => a.album.genre.ToLower().Contains(extension.ToLower()))
                                   .ToList();

                fittingSongs = Randomize(fittingSongs);

                var botResponse = new List <string>();

                foreach (var fittingSong in fittingSongs)
                {
                    var youTubeLink = new WebClient().DownloadString(BaseLink + "songs/" + fittingSong.id + "/youtube").Trim('"');

                    var album = JsonConvert.DeserializeObject <Album>
                                    (new WebClient().DownloadString(BaseLink + "albums/" + fittingSong.album.id));

                    var artist = JsonConvert.DeserializeObject <Artist>
                                     (new WebClient().DownloadString(BaseLink + "artists/" + album.artist.id));

                    botResponse.Add($"{artist.nickName} - {fittingSong.name}\n" +
                                    $"({youTubeLink})");
                }

                if (botResponse.Count > 0)
                {
                    var paginationNumeric = "<b>[1/" + fittingSongs.Count + "] </b>";

                    var respondMsg = await telegramBot.SendTextMessageAsync(cid, paginationNumeric + botResponse[0],
                                                                            ParseMode.Html, false, false, 0, Inline);

                    Program.paginationHistory.AddInList(new HistoryObject(respondMsg.Chat.Id, respondMsg.MessageId, botResponse));
                }
                else
                {
                    await telegramBot.SendTextMessageAsync
                        (cid, "Sorry, we didn't such music genre in our database 😱");
                }

                #region SearchAreaSession
                if (SearchArea.All(x => x.chatId != cid))
                {
                    Console.WriteLine("For someone in ChatId " + cid + " new session has been created");
                    SearchArea.Add(new _SearchArea(0, cid));
                }
                else
                {
                    SearchArea.Single(x => x.chatId == cid).area = 0;
                }
                #endregion
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: ({0}) - {1}", DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString(), e.Message);
                await telegramBot.SendTextMessageAsync
                    (cid, "Something went wrong, please, try again later 😔");
            }
        }