diff --git a/modules/Reputation/Reputation.cs b/modules/Reputation/Reputation.cs index 5ef8769..c2ad89b 100644 --- a/modules/Reputation/Reputation.cs +++ b/modules/Reputation/Reputation.cs @@ -1,5 +1,5 @@ using Kruzya.TelegramBot.Core; -using Kruzya.TelegramBot.Core.Options; +using Kruzya.TelegramBot.Core.Extensions; using Kruzya.TelegramBot.Core.Service; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; @@ -21,7 +21,7 @@ public class Reputation : Module var dsn = Configuration.GetConnectionString("Reputation"); services.AddDbContext(options => options.UseMySql(dsn, ServerVersion.AutoDetect(dsn))); + services.AddOption(); services.AddScoped(); - services.AddScoped(); } } \ No newline at end of file diff --git a/modules/Reputation/Service/ReputationService.cs b/modules/Reputation/Service/ReputationService.cs index 2a3c667..1169cf0 100644 --- a/modules/Reputation/Service/ReputationService.cs +++ b/modules/Reputation/Service/ReputationService.cs @@ -4,16 +4,19 @@ using Kruzya.TelegramBot.Core.Service; using Microsoft.EntityFrameworkCore; using Telegram.Bot.Types; using West.TelegramBot.Reputation.Data; +using West.TelegramBot.Reputation.Options; namespace West.TelegramBot.Reputation.Service; public class ReputationService : IReputation { private readonly ReputationContext _reputationContext; + private readonly KarmaMode _karmaMode; - public ReputationService(ReputationContext reputationContext) + public ReputationService(ReputationContext reputationContext, KarmaMode karmaMode) { _reputationContext = reputationContext; + _karmaMode = karmaMode; } public async Task GetUserReputationAsync(Chat chat, User user) @@ -45,14 +48,25 @@ public class ReputationService : IReputation public async Task GetReputationDiffAsync(Chat chat, User sender, User receiver) { var senderRep = await FindUserReputation(chat, sender); - if (senderRep == null) { return 1; } - + + var karmaMode = await _karmaMode.GetValueAsync(chat.Id); var senderValue = senderRep.Value; - return Math.Round(senderValue == 0 ? 1 : Math.Sqrt(senderValue), 2); + + double diff; + if (senderValue == 0 || karmaMode == "linear") + { + diff = 1; + } + else + { + diff = Math.Round(Math.Sqrt(senderValue), 2); + } + + return diff; } public async Task> GetChatRatingAsync(Chat chat, int limit = 10, int offset = 0)