12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- #nullable enable
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using Telegram.Bot.Types;
- namespace MafiaTelegramBot.Models
- {
- public abstract class UpdateModel<T> : ICloneable
- {
- protected abstract T Name { get; }
- protected long ChatId { get; set; }
- protected long UserId { get; set; }
- protected abstract Task<Message> Execute(Update update);
- protected abstract bool IsMatches(String command);
- protected static UpdateModel<T>? FirstOrDefault(IReadOnlyList<UpdateModel<T>> list, string data)
- {
- return (from item in list
- where item.IsMatches(data)
- select item).FirstOrDefault();
- }
- protected static async Task DeletePreviousMessage(long chatId, int messageId)
- {
- await Bot.Get().DeleteMessageAsync(chatId, messageId);
- }
- public object? Clone(long chatId, long userId)
- {
- var clone = (UpdateModel<T>?) MemberwiseClone();
- if(clone == null) return clone;
- clone.ChatId = chatId;
- clone.UserId = userId;
- return clone;
- }
- public object Clone()
- {
- return MemberwiseClone();
- }
- }
- }
|