mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
[code-watcher] Cleanup. Remove notification in 1 minute after sending.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
using BotFramework;
|
||||
using BotFramework.Attributes;
|
||||
using BotFramework.Enums;
|
||||
using BotFramework.Utils;
|
||||
using Kruzya.TelegramBot.Core.Extensions;
|
||||
using Telegram.Bot;
|
||||
using Telegram.Bot.Types;
|
||||
@@ -11,13 +10,6 @@ namespace West.TelegramBot.CodeWatcher;
|
||||
|
||||
public class Handler : BotEventHandler
|
||||
{
|
||||
private static readonly string ResponseMessage = new HtmlString()
|
||||
.Text(", не стоит публиковать столь большой код прямо в чат. Вместо этого загрузите его на ")
|
||||
.Url("https://pastebin.com", "https://pastebin.com")
|
||||
.Text(" и отправьте в виде ссылки.")
|
||||
.ToString();
|
||||
|
||||
|
||||
[Message(InChat.Public, MessageFlag.HasText)]
|
||||
public async Task HandleMessage()
|
||||
{
|
||||
@@ -42,13 +34,7 @@ public class Handler : BotEventHandler
|
||||
.SplitToLines()
|
||||
.ToList();
|
||||
|
||||
if (entityLines.Count >= 10)
|
||||
{
|
||||
await DeleteAndNotifyAsync(message);
|
||||
return;
|
||||
}
|
||||
|
||||
if (entityLines.Any(line => line.Length > 80))
|
||||
if (entityLines.Count >= 10 || entityLines.Any(line => line.Length > 80))
|
||||
{
|
||||
await DeleteAndNotifyAsync(message);
|
||||
return;
|
||||
@@ -60,8 +46,12 @@ public class Handler : BotEventHandler
|
||||
public async Task DeleteAndNotifyAsync(Message message)
|
||||
{
|
||||
await Bot.DeleteMessageAsync(Chat.Id, message.MessageId);
|
||||
await Bot.SendTextMessageAsync(Chat.Id,
|
||||
(message.From?.ToHtml() ?? "") + ResponseMessage,
|
||||
var notifyMsg = await Bot.SendTextMessageAsync(Chat.Id,
|
||||
(message.From?.ToHtml() ?? "") + ", не стоит публиковать столь большой код прямо в чат. " +
|
||||
"Вместо этого загрузите его на https://pastebin.com и отправьте в виде ссылки.",
|
||||
ParseMode.Html);
|
||||
|
||||
await Task.Delay(TimeSpan.FromMinutes(1));
|
||||
await Bot.DeleteMessageAsync(Chat.Id, notifyMsg.MessageId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user