2022-12-14 11:40:27 +02:00
|
|
|
using BotFramework.Attributes;
|
|
|
|
|
using BotFramework.Enums;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System;
|
|
|
|
|
using Kruzya.TelegramBot.Core;
|
|
|
|
|
using Kruzya.TelegramBot.Core.Data;
|
|
|
|
|
using Kruzya.TelegramBot.Core.Extensions;
|
|
|
|
|
using Kruzya.TelegramBot.Core.Service;
|
|
|
|
|
|
2022-12-14 11:50:02 +02:00
|
|
|
namespace West.Entertainment.Handler;
|
2022-12-14 11:40:27 +02:00
|
|
|
|
|
|
|
|
public class Roll : CommonHandler
|
|
|
|
|
{
|
|
|
|
|
private readonly IReputation _reputation;
|
|
|
|
|
|
|
|
|
|
[Command(InChat.Public, "roll", CommandParseMode.Both)]
|
|
|
|
|
public async Task HandleRoll()
|
|
|
|
|
{
|
|
|
|
|
var cdOption = await Db.UserValues.FindOrCreateOption(Chat.Id, From.Id, "rollNextUse");
|
|
|
|
|
var cd = cdOption.GetValue<DateTime>();
|
|
|
|
|
|
|
|
|
|
if (cd > DateTime.Now)
|
|
|
|
|
{
|
|
|
|
|
await Reply($"Следующее использование через {cd - DateTime.Now:hh\\:mm\\:ss}.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-14 11:50:02 +02:00
|
|
|
var newRep = new Random().Next(-50, 50);
|
2022-12-14 11:40:27 +02:00
|
|
|
|
|
|
|
|
await Reply($"Вы получили {newRep} кармы.");
|
|
|
|
|
await _reputation.IncrementReputationAsync(Chat, From, newRep);
|
|
|
|
|
|
2022-12-14 11:50:02 +02:00
|
|
|
cdOption.SetValue(DateTime.Now.AddDays(1));
|
2022-12-14 11:40:27 +02:00
|
|
|
Db.AddOrUpdate(cdOption);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Roll(CoreContext db, IReputation reputation) : base(db)
|
|
|
|
|
{
|
|
|
|
|
_reputation = reputation;
|
|
|
|
|
}
|
|
|
|
|
}
|