mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
47 lines
1.3 KiB
C#
47 lines
1.3 KiB
C#
using System.Threading.Tasks;
|
|
using BotFramework.Attributes;
|
|
using BotFramework.Enums;
|
|
using Kruzya.TelegramBot.Core.Data;
|
|
using Kruzya.TelegramBot.Core.Extensions;
|
|
using Telegram.Bot;
|
|
using Telegram.Bot.Exceptions;
|
|
|
|
namespace West.TelegramBot.ChatManagement.Handler
|
|
{
|
|
class Rules : ManagementHandler
|
|
{
|
|
[Command(InChat.Public, "setrules", CommandParseMode.Both)]
|
|
public async Task HandleSetRules()
|
|
{
|
|
var replyToMessage = Message?.ReplyToMessage;
|
|
|
|
if (replyToMessage == null || !await Bot.IsUserAdminAsync(Chat, From)) return;
|
|
|
|
var opt = await Db.UserValues.FindOrCreateOption(Chat.Id, "rulesMsgId");
|
|
opt.SetValue(replyToMessage.MessageId);
|
|
Db.MarkAsModified(opt);
|
|
}
|
|
|
|
[Command(InChat.Public, "rules", CommandParseMode.Both)]
|
|
public async Task HandleRules()
|
|
{
|
|
var opt = await Db.UserValues.FindOption(Chat.Id, "rulesMsgId");
|
|
if (opt == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
await Bot.CopyMessageAsync(Chat.Id, Chat.Id, opt.GetValue<int>());
|
|
}
|
|
catch (ApiRequestException)
|
|
{
|
|
Db.MarkAsDeleted(opt);
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public Rules(CoreContext db) : base(db) {}
|
|
}
|
|
} |