private async Task sendFolderContent(String botPath, String dirPath = "") { dirPath = CheckWayError(dirPath); String path = $"{botPath}" + ((dirPath == botPath) ? "" : (dirPath == "" ? "" : $"\\{dirPath}")); FileController file = new FileController($"{path}", sendSymbol, IsWithFiles); file.checkFinalDirectory(); List <String> directories = file.getDirectory(); ButtonsController btns = new ButtonsController(botPath, directories, " \\ ", sendSymbol); InlineKeyboardMarkup buttons = btns.getButtons(isMain: path != botPath, isBack: path != botPath); if (Users[chatID].MessagesForEdit.Where(s => s.Name == "Заголовок").FirstOrDefault() != null) { String text = ((dirPath == "" || dirPath.Contains(botPath)) ? "Выберите папку" : $"{dirPath} \\ <b>(Выберите папку)</b>").Replace("\\", " \\ "); List <ChoisenFile> settings = Users[chatID].MessagesForEdit; ChoisenFile setting = settings.Where(s => s.Name == "Заголовок").FirstOrDefault(); setEditMessage("Заголовок", text); await Bot.EditMessageTextAsync(chatID, setting.Message.MessageId, text, ParseMode.Html, replyMarkup : buttons); return; } dirPath = dirPath.Replace("\\", " \\ "); Message messForEdit = await Bot.SendTextMessageAsync(chatID, "Выберите папку", replyMarkup : buttons); Users[chatID].MessagesForEdit.Add(new ChoisenFile { Name = "Заголовок", Text = dirPath, Message = messForEdit }); }
private async Task WaitFile() { if (FilesUserQueue.ContainsValue(wayNow)) { ChoisenFile MessagesForEdit = Users[chatID].MessagesForEdit.Where(s => s.Name == "Заголовок").FirstOrDefault(); await Bot.EditMessageTextAsync(MessagesForEdit.Message.Chat.Id, MessagesForEdit.Message.MessageId, $"<b>{MessagesForEdit.Text}</b> <i>(Ожидание очереди...)</i>", ParseMode.Html); if (!FilesUserQueue.ContainsKey(chatID)) { FilesUserQueue.Add(chatID, wayNow); } while (true) { KeyValuePair <long, string> user = FilesUserQueue.FirstOrDefault(); if (user.Value == null || user.Key == chatID) { break; } await Task.Delay(300); } return; } if (!FilesUserQueue.ContainsKey(chatID)) { FilesUserQueue.Add(chatID, wayNow); } }
private async Task resetSettings(bool isActionCancel = false) { List <ChoisenFile> delete = Users[chatID].MessagesForDelete; if (delete.Count > 0) { for (int i = 0; i < delete.Count; i++) { await Bot.DeleteMessageAsync(chatID, delete[i].Message.MessageId); } } if (OrderQueue.ContainsKey(chatID) && isActionCancel) { ChoisenFile messForEdit = Users[chatID].MessagesForEdit.Where(e => e.Name == "Заголовок").FirstOrDefault(); await Bot.EditMessageTextAsync(chatID, messForEdit.Message.MessageId, $"{messForEdit.Text} <i>(Транзакция отменена)</i>", ParseMode.Html); await Bot.EditMessageTextAsync(Channel, OrderQueue[chatID].MessageId, $"" + OrderQueue[chatID].Text.Replace("🛒", "❌"), ParseMode.Html); OrderQueue.Remove(chatID); } Users[chatID].MessagesForEdit.Clear(); Users[chatID].MessagesForDelete.Clear(); Users[chatID].wayNow = ""; callback = null; msg = null; msgText = String.Empty; wayNow = ""; }
private void setEditMessage(String Name, String Text, Message message = null) { List <ChoisenFile> msgsForEdit = Users[chatID].MessagesForEdit; ChoisenFile msgForEdit = msgsForEdit.Where(m => m.Name == Name).FirstOrDefault(); var newMsgForEdit = new ChoisenFile { Message = (message == null) ? msgForEdit.Message : message, Text = Text, Name = Name }; if (msgForEdit != null) { Users[chatID].MessagesForEdit[Users[chatID].MessagesForEdit.IndexOf(msgForEdit)] = newMsgForEdit; } else { Users[chatID].MessagesForEdit.Add(newMsgForEdit); } ChoisenFile MessagesForEdit = Users[chatID].MessagesForEdit.Where(s => s.Name == Name).FirstOrDefault(); }
private async Task sendFiles(String Location, bool isPayed) { if (FilesUserQueue.ContainsKey(chatID)) { return; } await WaitFile(); ChoisenFile MessagesForEdit = Users[chatID].MessagesForEdit.Where(s => s.Name == "Заголовок").FirstOrDefault(); if (MessagesForEdit != null) { await Bot.EditMessageTextAsync(MessagesForEdit.Message.Chat.Id, MessagesForEdit.Message.MessageId, $"<b>{MessagesForEdit.Text}</b> <i>(Отправка...)</i>", ParseMode.Html); } String location = Location.Replace(sendSymbol[0], ""); if (location.Contains(sendSymbol[1])) { location = Location.Replace(sendSymbol[1], ""); await new FileController(Bot, chatID, $"{BotDirectory}\\{location}").sendFile(); } else { await new FileController(Bot, chatID, Directory.GetFiles($"{BotDirectory}\\{location}")).sendFiles(); } String Payed = isPayed ? " <i>(Оплачено ✅)</i>" : ""; if (MessagesForEdit != null) { await Bot.EditMessageTextAsync(MessagesForEdit.Message.Chat.Id, MessagesForEdit.Message.MessageId, $"<b>{location.Replace("\\", " \\ ")}</b>{Payed}", ParseMode.Html); } Users[chatID].MessagesForEdit = new List <ChoisenFile>(); wayNow = ""; FilesUserQueue.Remove(chatID); }
private async Task <bool> isSendFile() { String filesLocaton = wayNow; if (filesLocaton.Contains(sendSymbol[0]) || filesLocaton.Contains(sendSymbol[1])) { String newFilesLocaton = filesLocaton.Remove(filesLocaton.Length - 1, 1); filesLocaton = newFilesLocaton.Replace("\\", " \\ "); setEditMessage("Заголовок", filesLocaton); ChoisenFile MessagesForEdit = getEditMessage("Заголовок"); if (filesLocaton.Contains("грн)") && !adminsID.Contains(chatID)) { await Bot.EditMessageTextAsync(MessagesForEdit.Message.Chat.Id, MessagesForEdit.Message.MessageId, $"<b>{MessagesForEdit.Text}</b> <i>(Ожидание транзакции...)</i>", ParseMode.Html); bool isDonated = Users[chatID].isDonated; String filesLocation = MessagesForEdit.Text.Replace(" \\ ", "\\").Replace(sendSymbol[0], ""); string[] splitLocation = filesLocation.Split('\\'); String[] splitPrice = splitLocation[splitLocation.Length - 1].Split(' '); int price = int.Parse((double.Parse(splitPrice[splitPrice.Length - 1].Replace('.', ',').Replace("(", "").Replace("грн)", "")) * 100).ToString()); InlineKeyboardMarkup buttons = new InlineKeyboardMarkup(new[] { new[] { InlineKeyboardButton.WithPayment($"Оплатить"), InlineKeyboardButton.WithCallbackData("Отмена", "Отмена транзакции"), } //new[] { // InlineKeyboardButton.WithCallbackData("Скриншот файла","Скриншот файла"), //}, }); List <LabeledPrice> prices = new List <LabeledPrice>(); prices.Add(new LabeledPrice($"{MessagesForEdit.Text}", price)); if (isDonated) { prices.Add(new LabeledPrice($"Скидка {Discount}%", -(price * Discount / 100))); } Message messForDelete = sendInvoice( $"{MessagesForEdit.Text}", $"Готовое задание по предмету", $"{filesLocation}", prices, "https://lh3.googleusercontent.com/frJofbBD4ZHQQMLs_wcWZSAEckCkdakFQ2j0DbqxYuv_33xjG8zP2-RKXoO7jbyVFZUy-DLR2ekSoBiKgwFZxt1bycOaoJL6Q9XjBoexky30zTKyLht31LbVYNPa-eHmNOk_VQtsVdZabCeJcor9u-oq6Kg1OKJ8G2TQOsdnrj10d7Jvi378Ot5jYTdb_bES_ZbWcScoo3mHddBrebJlxm8vgLHjZ4VAYrKCdPbnYqTN3gxHozhlxQx8ySo_YGZKt_Bn6dzq9b0WAKTl6ahqyrzPGUC3j-4euuGfZLuUuJcFYNiwRDKxZDl5o_rxWJpQjuIhL0hy9F8zuY-cjxK9HySPmi1jpdOchjzyew0O-d-9gXYykCJV_ZH_GjnvCgnuIaxz_WuUa7Ynm2TqdbFuiaVXalPwOrjL3bteaCJLVoB8k-tiKh_15XZm1rMkBRgfu0zZ-YMXLPYNJSDwz4IJd7FmpQ9C6yIzZ6eHtkfNgOwEcjFnZW199sOPqybvvJ9ETVZ-NF7C8kZI1OaQNMA-fmgPyUpyOJICrtZC3WpTO0UhOWyBQC14ju9etfAav9aCygqFH76khQhYa3Qt7xHllO-mByzZTSPqqLc1AbQm6dwk2HnEjpWDHEQQngKuG8tgRBLmy-gg8eWDdAcezn2dl8TFd-wwl8uivo99DEH-hn_skgqi33f0ZYw-NaP3sQ=w976-h406-no?authuser=0", PhotoHeight: 800, PhotoWidth: 1920, ReplyMarkup: buttons ).Result; Message order = await Bot.SendTextMessageAsync( Channel, $"<b>Заказ 🛒</b>\n\n" + $"" + $"🤖 Бот: {BotLink}\n" + $"🆔 Пользователь: @{messForDelete.Chat.Username} ({getUserName(messForDelete.Chat)})\n" + $"📎 Файл: <i>{filesLocation}</i>\n" + $"💳 Сумма: {((double)messForDelete.Invoice.TotalAmount / 100).ToString().Replace(',', '.')} {messForDelete.Invoice.Currency}", ParseMode.Html); if (OrderQueue.ContainsKey(chatID)) { await Bot.DeleteMessageAsync(Channel, OrderQueue[chatID].MessageId); } OrderQueue.Add(chatID, order); Users[chatID].MessagesForDelete.Add(new ChoisenFile { Message = messForDelete, Name = "Оплата" }); return(true); } await Task.Run(async() => { await sendFiles(wayNow, false); }); return(true); } else { return(false); } }
private async Task <bool> isNavigation() { switch (callback.Data) { case "Главная": wayNow = ""; await sendFolderContent(BotDirectory); return(true); case "Назад": await backFolderContent(); return(true); case "Создатель": await sendCreatorInfo(); await resetSettings(true); return(true); case "Предложения": return(true); case "Отмена транзакции": ChoisenFile order = Users[chatID].MessagesForDelete.Where(d => d.Name == "Оплата").FirstOrDefault(); Users[chatID].MessagesForDelete.Remove(order); await Bot.DeleteMessageAsync(chatID, order.Message.MessageId); await resetSettings(true); await sendFolderContent(BotDirectory); return(true); case "btNext": AdminInfoCounter++; if (AdminInfoCounter == Social.Length) { AdminInfoCounter = 0; } await sendCreatorLink(); return(true); case "btBack": AdminInfoCounter--; if (AdminInfoCounter == -1) { AdminInfoCounter = Social.Length - 1; } await sendCreatorLink(); return(true); case "Инфо": await sendCommandInfo(true); return(true); case "Номер": await Bot.SendContactAsync(chatID, "+380936596683", "Дмитрий"); return(true); case "Поддержать": List <List <InlineKeyboardButton> > buttons = new List <List <InlineKeyboardButton> >(); buttons.Add( new List <InlineKeyboardButton>() { new InlineKeyboardButton { Pay = true, Text = "Поддержать" }, new InlineKeyboardButton { Text = "Другой способ оплаты", Url = "https://www.liqpay.ua/ru/checkout/card/i83626385734" } } ); await sendInvoice("Поддержка разработчика", "🍰 На кофе", "Донат", 1000, ReplyMarkup : new InlineKeyboardMarkup(buttons)); await sendInvoice("Поддержка разработчика", "🍰 На тортик", "Донат", 5000, ReplyMarkup : new InlineKeyboardMarkup(buttons)); await sendInvoice("Поддержка разработчика", "🍱 На обед", "Донат", 8000, ReplyMarkup : new InlineKeyboardMarkup(buttons)); await sendInvoice("Поддержка разработчика", "❤️ На спасибо", "Донат", 10000, ReplyMarkup : new InlineKeyboardMarkup(buttons)); return(true); default: return(false); } }