Skip to content

Commit

Permalink
fix gban and now filters and notes should support any character πŸ€”
Browse files Browse the repository at this point in the history
  • Loading branch information
rking32 committed Jun 29, 2020
1 parent 8107485 commit f79622b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 47 deletions.
77 changes: 34 additions & 43 deletions userge/plugins/admin/gban.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import requests
import spamwatch
from pyrogram.errors.exceptions.bad_request_400 import ChatAdminRequired

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

Expand All @@ -32,14 +33,6 @@ async def me_can_restrict_members(chat_id: int):
return False


async def user_is_admin(chat_id: int, user_id: int) -> bool:
check_status = await userge.get_chat_member(chat_id, user_id)
admin_strings = ["creator", "administrator"]
if check_status.status not in admin_strings:
return False
return True


@userge.on_cmd("gban", about={
'header': "Globally Ban A User",
'description': "Adds User to your GBan List. "
Expand All @@ -49,7 +42,7 @@ async def user_is_admin(chat_id: int, user_id: int) -> bool:
allow_channels=False, allow_bots=False)
async def gban_user(message: Message):
""" ban a user globally """
chat_id = message.chat.id
await message.edit("`GBanning...`")
if message.reply_to_message:
user_id = message.reply_to_message.from_user.id
reason = message.input_str
Expand Down Expand Up @@ -85,31 +78,27 @@ async def gban_user(message: Message):
"**#Already_GBanned**\n\nUser Already Exists in My Gban List.\n"
f"**Reason For GBan:** `{found['reason']}`", del_in=5)
return
async for chat in userge.get_common_chats(user_id):
await chat.kick_member(user_id)
sent = await message.edit(
r"\\**#GBanned_User**//"
f"\n\n**First Name:** [{firstname}](tg://user?id={user_id})\n"
f"**User ID:** `{user_id}`\n**Reason:** `{reason}`")
await asyncio.gather(
GBAN_USER_BASE.insert_one(
{'firstname': firstname, 'user_id': user_id, 'reason': reason}),
message.edit(
r"\\**#GBanned_User**//"
f"\n\n**First Name:** [{firstname}](tg://user?id={user_id})\n"
f"**User ID:** `{user_id}`\n**Reason:** `{reason}`"))
# TODO: can we add something like "GBanned by {any_sudo_user_fname}"
await GBAN_USER_BASE.insert_one(
{'firstname': firstname, 'user_id': user_id, 'reason': reason})
if message.chat.type not in ('private', 'bot') and await me_can_restrict_members(chat_id):
if await user_is_admin(chat_id, user_id):
await sent.reply(
f"**#GBanned_user** is admin of {message.chat.title}\n\n"
"**Failed to Ban** but still they are GBanned")
else:
await userge.kick_chat_member(chat_id, user_id)
for chat in await userge.get_common_chats(user_id):
try:
await chat.kick_member(user_id)
await CHANNEL.log(
r"\\**#Antispam_Log**//"
f"\n**User:** [{firstname}](tg://user?id={user_id})\n"
f"**User ID:** `{user_id}`\n"
f"**Chat:** {chat.title}\n"
f"**Chat ID:** `{chat.id}`\n"
f"**Reason:** `{reason}`\n\n$GBAN #id{user_id}")
except ChatAdminRequired:
pass
LOG.info("G-Banned %s", str(user_id))
await CHANNEL.log(
r"\\**#Antispam_Log**//"
f"\n**User:** [{firstname}](tg://user?id={user_id})\n"
f"**User ID:** `{user_id}`\n"
f"**Chat:** {message.chat.title}\n"
f"**Chat ID:** `{chat_id}`\n"
f"**Reason:** `{reason}`\n\n$GBAN #id{user_id}"
)
try:
if message.reply_to_message:
await CHANNEL.fwd_msg(message.reply_to_message)
Expand All @@ -126,7 +115,7 @@ async def gban_user(message: Message):
allow_channels=False, allow_bots=False)
async def ungban_user(message: Message):
""" unban a user globally """
chat_id = message.chat.id
await message.edit("`UnGBanning...`")
if message.reply_to_message:
user_id = message.reply_to_message.from_user.id
else:
Expand All @@ -141,21 +130,23 @@ async def ungban_user(message: Message):
if not found:
await message.err("User Not Found in My Gban List")
return
async for chat in userge.get_common_chats(user_id):
await chat.unban_member(user_id)
await asyncio.gather(
GBAN_USER_BASE.delete_one({'firstname': firstname, 'user_id': user_id}),
message.edit(
r"\\**#UnGbanned_User**//"
f"\n\n**First Name:** [{firstname}](tg://user?id={user_id})\n"
f"**User ID:** `{user_id}`"),
CHANNEL.log(
r"\\**#Antispam_Log**//"
f"\n**User:** [{firstname}](tg://user?id={user_id})\n"
f"**User ID:** `{user_id}`\n"
f"**Chat:** {message.chat.title}\n"
f"**Chat ID:** `{chat_id}`\n\n$UNGBAN #id{user_id}")
)
f"**User ID:** `{user_id}`"))
for chat in await userge.get_common_chats(user_id):
try:
await chat.unban_member(user_id)
await CHANNEL.log(
r"\\**#Antispam_Log**//"
f"\n**User:** [{firstname}](tg://user?id={user_id})\n"
f"**User ID:** `{user_id}`\n"
f"**Chat:** {chat.title}\n"
f"**Chat ID:** `{chat.id}`\n\n$UNGBAN #id{user_id}")
except ChatAdminRequired:
pass
LOG.info("UnGbanned %s", str(user_id))


Expand Down
2 changes: 1 addition & 1 deletion userge/plugins/utils/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ async def delete_filters(message: Message) -> None:
await message.edit(text=out, del_in=3)


@userge.on_cmd(r"addfilter (\w[^\|]*)(?:\s?\|\s?([\s\S]+))?",
@userge.on_cmd(r"addfilter ([^\s\|][^\|]*)(?:\s?\|\s?([\s\S]+))?",
about={
'header': "Adds a filter by name",
'options': {
Expand Down
6 changes: 3 additions & 3 deletions userge/plugins/utils/notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async def mv_to_global_note(message: Message) -> None:
await message.edit(text=out, del_in=3)


@userge.on_cmd(r"(?:#|get\s)(\w[\w_]*)",
@userge.on_cmd(r"(?:#|get\s)(\S+)",
about={'header': "Gets a note by name",
'usage': "#[notename]\nget notename"},
group=-1,
Expand Down Expand Up @@ -113,7 +113,7 @@ async def get_note(message: Message) -> None:
reply_to_message_id=reply_to_message_id)


@userge.on_cmd(r"addnote (\w[\w_]*)(?:\s([\s\S]+))?",
@userge.on_cmd(r"addnote (\S+)(?:\s([\s\S]+))?",
about={
'header': "Adds a note by name",
'options': {
Expand All @@ -134,7 +134,7 @@ async def add_note(message: Message) -> None:
if replied and replied.text:
content = replied.text.html
if content:
content = "πŸ—’ **--{}--** πŸ—’\n\n{}".format(notename, content)
content = "πŸ“ **--{}--** πŸ“\n\n{}".format(notename, content)
if not (content or (replied and replied.media)):
await message.err(text="No Content Found!")
return
Expand Down

0 comments on commit f79622b

Please sign in to comment.