[reputation] /addrep command

This commit is contained in:
West14
2022-04-23 21:42:17 +03:00
parent 634695d0d8
commit 4accf36ffa
3 changed files with 41 additions and 17 deletions
+38 -14
View File
@@ -128,27 +128,29 @@ public class Reputation : CommonHandler
[ParametrizedCommand(InChat.Public, "setrep", CommandParseMode.Both)]
public async Task HandleSetRep(double reputation)
{
if (!_userService.IsUserSuper(From))
{
_logger.LogInformation("{User} attempted to call /setrep in {Chat}", From, Chat.Title);
return;
}
if (RepliedUser == null || RepliedUser.IsBot)
if (!CanModifyUserReputation(RepliedUser))
{
return;
}
reputation = await _reputationService.SetUserReputationAsync(Chat, RepliedUser, reputation);
await Reply(
new HtmlString()
.Code("Пользователю ")
.UserMention(RepliedUser)
.Code($" установлена репутация: {reputation}")
.ToString()
await SendReputationModifyResponse(
await _reputationService.SetUserReputationAsync(Chat, RepliedUser, reputation)
);
}
[ParametrizedCommand(InChat.Public, "addrep", CommandParseMode.Both)]
public async Task HandleAddRep(double reputation)
{
if (!CanModifyUserReputation(RepliedUser))
{
return;
}
await SendReputationModifyResponse(
await _reputationService.IncrementReputationAsync(Chat, RepliedUser, reputation)
);
}
[Command(InChat.Public, "top", CommandParseMode.Both)]
public async Task HandleTop()
{
@@ -166,6 +168,28 @@ public class Reputation : CommonHandler
disableNotification: true);
}
private async Task SendReputationModifyResponse(double reputation)
{
await Reply(
new HtmlString()
.Code("Пользователю ")
.UserMention(RepliedUser)
.Code($" установлена репутация: {reputation}")
.ToString()
);
}
private bool CanModifyUserReputation(User? user)
{
if (!_userService.IsUserSuper(From))
{
_logger.LogInformation("{User} attempted to modify someones reputation in {Chat}", From, Chat.Title);
return false;
}
return user is {IsBot: false};
}
private async Task<double> GetUserReputation(User user)
{
return await _reputationService.GetUserReputationAsync(Chat, user);