فهرست منبع

Change sticker message to text message on choosing result

Tigran 4 سال پیش
والد
کامیت
35c06803ee

+ 1 - 1
CardCollector.sln.DotSettings.user

@@ -7,6 +7,6 @@
 	
 	<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=CardCollector_002FResources_002FMessages/@EntryIndexedValue">True</s:Boolean>
 	<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=CardCollector_002FResources_002FSortingTypes/@EntryIndexedValue">False</s:Boolean>
-	<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=CardCollector_002FResources_002FText/@EntryIndexedValue">False</s:Boolean>
+	<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=CardCollector_002FResources_002FText/@EntryIndexedValue">True</s:Boolean>
 	
 	<s:Boolean x:Key="/Default/ResxEditorPersonal/Initialized/@EntryValue">True</s:Boolean></wpf:ResourceDictionary>

+ 20 - 0
CardCollector/Commands/CallbackQuery/CombineCallback.cs

@@ -0,0 +1,20 @@
+using System.Threading.Tasks;
+using CardCollector.DataBase.Entity;
+using CardCollector.Resources;
+using Telegram.Bot.Types;
+
+namespace CardCollector.Commands.CallbackQuery
+{
+    public class CombineCallback : CallbackQuery
+    {
+        protected override string CommandText => Command.combine;
+        public override async Task Execute()
+        {
+            User.Session.CombineList.Add(User.Session.SelectedSticker);
+            
+        }
+
+        public CombineCallback() { }
+        public CombineCallback(UserEntity user, Update update) : base(user, update) { }
+    }
+}

+ 3 - 5
CardCollector/Commands/ChosenInlineResult/ChosenInlineResult.cs

@@ -50,18 +50,16 @@ namespace CardCollector.Commands.ChosenInlineResult
             
             // Возвращаем объект, если команда совпала
             foreach (var item in List.Where(item => item.IsMatches(command)))
-                if(Activator.CreateInstance(item.GetType(), 
-                    user, update, update.ChosenInlineResult.ResultId) is ChosenInlineResult executor)
+                if(Activator.CreateInstance(item.GetType(), user, update) is ChosenInlineResult executor)
                     if (executor.IsMatches(command)) return executor;
         
             // Возвращаем команда не найдена, если код дошел до сюда
             return new CommandNotFound(user, update, command);
         }
 
-        protected ChosenInlineResult(UserEntity user, Update update, string inlineResult)
-            : base(user, update)
+        protected ChosenInlineResult(UserEntity user, Update update) : base(user, update)
         {
-            InlineResult = inlineResult;
+            InlineResult = update.ChosenInlineResult!.ResultId;
         }
 
         protected ChosenInlineResult() { }

+ 1 - 2
CardCollector/Commands/ChosenInlineResult/GetUnlimitedStickerAndExecuteCommand.cs

@@ -26,8 +26,7 @@ namespace CardCollector.Commands.ChosenInlineResult
         }
         
         public GetUnlimitedStickerAndExecuteCommand() { }
-        public GetUnlimitedStickerAndExecuteCommand(UserEntity user, Update update, string inlineResult)
-            : base(user, update, inlineResult) { }
+        public GetUnlimitedStickerAndExecuteCommand(UserEntity user, Update update) : base(user, update) { }
         
         
         /* Список команд, аналогичный родительскому, только не включает эту команду (unlimited) */

+ 1 - 1
CardCollector/Commands/ChosenInlineResult/SelectStickerInlineResult.cs

@@ -31,6 +31,6 @@ namespace CardCollector.Commands.ChosenInlineResult
         }
 
         public SelectStickerInlineResult() { }
-        public SelectStickerInlineResult(UserEntity user, Update update, string inlineResult) : base(user, update, inlineResult) { }
+        public SelectStickerInlineResult(UserEntity user, Update update) : base(user, update) { }
     }
 }

+ 1 - 1
CardCollector/Commands/ChosenInlineResult/SelectTraderResult.cs

