async def lydia_ai_chat(message: Message): """ incomming message handler """ if CH_LYDIA_API is None: return data = ACTIVE_CHATS.get(message.from_user.id, None) chat_id = message.from_user.id if not data: data = ACTIVE_CHATS.get(message.chat.id, None) chat_id = message.chat.id if data: ses_id, ses_time = data if int(ses_time) < time(): ses = await _create_lydia() await LYDIA_CHATS.update_one( {'_id': chat_id}, {"$set": { 'session_id': ses.id, 'session_exp': ses.expires }}) ACTIVE_CHATS[chat_id] = (ses.id, ses.expires) ses_id = ses.id try: out = '' await userge.send_read_acknowledge(chat_id=chat_id, message=message, clear_mentions=True) if not message.media and message.text: out = await _think_lydia(ses_id, message.text) QUEUE.put_nowait((message, out)) except CoffeeHouseError: pass message.continue_propagation()
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 lydia_ai_chat(message: Message): """ incomming message handler """ if CH_LYDIA_API is None: return data = ACTIVE_CHATS.get(message.from_user.id, None) or ACTIVE_CHATS.get( message.chat.id, None) if data: if message.media: await custom_media_reply(message) else: ses = LYDIA.get_session(data[0]) mess_text = message.text # if int(ses_exp) < time(): # ses = lydia.create_session("en") # ses_id = ses.id # ses_exp = ses.expires # await LYDIA_SESSION.find_one_and_update( # {'uid': "LYDIA_SES"}, # {"$set": {'session_id': ses_id, 'session_exp': ses_exp}}) try: output_ = LYDIA.think_thought(ses.id, mess_text) await message.reply_chat_action("typing") await asyncio.sleep(7) await message.reply_chat_action("typing") await asyncio.sleep(2) await message.reply_chat_action("cancel") await message.reply(output_) except CoffeeHouseError: pass message.continue_propagation()
async def gban_at_entry(message: Message): """ handle gbans """ if isinstance(HANDLER, Handler): try: for user in message.new_chat_members: if await is_whitelist(user.id): continue await HANDLER.handle(message, user) except (ChatAdminRequired, UserAdminInvalid): pass message.continue_propagation()
async def gban_at_entry(message: Message): # TODO:2. Ban Users when they join try: if message.service: if message.new_chat_members: #New Member still not working 🤔hmmmm chat_id = message.chat.id user_id = message.new_chat_members[0].id firstname = message.new_chat_members[0].first_name else: chat_id = message.chat.id user_id = message.from_user.id firstname = message.from_user.first_name except: pass try: for c in GBAN_USER_BASE.find({}): if c['user_id'] == user_id: reason = c['reason'] try: await userge.kick_chat_member(chat_id, user_id) await message.reply( r"\\**#Userge_Antispam**//" "\n\n\nGlobally Banned User Detected in this Chat.\n\n" f"**User:** [{firstname}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{reason}`\n\n" "**Quick Action:** Banned.") await GBAN_LOG.log( r"\\**#Antispam_Log**//" "\n\n**GBanned User $SPOTTED**\n" f"**User:** [{firstname}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Quick Action:** Banned in {message.chat.title}" ) except: break except: pass message.continue_propagation()
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): try: if message.service: if message.new_chat_members: chat_id = message.chat.id user_id = message.new_chat_members[0].id firstname = message.new_chat_members[0].first_name except Exception: return # Nu use to continue if u can't get id of user from message 🤔 async for w in WHITELIST.find({}): if w['user_id'] == user_id: return try: async for c in GBAN_USER_BASE.find({}): if c['user_id'] == user_id: reason = c['reason'] try: if await guadmin_check(chat_id, user_id): await userge.kick_chat_member(chat_id, user_id) await message.reply( r"\\**#Userge_Antispam**//" "\n\n\nGlobally Banned User Detected in this Chat.\n\n" f"**User:** [{firstname}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{reason}`\n\n" "**Quick Action:** Banned.") await GBAN_LOG.log( r"\\**#Antispam_Log**//" "\n\n**GBanned User $SPOTTED**\n" f"**User:** [{firstname}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** {reason}\n**Quick Action:** " "Banned in {message.chat.title}") except Exception: break except Exception: pass if Config.ANTISPAM_SENTRY: try: if Config.SPAM_WATCH_API is not None: SENTRY = spamwatch.Client(Config.SPAM_WATCH_API) intruder = SENTRY.get_ban(user_id) if intruder and await guadmin_check(chat_id, user_id): await userge.kick_chat_member(chat_id, user_id) await message.reply( r"\\**#Userge_Antispam**//" "\n\n\nGlobally Banned User Detected in this Chat.\n\n" "**$SENTRY SpamWatch Federation Ban**\n" f"**User:** [{firstname}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{intruder.reason}`\n\n" "**Quick Action:** Banned.") await GBAN_LOG.log( r"\\**#Antispam_Log**//" "\n\n**GBanned User $SPOTTED**\n" "**$SENRTY #SPAMWATCH_API BAN**" f"\n**User:** [{firstname}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{intruder.reason}`\n" "**Quick Action:** Banned in {message.chat.title}\n\n$AUTOBAN #id{user_id}" ) except Exception: pass try: res = requests.get( f'https://combot.org/api/cas/check?user_id={user_id}') res_dict = json.loads(res.text) if res_dict['ok'] and await guadmin_check(chat_id, user_id): try: reason = res_dict['result']['offenses'] await userge.kick_chat_member(chat_id, user_id) await message.reply( r"\\**#Userge_Antispam**//" "\n\n\nGlobally Banned User Detected in this Chat.\n\n" "**$SENTRY CAS Federation Ban**\n" f"**User:** [{firstname}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{reason}`\n\n" "**Quick Action:** Banned.") await GBAN_LOG.log( r"\\**#Antispam_Log**//" "\n\n**GBanned User $SPOTTED**\n" "**$SENRTY #CAS BAN**" f"\n**User:** [{firstname}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{reason}`\n**Quick Action:**" " Banned in {message.chat.title}\n\n$AUTOBAN #id{user_id}" ) except Exception: pass except Exception: pass 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), 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), 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 iv = await getData( "https://api.intellivoid.net/spamprotection/v1/lookup?query=" + str(user_id) ) 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), 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), 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()