Skip to content

Commit

Permalink
Revert "Added Info button in message.err [t.me/usergeot/736663] + upd…
Browse files Browse the repository at this point in the history
…ated Use… (UsergeTeam#348)" (UsergeTeam#357)

This reverts commit e931de5.
  • Loading branch information
rking32 authored Jul 24, 2021
1 parent f46bd50 commit 357edb4
Show file tree
Hide file tree
Showing 37 changed files with 219 additions and 307 deletions.
138 changes: 27 additions & 111 deletions userge/core/types/bound/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@
import asyncio
from typing import List, Dict, Tuple, Union, Optional, Sequence

from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, Message as RawMessage
from pyrogram.errors import (
MessageAuthorRequired, MessageTooLong, MessageNotModified,
MessageIdInvalid, MessageDeleteForbidden, BotInlineDisabled
)

from userge import logging, Config
from userge.utils import is_command
from pyrogram.types import InlineKeyboardMarkup, Message as RawMessage
from pyrogram.errors.exceptions import MessageAuthorRequired, MessageTooLong
from pyrogram.errors.exceptions.bad_request_400 import MessageNotModified, MessageIdInvalid
from pyrogram.errors.exceptions.forbidden_403 import MessageDeleteForbidden

from userge import logging
from ... import client as _client # pylint: disable=unused-import

_CANCEL_LIST: List[int] = []
_ERROR_MSG_DELETE_TIMEOUT = 5
_ERROR_STRING = "**ERROR**: `{}`"

_LOG = logging.getLogger(__name__)
Expand Down Expand Up @@ -458,7 +457,7 @@ async def err(self,
parse_mode: Union[str, object] = object,
disable_web_page_preview: Optional[bool] = None,
reply_markup: InlineKeyboardMarkup = None) -> Union['Message', bool]:
"""\nYou can send error messages with command info button using this method
"""\nYou can send error messages using this method
Example:
message.err(text='error', del_in=3)
Expand Down Expand Up @@ -493,57 +492,18 @@ async def err(self,
An InlineKeyboardMarkup object.
Returns:
On success,
If Client of message is Userge:
the sent :obj:`Message` or True is returned.
if Client of message is UsergeBot:
the edited :obj:`Message` or True is returned.
On success, the edited
:obj:`Message` or True is returned.
"""
command_name = self.text.split()[0].strip()
cmd = command_name.lstrip(Config.CMD_TRIGGER).lstrip(Config.SUDO_TRIGGER)
is_cmd = is_command(cmd)
if not is_cmd or not bool(Config.BOT_TOKEN):
return await self.edit(text=_ERROR_STRING.format(text),
del_in=del_in,
log=log,
sudo=sudo,
parse_mode=parse_mode,
disable_web_page_preview=disable_web_page_preview,
reply_markup=reply_markup)
bot_username = (await self._client.get_me()).username
if self._client.is_bot:
btn = [InlineKeyboardButton("Info!", url=f"t.me/{bot_username}?start={cmd}")]
if reply_markup:
reply_markup.inline_keyboard.append(btn)
else:
reply_markup = InlineKeyboardMarkup([btn])
msg_obj = await self.edit(text=_ERROR_STRING.format(text),
del_in=del_in,
log=log,
sudo=sudo,
parse_mode=parse_mode,
disable_web_page_preview=disable_web_page_preview,
reply_markup=reply_markup)
else:
bot_username = (await self._client.bot.get_me()).username
try:
k = await self._client.get_inline_bot_results(
bot_username, f"msg.err {cmd} {_ERROR_STRING.format(text)}"
)
await self.delete()
msg_obj = await self._client.send_inline_bot_result(
self.chat.id, query_id=k.query_id,
result_id=k.results[2].id, hide_via=True
)
except (IndexError, BotInlineDisabled):
msg_obj = await self.edit(text=_ERROR_STRING.format(text),
del_in=del_in,
log=log,
sudo=sudo,
parse_mode=parse_mode,
disable_web_page_preview=disable_web_page_preview,
reply_markup=reply_markup)
return msg_obj
del_in = del_in if del_in > 0 \
else _ERROR_MSG_DELETE_TIMEOUT
return await self.edit(text=_ERROR_STRING.format(text),
del_in=del_in,
log=log,
sudo=sudo,
parse_mode=parse_mode,
disable_web_page_preview=disable_web_page_preview,
reply_markup=reply_markup)

async def force_err(self,
text: str,
Expand All @@ -553,7 +513,7 @@ async def force_err(self,
disable_web_page_preview: Optional[bool] = None,
reply_markup: InlineKeyboardMarkup = None,
**kwargs) -> Union['Message', bool]:
"""\nThis will first try to message.err.
"""\nThis will first try to message.edit.
If it raise MessageAuthorRequired or
MessageIdInvalid error, run message.reply.
Expand Down Expand Up @@ -590,62 +550,18 @@ async def force_err(self,
**kwargs (for message.reply)
Returns:
On success,
If Client of message is Userge:
the sent :obj:`Message` or True is returned.
if Client of message is UsergeBot:
the edited or replied :obj:`Message` or True is returned.
On success, the edited or replied
:obj:`Message` or True is returned.
"""
try:
msg_obj = await self.err(text=_ERROR_STRING.format(text),
del_in = del_in if del_in > 0 \
else _ERROR_MSG_DELETE_TIMEOUT
return await self.force_edit(text=_ERROR_STRING.format(text),
del_in=del_in,
log=log,
parse_mode=parse_mode,
disable_web_page_preview=disable_web_page_preview,
reply_markup=reply_markup)
except (MessageAuthorRequired, MessageIdInvalid):
command_name = self.text.split()[0].strip()
cmd = command_name.lstrip(Config.CMD_TRIGGER).lstrip(Config.SUDO_TRIGGER)
is_cmd = is_command(cmd)
if not is_cmd or not bool(Config.BOT_TOKEN):
return await self.reply(text=_ERROR_STRING.format(text),
del_in=del_in,
log=log,
parse_mode=parse_mode,
disable_web_page_preview=disable_web_page_preview,
reply_markup=reply_markup)
bot_username = (await self._client.get_me()).username
if self._client.is_bot:
btn = [InlineKeyboardButton("Info!", url=f"t.me/{bot_username}?start={cmd}")]
if reply_markup:
reply_markup.inline_keyboard.append(btn)
else:
reply_markup = InlineKeyboardMarkup([btn])
msg_obj = await self.reply(text=_ERROR_STRING.format(text),
del_in=del_in,
log=log,
parse_mode=parse_mode,
disable_web_page_preview=disable_web_page_preview,
reply_markup=reply_markup)
else:
bot_username = (await self._client.bot.get_me()).username
try:
k = await self._client.get_inline_bot_results(
bot_username, f"msg.err {cmd} {_ERROR_STRING.format(text)}"
)
await self.delete()
msg_obj = await self._client.send_inline_bot_result(
self.chat.id, query_id=k.query_id,
result_id=k.results[2].id, hide_via=True
)
except (IndexError, BotInlineDisabled):
msg_obj = await self.reply(text=_ERROR_STRING.format(text),
del_in=del_in,
log=log,
parse_mode=parse_mode,
disable_web_page_preview=disable_web_page_preview,
reply_markup=reply_markup)
return msg_obj
reply_markup=reply_markup,
**kwargs)

async def edit_or_send_as_file(self,
text: str,
Expand Down
18 changes: 9 additions & 9 deletions userge/plugins/admin/antiflood.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ async def set_flood(msg: Message):
""" Set flood on/off and flood limit """
args = msg.input_str
if not args:
await msg.err("Input not found!")
await msg.err("read .help setflood")
return
if 'on' in args.lower():
if msg.chat.id in ANTIFLOOD_DATA and ANTIFLOOD_DATA[msg.chat.id].get("data") == "on":
return await msg.edit("Antiflood Already enabled for this chat.", del_in=5)
return await msg.err("Antiflood Already enabled for this chat.")
chat_limit = 5
chat_mode = "Ban"
if ANTIFLOOD_DATA.get(msg.chat.id):
Expand All @@ -80,7 +80,7 @@ async def set_flood(msg: Message):
if msg.chat.id not in ANTIFLOOD_DATA or (
msg.chat.id in ANTIFLOOD_DATA and ANTIFLOOD_DATA[msg.chat.id].get("data") == "off"
):
return await msg.edit("Antiflood Already Disabled for this chat.", del_in=5)
return await msg.err("Antiflood Already Disabled for this chat.")
ANTIFLOOD_DATA[msg.chat.id]["data"] = "off"
await ANTI_FLOOD.update_one(
{'chat_id': msg.chat.id}, {"$set": {'data': 'off'}}, upsert=True)
Expand All @@ -89,7 +89,7 @@ async def set_flood(msg: Message):
if msg.chat.id not in ANTIFLOOD_DATA or (
msg.chat.id in ANTIFLOOD_DATA and ANTIFLOOD_DATA[msg.chat.id].get("data") == "off"
):
return await msg.edit("First turn ON ANTIFLOOD then set Limit.", del_in=5)
return await msg.err("First turn ON ANTIFLOOD then set Limit.")
input_ = int(args)
if input_ < 3:
await msg.err("Can't set Antiflood Limit less then 3")
Expand All @@ -102,7 +102,7 @@ async def set_flood(msg: Message):
log=__name__, del_in=5
)
else:
await msg.err("Invalid argument!")
await msg.err("Invalid argument, read .help setflood")


@userge.on_cmd("setmode", about={
Expand All @@ -114,12 +114,12 @@ async def set_mode(msg: Message):
""" Set flood mode to take action """
mode = msg.input_str
if not mode:
await msg.err("Input not found!")
await msg.err("read .help setmode")
return
if msg.chat.id not in ANTIFLOOD_DATA or (
msg.chat.id in ANTIFLOOD_DATA and ANTIFLOOD_DATA[msg.chat.id].get("data") == "off"
):
return await msg.edit("First turn ON ANTIFLOOD then set Mode.", del_in=5)
return await msg.err("First turn ON ANTIFLOOD then set Mode.")
if mode.lower() in ('ban', 'kick', 'mute'):
ANTIFLOOD_DATA[msg.chat.id]["mode"] = mode.lower()
await ANTI_FLOOD.update_one(
Expand All @@ -129,7 +129,7 @@ async def set_mode(msg: Message):
log=__name__, del_in=5
)
else:
await msg.err("Invalid argument!")
await msg.err("Invalid argument, read .help setmode")


@userge.on_cmd("vflood", about={
Expand All @@ -139,7 +139,7 @@ async def view_flood_settings(msg: Message):
""" view Current Flood Settings """
chat_data = ANTIFLOOD_DATA.get(msg.chat.id)
if not chat_data or (chat_data and chat_data.get("data") == "off"):
return await msg.edit("`Anti-Flood Disabled in this chat.`")
return await msg.err("Anti-Flood Disabled in this chat.")
limit = chat_data["limit"]
mode = chat_data["mode"]
await msg.edit(
Expand Down
Loading

0 comments on commit 357edb4

Please sign in to comment.