mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
65 lines
1.8 KiB
C#
65 lines
1.8 KiB
C#
using BotFramework;
|
|
using BotFramework.Attributes;
|
|
using BotFramework.Enums;
|
|
using Kruzya.TelegramBot.Core.Data;
|
|
using Kruzya.TelegramBot.Core.Service;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using West.TelegramBot.Reputation.Data;
|
|
|
|
namespace West.TelegramBot.Reputation.Handler;
|
|
|
|
public class Debug : BotEventHandler
|
|
{
|
|
private readonly CoreContext _coreContext;
|
|
private readonly ReputationContext _reputationContext;
|
|
private readonly UserService _userService;
|
|
|
|
|
|
public Debug(CoreContext coreContext, ReputationContext reputationContext, UserService userService)
|
|
{
|
|
_coreContext = coreContext;
|
|
_reputationContext = reputationContext;
|
|
_userService = userService;
|
|
}
|
|
|
|
[InChat(InChat.Public)]
|
|
[Command("dbg_migrate", CommandParseMode.Both)]
|
|
public async Task HandleMigrate()
|
|
{
|
|
if (!_userService.IsUserSuper(From))
|
|
{
|
|
return;
|
|
}
|
|
|
|
var reputationValues = _coreContext.UserValues.AsNoTracking()
|
|
.Where(value => value.Name == "reputation").Include(v => v.BotUser);
|
|
|
|
foreach (var reputationValue in reputationValues)
|
|
{
|
|
var value = reputationValue.GetValue<double>();
|
|
if (value == 0D)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var userReputation = new UserReputation
|
|
{
|
|
ChatId = reputationValue.BotUser.ChatId,
|
|
UserId = reputationValue.BotUser.UserId,
|
|
Value = value
|
|
};
|
|
|
|
var repList = _reputationContext.UserReputation;
|
|
if (repList.Contains(userReputation))
|
|
{
|
|
repList.Update(userReputation);
|
|
}
|
|
else
|
|
{
|
|
repList.Add(userReputation);
|
|
}
|
|
}
|
|
|
|
await _reputationContext.SaveChangesAsync();
|
|
}
|
|
} |