mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
🚧 CAS integration
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using BotFramework;
|
||||
using BotFramework.Attributes;
|
||||
using BotFramework.Setup;
|
||||
using Kruzya.TelegramBot.CombotAntiSpam.Combot;
|
||||
using Kruzya.TelegramBot.Core.Extensions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Telegram.Bot.Types.Enums;
|
||||
|
||||
namespace Kruzya.TelegramBot.CombotAntiSpam
|
||||
{
|
||||
public class UserJoinHandler : BotEventHandler
|
||||
{
|
||||
protected ICombotClient _combotClient;
|
||||
protected ILogger _logger;
|
||||
|
||||
public UserJoinHandler(ICombotClient combotClient)
|
||||
{
|
||||
_combotClient = combotClient;
|
||||
}
|
||||
|
||||
[Message(MessageType.ChatMembersAdded, InChat.Public)]
|
||||
public async Task OnUserJoined()
|
||||
{
|
||||
var canKickMembers = ((await Bot.GetChatMemberAsync(Chat, (await Bot.GetMeAsync()).Id)).CanRestrictMembers == true);
|
||||
|
||||
foreach (var member in RawUpdate.Message.NewChatMembers)
|
||||
{
|
||||
if (!(await _combotClient.IsSpammerAsync(member)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var messageText = new StringBuilder();
|
||||
messageText.Append($"⚠️ <b>Combot Anti-Spam</b>\n\n");
|
||||
messageText.Append($"User {member.ToHtml()} is spammer.\n");
|
||||
messageText.Append(
|
||||
$"More details you can find on <a href=\"https://cas.chat/query?u={member.Id}\">CAS site</a>.");
|
||||
|
||||
await Bot.SendTextMessageAsync(Chat, messageText.ToString(), ParseMode.Html);
|
||||
|
||||
if (canKickMembers)
|
||||
{
|
||||
await Bot.KickChatMemberAsync(Chat, member.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user