Skip to content

Commit

Permalink
some fixes + mention fixed in private msg (UsergeTeam#140)
Browse files Browse the repository at this point in the history
* changed reason to text.

* fixed here.

* fixed here.

* fixed here.

* fixed mention issue.
  • Loading branch information
Krishna-Singhal authored Aug 30, 2020
1 parent 53a6cdc commit e90b2e5
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
16 changes: 8 additions & 8 deletions userge/core/types/bound/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,24 +118,24 @@ def process_is_canceled(self) -> bool:
return self._process_canceled

@property
def extract_user_and_reason(self) -> Tuple[Optional[Union[str, int]], Optional[str]]:
""" Extracts User and Reason
def extract_user_and_text(self) -> Tuple[Optional[Union[str, int]], Optional[str]]:
""" Extracts User and Text
[NOTE]: This method checks for reply first.
On Success:
user (```str | int | None```) and reason (```str | None```)
user (``str | int | None``) and text (``str | None``)
"""
user_e: Optional[Union[str, int]] = None
reason: Optional[str] = None
text: Optional[str] = None
if self.reply_to_message:
if self.reply_to_message.from_user:
user_e = self.reply_to_message.from_user.id
reason = self.input_str
return user_e, reason
text = self.input_str
return user_e, text
if self.input_str:
data = self.input_str.split(maxsplit=1)
# Grab First Word and Process it.
if len(data) == 2:
user, reason = data
user, text = data
elif len(data) == 1:
user = data[0]
# if user id, convert it to integer
Expand All @@ -151,7 +151,7 @@ def extract_user_and_reason(self) -> Tuple[Optional[Union[str, int]], Optional[s
# User @ Mention.
if user.startswith("@"):
user_e = user
return user_e, reason
return user_e, text

def cancel_the_process(self) -> None:
""" Set True to the self.process_is_canceled """
Expand Down
14 changes: 7 additions & 7 deletions userge/plugins/admin/gadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async def promote_usr(message: Message):
custom_rank = ""
chat_id = message.chat.id
await message.edit("`Trying to Promote User.. Hang on!! ⏳`")
user_id, custom_rank = message.extract_user_and_reason
user_id, custom_rank = message.extract_user_and_text
if not user_id:
await message.edit(
text="`no valid user_id or message specified,`"
Expand Down Expand Up @@ -84,7 +84,7 @@ async def demote_usr(message: Message):
""" demote members in tg group """
chat_id = message.chat.id
await message.edit("`Trying to Demote User.. Hang on!! ⏳`")
user_id, _ = message.extract_user_and_reason
user_id, _ = message.extract_user_and_text
if not user_id:
await message.edit(
text="`no valid user_id or message specified,`"
Expand Down Expand Up @@ -126,7 +126,7 @@ async def ban_usr(message: Message):
reason = ""
chat_id = message.chat.id
await message.edit("`Trying to Ban User.. Hang on!! ⏳`")
user_id, reason = message.extract_user_and_reason
user_id, reason = message.extract_user_and_text
if not user_id:
await message.edit(
text="`no valid user_id or message specified,`"
Expand Down Expand Up @@ -162,7 +162,7 @@ async def unban_usr(message: Message):
""" unban user from tg group """
chat_id = message.chat.id
await message.edit("`Trying to Unban User.. Hang on!! ⏳`")
user_id, _ = message.extract_user_and_reason
user_id, _ = message.extract_user_and_text
if not user_id:
await message.edit(
text="`no valid user_id or message specified,`"
Expand Down Expand Up @@ -197,7 +197,7 @@ async def kick_usr(message: Message):
""" kick user from tg group """
chat_id = message.chat.id
await message.edit("`Trying to Kick User.. Hang on!! ⏳`")
user_id, _ = message.extract_user_and_reason
user_id, _ = message.extract_user_and_text
if not user_id:
await message.edit(
text="`no valid user_id or message specified,`"
Expand Down Expand Up @@ -243,7 +243,7 @@ async def mute_usr(message: Message):
hours = flags.get('-h', 0)
days = flags.get('-d', 0)
await message.edit("`Trying to Mute User.. Hang on!! ⏳`")
user_id, reason = message.extract_user_and_reason
user_id, reason = message.extract_user_and_text
if not user_id:
await message.edit(
text="`no valid user_id or message specified,`"
Expand Down Expand Up @@ -314,7 +314,7 @@ async def unmute_usr(message: Message):
""" unmute user from tg group """
chat_id = message.chat.id
await message.edit("`Trying to Unmute User.. Hang on!! ⏳`")
user_id, _ = message.extract_user_and_reason
user_id, _ = message.extract_user_and_text
if not user_id:
await message.edit(
text="`no valid user_id or message specified,`"
Expand Down
8 changes: 4 additions & 4 deletions userge/plugins/admin/gban.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async def antispam_(message: Message):
async def gban_user(message: Message):
""" ban a user globally """
await message.edit("`GBanning...`")
user_id, reason = message.extract_user_and_reason
user_id, reason = message.extract_user_and_text
if not user_id:
await message.edit(
"`no valid user_id or message specified,`"
Expand Down Expand Up @@ -125,7 +125,7 @@ async def gban_user(message: Message):
async def ungban_user(message: Message):
""" unban a user globally """
await message.edit("`UnGBanning...`")
user_id, _ = message.extract_user_and_reason
user_id, _ = message.extract_user_and_text
if not user_id:
await message.err("user-id not found")
return
Expand Down Expand Up @@ -180,7 +180,7 @@ async def list_gbanned(message: Message):
allow_channels=False, allow_bots=False)
async def whitelist(message: Message):
""" add user to whitelist """
user_id, _ = message.extract_user_and_reason
user_id, _ = message.extract_user_and_text
if not user_id:
await message.err("user-id not found")
return
Expand Down Expand Up @@ -215,7 +215,7 @@ async def whitelist(message: Message):
allow_channels=False, allow_bots=False)
async def rmwhitelist(message: Message):
""" remove a user from whitelist """
user_id, _ = message.extract_user_and_reason
user_id, _ = message.extract_user_and_text
if not user_id:
await message.err("user-id not found")
return
Expand Down
4 changes: 2 additions & 2 deletions userge/plugins/admin/gmute.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
async def gmute_user(msg: Message):
""" Mute a user globally """
await msg.edit("`Globally Muting this User...`")
user_id, reason = msg.extract_user_and_reason
user_id, reason = msg.extract_user_and_text
if not user_id:
await msg.edit(
"`no valid user_id or message specified,`"
Expand Down Expand Up @@ -97,7 +97,7 @@ async def gmute_user(msg: Message):
async def ungmute_user(msg: Message):
""" unmute a user globally """
await msg.edit("`UnGMuting this User...`")
user_id, _ = msg.extract_user_and_reason
user_id, _ = msg.extract_user_and_text
if not user_id:
await msg.err("user-id not found")
return
Expand Down
10 changes: 5 additions & 5 deletions userge/plugins/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,23 +390,23 @@ async def inline_answer(_, inline_query: InlineQuery):
)
)
if '-' in inline_query.query:
username, msg = inline_query.query.split('-', maxsplit=1)
_id, msg = inline_query.query.split('-', maxsplit=1)
if not msg:
return
if not msg.strip().endswith(':'):
return
try:
user = await userge.get_user_dict(username.strip())
user = await userge.get_users(_id.strip())
except Exception: # pylint: disable=broad-except
return
PRVT_MSGS[inline_query.id] = (user['id'], user['flname'], msg.strip(': '))
PRVT_MSGS[inline_query.id] = (user.id, user.first_name, msg.strip(': '))
prvte_msg = [[InlineKeyboardButton(
"Show Message 🔐", callback_data=f"prvtmsg({inline_query.id})")]]
msg_c = f"🔒 A **private message** to {user['mention']}, Only he/she can open it."
msg_c = f"🔒 A **private message** to {user.mention}, Only he/she can open it."
results.append(
InlineQueryResultArticle(
id=uuid4(),
title=f"A Private Msg to {user['flname']}",
title=f"A Private Msg to {user.first_name}",
input_message_content=InputTextMessageContent(msg_c),
description="Only he/she can open it",
thumb_url="https://imgur.com/download/Inyeb1S",
Expand Down

0 comments on commit e90b2e5

Please sign in to comment.