mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
[reputation] KarmaMode now actually changes smth
This commit is contained in:
@@ -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<double> GetUserReputationAsync(Chat chat, User user)
|
||||
@@ -45,14 +48,25 @@ public class ReputationService : IReputation
|
||||
public async Task<double> 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<IEnumerable<IReputationEntity>> GetChatRatingAsync(Chat chat, int limit = 10, int offset = 0)
|
||||
|
||||
Reference in New Issue
Block a user