mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
55 lines
1.4 KiB
C#
55 lines
1.4 KiB
C#
using System.Threading.Tasks;
|
|
using BotFramework.Attributes;
|
|
using BotFramework.Enums;
|
|
using Kruzya.TelegramBot.Core.Data;
|
|
using Kruzya.TelegramBot.Core.Extensions;
|
|
using Kruzya.TelegramBot.Core.Handler;
|
|
using Telegram.Bot;
|
|
using Telegram.Bot.Exceptions;
|
|
using West.TelegramBot.ChatManagement.Service;
|
|
|
|
namespace West.TelegramBot.ChatManagement.Handler;
|
|
|
|
class Rules : CommonHandler
|
|
{
|
|
private readonly RulesService _rulesService;
|
|
|
|
[InChat(InChat.Public)]
|
|
[Command("setrules", CommandParseMode.Both)]
|
|
public async Task HandleSetRules()
|
|
{
|
|
var replyToMessage = Message?.ReplyToMessage;
|
|
|
|
if (replyToMessage == null || !await Bot.IsUserAdminAsync(Chat, From))
|
|
{
|
|
return;
|
|
}
|
|
|
|
await _rulesService.SetRulesAsync(Chat, replyToMessage.MessageId);
|
|
}
|
|
|
|
[InChat(InChat.Public)]
|
|
[Command("rules", CommandParseMode.Both)]
|
|
public async Task HandleRules()
|
|
{
|
|
if (!await _rulesService.HasRulesAsync(Chat))
|
|
{
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
await Bot.CopyMessage(Chat.Id, Chat.Id, await _rulesService.GetRulesMessageIdAsync(Chat) ?? 0);
|
|
}
|
|
catch (ApiRequestException)
|
|
{
|
|
await _rulesService.RemoveChatRulesAsync(Chat);
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public Rules(CoreContext db, RulesService rulesService) : base(db)
|
|
{
|
|
_rulesService = rulesService;
|
|
}
|
|
} |