mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
Change reputation counting algo.
This commit is contained in:
+1
-2
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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<int>();
|
||||
var receiverRepOption = await GetReputationOption(receiver!);
|
||||
var receiverRepCount = receiverRepOption.GetValue<double>();
|
||||
var senderRepCount = (await GetReputationOption(From)).GetValue<double>();
|
||||
|
||||
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()}<code>({await GetUserReputation(From)}) " +
|
||||
$"{action} репутацию </code>{receiver.ToHtml()}<code>({repCount})</code>");
|
||||
$"{action} репутацию </code>{receiver.ToHtml()}<code>({Math.Round(receiverRepCount, 2)})</code>");
|
||||
}
|
||||
}
|
||||
|
||||
[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);
|
||||
@@ -135,10 +147,9 @@ namespace West.TelegramBot.ChatManagement.Handler
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
private async Task<int> GetUserReputation(User user)
|
||||
private async Task<double> GetUserReputation(User user)
|
||||
{
|
||||
return (await GetReputationOption(user)).GetValue<int>();
|
||||
return Math.Round((await GetReputationOption(user)).GetValue<double>(), 2);
|
||||
}
|
||||
|
||||
private async Task<BotUserValue> GetReputationOption(User user)
|
||||
|
||||
Reference in New Issue
Block a user