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:
@@ -1,5 +1,5 @@
|
|||||||
using Kruzya.TelegramBot.Core;
|
using Kruzya.TelegramBot.Core;
|
||||||
using Kruzya.TelegramBot.Core.Options;
|
using Kruzya.TelegramBot.Core.Extensions;
|
||||||
using Kruzya.TelegramBot.Core.Service;
|
using Kruzya.TelegramBot.Core.Service;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
@@ -21,7 +21,7 @@ public class Reputation : Module
|
|||||||
var dsn = Configuration.GetConnectionString("Reputation");
|
var dsn = Configuration.GetConnectionString("Reputation");
|
||||||
services.AddDbContext<ReputationContext>(options => options.UseMySql(dsn, ServerVersion.AutoDetect(dsn)));
|
services.AddDbContext<ReputationContext>(options => options.UseMySql(dsn, ServerVersion.AutoDetect(dsn)));
|
||||||
|
|
||||||
|
services.AddOption<KarmaMode>();
|
||||||
services.AddScoped<IReputation, ReputationService>();
|
services.AddScoped<IReputation, ReputationService>();
|
||||||
services.AddScoped<IOption, KarmaMode>();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,16 +4,19 @@ using Kruzya.TelegramBot.Core.Service;
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using West.TelegramBot.Reputation.Data;
|
using West.TelegramBot.Reputation.Data;
|
||||||
|
using West.TelegramBot.Reputation.Options;
|
||||||
|
|
||||||
namespace West.TelegramBot.Reputation.Service;
|
namespace West.TelegramBot.Reputation.Service;
|
||||||
|
|
||||||
public class ReputationService : IReputation
|
public class ReputationService : IReputation
|
||||||
{
|
{
|
||||||
private readonly ReputationContext _reputationContext;
|
private readonly ReputationContext _reputationContext;
|
||||||
|
private readonly KarmaMode _karmaMode;
|
||||||
|
|
||||||
public ReputationService(ReputationContext reputationContext)
|
public ReputationService(ReputationContext reputationContext, KarmaMode karmaMode)
|
||||||
{
|
{
|
||||||
_reputationContext = reputationContext;
|
_reputationContext = reputationContext;
|
||||||
|
_karmaMode = karmaMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<double> GetUserReputationAsync(Chat chat, User user)
|
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)
|
public async Task<double> GetReputationDiffAsync(Chat chat, User sender, User receiver)
|
||||||
{
|
{
|
||||||
var senderRep = await FindUserReputation(chat, sender);
|
var senderRep = await FindUserReputation(chat, sender);
|
||||||
|
|
||||||
if (senderRep == null)
|
if (senderRep == null)
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var karmaMode = await _karmaMode.GetValueAsync(chat.Id);
|
||||||
var senderValue = senderRep.Value;
|
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)
|
public async Task<IEnumerable<IReputationEntity>> GetChatRatingAsync(Chat chat, int limit = 10, int offset = 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user