Skip to content

Commit

Permalink
new alive template (UsergeTeam#135)
Browse files Browse the repository at this point in the history
* new template

* optimizing

Co-authored-by: rking32 <[email protected]>
  • Loading branch information
Krishna-Singhal and rking32 authored Aug 29, 2020
1 parent 596568e commit f7168f3
Showing 1 changed file with 35 additions and 41 deletions.
76 changes: 35 additions & 41 deletions userge/plugins/tools/alive.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,69 +12,63 @@
from userge.core.ext import RawClient
from userge import userge, Message, Config, versions, get_version

LOGO_STICKER_ID, LOGO_STICKER_REF = None, None
LOGO_ID, LOGO_REF = None, None


@userge.on_cmd("alive", about={
'header': "This command is just for fun"}, allow_channels=False)
async def alive(message: Message):
await message.delete()
await sendit(message)
output = f"""
**uptime** : `{userge.uptime}`
**version** : `{get_version()}`
**uptime** : `{userge.uptime}`
**💥 version** : `{get_version()}`
• **sudo** : `{_parse_arg(Config.SUDO_ENABLED)}`
• **anti-spam** : `{_parse_arg(Config.ANTISPAM_SENTRY)}`
• **dual-mode** : `{_parse_arg(RawClient.DUAL_MODE)}`
• **sudo**: `{_parse_arg(Config.SUDO_ENABLED)}`
• **anti-spam**: `{_parse_arg(Config.ANTISPAM_SENTRY)}`
• **dual-mode**: `{_parse_arg(RawClient.DUAL_MODE)}`
"""
if Config.HEROKU_APP:
output += f"• **dyno-saver** : `{_parse_arg(Config.RUN_DYNO_SAVER)}`"
output += f"• **dyno-saver**: `{_parse_arg(Config.RUN_DYNO_SAVER)}`"
output += f"""
• **unofficial** : `{_parse_arg(Config.LOAD_UNOFFICIAL_PLUGINS)}`
• **unofficial**: `{_parse_arg(Config.LOAD_UNOFFICIAL_PLUGINS)}`
**__python__** : `{versions.__python_version__}`
**__pyrogram__** : `{versions.__pyro_version__}`
**__Python__**: `{versions.__python_version__}`
**__Pyrogram__**: `{versions.__pyro_version__}`
**{versions.__license__}** | **{versions.__copyright__}** | **[Repo]({Config.UPSTREAM_REPO})**
"""
await message.client.send_message(message.chat.id, output, disable_web_page_preview=True)
try:
await _send_alive(message, output)
except (FileIdInvalid, FileReferenceEmpty, BadRequest):
await _refresh_id()
await _send_alive(message, output)


def _parse_arg(arg: bool) -> str:
return "✅" if arg else "❎"

return "enabled" if arg else "disabled"

async def refresh_id():
global LOGO_STICKER_ID, LOGO_STICKER_REF # pylint: disable=global-statement
sticker = (await userge.get_messages('theUserge', 8)).sticker
LOGO_STICKER_ID = sticker.file_id
LOGO_STICKER_REF = sticker.file_ref


async def send_sticker(message):
async def _send_alive(message: Message, text: str) -> None:
if not (LOGO_ID and LOGO_REF):
await _refresh_id()
try:
await message.client.send_sticker(
message.chat.id, LOGO_STICKER_ID, file_ref=LOGO_STICKER_REF)
await message.client.send_animation(chat_id=message.chat.id,
animation=LOGO_ID,
file_ref=LOGO_REF,
caption=text)
except MediaEmpty:
pass
await message.client.send_message(chat_id=message.chat.id,
text=text,
disable_web_page_preview=True)


async def sendit(message):
if LOGO_STICKER_ID:
try:
await send_sticker(message)
except (FileIdInvalid, FileReferenceEmpty, BadRequest):
try:
await refresh_id()
except ChannelInvalid:
pass
else:
await send_sticker(message)
async def _refresh_id():
global LOGO_ID, LOGO_REF # pylint: disable=global-statement
try:
gif = (await userge.get_messages('theUserge', 31)).animation
except ChannelInvalid:
LOGO_ID = None
LOGO_REF = None
else:
try:
await refresh_id()
except ChannelInvalid:
pass
else:
await send_sticker(message)
LOGO_ID = gif.file_id
LOGO_REF = gif.file_ref

0 comments on commit f7168f3

Please sign in to comment.