|
@@ -4,6 +4,7 @@ using System.Threading.Tasks;
|
|
|
using MafiaTelegramBot.Commands;
|
|
|
using MafiaTelegramBot.Commands.CallbackQueries;
|
|
|
using MafiaTelegramBot.Commands.ChannelPost;
|
|
|
+using MafiaTelegramBot.Commands.ChatMember;
|
|
|
using MafiaTelegramBot.Commands.Messages;
|
|
|
using MafiaTelegramBot.DataBase.Entity;
|
|
|
using Telegram.Bot;
|
|
@@ -44,7 +45,7 @@ namespace MafiaTelegramBot.Controllers
|
|
|
await UpdateHandler.Factory(update.CallbackQuery.From, update.CallbackQuery.Data, new CallbackQueryHandler(null)),
|
|
|
UpdateType.ChannelPost =>
|
|
|
await UpdateHandler.Factory(ChatToUser(update.ChannelPost.Chat), update.ChannelPost.Text, new ChannelPost(null)),
|
|
|
- // UpdateType.ChatMember => ChatMember.Update(update),
|
|
|
+ UpdateType.MyChatMember => await MyChatMemberHandler.Factory(update.MyChatMember.From),
|
|
|
_ => await UnknownUpdateHandlerAsync(update)
|
|
|
};
|
|
|
var unused = await handler.Execute(update);
|
|
@@ -78,37 +79,98 @@ namespace MafiaTelegramBot.Controllers
|
|
|
|
|
|
public static async Task<Message> SendText(UserEntity info, string message, IReplyMarkup keyboard = null)
|
|
|
{
|
|
|
- return await Bot.Client.SendTextMessageAsync(info.ChatId, message, replyMarkup: keyboard, disableNotification: true);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (!info.IsBlocked)
|
|
|
+ return await Bot.Client.SendTextMessageAsync(info.ChatId, message, replyMarkup: keyboard, disableNotification: true);
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ LogOutWarning("Can't send text message " + e);
|
|
|
+ }
|
|
|
+ return new Message();
|
|
|
}
|
|
|
|
|
|
public static async Task<Message> SendTextWithHtml(UserEntity info, string message, IReplyMarkup keyboard = null)
|
|
|
{
|
|
|
- return await Bot.Client.SendTextMessageAsync(info.ChatId, message, ParseMode.Html, replyMarkup: keyboard, disableNotification: true);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (!info.IsBlocked)
|
|
|
+ return await Bot.Client.SendTextMessageAsync(info.ChatId, message, ParseMode.Html, replyMarkup: keyboard, disableNotification: true);
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ LogOutWarning("Can't send text message with html " + e);
|
|
|
+ }
|
|
|
+ return new Message();
|
|
|
}
|
|
|
|
|
|
public static async Task<Message> SendSticker(UserEntity info, string fileId)
|
|
|
{
|
|
|
- return await Bot.Client.SendStickerAsync(info.ChatId, fileId, true);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (!info.IsBlocked)
|
|
|
+ return await Bot.Client.SendStickerAsync(info.ChatId, fileId, true);
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ LogOutWarning("Can't send sticker " + e);
|
|
|
+ }
|
|
|
+ return new Message();
|
|
|
}
|
|
|
|
|
|
public static async Task<Message> EditMessage(UserEntity info, int messageId, string message, InlineKeyboardMarkup keyboard = null)
|
|
|
{
|
|
|
- return await Bot.Client.EditMessageTextAsync(info.ChatId, messageId, message, replyMarkup: keyboard);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (!info.IsBlocked)
|
|
|
+ return await Bot.Client.EditMessageTextAsync(info.ChatId, messageId, message, replyMarkup: keyboard);
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ LogOutWarning("Can't edit message text " + e);
|
|
|
+ }
|
|
|
+ return new Message();
|
|
|
}
|
|
|
|
|
|
public static async Task<Message> EditReplyMarkup(UserEntity info, int messageId, InlineKeyboardMarkup keyboard)
|
|
|
{
|
|
|
- return await Bot.Client.EditMessageReplyMarkupAsync(info.ChatId, messageId, keyboard);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (!info.IsBlocked)
|
|
|
+ return await Bot.Client.EditMessageReplyMarkupAsync(info.ChatId, messageId, keyboard);
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ LogOutWarning("Can't edit reply markup " + e);
|
|
|
+ }
|
|
|
+ return new Message();
|
|
|
}
|
|
|
|
|
|
public static async Task DeleteMessage(long chatId, int messageId)
|
|
|
{
|
|
|
- await Bot.Client.DeleteMessageAsync(chatId, messageId);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ await Bot.Client.DeleteMessageAsync(chatId, messageId);
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ LogOutWarning("Can't delete message " + e);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public static async Task<Message> SendImage(UserEntity info, InputOnlineFile inputOnlineFile, string message, InlineKeyboardMarkup replyMarkup)
|
|
|
{
|
|
|
- return await Bot.Client.SendPhotoAsync(info.ChatId, inputOnlineFile, message, replyMarkup: replyMarkup);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (!info.IsBlocked)
|
|
|
+ return await Bot.Client.SendPhotoAsync(info.ChatId, inputOnlineFile, message, replyMarkup: replyMarkup);
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ LogOutWarning("Can't send photo " + e);
|
|
|
+ }
|
|
|
+ return new Message();
|
|
|
}
|
|
|
}
|
|
|
}
|