mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
Merge pull request #23 from Bubuni-Team/feature/reputation-roll
[entertainment] roll comes back with improved logging
This commit is contained in:
@@ -17,12 +17,19 @@ public class Roll : CommonHandler
|
|||||||
private readonly IReputation _reputation;
|
private readonly IReputation _reputation;
|
||||||
private readonly UserService _userService;
|
private readonly UserService _userService;
|
||||||
|
|
||||||
// [Command(InChat.Public, "roll", CommandParseMode.Both)]
|
[Command(InChat.Public, "roll", CommandParseMode.Both)]
|
||||||
public async Task HandleRoll()
|
public async Task HandleRoll()
|
||||||
{
|
{
|
||||||
var cdOption = await Db.UserValues.FindOrCreateOption(Chat.Id, From.Id, "rollNextUse");
|
var cdOption = await Db.UserValues.FindOrCreateOption(Chat.Id, From.Id, "rollNextUse");
|
||||||
var cd = cdOption.GetValue<DateTime>();
|
var cd = cdOption.GetValue<DateTime>();
|
||||||
|
|
||||||
|
_logger.LogInformation("[{Datetime}] {User} used /roll in {Chat}. Cooldown is: {Cooldown}",
|
||||||
|
DateTime.Now,
|
||||||
|
From.ToLog(),
|
||||||
|
Chat.ToLog(),
|
||||||
|
cd
|
||||||
|
);
|
||||||
|
|
||||||
if (cd > DateTime.Now)
|
if (cd > DateTime.Now)
|
||||||
{
|
{
|
||||||
await Reply($"Следующее использование через {cd - DateTime.Now:hh\\:mm\\:ss}.");
|
await Reply($"Следующее использование через {cd - DateTime.Now:hh\\:mm\\:ss}.");
|
||||||
@@ -34,11 +41,25 @@ public class Roll : CommonHandler
|
|||||||
await Reply($"Вы получили {newRep} кармы.");
|
await Reply($"Вы получили {newRep} кармы.");
|
||||||
await _reputation.IncrementReputationAsync(Chat, From, newRep);
|
await _reputation.IncrementReputationAsync(Chat, From, newRep);
|
||||||
|
|
||||||
|
_logger.LogInformation("[{Datetime}] Added {Count} reputation to {User} in {Chat} from /roll",
|
||||||
|
DateTime.Now,
|
||||||
|
newRep,
|
||||||
|
From.ToLog(),
|
||||||
|
Chat.ToLog()
|
||||||
|
);
|
||||||
|
|
||||||
cdOption.SetValue(DateTime.Now.AddDays(1));
|
cdOption.SetValue(DateTime.Now.AddDays(1));
|
||||||
Db.AddOrUpdate(cdOption);
|
Db.AddOrUpdate(cdOption);
|
||||||
|
|
||||||
|
_logger.LogInformation("[{Datetime}] Updated /roll cooldown for {User} in {Chat} to {Cooldown}",
|
||||||
|
DateTime.Now,
|
||||||
|
From.ToLog(),
|
||||||
|
Chat.ToLog(),
|
||||||
|
cdOption.GetValue<DateTime>()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// [Command(InChat.Public, "reset_roll", CommandParseMode.Both)]
|
[Command(InChat.Public, "reset_roll", CommandParseMode.Both)]
|
||||||
public async Task HandleResetRoll()
|
public async Task HandleResetRoll()
|
||||||
{
|
{
|
||||||
if (!_userService.IsUserSuper(From))
|
if (!_userService.IsUserSuper(From))
|
||||||
@@ -56,6 +77,7 @@ public class Roll : CommonHandler
|
|||||||
Db.UserValues.RemoveRange(cooldownList);
|
Db.UserValues.RemoveRange(cooldownList);
|
||||||
await Db.SaveChangesAsync();
|
await Db.SaveChangesAsync();
|
||||||
|
|
||||||
|
_logger.LogInformation("/roll cooldowns have been reset for {Chat} by {User}", Chat.ToLog(), From.ToLog());
|
||||||
await Reply($"Кулдаун /roll сброшен для чата \"{Chat.Title}\".");
|
await Reply($"Кулдаун /roll сброшен для чата \"{Chat.Title}\".");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user