2025-05-19 13:25:06 +03:00
|
|
|
using System.Text.Encodings.Web;
|
|
|
|
|
using BotFramework;
|
2022-03-17 17:39:57 +02:00
|
|
|
using BotFramework.Attributes;
|
|
|
|
|
using BotFramework.Enums;
|
2023-11-13 00:21:15 +02:00
|
|
|
using BotFramework.Utils;
|
2022-03-17 18:54:07 +02:00
|
|
|
using Kruzya.TelegramBot.Core.Extensions;
|
2022-03-17 17:39:57 +02:00
|
|
|
using Kruzya.TelegramBot.Core.Service;
|
2025-02-09 17:40:03 +02:00
|
|
|
using System.Text.Json;
|
2025-05-19 13:25:06 +03:00
|
|
|
using Telegram.Bot;
|
2026-05-09 18:12:22 +03:00
|
|
|
using Telegram.Bot.Types.Enums;
|
2022-03-17 17:39:57 +02:00
|
|
|
|
|
|
|
|
namespace West.TelegramBot.DebugTools;
|
|
|
|
|
|
|
|
|
|
public class Handler : BotEventHandler
|
|
|
|
|
{
|
|
|
|
|
private readonly UserService _userService;
|
2025-05-19 13:25:06 +03:00
|
|
|
private static readonly JsonSerializerOptions DumpOptions = new(JsonBotAPI.Options)
|
|
|
|
|
{
|
|
|
|
|
WriteIndented = true,
|
|
|
|
|
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
|
|
|
|
};
|
2022-03-17 17:39:57 +02:00
|
|
|
|
|
|
|
|
public Handler(UserService userService)
|
|
|
|
|
{
|
|
|
|
|
_userService = userService;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-29 01:50:28 +03:00
|
|
|
[Command("dump", CommandParseMode.Both)]
|
2022-03-17 17:39:57 +02:00
|
|
|
public async Task HandleDump()
|
|
|
|
|
{
|
2026-05-09 18:12:22 +03:00
|
|
|
var isChatAdmin = (Chat.Type == ChatType.Private || await Bot.IsUserAdminAsync(Chat, From));
|
|
|
|
|
if (!_userService.IsUserSuper(From) && !isChatAdmin)
|
2022-03-17 17:39:57 +02:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-11-13 00:21:15 +02:00
|
|
|
var message = RawUpdate.Message!.ReplyToMessage ?? RawUpdate.Message;
|
|
|
|
|
var text = HtmlString.Empty
|
2025-02-09 17:40:03 +02:00
|
|
|
.CodeWithStyle("language-json", JsonSerializer.Serialize(message, DumpOptions));
|
2022-03-17 17:39:57 +02:00
|
|
|
|
2023-11-13 00:21:15 +02:00
|
|
|
await Bot.SendHtmlStringAsync(Chat, text, replyTo: message.MessageId);
|
2022-03-17 17:39:57 +02:00
|
|
|
}
|
|
|
|
|
}
|