mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
Merge branch 'feature/antiflood' into dev
This commit is contained in:
@@ -19,6 +19,7 @@ public class Reputation : CommonHandler
|
||||
private readonly UserService _userService;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IReputation _reputationService;
|
||||
private readonly IAntiFlood _antiFlood;
|
||||
|
||||
private static readonly List<string> RepUpChars = new()
|
||||
{
|
||||
@@ -45,10 +46,12 @@ public class Reputation : CommonHandler
|
||||
CoreContext db,
|
||||
UserService userService,
|
||||
IReputation reputationService,
|
||||
IAntiFlood antiFlood,
|
||||
ILogger<Reputation> logger) : base(db)
|
||||
{
|
||||
_reputationService = reputationService;
|
||||
_userService = userService;
|
||||
_antiFlood = antiFlood;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
@@ -56,7 +59,7 @@ public class Reputation : CommonHandler
|
||||
public async Task HandleReputation()
|
||||
{
|
||||
var text = Message?.Text;
|
||||
|
||||
|
||||
if (string.IsNullOrEmpty(text))
|
||||
{
|
||||
text = Message?.Sticker?.Emoji;
|
||||
@@ -65,14 +68,23 @@ public class Reputation : CommonHandler
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var receiver = RepliedUser;
|
||||
var canChangeRep = receiver is { IsBot: false } && !From.IsBot && receiver.Id != From.Id;
|
||||
|
||||
if (canChangeRep && (RepUpChars.Contains(text) || RepDownChars.Contains(text)))
|
||||
{
|
||||
var senderRepCount = await GetUserReputation(From);
|
||||
if (!_userService.IsUserSuper(From))
|
||||
{
|
||||
if (_antiFlood.IsUserFlooding(Chat, From))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_antiFlood.RecordAction(Chat, From);
|
||||
}
|
||||
|
||||
var senderRepCount = await GetUserReputation(From);
|
||||
if (senderRepCount < 0)
|
||||
{
|
||||
await Reply(new HtmlString()
|
||||
@@ -143,7 +155,7 @@ public class Reputation : CommonHandler
|
||||
i++;
|
||||
}
|
||||
|
||||
await Bot.SendTextMessageAsync(Chat, msg.ToString(), ParseMode.Html,
|
||||
await Bot.SendTextMessageAsync(Chat!, msg.ToString(), ParseMode.Html,
|
||||
disableNotification: true);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user