async def handle_afk_incomming(message: Message) -> None: """handle incomming messages when you afk""" if not message.from_user: return user_id = message.from_user.id chat = message.chat user_dict = await message.client.get_user_dict(user_id) afk_time = time_formatter(round(time.time() - TIME)) coro_list = [] if user_id in USERS: if not (USERS[user_id][0] + USERS[user_id][1]) % randint(2, 4): if REASON: out_str = ( f"I'm still **AFK**.\nReason: <code>{REASON}</code>\n" f"Last Seen: `{afk_time} ago`") else: out_str = choice(AFK_REASONS) coro_list.append(message.reply(out_str)) if chat.type == "private": USERS[user_id][0] += 1 else: USERS[user_id][1] += 1 else: if REASON: out_str = ( f"I'm **AFK** right now.\nReason: <code>{REASON}</code>\n" f"Last Seen: `{afk_time} ago`") else: out_str = choice(AFK_REASONS) coro_list.append(message.reply(out_str)) if chat.type == "private": USERS[user_id] = [1, 0, user_dict["mention"]] else: USERS[user_id] = [0, 1, user_dict["mention"]] if chat.type == "private": coro_list.append( CHANNEL.log(f"#PRIVATE\n{user_dict['mention']} send you\n\n" f"{message.text}")) else: coro_list.append( CHANNEL.log( "#GROUP\n" f"{user_dict['mention']} tagged you in [{chat.title}](http://t.me/{chat.username})\n\n" f"{message.text}\n\n" f"[goto_msg](https://t.me/c/{str(chat.id)[4:]}/{message.message_id})" )) coro_list.append( AFK_COLLECTION.update_one( {"_id": user_id}, { "$set": { "pcount": USERS[user_id][0], "gcount": USERS[user_id][1], "men": USERS[user_id][2], } }, upsert=True, )) await asyncio.gather(*coro_list)
async def handle_afk_incomming(message: Message) -> None: """ handle incomming messages when you afk """ user_id = message.from_user.id chat = message.chat user_dict = await message.client.get_user_dict(user_id) afk_time = time_formatter(round(time.time() - TIME)) coro_list = [] if user_id in USERS: if not (USERS[user_id][0] + USERS[user_id][1]) % randint(2, 4): if REASON: out_str = ( f"Saya **OFFLINE** Sekarang.\nKarena: <code>{REASON}</code>\n" f"Sejak: `{afk_time} Lalu`") else: out_str = choice(AFK_REASONS) coro_list.append(message.reply(out_str)) if chat.type == 'private': USERS[user_id][0] += 1 else: USERS[user_id][1] += 1 else: if REASON: out_str = ( f"Saya **OFFLINE** Sekarang.\nKarena: <code>{REASON}</code>\n" f"Sejak: `{afk_time} Lalu`") else: out_str = choice(AFK_REASONS) coro_list.append(message.reply(out_str)) if chat.type == 'private': USERS[user_id] = [1, 0, user_dict['mention']] else: USERS[user_id] = [0, 1, user_dict['mention']] if chat.type == 'private': coro_list.append( CHANNEL.log(f"#PRIVATE\n{user_dict['mention']} send you\n\n" f"{message.text}")) else: coro_list.append( CHANNEL.log( "#GROUP\n" f"{user_dict['mention']} tagged you in [{chat.title}](http://t.me/{chat.username})\n\n" f"{message.text}\n\n" f"[goto_msg](https://t.me/c/{str(chat.id)[4:]}/{message.message_id})" )) coro_list.append( AFK_COLLECTION.update_one({'_id': user_id}, { "$set": { 'pcount': USERS[user_id][0], 'gcount': USERS[user_id][1], 'men': USERS[user_id][2] } }, upsert=True)) await asyncio.gather(*coro_list)
async def handle_afk_incomming(message: Message) -> None: user_id = message.from_user.id chat = message.chat user_dict = await userge.get_user_dict(user_id) afk_time = time_formatter(round(time.time() - TIME)) coro_list = [] if user_id in USERS: if not (USERS[user_id][0] + USERS[user_id][1]) % randint(2, 4): if REASON: out_str = f"I'm still **AFK**.\nReason: `{REASON}`\nLast Seen: `{afk_time} ago`" else: out_str = choice(AFK_REASONS) coro_list.append(message.reply(out_str)) if chat.type == 'private': USERS[user_id][0] += 1 else: USERS[user_id][1] += 1 else: if REASON: out_str = f"I'm **AFK** right now.\nReason: `{REASON}`\nLast Seen: `{afk_time} ago`" else: out_str = choice(AFK_REASONS) coro_list.append(message.reply(out_str)) if chat.type == 'private': USERS[user_id] = [1, 0, user_dict['mention']] else: USERS[user_id] = [0, 1, user_dict['mention']] if chat.type == 'private': coro_list.append( CHANNEL.log(f"#PRIVATE\n{user_dict['mention']} send you\n\n" f"{message.text}")) else: coro_list.append( CHANNEL.log( "#GROUP\n" f"{user_dict['mention']} tagged you in [{chat.title}](http://t.me/{chat.username})\n\n" f"{message.text}\n\n" "[goto_msg](https://t.me/c/{str(chat.id)[4:]}/{message.message_id})" )) coro_list.append( AFK_COLLECTION.update_one({'_id': user_id}, { "$set": { 'pcount': USERS[user_id][0], 'gcount': USERS[user_id][1], 'men': USERS[user_id][2] } }, upsert=True)) await asyncio.gather(*coro_list)
async def _do_handle(self, message: Message, user: User, data) -> None: reason = self.get_reason(data) msg, log = _get_msg_and_log(message.chat, user, reason or 'None', self._name) task = asyncio.create_task(message.reply(msg, del_in=10)) await CHANNEL.log(log) await task
async def gmute_at_entry(msg: Message): """ handle gmute """ chat_id = msg.chat.id for user in msg.new_chat_members: user_id = user.id first_name = user.first_name gmuted = await GMUTE_USER_BASE.find_one({'user_id': user_id}) if gmuted: await asyncio.gather( msg.client.restrict_chat_member(chat_id, user_id, ChatPermissions()), msg.reply( r"\\**#Userge_Antispam**//" "\n\nGlobally Muted User Detected in this Chat.\n\n" f"**User:** [{first_name}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{gmuted['reason']}`\n\n" "**Quick Action:** Muted", del_in=10), CHANNEL.log( r"\\**#Antispam_Log**//" "\n\n**GMuted User $SPOTTED**\n" f"**User:** [{first_name}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** {gmuted['reason']}\n**Quick Action:** " f"Muted in {msg.chat.title}")) msg.continue_propagation()
async def anti_flood_handler(msg: Message): """ Filtering msgs for Handling Flooding """ if not msg.from_user: return chat_id = msg.chat.id user_id = msg.from_user.id first_name = msg.from_user.first_name if chat_id not in ANTIFLOOD_DATA or ( chat_id in ANTIFLOOD_DATA and ANTIFLOOD_DATA[chat_id].get("data") == "off" ): return if not ADMINS.get(msg.chat.id): await cache_admins(msg) if user_id in ADMINS[chat_id]: if chat_id in FLOOD_CACHE: del FLOOD_CACHE[chat_id] return mode = ANTIFLOOD_DATA[msg.chat.id]["mode"] limit = ANTIFLOOD_DATA[msg.chat.id]["limit"] if check_flood(chat_id, user_id): if mode.lower() == 'ban': await msg.client.kick_chat_member( chat_id, user_id) exec_str = "#BANNED" elif mode.lower() == 'kick': await msg.client.kick_chat_member( chat_id, user_id, int(time.time() + 60)) exec_str = "#KICKED" else: await msg.client.restrict_chat_member( chat_id, user_id, ChatPermissions()) exec_str = "#MUTED" await asyncio.gather( msg.reply( r"\\**#Userge_AntiFlood**//" "\n\nThis User Reached His Limit of Spamming\n\n" f"**User:** [{first_name}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Limit:** `{limit}`\n\n" f"**Quick Action:** {exec_str}"), CHANNEL.log( r"\\**#AntiFlood_Log**//" "\n\n**User Anti-Flood Limit reached**\n" f"**User:** [{first_name}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Limit:** {limit}\n" f"**Quick Action:** {exec_str} in {msg.chat.title}") )
async def gban_at_entry(message: Message): """ handle gbans """ chat_id = message.chat.id # Trying To Avoid Flood Waits if chat_id not in ADMEME_CHATS + PATHETIC_CHATS: if await me_can_restrict_members(message, chat_id): ADMEME_CHATS.append(chat_id) else: PATHETIC_CHATS.append(chat_id) if chat_id in PATHETIC_CHATS: return for user in message.new_chat_members: user_id = user.id first_name = user.first_name if await WHITELIST.find_one({'user_id': user_id}): continue gbanned = await GBAN_USER_BASE.find_one({'user_id': user_id}) if gbanned: await asyncio.gather( message.client.kick_chat_member(chat_id, user_id), message.reply( r"\\**#Userge_Antispam**//" "\n\nGlobally Banned User Detected in this Chat.\n\n" f"**User:** [{first_name}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{gbanned['reason']}`\n\n" "**Quick Action:** Banned"), CHANNEL.log( r"\\**#Antispam_Log**//" "\n\n**GBanned User $SPOTTED**\n" f"**User:** [{first_name}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** {gbanned['reason']}\n**Quick Action:** " f"Banned in {message.chat.title}")) elif Config.ANTISPAM_SENTRY: res = requests.get( f'https://api.cas.chat/check?user_id={user_id}').json() if res['ok']: reason = res['description'] if 'description' in res else None await asyncio.gather( message.client.kick_chat_member(chat_id, user_id), message.reply( r"\\**#Userge_Antispam**//" "\n\nGlobally Banned User Detected in this Chat.\n\n" "**$SENTRY CAS Federation Ban**\n" f"**User:** [{first_name}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{reason}`\n\n" "**Quick Action:** Banned"), CHANNEL.log( r"\\**#Antispam_Log**//" "\n\n**GBanned User $SPOTTED**\n" "**$SENRTY #CAS BAN**" f"\n**User:** [{first_name}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{reason}`\n**Quick Action:**" f" Banned in {message.chat.title}\n\n$AUTOBAN #id{user_id}" )) elif Config.SPAM_WATCH_API: intruder = spamwatch.Client( Config.SPAM_WATCH_API).get_ban(user_id) if intruder: await asyncio.gather( message.client.kick_chat_member(chat_id, user_id), message.reply( r"\\**#Userge_Antispam**//" "\n\nGlobally Banned User Detected in this Chat.\n\n" "**$SENTRY SpamWatch Federation Ban**\n" f"**User:** [{first_name}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{intruder.reason}`\n\n" "**Quick Action:** Banned"), CHANNEL.log( r"\\**#Antispam_Log**//" "\n\n**GBanned User $SPOTTED**\n" "**$SENRTY #SPAMWATCH_API BAN**" f"\n**User:** [{first_name}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{intruder.reason}`\n" f"**Quick Action:** Banned in {message.chat.title}\n\n" f"$AUTOBAN #id{user_id}")) message.continue_propagation()
async def gban_at_entry(message: Message): """ handle gbans """ chat_id = message.chat.id for user in message.new_chat_members: user_id = user.id first_name = user.first_name if await WHITELIST.find_one({"user_id": user_id}): continue gbanned = await GBAN_USER_BASE.find_one({"user_id": user_id}) if gbanned: if "chat_ids" in gbanned: chat_ids = gbanned["chat_ids"] chat_ids.append(chat_id) else: chat_ids = [chat_id] await asyncio.gather( message.client.kick_chat_member(chat_id, user_id), message.reply( r"\\**#Userge_Antispam**//" "\n\nGlobally Banned User Detected in this Chat.\n\n" f"**User:** [{first_name}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{gbanned['reason']}`\n\n" "**Quick Action:** Banned", del_in=10, ), CHANNEL.log( r"\\**#Antispam_Log**//" "\n\n**GBanned User $SPOTTED**\n" f"**User:** [{first_name}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** {gbanned['reason']}\n**Quick Action:** " f"Banned in {message.chat.title}"), GBAN_USER_BASE.update_one( { "user_id": user_id, "firstname": first_name }, {"$set": { "chat_ids": chat_ids }}, upsert=True, ), ) elif Config.ANTISPAM_SENTRY: async with aiohttp.ClientSession() as ses: async with ses.get( f"https://api.cas.chat/check?user_id={user_id}" ) as resp: res = json.loads(await resp.text()) if res["ok"]: reason = (" | ".join(res["result"]["messages"]) if "result" in res else None) await asyncio.gather( message.client.kick_chat_member(chat_id, user_id), message.reply( r"\\**#Userge_Antispam**//" "\n\nGlobally Banned User Detected in this Chat.\n\n" "**$SENTRY CAS Federation Ban**\n" f"**User:** [{first_name}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{reason}`\n\n" "**Quick Action:** Banned", del_in=10, ), CHANNEL.log( r"\\**#Antispam_Log**//" "\n\n**GBanned User $SPOTTED**\n" "**$SENRTY #CAS BAN**" f"\n**User:** [{first_name}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{reason}`\n**Quick Action:**" f" Banned in {message.chat.title}\n\n$AUTOBAN #id{user_id}" ), ) elif Config.SPAM_WATCH_API: intruder = await _get_spamwatch_data(user_id) if intruder: await asyncio.gather( message.client.kick_chat_member(chat_id, user_id), message.reply( r"\\**#Userge_Antispam**//" "\n\nGlobally Banned User Detected in this Chat.\n\n" "**$SENTRY SpamWatch Federation Ban**\n" f"**User:** [{first_name}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{intruder.reason}`\n\n" "**Quick Action:** Banned", del_in=10, ), CHANNEL.log( r"\\**#Antispam_Log**//" "\n\n**GBanned User $SPOTTED**\n" "**$SENRTY #SPAMWATCH_API BAN**" f"\n**User:** [{first_name}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{intruder.reason}`\n" f"**Quick Action:** Banned in {message.chat.title}\n\n" f"$AUTOBAN #id{user_id}"), ) message.continue_propagation()
async def gban_at_entry(message: Message): """ handle gbans """ chat_id = message.chat.id for user in message.new_chat_members: user_id = user.id firstname = user.first_name if await WHITELIST.find_one({"user_id": user_id}): continue gbanned = await GBAN_USER_BASE.find_one({"user_id": user_id}) if gbanned: if "chat_ids" in gbanned: chat_ids = gbanned["chat_ids"] chat_ids.append(chat_id) else: chat_ids = [chat_id] await asyncio.gather( message.client.kick_chat_member(chat_id, user_id), message.reply( r"\\**#𝑿_Antispam**//" "\n\nGlobally Banned User Detected in this Chat.\n\n" f"**User:** {mention_html(user_id, firstname)}\n" f"**ID:** `{user_id}`\n**Reason:** `{gbanned['reason']}`\n\n" "**Quick Action:** Banned", del_in=10, ), CHANNEL.log( r"\\**#Antispam_Log**//" "\n\n**GBanned User $SPOTTED**\n" f"**User:** {mention_html(user_id, firstname)}\n" f"**ID:** `{user_id}`\n**Reason:** {gbanned['reason']}\n**Quick Action:** " f"Banned in {message.chat.title}"), GBAN_USER_BASE.update_one( { "user_id": user_id, "firstname": firstname }, {"$set": { "chat_ids": chat_ids }}, upsert=True, ), ) elif Config.ANTISPAM_SENTRY: try: res = await get_response.json( f"https://api.cas.chat/check?user_id={user_id}") except ValueError: # api down pass else: if res and (res["ok"]): reason = (" | ".join(res["result"]["messages"]) if "result" in res else None) await asyncio.gather( message.client.kick_chat_member(chat_id, user_id), message.reply( r"\\**#𝑿_Antispam**//" "\n\nGlobally Banned User Detected in this Chat.\n\n" "**$SENTRY CAS Federation Ban**\n" f"**User:** {mention_html(user_id, firstname)}\n" f"**ID:** `{user_id}`\n**Reason:** `{reason}`\n\n" "**Quick Action:** Banned", del_in=10, ), CHANNEL.log( r"\\**#Antispam_Log**//" "\n\n**GBanned User $SPOTTED**\n" "**$SENRTY #CAS BAN**" f"\n**User:** {mention_html(user_id, firstname)}\n" f"**ID:** `{user_id}`\n**Reason:** `{reason}`\n**Quick Action:**" f" Banned in {message.chat.title}\n\n$AUTOBAN #id{user_id}" ), ) elif Config.SPAM_PROTECTION: try: iv = await get_response.json( "https://api.intellivoid.net/spamprotection/v1/lookup?query=" + str(user_id)) except ValueError: pass else: if iv and (iv["success"] and iv["results"]["attributes"]["is_blacklisted"] is True): reason = iv["results"]["attributes"]["blacklist_reason"] await asyncio.gather( message.client.kick_chat_member(chat_id, user_id), message.reply( r"\\**#𝑿_Antispam**//" "\n\nGlobally Banned User Detected in this Chat.\n\n" "**$Intellivoid Spam Protection**" f"\n**User:** {mention_html(user_id, firstname)}\n" f"**ID:** `{user_id}`\n**Reason:** `{reason}`\n\n" "**Quick Action:** Banned", del_in=10, ), CHANNEL.log( r"\\**#Antispam_Log**//" "\n\n**GBanned User $SPOTTED**\n" "**$Intellivoid Spam Protection**" f"\n**User:** {mention_html(user_id, firstname)}\n" f"**ID:** `{user_id}`\n**Reason:** `{reason}`\n**Quick Action:**" f" Banned in {message.chat.title}\n\n$AUTOBAN #id{user_id}" ), ) elif Config.SPAM_WATCH_API: try: intruder = await _get_spamwatch_data(user_id) except spamwatch.errors.Error as err: LOG.error(str(err)) intruder = False if intruder: await asyncio.gather( message.client.kick_chat_member(chat_id, user_id), message.reply( r"\\**#𝑿_Antispam**//" "\n\nGlobally Banned User Detected in this Chat.\n\n" "**$SENTRY SpamWatch Federation Ban**\n" f"**User:** {mention_html(user_id, firstname)}\n" f"**ID:** `{user_id}`\n**Reason:** `{intruder.reason}`\n\n" "**Quick Action:** Banned", del_in=10, ), CHANNEL.log( r"\\**#Antispam_Log**//" "\n\n**GBanned User $SPOTTED**\n" "**$SENRTY #SPAMWATCH_API BAN**" f"\n**User:** {mention_html(user_id, firstname)}\n" f"**ID:** `{user_id}`\n**Reason:** `{intruder.reason}`\n" f"**Quick Action:** Banned in {message.chat.title}\n\n" f"$AUTOBAN #id{user_id}"), ) message.continue_propagation()
async def gban_at_entry(message: Message): """ handle gbans """ chat_id = message.chat.id for user in message.new_chat_members: user_id = user.id first_name = user.first_name if await WHITELIST.find_one({'user_id': user_id}): continue gbanned = await GBAN_USER_BASE.find_one({'user_id': user_id}) if gbanned: await asyncio.gather( message.client.kick_chat_member(chat_id, user_id), message.reply( r"\\**#Userge_Antispam**//" "\n\nGlobally Banned User Detected in this Chat.\n\n" f"**User:** [{first_name}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{gbanned['reason']}`\n\n" "**Quick Action:** Banned", del_in=10), CHANNEL.log( r"\\**#Antispam_Log**//" "\n\n**GBanned User $SPOTTED**\n" f"**User:** [{first_name}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** {gbanned['reason']}\n**Quick Action:** " f"Banned in {message.chat.title}")) elif Config.ANTISPAM_SENTRY: async with aiohttp.ClientSession() as ses: async with ses.get( f'https://api.cas.chat/check?user_id={user_id}' ) as resp: res = await resp.json() if res['ok']: reason = ' | '.join( res['result']['messages']) if 'result' in res else None await asyncio.gather( message.client.kick_chat_member(chat_id, user_id), message.reply( r"\\**#Userge_Antispam**//" "\n\nGlobally Banned User Detected in this Chat.\n\n" "**$SENTRY CAS Federation Ban**\n" f"**User:** [{first_name}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{reason}`\n\n" "**Quick Action:** Banned", del_in=10), CHANNEL.log( r"\\**#Antispam_Log**//" "\n\n**GBanned User $SPOTTED**\n" "**$SENRTY #CAS BAN**" f"\n**User:** [{first_name}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{reason}`\n**Quick Action:**" f" Banned in {message.chat.title}\n\n$AUTOBAN #id{user_id}" )) elif Config.SPAM_WATCH_API: intruder = await _get_spamwatch_data(user_id) if intruder: await asyncio.gather( message.client.kick_chat_member(chat_id, user_id), message.reply( r"\\**#Userge_Antispam**//" "\n\nGlobally Banned User Detected in this Chat.\n\n" "**$SENTRY SpamWatch Federation Ban**\n" f"**User:** [{first_name}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{intruder.reason}`\n\n" "**Quick Action:** Banned", del_in=10), CHANNEL.log( r"\\**#Antispam_Log**//" "\n\n**GBanned User $SPOTTED**\n" "**$SENRTY #SPAMWATCH_API BAN**" f"\n**User:** [{first_name}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{intruder.reason}`\n" f"**Quick Action:** Banned in {message.chat.title}\n\n" f"$AUTOBAN #id{user_id}")) message.continue_propagation()
async def gban_at_entry(message: Message): """ handle gbans """ chat_id = message.chat.id warned = False for user in message.new_chat_members: user_id = user.id first_name = user.first_name if await WHITELIST.find_one({'user_id': user_id}): continue gbanned = await GBAN_USER_BASE.find_one({'user_id': user_id}) if gbanned: if 'chat_ids' in gbanned: chat_ids = gbanned['chat_ids'] chat_ids.append(chat_id) else: chat_ids = [chat_id] await asyncio.gather( message.client.kick_chat_member(chat_id, user_id), message.reply( r"\\**#Userge_Antispam**//" "\n\nGlobally Banned User Detected in this Chat.\n\n" f"**User:** [{first_name}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{gbanned['reason']}`\n\n" "**Quick Action:** Banned", del_in=10), CHANNEL.log( r"\\**#Antispam_Log**//" "\n\n**GBanned User $SPOTTED**\n" f"**User:** [{first_name}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** {gbanned['reason']}\n**Quick Action:** " f"Banned in {message.chat.title}"), GBAN_USER_BASE.update_one( { 'user_id': user_id, 'firstname': first_name }, {"$set": { 'chat_ids': chat_ids }}, upsert=True)) elif Config.ANTISPAM_SENTRY: res = await getData(f'https://api.cas.chat/check?user_id={user_id}' ) if res['ok']: reason = ' | '.join( res['result']['messages']) if 'result' in res else None await asyncio.gather( message.client.kick_chat_member(chat_id, user_id), message.reply( r"\\**#Userge_Antispam**//" "\n\nGlobally Banned User Detected in this Chat.\n\n" "**$SENTRY CAS Federation Ban**\n" f"**User:** [{first_name}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{reason}`\n\n" "**Quick Action:** Banned", del_in=10), CHANNEL.log( r"\\**#Antispam_Log**//" "\n\n**GBanned User $SPOTTED**\n" "**$SENRTY #CAS BAN**" f"\n**User:** [{first_name}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{reason}`\n**Quick Action:**" f" Banned in {message.chat.title}\n\n$AUTOBAN #id{user_id}" )) continue if Config.USERGE_ANTISPAM_API: try: ban = await _get_userge_antispam_data(user_id) except Exception as err: if not warned: LOG.error(err) await CHANNEL.log(err) warned = True else: if ban: await asyncio.gather( message.client.kick_chat_member(chat_id, user_id), message.reply( r"\\**#Userge_Antispam**//" "\n\nGlobally Banned User Detected in this Chat.\n\n" "**$SENTRY Userge AntiSpam API Ban**\n" f"**User:** [{first_name}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{ban.reason}`\n\n" "**Quick Action:** Banned", del_in=10), CHANNEL.log( r"\\**#Antispam_Log**//" "\n\n**GBanned User $SPOTTED**\n" "**$SENRTY #USERGE_ANTISPAM_API BAN**" f"\n**User:** [{first_name}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{ban.reason}`\n" f"**Quick Action:** Banned in {message.chat.title}\n\n" f"$AUTOBAN #id{user_id}")) continue if Config.SPAM_WATCH_API: intruder = await _get_spamwatch_data(user_id) if intruder: await asyncio.gather( message.client.kick_chat_member(chat_id, user_id), message.reply( r"\\**#Userge_Antispam**//" "\n\nGlobally Banned User Detected in this Chat.\n\n" "**$SENTRY SpamWatch Federation Ban**\n" f"**User:** [{first_name}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{intruder.reason}`\n\n" "**Quick Action:** Banned", del_in=10), CHANNEL.log( r"\\**#Antispam_Log**//" "\n\n**GBanned User $SPOTTED**\n" "**$SENRTY #SPAMWATCH_API BAN**" f"\n**User:** [{first_name}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{intruder.reason}`\n" f"**Quick Action:** Banned in {message.chat.title}\n\n" f"$AUTOBAN #id{user_id}")) message.continue_propagation()
async def gban_at_entry(message: Message): """ handle gbans """ chat_id = message.chat.id for user in message.new_chat_members: user_id = user.id first_name = user.first_name if await WHITELIST.find_one({'user_id': user_id}): continue gbanned = await GBAN_USER_BASE.find_one({'user_id': user_id}) if gbanned: if 'chat_ids' in gbanned: chat_ids = gbanned['chat_ids'] chat_ids.append(chat_id) else: chat_ids = [chat_id] await asyncio.gather( message.client.kick_chat_member(chat_id, user_id), message.reply( r"\\**#Userge_Antispam**//" "\n\nGlobally Banned User Detected in this Chat.\n\n" f"**User:** [{first_name}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{gbanned['reason']}`\n\n" "**Quick Action:** Banned", del_in=10), CHANNEL.log( r"\\**#Antispam_Log**//" "\n\n**GBanned User $SPOTTED**\n" f"**User:** [{first_name}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** {gbanned['reason']}\n**Quick Action:** " f"Banned in {message.chat.title}"), GBAN_USER_BASE.update_one( {'user_id': user_id, 'firstname': first_name}, {"$set": {'chat_ids': chat_ids}}, upsert=True) ) elif Config.ANTISPAM_SENTRY: async with aiohttp.ClientSession() as ses: async with ses.get(f'https://api.cas.chat/check?user_id={user_id}') as resp: res = json.loads(await resp.text()) if res['ok']: reason = ' | '.join( res['result']['messages']) if 'result' in res else None await asyncio.gather( message.client.kick_chat_member(chat_id, user_id), message.reply( r"\\**#Userge_Antispam**//" "\n\nGlobally Banned User Detected in this Chat.\n\n" "**$SENTRY CAS Federation Ban**\n" f"**User:** [{first_name}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{reason}`\n\n" "**Quick Action:** Banned", del_in=10), CHANNEL.log( r"\\**#Antispam_Log**//" "\n\n**GBanned User $SPOTTED**\n" "**$SENRTY #CAS BAN**" f"\n**User:** [{first_name}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{reason}`\n**Quick Action:**" f" Banned in {message.chat.title}\n\n$AUTOBAN #id{user_id}") ) continue async with aiohttp.ClientSession() as ses: async with ses.get( "https://api.intellivoid.net/spamprotection/v1/lookup?query=" + str(user_id) ) as resp: iv = json.loads(await resp.text()) if iv['success'] and iv['results']['attributes']['is_blacklisted'] is True: reason = iv['results']['attributes']['blacklist_reason'] await asyncio.gather( message.client.kick_chat_member(chat_id, user_id), message.reply( r"\\**#Userge_Antispam**//" "\n\nGlobally Banned User Detected in this Chat.\n\n" "**$Intellivoid SpamProtection**\n" f"**User:** [{first_name}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{reason}`\n\n" "**Quick Action:** Banned", del_in=10), CHANNEL.log( r"\\**#Antispam_Log**//" "\n\n**GBanned User $SPOTTED**\n" "**$Intellivoid SpamProtection**" f"\n**User:** [{first_name}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{reason}`\n**Quick Action:**" f" Banned in {message.chat.title}\n\n$AUTOBAN #id{user_id}") ) elif Config.SPAM_WATCH_API: intruder = await _get_spamwatch_data(user_id) if intruder: await asyncio.gather( message.client.kick_chat_member(chat_id, user_id), message.reply( r"\\**#Userge_Antispam**//" "\n\nGlobally Banned User Detected in this Chat.\n\n" "**$SENTRY SpamWatch Federation Ban**\n" f"**User:** [{first_name}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{intruder.reason}`\n\n" "**Quick Action:** Banned", del_in=10), CHANNEL.log( r"\\**#Antispam_Log**//" "\n\n**GBanned User $SPOTTED**\n" "**$SENRTY #SPAMWATCH_API BAN**" f"\n**User:** [{first_name}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{intruder.reason}`\n" f"**Quick Action:** Banned in {message.chat.title}\n\n" f"$AUTOBAN #id{user_id}") ) message.continue_propagation()