Skip to content

Commit

Permalink
Add android module, stability tweaks (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
user838492843 committed Aug 2, 2020
1 parent 8ebd2a8 commit 11e5a07
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 12 deletions.
7 changes: 2 additions & 5 deletions modules/afk.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,20 @@
from telethon.tl import functions, types



client.storage.USER_AFK = {} # pylint:disable=E0602
client.storage.afk_time = None # pylint:disable=E0602
client.storage.last_afk_message = {} # pylint:disable=E0602
@client.on(register(outgoing=True)) # pylint:disable=E0602
async def set_not_afk(event):
current_message = event.message.message
if f"{Config.COMMAND_HANDLER}afk" not in current_message and "yes" in client.storage.USER_AFK: # pylint:disable=E0602
if "afk" not in current_message.lower() and "yes" in client.storage.USER_AFK: # pylint:disable=E0602
try:
status = "Set AFK mode to False"
await log(status)
except Exception as e: # pylint:disable=C0103,W0703
await client.send_message( # pylint:disable=E0602
event.chat_id,
"**AFK LOGGER " + \
"turned" + \
"off**",
"**Please set** `LOGGER_GROUP` **env variable for proper functioning**",
reply_to=event.message.id,
silent=True
)
Expand Down
72 changes: 72 additions & 0 deletions modules/android.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Copyright (C) 2019 The Raphielscape Company LLC.
#
# Licensed under the Raphielscape Public License, Version 1.c (the "License");
# you may not use this file except in compliance with the License.

from telethon import events
import re
from requests import get
from bs4 import BeautifulSoup

GITHUB = 'https://github.com'
DEVICES_DATA = 'https://raw.githubusercontent.com/androidtrackers/' \
'certified-android-devices/master/devices.json'


@client.on(register("magisk ?(.*)"))
async def magisk(event):
if event.fwd_from:
return
magisk_dict = {
"Stable":
"https://raw.githubusercontent.com/topjohnwu/magisk_files/master/stable.json",
"Beta":
"https://raw.githubusercontent.com/topjohnwu/magisk_files/master/beta.json"
}
releases = 'Latest Magisk Releases:\n'
for name, release_url in magisk_dict.items():
data = get(release_url).json()
releases += f'{name}: [ZIP v{data["magisk"]["version"]}]({data["magisk"]["link"]}) | ' \
f'[APK v{data["app"]["version"]}]({data["app"]["link"]}) | ' \
f'[Uninstaller]({data["uninstaller"]["link"]})\n'
await event.edit(releases)


@client.on(register(pattern="twrp ?(.*)"))
async def twrp(event):
if event.fwd_from:
return
device = event.pattern_match.group(1)
if not device:
clip = await event.get_reply_message()
device = clip.text
device = event.pattern_match.group(1)
if device:
pass
else:
await event.edit("**Usage:** `.twrp <codename>`")
return
url = get(f'https://dl.twrp.me/{device}/')
if url.status_code == 404:
reply = f"`Couldn't find twrp downloads for {device}!`\n"
await event.edit(reply)
return
page = BeautifulSoup(url.content, 'lxml')
download = page.find('table').find('tr').find('a')
dl_link = f"https://dl.twrp.me{download['href']}"
dl_file = download.text
size = page.find("span", {"class": "filesize"}).text
date = page.find("em").text.strip()
reply = f'**Latest TWRP for {device}:**\n' \
f'[{dl_file}]({dl_link}) - __{size}__\n' \
f'**Updated:** __{date}__\n'
await event.edit(reply)


Config.HELPER.update({"android": "\
**Requested module --> Android**\
\n\n```.magisk```\
\nUsage: Get latest Magisk releases\
\n\n```.twrp <codename>```\
\nUsage: Get latest twrp download for android device.\
"})
2 changes: 2 additions & 0 deletions requirements-optional.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ aiofiles
aiohttp
aria2p
beautifulsoup4
bs4
cfscrape
cryptg
emoji
Expand All @@ -11,6 +12,7 @@ gsearch
gtts
gitpython
hachoir
lxml
Pillow
psycopg2
psutil
Expand Down
9 changes: 2 additions & 7 deletions userbot/core.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# This Source C
# ode Form is subject to the terms of the Mozilla Public
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

Expand Down Expand Up @@ -148,7 +147,7 @@ async def alive(event):
username = f"\nUser: `{user}\n"
memory = psutil.virtual_memory()
specs = f"`System: {uname.system}\nRelease: {uname.release}\nVersion: {uname.version}\nProcessor: {uname.processor}\nMemory [RAM]: {get_size(memory.total)}`"
help_string = f"**// The-TG-Bot v3 is running //**\n\n**General Info:**\n`Build Version: {build} {username}`Github Repository: `{Config.GITHUB_REPO_LINK}\n\n**System Specifications:**\n{specs}\n```Python: {sys.version}```\n```Telethon: {__version__}```\n\n**Contact developer:** [justaprudev](https://t.me/justaprudev) \n**Update channel:** [Join](https://t.me/The_TG_Bot) \n**Support group:** [Join](https://t.me/The_TG_Bot_Support)"
help_string = f"**// The-TG-Bot v3 is running //**\n\n**General Info:**\n`Build Version: {build} {username}`Github Repository: `{Config.GITHUB_REPO_LINK}\n\n**System Specifications:**\n{specs}\n```Python: {sys.version}```\n```Telethon: {__version__}```\n\n**Contact developer:** [Priyam Kalra](https://t.me/justaprudev) \n**Update channel:** [Join](https://t.me/The_TG_Bot) \n**Support group:** [Join](https://t.me/The_TG_Bot_Support)"
await client.send_file(
event.chat_id,
caption=help_string,
Expand Down Expand Up @@ -182,9 +181,5 @@ def get_size(bytes, suffix="B"):
\nUsage: Restarts the userbot.\
\n\n```.share <module_name>```\
\nUsage: Share any loaded module.\
\n\n```.nuke <module_name>```\
\nUsage: Nuke any module, loaded or unloaded.\
\n\n```.recovery <module_name>```\
\nUsage: Recover and load any nuked module.\
"
})

0 comments on commit 11e5a07

Please sign in to comment.