Skip to content

Commit

Permalink
Fixes Gban Filter Logic 😐 (UsergeTeam#44)
Browse files Browse the repository at this point in the history
* Okay!

* Lol

* DeepSource
  • Loading branch information
Phyco-Ninja authored Jun 4, 2020
1 parent 6657583 commit 0e360cf
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions userge/plugins/admin/gban.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import requests
import spamwatch

from pyrogram.errors import ChatAdminRequired

from userge import userge, Message, Config, get_collection, Filters

GBAN_USER_BASE = get_collection("GBAN_USER")
Expand Down Expand Up @@ -328,31 +330,30 @@ async def gban_at_entry(message: Message):
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:
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 ChatAdminRequired:
break
except Exception:
pass
except Exception as e:
LOG.exception(e)

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):
if intruder:
await userge.kick_chat_member(chat_id, user_id)
await message.reply(
r"\\**#Userge_Antispam**//"
Expand All @@ -368,13 +369,13 @@ async def gban_at_entry(message: Message):
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:
except ChatAdminRequired:
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):
if res_dict['ok']:
try:
reason = res_dict['result']['offenses']
await userge.kick_chat_member(chat_id, user_id)
Expand All @@ -392,8 +393,9 @@ async def gban_at_entry(message: Message):
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:
except ChatAdminRequired:
pass
except Exception:
pass
except Exception as e:
LOG.exception(e)

message.continue_propagation()

0 comments on commit 0e360cf

Please sign in to comment.