mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
4f89be554a
Co-authored-by: Frolish <lonkura.zip@gmail.com>
41 lines
1.2 KiB
C#
41 lines
1.2 KiB
C#
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;
|
|
|
|
namespace West.Entertainment;
|
|
|
|
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;
|
|
}
|
|
|
|
var newRep = new Random().Next(0, 50);
|
|
|
|
await Reply($"Вы получили {newRep} кармы.");
|
|
await _reputation.IncrementReputationAsync(Chat, From, newRep);
|
|
|
|
cdOption.SetValue(DateTime.Now.AddHours(1));
|
|
Db.AddOrUpdate(cdOption);
|
|
}
|
|
|
|
public Roll(CoreContext db, IReputation reputation) : base(db)
|
|
{
|
|
_reputation = reputation;
|
|
}
|
|
} |