Skip to content

Commit

Permalink
Merge pull request #1 from igoose1/improve-admin-flow
Browse files Browse the repository at this point in the history
Improve admin flow
  • Loading branch information
TiraelSedai authored Jun 29, 2024
2 parents 121c779 + d846a19 commit 5a7ed1d
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions ClubDoorman/Worker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ private async Task HandleUpdate(Update update, User me, CancellationToken stoppi
}
if (SimpleFilters.TooManyEmojis(text))
{
const string reason = "В этом сообщени многовато эмоджи";
const string reason = "В этом сообщении многовато эмоджи";
await DeleteAndReportMessage(message, user, reason, stoppingToken);
return;
}
Expand All @@ -165,7 +165,7 @@ private async Task HandleUpdate(Update update, User me, CancellationToken stoppi

if (SimpleFilters.HasStopWords(normalized))
{
const string reason = "В этом сообщени есть стоп-слова";
const string reason = "В этом сообщении есть стоп-слова";
await DeleteAndReportMessage(message, user, reason, stoppingToken);
return;
}
Expand All @@ -186,9 +186,8 @@ private async Task HandleUpdate(Update update, User me, CancellationToken stoppi
if (goodInteractions >= 5)
{
logger.LogInformation(
"User {First} {Last} behaved well for the last {Count} messages, approving",
user.FirstName,
user.LastName,
"User {FullName} behaved well for the last {Count} messages, approving",
FullName(user.FirstName, user.LastName),
goodInteractions
);
await userManager.Approve(user.Id);
Expand Down Expand Up @@ -292,6 +291,11 @@ private async ValueTask IntroFlow(Message message, User user)
_captchaNeededUsers.TryAdd(key, new CaptchaInfo(message, DateTime.UtcNow, user, correctAnswer, cts));
}

private static string FullName(string firstName, string? lastName) =>
string.IsNullOrEmpty(lastName)
? firstName
: $"{firstName} {lastName}";

private async Task HandleAdminCallback(string cbData, CallbackQuery cb)
{
var split = cbData.Split('_').ToList();
Expand All @@ -302,7 +306,7 @@ private async Task HandleAdminCallback(string cbData, CallbackQuery cb)
await _bot.BanChatMemberAsync(new ChatId(chatId), userId);
await _bot.SendTextMessageAsync(
new ChatId(Config.AdminChatId),
$"{cb.From.FirstName} {cb.From.LastName} забанил",
$"{FullName(cb.From.FirstName, cb.From.LastName)} забанил",
replyToMessageId: cb.Message?.MessageId
);
}
Expand Down Expand Up @@ -342,14 +346,24 @@ private async Task DeleteAndReportMessage(Message message, User user, string rea
message.MessageId,
cancellationToken: stoppingToken
);
await _bot.DeleteMessageAsync(message.Chat.Id, message.MessageId, cancellationToken: stoppingToken);
var deletionMessagePart = $"{reason}";
try
{
await _bot.DeleteMessageAsync(message.Chat.Id, message.MessageId, cancellationToken: stoppingToken);
deletionMessagePart += ", сообщение удалено.";
}
catch (Exception e)
{
logger.LogWarning(e, "Unable to delete");
deletionMessagePart += ", сообщение НЕ удалено (не хватило могущества?).";
}

var callbackData = $"ban_{message.Chat.Id}_{user.Id}";
var postLink = LinkToMessage(message.Chat, message.MessageId);

await _bot.SendTextMessageAsync(
new ChatId(Config.AdminChatId),
$"{reason}, сообщение удалено.{Environment.NewLine}Юзер {user.FirstName} {user.LastName}; Чат {message.Chat.Title}{Environment.NewLine}{postLink}",
$"{deletionMessagePart}{Environment.NewLine}Юзер {FullName(user.FirstName, user.LastName)} из чата {message.Chat.Title}{Environment.NewLine}{postLink}",
replyToMessageId: forward.MessageId,
replyMarkup: new InlineKeyboardMarkup(
[
Expand Down

0 comments on commit 5a7ed1d

Please sign in to comment.