mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
49 lines
1.5 KiB
C#
49 lines
1.5 KiB
C#
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using BotFramework;
|
|
using BotFramework.Attributes;
|
|
using BotFramework.Enums;
|
|
using Kruzya.TelegramBot.CombotAntiSpam.Combot;
|
|
using Kruzya.TelegramBot.Core.Extensions;
|
|
using Telegram.Bot;
|
|
using Telegram.Bot.Types.Enums;
|
|
|
|
namespace Kruzya.TelegramBot.CombotAntiSpam;
|
|
|
|
public class UserJoinHandler : BotEventHandler
|
|
{
|
|
private readonly ICombotClient _combotClient;
|
|
|
|
public UserJoinHandler(ICombotClient combotClient)
|
|
{
|
|
_combotClient = combotClient;
|
|
}
|
|
|
|
[InChat(InChat.Public)]
|
|
[Message(MessageFlag.HasNewChatMembers)]
|
|
public async Task OnUserJoined()
|
|
{
|
|
var canKickMembers = await Bot.IsUserAdminAsync(Chat, await Bot.GetMe());
|
|
|
|
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(true)} 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.SendMessage(Chat, messageText.ToString(), parseMode: ParseMode.Html);
|
|
|
|
if (canKickMembers)
|
|
{
|
|
await Bot.BanChatMember(Chat, member.Id);
|
|
}
|
|
}
|
|
}
|
|
} |