Skip to content
Merged

Beta #74

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ class Config(object):
THUMB_PIC = os.getenv("THUMB_PIC", "material/images/tron.png")
# ---------------------
TL_NAME = os.getenv("TL_NAME")

HELP_EMOJI = os.getenv("HELP_EMOJI")


4 changes: 3 additions & 1 deletion tronx/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
async def start_assistant():
""" Start assistant """
if app.bot:
await app.bot.start()
app.log.info("Assistant activated, startup in progress . . .\n")
else:
app.log.info("Assistant start unsuccessful, please check that you have given the bot token.\n")
Expand All @@ -23,6 +24,7 @@ async def start_assistant():
async def start_userbot():
""" Start userbot """
if app:
await app.start()
app.log.info("Userbot activated, startup in progress . . .\n")
else:
app.log.info("Userbot startup unsuccessful, please check everything again ...")
Expand All @@ -43,7 +45,7 @@ async def start_bot():
print(f"\n\n{_mods} modules Loaded")
await start_assistant()
await start_userbot()
idle()
await idle()



Expand Down
49 changes: 15 additions & 34 deletions tronx/clients/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,15 @@ def __init__(self):
workers=self.WORKERS,
)
self.start()

def tron(self):
return print(self.get_me())

def dc_id(self):
return (self.get_me())

def id(self):
return (self.get_me())

def name(self):
return (self.get_me())

def username(self):
return "@" + (self.get_me()) if (self.get_me()) else ""


class bot(Client, Utils):
self.bot = self.Bot()
self.me = self.get_me()
self.id = self.me.id
self.dc_id = self.me.dc_id
self.name = self.me.first_name
self.username = "@" + self.me.username if self.me.username else ""
self.stop()

class Bot(Client, Utils):
""" Assistant (Nora) """
def __init__(self):
super().__init__(
Expand All @@ -41,19 +32,9 @@ def __init__(self):
bot_token=self.TOKEN,
)
self.start()

def nora(self):
return self.bot.get_me()

def dc_id(self):
return (self.bot.get_me())

def id(self):
return (self.bot.get_me())

def name(self):
return (self.bot.get_me())

def username(self):
return "@" + (self.bot.get_me())

