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()); } catch (ApiRequestException) { Db.MarkAsDeleted(opt); throw; } } public Rules(CoreContext db) : base(db) {} } }