Use file-scoped namespaces

This commit is contained in:
Andriy
2023-07-29 15:14:52 +03:00
parent a24332370d
commit 8ab067a027
58 changed files with 2222 additions and 2280 deletions
+32 -33
View File
@@ -5,46 +5,46 @@ using Telegram.Bot;
using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums;
namespace Kruzya.TelegramBot.UrlLimitations
namespace Kruzya.TelegramBot.UrlLimitations;
public static class MessageExtension
{
public static class MessageExtension
public static async Task<bool> HasUnknownMention(this Message message, ITelegramBotClient bot)
{
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))
{
foreach (var mention in message.Entities.Where(e =>
e.Type == MessageEntityType.Mention || e.Type == MessageEntityType.TextMention))
long userId = 0;
if (mention.Type == MessageEntityType.TextMention)
{
long userId = 0;
if (mention.Type == MessageEntityType.TextMention)
userId = mention.User.Id;
}
else
{
try
{
userId = mention.User.Id;
}
else
{
try
{
var chat = await bot.GetChatAsync(
new ChatId(message.Text.Substring(mention.Offset, mention.Length)));
var chat = await bot.GetChatAsync(
new ChatId(message.Text.Substring(mention.Offset, mention.Length)));
if (chat != null)
if (chat != null)
{
if (chat.Type != ChatType.Private)
{
if (chat.Type != ChatType.Private)
{
return true;
}
userId = Convert.ToInt64(chat.Id);
return true;
}
}
catch (Exception)
{
return true;
userId = Convert.ToInt64(chat.Id);
}
}
catch (Exception)
{
return true;
}
}
var status = (await bot.GetChatMemberAsync(message.Chat, userId)).Status;
var status = (await bot.GetChatMemberAsync(message.Chat, userId)).Status;
if ((new ChatMemberStatus[]
if ((new ChatMemberStatus[]
{
ChatMemberStatus.Administrator, ChatMemberStatus.Creator, ChatMemberStatus.Member,
ChatMemberStatus.Restricted
@@ -52,12 +52,11 @@ namespace Kruzya.TelegramBot.UrlLimitations
// i'm not sure about "Restricted"
// maybe leaved members with some restrictions also can be "Restricted".
}).Any(e => e == status) == false)
{
return true;
}
{
return true;
}
return false;
}
return false;
}
}