self.me = self.get_me()
self.id = self.me.id
self.dc_id = self.me.dc_id
self.name = self.me.first_name
self.username = "@" + self.me.username
self.stop()
2 changes: 1 addition & 1 deletion tronx/helpers/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class Decorators(object):
def alert_user(self, func):
async def wrapper(_, cb: CallbackQuery):
if cb.from_user and not cb.from_user.id in self.USER_ID:
if cb.from_user and not cb.from_user.id == self.id:
await cb.answer(
f"Sorry, but you can't use this userbot ! make your own userbot at @tronuserbot",
show_alert=True
Expand Down
12 changes: 6 additions & 6 deletions tronx/helpers/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ async def send_edit(
formats = [mono, bold, italic, strike, underline]

format_dict = {
"mono" : f"<code>{text}</code>",
"bold" : f"<b>{text}</b>",
"italic" : f"<i>{text}</i>",
"strike" : f"<s>{text}</s>",
"underline" : f"<u>{text}</u>"
mono : f"<code>{text}</code>",
bold : f"<b>{text}</b>",
italic : f"<i>{text}</i>",
strike : f"<s>{text}</s>",
underline : f"<u>{text}</u>"
}

edited = False
Expand All @@ -150,7 +150,7 @@ async def send_edit(
await self.edit_text(
m,
format_dict[x],
disable_wab_page_preview=disable_wab_page_preview,
disable_web_page_preview=disable_web_page_preview,
parse_mode=parse_mode
)
edited = True
Expand Down
9 changes: 8 additions & 1 deletion tronx/helpers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def UserUsername(self):

# mention of bot owner
def UserMention(self):
return self.mention_markdown(self.UserId(), self.UserName()) if self.UserName() and self.UserId() else None
return self.MentionMarkdown(self.UserId(), self.UserName()) if self.UserName() and self.UserId() else None


# telegram id of bot owner
Expand All @@ -32,3 +32,10 @@ def UserId(self):
def UserDc(self):
data = self.USER_DC if self.USER_DC else self.dc_id
return data if data else None


# custom user pic
def UserPic(self):
var = self.getdv("USER_PIC")
one = var if bool(var) is True else self.USER_PIC
return one if one else None
4 changes: 2 additions & 2 deletions tronx/helpers/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def DictSizeInBytes(self, directory):
elif entry.is_dir():
# if it's a directory, recursively call this function

total += DictSizeInBytes(entry.path)
total += self.DictSizeInBytes(entry.path)
except NotADirectoryError:
# if `directory` isn't a directory, get the file size then
return os.path.getsize(directory)
Expand All @@ -348,7 +348,7 @@ def SizeFormat(self, b, factor=1024, suffix="B"):


def DictSize(self, location):
return SizeFormat(DictSizeInBytes(location))
return self.SizeFormat(self.DictSizeInBytes(location))


def CleanHtml(self, raw_html):
Expand Down
18 changes: 8 additions & 10 deletions tronx/modules/afk.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async def go_offline(_, m: Message):
app.set_afk(True, m.text.split(None, 1)[1], start) # with reason
await app.send_edit(
m,
"{} is now Offline.\nBecause: {}".format(app.mymention(), m.text.split(None, 1)[1]),
"{} is now Offline.\nBecause: {}".format(app.UserMention(), m.text.split(None, 1)[1]),
delme=2
)
elif app.long(m) == 1 and app.long(m) < 4096:
Expand All @@ -51,7 +51,7 @@ async def go_offline(_, m: Message):
app.set_afk(True, "", start) # without reason
await app.send_edit(
m,
"{} is now offline.".format(app.mymention()),
"{} is now offline.".format(app.UserMention()),
delme=2
)
except Exception as e:
Expand Down Expand Up @@ -79,17 +79,17 @@ async def offline_mention(_, m: Message):
if get["reason"] and get["afktime"]:
msg = await app.send_message(
m.chat.id,
"Sorry {} is currently offline !\n**Time:** {}\n**Because:** {}".format(app.mymention(), otime, get['reason']),
"Sorry {} is currently offline !\n**Time:** {}\n**Because:** {}".format(app.UserMention(), otime, get['reason']),
reply_to_message_id=m.message_id
)
await delete(msg, 3)
await app.delete(msg, 3)
elif get["afktime"] and not get["reason"]:
await app.send_message(
msg = await app.send_message(
m.chat.id,
"Sorry {} is currently offline !\n**Time:** {}".format(app.mymention(), otime),
"Sorry {} is currently offline !\n**Time:** {}".format(app.UserMention(), otime),
reply_to_message_id=m.message_id
)
await delete(msg, 3)
await app.delete(msg, 3)
content, message_type = app.GetMessageType(m)
if message_type == app.TEXT:
if m.text:
Expand Down Expand Up @@ -135,11 +135,9 @@ async def back_online(_, m: Message):
afk_time = app.GetReadableTime(end - get["afktime"])
msg = await app.send_message(
m.chat.id,
f"{app.mymention()} is now online !\n**Time:** `{afk_time}`"
f"{app.UserMention()} is now online !\n**Time:** `{afk_time}`"
)
app.set_afk(False, "", 0)
else:
return

except Exception as e:
await app.error(m, e)
Expand Down
4 changes: 2 additions & 2 deletions tronx/modules/alive.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async def simple_alive(_, m: Message):
alive_msg = f"\n"
if BIO:
alive_msg += f"⦿ {BIO}\n\n"
alive_msg += f"⟜ **Owner:** {app.mymention()}\n"
alive_msg += f"⟜ **Owner:** {app.UserMention()}\n"
alive_msg += f"⟜ **Tron:** `{app.userbot_version}`\n"
alive_msg += f"⟜ **Python:** `{app.python_version}`\n"
alive_msg += f"⟜ **Pyrogram:** `{app.pyrogram_version}`\n"
Expand Down Expand Up @@ -106,7 +106,7 @@ async def inline_quote(_, m: Message):
try:
await app.send_edit(m,". . .")
try:
result = await app.get_inline_bot_results(BOT_USERNAME, "#q7o5e")
result = await app.get_inline_bot_results(app.bot.username, "#q7o5e")
except BotInvalid:
return await app.send_edit(m,"This bot can't be used in inline mode.", delme=2)

Expand Down
2 changes: 1 addition & 1 deletion tronx/modules/carbon.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ async def create_carbon(m: Message, text, colour):
await app.send_document(
m.chat.id,
filename,
caption=f"**Carbon Made by:** {app.mymention()}",
caption=f"**Carbon Made by:** {app.UserMention()}",
reply_to_message_id=reply_msg_id,
)
await m.delete()
Expand Down
4 changes: 2 additions & 2 deletions tronx/modules/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ async def list_directories(_, m: Message):
for file in files:
if not file.endswith(".session") and not file in ["__pycache__", ".git", ".github", ".profile.d", ".heroku", ".cache"]:
if os.path.isfile(f"{location}/{file}"):
collect.append(f"📑 `{file}` ({DictSize(os.path.abspath(location+file))})")
collect.append(f"📑 `{file}` ({app.DictSize(os.path.abspath(location+file))})")
if os.path.isdir(f"{location}/{file}"):
collect.append(f"🗂️ `{file}` ({DictSize(os.path.abspath(location+file))})")
collect.append(f"🗂️ `{file}` ({app.DictSize(os.path.abspath(location+file))})")

collect.sort() # sort the files
file = "\n".join(collect)
Expand Down
2 changes: 1 addition & 1 deletion tronx/modules/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async def slap_friends(app, m):
try:
await app.send_edit(m,"...")

my_info = app.mymention()
my_info = app.UserMention()
user = m.reply_to_message.from_user
user_info = app.mention_markdown(user.id, user.first_name)
TASK = (
Expand Down
5 changes: 2 additions & 3 deletions tronx/modules/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,9 @@ async def image_sauce(_, m: Message):
file_name="./downloads/" + universe
)
else:
await app.send_edit(m, "Only photo & animation media supported.", delme=3)
return
return await app.send_edit(m, "Only photo & animation media supported.", delme=3)
searchUrl = 'http://www.google.co.id/searchbyimage/upload'
filePath = 'tronx/downloads/{}'.format(universe)
filePath = './downloads/{}'.format(universe)
multipart = {'encoded_image': (filePath, open(filePath, 'rb')), 'image_content': ''}
response = requests.post(searchUrl, files=multipart, allow_redirects=False)
fetchUrl = response.headers['Location']
Expand Down
30 changes: 10 additions & 20 deletions tronx/modules/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
{"group" : (
"group",
{
"group [group name]" : "Creates a basic group.",
"bgroup [group name]" : "Creates a basic group.",
"sgroup [group name]" : "Creates a super group.",
"unread" : "Mark a chat as unread in your telegram folders."
"unread" : "Mark a chat as unread in your telegram folders.",
"channel [channel name]" : "Create a channel through this command."
}
)
}
Expand All @@ -31,21 +32,16 @@
@app.on_message(gen(["bgroup", "bgp"]))
async def create_basic_group(_, m: Message):
if app.long(m) < 2:
return await app.send_edit(m, f"`Usage: {app.PREFIX}group [group name]`", delme=3)
return await app.send_edit(m, f"`Usage: {app.PREFIX}bgroup [group name]`", delme=3)

args = m.text.split(None, 1)
grpname = args[1]
grptype = "basic"
user_id = "@Alita_Robot"
try:
if grptype == "basic":
try:
await app.send_edit(m, f"Creating a new basic group: `{grpname}`")
groupjson = await app.create_group(f"{grpname}", user_id)
print(groupjson)
except Exception as e:
await app.error(m, e)
await app.send_edit(m, f"**Created a new basic group:** `{grpname}`")
await app.send_edit(m, f"Creating a new basic group: `{grpname}`")
groupjson = await app.create_group(f"{grpname}", user_id)
await app.send_edit(m, f"**Created a new basic group:** `{grpname}`")
except Exception as e:
await app.error(m, e)

Expand All @@ -62,15 +58,9 @@ async def create_supergroup(_, m: Message):
grptype = "super"
user_id = "@Alita_Robot"
try:
if grptype == "super":
try:
await app.send_edit(m, f"Creating a new super Group: `{grpname}`")
await app.create_group(
f"{grpname}", user_id
)
except Exception as e:
await app.error(m, e)
await app.send_edit(m, f"**Created a new super Group:** `{grpname}`")
await app.send_edit(m, f"Creating a new super Group: `{grpname}`")
await app.create_supergroup(f"{grpname}", user_id)
await app.send_edit(m, f"**Created a new super Group:** `{grpname}`")
except Exception as e:
await app.error(m, e)

Expand Down
4 changes: 2 additions & 2 deletions tronx/modules/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@



@app.bot.on_callback_query(filters.regex("delete-dex") & filters.user(app.id()))
@app.bot.on_callback_query(filters.regex("delete-dex") & filters.user(app.id))
@app.alert_user
async def delete_helpdex(_, cb: CallbackQuery):
if bool(app.message_ids) is False:
Expand Down Expand Up @@ -64,7 +64,7 @@ async def help_menu(app, m):
if args is False:
await app.send_edit(m, ". . .", mono=True)
result = await app.get_inline_bot_results(
app.bot.username(),
app.bot.username,
"#t5r4o9nn6"
)
if result:
Expand Down
Loading