@@ -26,6 +26,6 @@ namespace CardCollector.Commands.ChosenInlineResult
         }
 
         public SelectTraderResult() { }
-        public SelectTraderResult(UserEntity user, Update update, string inlineResult) : base(user, update, inlineResult) { }
+        public SelectTraderResult(UserEntity user, Update update) : base(user, update) { }
     }
 }

+ 1 - 2
CardCollector/Commands/ChosenInlineResult/SendStickerResult.cs

@@ -21,7 +21,6 @@ namespace CardCollector.Commands.ChosenInlineResult
         }
         
         public SendStickerResult() { }
-        public SendStickerResult(UserEntity user, Update update, string inlineResult)
-            : base(user, update, inlineResult) { }
+        public SendStickerResult(UserEntity user, Update update) : base(user, update) { }
     }
 }

+ 3 - 3
CardCollector/Commands/InlineQuery/InlineQuery.cs

@@ -52,16 +52,16 @@ namespace CardCollector.Commands.InlineQuery
             
             // Возвращаем объект, если команда совпала
             foreach (var item in List.Where(item => item.IsMatches(command)))
-                if(Activator.CreateInstance(item.GetType(), user, update, update.InlineQuery.Id) is InlineQuery executor)
+                if(Activator.CreateInstance(item.GetType(), user, update) is InlineQuery executor)
                     if (executor.IsMatches(command)) return executor;
         
             // Возвращаем команда не найдена, если код дошел до сюда
             return new CommandNotFound(user, update, command);
         }
 
-        protected InlineQuery(UserEntity user, Update update, string inlineQueryId) : base(user, update)
+        protected InlineQuery(UserEntity user, Update update) : base(user, update)
         {
-            InlineQueryId = inlineQueryId;
+            InlineQueryId = update.InlineQuery!.Id;
         }
         
         protected InlineQuery() { }

+ 1 - 1
CardCollector/Commands/InlineQuery/ShowAuctionStickers.cs

@@ -31,6 +31,6 @@ namespace CardCollector.Commands.InlineQuery
         }
 
         public ShowAuctionStickers() { }
-        public ShowAuctionStickers(UserEntity user, Update update, string inlineQueryId) : base(user, update, inlineQueryId) { }
+        public ShowAuctionStickers(UserEntity user, Update update) : base(user, update) { }
     }
 }

+ 1 - 1
CardCollector/Commands/InlineQuery/ShowCollectionStickers.cs

@@ -32,6 +32,6 @@ namespace CardCollector.Commands.InlineQuery
         }
 
         public ShowCollectionStickers() { }
-        public ShowCollectionStickers(UserEntity user, Update update, string inlineQueryId) : base(user, update, inlineQueryId) { }
+        public ShowCollectionStickers(UserEntity user, Update update) : base(user, update) { }
     }
 }

+ 1 - 1
CardCollector/Commands/InlineQuery/ShowShopStickers.cs

@@ -31,6 +31,6 @@ namespace CardCollector.Commands.InlineQuery
         }
 
         public ShowShopStickers() { }
-        public ShowShopStickers(UserEntity user, Update update, string inlineQueryId) : base(user, update, inlineQueryId) { }
+        public ShowShopStickers(UserEntity user, Update update) : base(user, update) { }
     }
 }

+ 1 - 1
CardCollector/Commands/InlineQuery/ShowStickersInBotChat.cs

@@ -34,6 +34,6 @@ namespace CardCollector.Commands.InlineQuery
         }
 
         public ShowStickersInBotChat() { }
-        public ShowStickersInBotChat(UserEntity user, Update update, string inlineQueryId) : base(user, update, inlineQueryId) { }
+        public ShowStickersInBotChat(UserEntity user, Update update) : base(user, update) { }
     }
 }

+ 2 - 2
CardCollector/Commands/InlineQuery/ShowStickersInGroup.cs

