diff --git a/Core/Program.cs b/Core/Program.cs index 9af553b..e8900aa 100644 --- a/Core/Program.cs +++ b/Core/Program.cs @@ -8,8 +8,7 @@ namespace Kruzya.TelegramBot.Core { public static void Main(string[] args) { - CultureInfo.CurrentCulture = new CultureInfo("ru-RU"); - + CultureInfo.CurrentCulture = new CultureInfo("en-US"); CreateHostBuilder(args).Build().Run(); } diff --git a/modules/ChatManagement/Handler/Reputation.cs b/modules/ChatManagement/Handler/Reputation.cs index dc8b34c..84bbece 100644 --- a/modules/ChatManagement/Handler/Reputation.cs +++ b/modules/ChatManagement/Handler/Reputation.cs @@ -1,5 +1,6 @@ #nullable enable +using System; using System.Collections.Generic; using System.Threading.Tasks; using BotFramework.Attributes; @@ -8,7 +9,6 @@ using BotFramework.Utils; using Kruzya.TelegramBot.Core.Data; using Kruzya.TelegramBot.Core.Extensions; using Kruzya.TelegramBot.Core.Service; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using Telegram.Bot; using Telegram.Bot.Types; @@ -84,32 +84,43 @@ namespace West.TelegramBot.ChatManagement.Handler if (canChangeRep && (RepUpChars.Contains(text) || RepDownChars.Contains(text))) { - var repOption = await GetReputationOption(receiver!); - var repCount = repOption.GetValue(); + var receiverRepOption = await GetReputationOption(receiver!); + var receiverRepCount = receiverRepOption.GetValue(); + var senderRepCount = (await GetReputationOption(From)).GetValue(); + + if (senderRepCount < 0) + { + await Reply(new HtmlString() + .Code("Ты не можешь голосовать с отрицательной репутацией.") + .ToString() + ); + return; + } + + var diff = Math.Round(senderRepCount == 0 ? 1 : Math.Sqrt(senderRepCount), 2); string action; - if (RepUpChars.Contains(text)) { - repCount++; + receiverRepCount += diff; action = "увеличил"; } else { - repCount--; + receiverRepCount -= diff; action = "уменьшил"; } - repOption.SetValue(repCount); - Db.MarkAsModified(repOption); + receiverRepOption.SetValue(receiverRepCount); + Db.MarkAsModified(receiverRepOption); await Reply($"{From.ToHtml()}({await GetUserReputation(From)}) " + - $"{action} репутацию {receiver.ToHtml()}({repCount})"); + $"{action} репутацию {receiver.ToHtml()}({Math.Round(receiverRepCount, 2)})"); } } [ParametrizedCommand(InChat.Public, "setrep", CommandParseMode.Both)] - public async Task HandleSetRep(int reputation) + public async Task HandleSetRep(double reputation) { if (!_userService.IsUserSuper(From)) { @@ -122,6 +133,7 @@ namespace West.TelegramBot.ChatManagement.Handler return; } + reputation = Math.Round(reputation, 2); var opt = await GetReputationOption(RepliedUser); opt.SetValue(reputation); Db.MarkAsModified(opt); @@ -134,11 +146,10 @@ namespace West.TelegramBot.ChatManagement.Handler .ToString() ); } - - - private async Task GetUserReputation(User user) + + private async Task GetUserReputation(User user) { - return (await GetReputationOption(user)).GetValue(); + return Math.Round((await GetReputationOption(user)).GetValue(), 2); } private async Task GetReputationOption(User user)