mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
35 lines
1.0 KiB
C#
35 lines
1.0 KiB
C#
using BotFramework;
|
|
using BotFramework.Attributes;
|
|
using BotFramework.Enums;
|
|
using BotFramework.Utils;
|
|
using Kruzya.TelegramBot.Core.Extensions;
|
|
using Kruzya.TelegramBot.Core.Service;
|
|
using System.Text.Json;
|
|
|
|
namespace West.TelegramBot.DebugTools;
|
|
|
|
public class Handler : BotEventHandler
|
|
{
|
|
private readonly UserService _userService;
|
|
private static readonly JsonSerializerOptions DumpOptions = new() { WriteIndented = true };
|
|
|
|
|
|
public Handler(UserService userService)
|
|
{
|
|
_userService = userService;
|
|
}
|
|
|
|
[Command("dump", CommandParseMode.Both)]
|
|
public async Task HandleDump()
|
|
{
|
|
if (!_userService.IsUserSuper(From) && !await Bot.IsUserAdminAsync(Chat, From))
|
|
{
|
|
return;
|
|
}
|
|
var message = RawUpdate.Message!.ReplyToMessage ?? RawUpdate.Message;
|
|
var text = HtmlString.Empty
|
|
.CodeWithStyle("language-json", JsonSerializer.Serialize(message, DumpOptions));
|
|
|
|
await Bot.SendHtmlStringAsync(Chat, text, replyTo: message.MessageId);
|
|
}
|
|
} |