@@ -19,7 +19,7 @@ namespace CardCollector.Commands.InlineQuery
             var filter = Update.InlineQuery!.Query;
             // Получаем список стикеров
             var stickersList = await User.GetStickersList(filter);
-            var results = stickersList.ToTelegramResults(Command.send_sticker);
+            var results = stickersList.ToTelegramResults(Command.send_sticker, false);
             // Посылаем пользователю ответ на его запрос
             await MessageController.AnswerInlineQuery(InlineQueryId, results);
         }
@@ -32,6 +32,6 @@ namespace CardCollector.Commands.InlineQuery
         }
 
         public ShowStickersInGroup() { }
-        public ShowStickersInGroup(UserEntity user, Update update, string inlineQueryId) : base(user, update, inlineQueryId) { }
+        public ShowStickersInGroup(UserEntity user, Update update) : base(user, update) { }
     }
 }

+ 1 - 1
CardCollector/Commands/InlineQuery/ShowTradersInBotChat.cs

@@ -31,6 +31,6 @@ namespace CardCollector.Commands.InlineQuery
         }
 
         public ShowTradersInBotChat() { }
-        public ShowTradersInBotChat(UserEntity user, Update update, string inlineQueryId) : base(user, update, inlineQueryId) { }
+        public ShowTradersInBotChat(UserEntity user, Update update) : base(user, update) { }
     }
 }

+ 9 - 6
CardCollector/Extensions.cs

@@ -14,14 +14,17 @@ namespace CardCollector
     {
         /* Преобразует список стикеров в список результатов для телеграм */
         public static IEnumerable<InlineQueryResult> ToTelegramResults
-            (this IEnumerable<StickerEntity> list, string command)
+            (this IEnumerable<StickerEntity> list, string command, bool asMessage = true)
         {
             var result = new List<InlineQueryResult>();
             foreach (var item in list)
             {
-                result.Add(new InlineQueryResultCachedSticker(
-                    $"{(Constants.UNLIMITED_ALL_STICKERS ? Command.unlimited_stickers : "")}{command}={item.Md5Hash}",
-                    item.Id));
+                result.Add( asMessage 
+                    ? new InlineQueryResultCachedSticker($"{(Constants.UNLIMITED_ALL_STICKERS ? Command.unlimited_stickers : "")}" +
+                                                         $"{command}={item.Md5Hash}", item.Id) 
+                                                        {InputMessageContent = new InputTextMessageContent(Text.select)}
+                    : new InlineQueryResultCachedSticker($"{(Constants.UNLIMITED_ALL_STICKERS ? Command.unlimited_stickers : "")}" +
+                                                         $"{command}={item.Md5Hash}", item.Id));
                 /* Ограничение Telegram API по количеству результатов в 50 шт. */
                 if (result.Count > 49) return result;
             }
@@ -35,8 +38,8 @@ namespace CardCollector
             foreach (var item in list)
             {
                 result.Add(new InlineQueryResultArticle($"{command}={item.Id}",
-                        $"{item.Username} {item.Quantity}{Text.items}", new InputTextMessageContent("Купить")) 
-                    { Description = $"{item.PriceCoins}{Text.coin}/{item.PriceGems}{Text.gem} {Text.per} 1{Text.items}" });
+                    $"{item.Username} {item.Quantity}{Text.items}", new InputTextMessageContent(Text.buy))
+                { Description = $"{item.PriceCoins}{Text.coin}/{item.PriceGems}{Text.gem} {Text.per} 1{Text.items}" });
                 /* Ограничение Telegram API по количеству результатов в 50 шт. */
                 if (result.Count > 49) return result;
             }

+ 5 - 0
CardCollector/Others/Session.cs

@@ -24,6 +24,10 @@ namespace CardCollector.Others
         
         /* Выбранный пользователем стикер для покупки (продажи, слияния) */
         public StickerInfo SelectedSticker { get; set; }
