2020-03-08 12:38:00 +04:00
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Telegram.Bot;
|
|
|
|
|
using Telegram.Bot.Types;
|
|
|
|
|
using Telegram.Bot.Types.Enums;
|
|
|
|
|
|
|
|
|
|
namespace Kruzya.TelegramBot.UrlLimitations
|
|
|
|
|
{
|
|
|
|
|
public static class MessageExtension
|
|
|
|
|
{
|
|
|
|
|
public static async Task<bool> HasUnknownMention(this Message message, ITelegramBotClient bot)
|
|
|
|
|
{
|
|
|
|
|
foreach (var mention in message.Entities.Where(e =>
|
|
|
|
|
e.Type == MessageEntityType.Mention || e.Type == MessageEntityType.TextMention))
|
|
|
|
|
{
|
2021-12-22 01:27:56 +04:00
|
|
|
long userId = 0;
|
2020-03-08 12:38:00 +04:00
|
|
|
if (mention.Type == MessageEntityType.TextMention)
|
|
|
|
|
{
|
|
|
|
|
userId = mention.User.Id;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var chat = await bot.GetChatAsync(
|
|
|
|
|
new ChatId(message.Text.Substring(mention.Offset, mention.Length)));
|
|
|
|
|
|
|
|
|
|
if (chat != null)
|
|
|
|
|
{
|
|
|
|
|
if (chat.Type != ChatType.Private)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-22 01:27:56 +04:00
|
|
|
userId = Convert.ToInt64(chat.Id);
|
2020-03-08 12:38:00 +04:00
|
|
|
}
|
|
|
|
|
}
|
2021-12-22 01:27:56 +04:00
|
|
|
catch (Exception)
|
2020-03-08 12:38:00 +04:00
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var status = (await bot.GetChatMemberAsync(message.Chat, userId)).Status;
|
|
|
|
|
|
|
|
|
|
if ((new ChatMemberStatus[]
|
|
|
|
|
{
|
|
|
|
|
ChatMemberStatus.Administrator, ChatMemberStatus.Creator, ChatMemberStatus.Member,
|
|
|
|
|
ChatMemberStatus.Restricted
|
|
|
|
|
|
|
|
|
|
// i'm not sure about "Restricted"
|
|
|
|
|
// maybe leaved members with some restrictions also can be "Restricted".
|
|
|
|
|
}).Any(e => e == status) == false)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|