Prechádzať zdrojové kódy

Back to profile button

Tigran 4 rokov pred
rodič
commit
8277caa425

+ 1 - 0
MafiaTelegramBot/Models/Bot.cs

@@ -94,6 +94,7 @@ namespace MafiaTelegramBot.Models
                 new PackInfoQuery(),
                 new PackOpenQuery(),
                 new ShowMyPacksQuery(),
+                new BackToProfileQuery(),
             };
         }
         

+ 30 - 0
MafiaTelegramBot/Models/Inlines/BackToProfileQuery.cs

@@ -0,0 +1,30 @@
+using System;
+using System.Linq;
+using System.Threading.Tasks;
+using MafiaTelegramBot.DataBase.EntityDao;
+using MafiaTelegramBot.Resources;
+using Telegram.Bot.Types;
+
+namespace MafiaTelegramBot.Models.Inlines
+{
+    public class BackToProfileQuery : Query
+    {
+        protected override Callback Name => Callback.BackToProfile;
+        protected override async Task<Message> Execute(Update update)
+        {
+            await DeletePreviousMessage(ChatId, update.CallbackQuery.Message.MessageId);
+            var user = await UserDao.GetPlayerById(UserId);
+            var rolesList = Enum.GetValues(typeof(Roles)).Cast<Roles>().ToList();
+            rolesList.Remove(Roles.None);
+            rolesList.Remove(Roles.All);
+            var allStatsRow = user.Statistics[Roles.All];
+            var message =
+                $"__*{strings.statistics_for} _{user.NickName}_*__\n" +
+                $"{strings.games_count} {allStatsRow.Games}\n" +
+                $"{strings.wins_count} {allStatsRow.Wins}\n" +
+                $"{strings.winrate} {(int)(allStatsRow.GetWinrate()*100)}%\n" +
+                $"{strings.rate} {user.RankNumber}";
+            return await Bot.SendWithMarkdown2(ChatId, message, Keyboard.ProfileKeyboard(UserId));
+        }
+    }
+}

+ 1 - 1
MafiaTelegramBot/Models/Inlines/ShopMenuQuery.cs

@@ -18,7 +18,7 @@ namespace MafiaTelegramBot.Models.Inlines
             return await Bot.Get().SendInvoiceAsync(ChatId, strings.random_role_payment,
                 strings.random_role_description, $"{Payloads.RandomRole}|{UserId}",
                 AppSettings.ProviderToken, Constants.SHOP_CURRENCY, Constants.RANDOM_ROLE_PRICE);*/
-            return await Bot.SendWithMarkdown2(ChatId, strings.work_in_progress);
+            return await Bot.SendWithMarkdown2(ChatId, strings.work_in_progress, Keyboard.BackButton(UserId));
         }
     }
 }

+ 1 - 1
MafiaTelegramBot/Models/Inlines/ShowMyExtendedStatsQuery.cs

@@ -30,7 +30,7 @@ namespace MafiaTelegramBot.Models.Inlines
             {
                 message += strings.no_stats_by_roles;
             }
-            return await Bot.SendWithMarkdown2(ChatId, message);
+            return await Bot.SendWithMarkdown2(ChatId, message, Keyboard.BackButton(UserId));
         }
     }
 }

+ 1 - 1
MafiaTelegramBot/Models/Inlines/ShowMyRolesQuery.cs

@@ -31,7 +31,7 @@ namespace MafiaTelegramBot.Models.Inlines
                 message += AddMessage(tier4, strings.epic);
             if (tier5.Count > 0)
                 message += AddMessage(tier5, strings.legendary);
-            return await Bot.SendWithMarkdown2(ChatId, message);
+            return await Bot.SendWithMarkdown2(ChatId, message, Keyboard.BackButton(UserId));
         }
 
         private string AddMessage(List<Roles> list, string rarity)

+ 2 - 1
MafiaTelegramBot/Resources/Callback.cs

@@ -34,6 +34,7 @@ namespace MafiaTelegramBot.Resources
         Continue,
         PackOpen,
         PackInfo,
-        ShowMyPacks
+        ShowMyPacks,
+        BackToProfile
     }
 }

+ 20 - 1
MafiaTelegramBot/Resources/Keyboard.cs

@@ -161,7 +161,17 @@ namespace MafiaTelegramBot.Resources
 
         public static InlineKeyboardMarkup ChangeNameKeyboard(long userId)
         {
-            return new(InlineKeyboardButton.WithCallbackData(strings.change_name, $"{Callback.ChangeNickName}|{userId}"));
+            return new(new[]
+            {
+                new[]
+                {
+                    InlineKeyboardButton.WithCallbackData(strings.change_name, $"{Callback.ChangeNickName}|{userId}")
+                },
+                new[]
+                {
+                    InlineKeyboardButton.WithCallbackData(strings.back_to_profile, $"{Callback.BackToProfile}|{userId}")
+                }
+            });
         }
 
         public static InlineKeyboardMarkup RoomsKeyboard(List<GameRoom> rooms, long userId, int page)
@@ -364,6 +374,15 @@ namespace MafiaTelegramBot.Resources
             {
                 new[]{ InlineKeyboardButton.WithCallbackData(strings.pack_open, $"{Callback.PackOpen}|{userId}") },
                 new[]{ InlineKeyboardButton.WithCallbackData(strings.pack_info, $"{Callback.PackInfo}|{userId}") },
+                new[] { InlineKeyboardButton.WithCallbackData(strings.back_to_profile, $"{Callback.BackToProfile}|{userId}") }
+            });
+        }
+
+        public static InlineKeyboardMarkup BackButton(long userId)
+        {
+            return new InlineKeyboardMarkup(new[]
+            {
+                InlineKeyboardButton.WithCallbackData(strings.back_to_profile, $"{Callback.BackToProfile}|{userId}")
             });
         }
     }

+ 6 - 0
MafiaTelegramBot/Resources/strings.Designer.cs

@@ -1502,5 +1502,11 @@ namespace MafiaTelegramBot {
                 return ResourceManager.GetString("rarity", resourceCulture);
             }
         }
+        
+        internal static string back_to_profile {
+            get {
+                return ResourceManager.GetString("back_to_profile", resourceCulture);
+            }
+        }
     }
 }

+ 3 - 0
MafiaTelegramBot/Resources/strings.resx

@@ -747,4 +747,7 @@
     <data name="rarity" xml:space="preserve">
         <value>Редкость</value>
     </data>
+    <data name="back_to_profile" xml:space="preserve">
+        <value>&lt;- назад</value>
+    </data>
 </root>