+        
+        /* Выбранные пользователем стикеры для слияния */
+        public List<StickerInfo> CombineList { get; set; } = new();
+        
 
         public void UpdateLastAccess()
         {
@@ -120,6 +124,7 @@ namespace CardCollector.Others
         {
             await ClearMessages();
             SelectedSticker = null;
+            CombineList.Clear();
         }
         
         public void Dispose()

+ 1 - 1
CardCollector/Resources/Constants.cs

@@ -10,7 +10,7 @@ namespace CardCollector.Resources
         /* Время кэширования результатов @имя_бота команд */
         public const int INLINE_RESULTS_CACHE_TIME = 1;
         /* Включает бесконечные стикеры без наличия их в коллекции */
-        public static readonly bool UNLIMITED_ALL_STICKERS = !DEBUG;
+        public static readonly bool UNLIMITED_ALL_STICKERS = DEBUG;
 
 
         /* Уровни привилегий пользователей системы */

+ 8 - 5
CardCollector/Resources/Keyboard.cs

@@ -195,17 +195,19 @@ namespace CardCollector.Resources
 
         public static InlineKeyboardMarkup GetCollectionStickerKeyboard(StickerInfo stickerInfo)
         {
-            return new InlineKeyboardMarkup(new[] {
+            var keyboard = new List<InlineKeyboardButton[]>
+            {
                 new[] {InlineKeyboardButton.WithSwitchInlineQuery(Text.send_sticker, stickerInfo.Title)},
                 new[] {InlineKeyboardButton.WithCallbackData($"{Text.sell_on_auction} ({stickerInfo.Count})", Command.confirm_selling)},
                 new[]
                 {
                     InlineKeyboardButton.WithCallbackData(Text.minus, $"{Command.count}-"),
                     InlineKeyboardButton.WithCallbackData(Text.plus, $"{Command.count}+"),
-                },
-                new[] {InlineKeyboardButton.WithCallbackData(Text.combine, Command.combine)},
-                new[] {InlineKeyboardButton.WithCallbackData(Text.back, $"{Command.back}={Command.clear_chat}")},
-            });
+                }
+            };
+            if (stickerInfo.Tier != 5) keyboard.Add(new[] {InlineKeyboardButton.WithCallbackData(Text.combine, Command.combine)});
+            keyboard.Add(new[] {InlineKeyboardButton.WithCallbackData(Text.back, $"{Command.back}={Command.clear_chat}")});
+            return new InlineKeyboardMarkup(keyboard);
         }
 
         public static InlineKeyboardMarkup GetAuctionStickerKeyboard()
@@ -262,6 +264,7 @@ namespace CardCollector.Resources
                 UserState.AuctionMenu when session.SelectedSticker.TraderInfo is not null => GetAuctionProductKeyboard(session.SelectedSticker),
                 UserState.AuctionMenu => GetAuctionStickerKeyboard(),
                 UserState.ShopMenu => GetShopStickerKeyboard(session.SelectedSticker),
+                UserState.CollectionMenu when session.CombineList.Count > 0 => GetCollectionStickerKeyboard(session.SelectedSticker),
                 UserState.CollectionMenu => GetCollectionStickerKeyboard(session.SelectedSticker),
                 _ => GetStickerKeyboard(session.SelectedSticker)
             };

+ 9 - 0
CardCollector/Resources/Text.Designer.cs

@@ -330,6 +330,15 @@ namespace CardCollector.Resources {
             }
         }
         
+        /// <summary>
+        ///   Looks up a localized string similar to Выбрать.
+        /// </summary>
+        internal static string select {
+            get {
+                return ResourceManager.GetString("select", resourceCulture);
+            }
+        }
+        
         /// <summary>
         ///   Looks up a localized string similar to Выставить на аукцион.
         /// </summary>

+ 3 - 0
CardCollector/Resources/Text.resx

@@ -147,4 +147,7 @@
     <data name="yes" xml:space="preserve">
         <value>Да</value>
     </data>
+    <data name="select" xml:space="preserve">
+        <value>Выбрать</value>
+    </data>
 </root>