diff --git a/config.py b/config.py
index 1842f6e6..0b1cfc63 100644
--- a/config.py
+++ b/config.py
@@ -65,8 +65,10 @@ class Config(object):
BOT_NAME = os.getenv("BOT_NAME", "LARA")
# your aassistants alive pic (optional)
BOT_PIC = os.getenv("BOT_PIC", "https://telegra.ph/file/4d93e5fa480b5e53d898f.jpg")
- # bot username for bot
+ # bot username of bot
BOT_USERNAME = os.getenv("BOT_USERNAME")
+ # bot id of bot
+ BOT_ID = os.getenv("BOT_ID")
# token of your bot if you want to use assistant
TOKEN = os.getenv("TOKEN")
# ---------------------
diff --git a/tronx/helpers/bots.py b/tronx/helpers/bots.py
index 92a5f782..7078b9a6 100644
--- a/tronx/helpers/bots.py
+++ b/tronx/helpers/bots.py
@@ -1,16 +1,9 @@
-from tronx.helpers.utils import mention_markdown
-
-try:
- from tronx import (
- BOT_ID,
- BOT_NAME,
- BOT_USERNAME,
- Config
- )
-except ImportError:
- BOT_ID = Config.BOT_ID if Config.BOT_ID else None
- BOT_NAME = Config.BOT_NAME if Config.BOT_NAME else None
- BOT_USERNAME = Config.BOT_USERNAME if Config.BOT_USERNAME else None
+from tronx import (
+ BOT_ID,
+ BOT_NAME,
+ BOT_USERNAME,
+ Config
+)
from tronx.database.postgres import dv_sql as dv
from pyrogram.types import Message
@@ -18,59 +11,48 @@
-# name of bot (1st priority to database variable)
def botname():
+ """Get your bot name"""
var = dv.getdv("BOT_NAME")
var_data = var if bool(var) is True else Config.BOT_NAME
data = var_data if var_data else BOT_NAME
return data if data else None
-# username of bot
def botusername():
+ """Get your bot username"""
var = dv.getdv("BOT_USERNAME")
var_data = var if bool(var) is True else Config.BOT_USERNAME
data = var_data if var_data else BOT_USERNAME
return data if data else None
-# mention of bot
def botmention():
- return mention_markdown(botid(), botname()) if botid() and bname() else None
+ """Get bot mention"""
+ return f"[{botname()}](tg://user?id={botid()})" if botid() and botname() else None
-# id of bot
def botid():
+ """Get your bots telegram id"""
var = dv.getdv("BOT_ID")
var_data = var if bool(var) is True else Config.BOT_ID
data = var_data if var_data else BOT_ID
return data if data else None
-
-# bio of bot
def bot_bio(m: Message):
- if bool(dv.getdv("BOT_BIO")):
- msg = dv.getdv("BOT_BIO") + "\n\nCatagory: "
- elif Config.BOT_BIO:
- msg = Config.BOT_BIO + "\n\nCatagory: "
- else:
- msg = f"Hey {m.from_user.mention} my name is LARA and I am your assistant bot. I can help you in many ways . Just use the buttons below to get list of possible commands...And Other Functions.\n\nCatagory: "
- return msg
-
-
+ """Get your bots bio"""
+ msg = f"Hey {m.from_user.mention} my name is LARA and I am your assistant bot. I can help you in many ways . Just use the buttons below to get list of possible commands.\n\nCatagory: "
+ var = dv.getdv("BOT_BIO")
+ var_data = var + "\n\nCatagory: " if bool(var) else Config.BOT_BIO + "\n\nCatagory: "
+ data = var_data if var_data else msg
+ return data if data else None
-# pic of bot
def bot_pic():
- if bool(dv.getdv("BOT_PIC")):
- _pic = dv.getdv("BOT_PIC")
- elif Config.BOT_PIC:
- _pic = Config.BOT_PIC
- else:
- _pic = False
- return _pic
-
-#End
-
-
+ """Get your bot pic url"""
+ var = dv.getdv("BOT_PIC")
+ var_data = var if bool(var) else Config.BOT_PIC
+ data = var_data if bool(var_data) else False
+ return data if data else None
+
diff --git a/tronx/helpers/functions.py b/tronx/helpers/functions.py
index e97e3401..488e17f1 100644
--- a/tronx/helpers/functions.py
+++ b/tronx/helpers/functions.py
@@ -8,7 +8,7 @@
from pyrogram import Client
from pyrogram.types import Message
-from pyrogram.errors import YouBlockedUser
+from pyrogram.errors import YouBlockedUser, MessageIdInvalid
from tronx import (
app,
@@ -26,27 +26,22 @@
-# date
def showdate():
- today = pytz.timezone(
- Config.TIME_ZONE
- )
+ """Your location's date"""
+ today = pytz.timezone(Config.TIME_ZONE)
get_date = datetime.datetime.now(today)
mydate = get_date.strftime("%d %b %Y")
return mydate
-# time
def showtime():
- today = pytz.timezone(
- Config.TIME_ZONE
- )
+ """Your location's time"""
+ today = pytz.timezone(Config.TIME_ZONE)
get_time = datetime.datetime.now(today)
mytime = get_time.strftime("%r")
return mytime
-# send or edit msg
async def send_edit(
m: Message,
text,
@@ -59,6 +54,7 @@ async def send_edit(
strike=False,
underline=False,
):
+ """This function edits or sends the message"""
mono_text = f"{text}"
bold_text = f"{text}"
@@ -117,16 +113,15 @@ async def send_edit(
await error(m, e)
-
-
async def edit_text(m: Message, text, disable_web_page_preview=False, parse_mode="combined"):
+ """edit or send that message"""
try:
await m.edit(
text,
parse_mode=parse_mode,
disable_web_page_preview=disable_web_page_preview,
)
- except:
+ except MessageidInvalid:
await app.send_message(
m.chat.id,
text,
@@ -135,10 +130,8 @@ async def edit_text(m: Message, text, disable_web_page_preview=False, parse_mode
)
-
-
-# send msg
async def sendmsg(m: Message, text):
+ """Send message"""
try:
await app.send_message(
m.chat.id,
@@ -146,11 +139,10 @@ async def sendmsg(m: Message, text):
)
except Exception as e:
await error(m, e)
- return
-# show error
async def error(m: Message, e):
+ """Error tracing"""
teks = f"Traceback Report:\n\n"
teks += f"Date: {showdate()}\nTime: {showtime()}\n\n"
teks += f"This can be a error in tronuserbot, if you want you can forward this to @tronuserbot.\n\n"
@@ -163,37 +155,28 @@ async def error(m: Message, e):
Config.LOG_CHAT,
teks
)
+ except PeerIdInvalid:
print(teks)
- except:
- print(teks)
- log.error("Please check your logs online !")
- return
-
-
+ log.error("Please check your logs online.")
async def sleep(m: Message, sec, del_msg=False):
+ """Delete a message after some time"""
await asyncio.sleep(sec)
if del_msg:
await m.delete()
- return
-
-
-# delete msg
async def delete(m: Message, sec: int = 0):
+ """Delete a message after some time using sleep func"""
if not sec > 600: # 10 min
asyncio.create_task(sleep(m, sec=sec, del_msg=True))
else:
- log.error("maximum sleep of 10 ( 600 sec ) minutes")
- return
-
-
+ log.error("Delete function can sleep for 10 ( 600 sec ) minutes")
-# plugin information (CMD_HELP)
async def data(plug):
+ """Create help information page for each module"""
try:
plugin_data = []
plugin_data.clear()
@@ -211,10 +194,8 @@ async def data(plug):
return None
-
-
-# disallow use of cmds in private (user) chats
async def private(m : Message, back=True):
+ """Warn if command used group is private"""
if m.chat.type == "private":
await send_edit(
m,
@@ -224,29 +205,24 @@ async def private(m : Message, back=True):
)
if back:
return
-
-
-
async def code(my_codes):
+ """noobie code"""
try:
my_codes
except Exception as e:
await error(m, e)
-
-# it is equal to --> len(message.text.split())
def long(m: Message):
+ """to check args, same as len(message.text.split())"""
text = len(m.command)
return text if text else None
-
-
-# file creator
async def create_file(m: Message, filename, text):
+ """Create any file with any extension"""
try:
name = filename
content = text
@@ -264,16 +240,14 @@ async def create_file(m: Message, filename, text):
await error(m, e)
-
-# remove multiples of same element from a list
def rem_dual(one, two):
+ """remove multiples of same element from a list"""
data = list(set(one) - set(two))
return data
-
-# kick users from a chat
async def kick(chat_id, user_id):
+ """kick user from chat"""
try:
await app.kick_chat_member(
chat_id,
@@ -283,44 +257,39 @@ async def kick(chat_id, user_id):
print(e)
-
-# True if string else False
def is_str(element):
+ """True if string else False"""
check = isinstance(element, str)
return check
-
-# True if boolean else False
def is_bool(element):
+ """True if boolean else False"""
check = isinstance(element, bool)
return check
-
-# True if float else False
def is_float(element):
+ """True if float else False"""
check = isinstance(element, float)
return check
-
-# True if integer else False
def is_int(element):
+ """True if int else False"""
check = isinstance(element, int)
return check
-
-#
-async def textlen(m: Message, one: int = 1):
+async def textlen(m: Message, num: int = 1):
+ """auto check and warn if not suffix with command"""
try:
- cmd = True if len(m.command) > one else False
- text = True if len(m.text) <=4096 else False
+ cmd = True if len(m.command) > num else False
+ text = True if len(m.text) > 1 and len(m.text) <= 4096 else False
if cmd is False:
await send_edit(m, "Please give me some suffix . . .", mono=True, delme=3)
elif text is False:
- await send_edit(m, "Only 4096 charactors are allowed !", mono=True, delme=3)
+ await send_edit(m, "Only 4096 characters are allowed !", mono=True, delme=3)
else:
return False
except Exception as e:
@@ -328,15 +297,17 @@ async def textlen(m: Message, one: int = 1):
await error(m, e)
-
-
-async def get_last_msg(m: Message):
- return await app.get_history(93372553, limit=1)
-
-
+async def get_last_msg(m: Message, user_id: int, reverse=False):
+ """Get the first or last message of user chat"""
+ if reverse:
+ data = await app.get_history(user_id, limit=1, reverse=True)
+ else:
+ data = await app.get_history(user_id, limit=1)
+ return data
async def toggle_inline(m: Message):
+ """Turn on | off inline mode of your bot"""
try:
await send_edit(m, "Processing command . . .", mono=True)
await app.send_message("BotFather", "/mybots") # BotFather (93372553)
@@ -389,11 +360,8 @@ async def toggle_inline(m: Message):
await error(m, e)
-
-
-
-# inline quotes
def quote():
+ """anime quotes for weebs"""
results = requests.get("https://animechan.vercel.app/api/random").json()
msg = f"❝ {results.get('quote')} ❞"
msg += f" [ {results.get('anime')} ]\n\n"
@@ -401,14 +369,10 @@ def quote():
return msg
-
-
-# inline alive pic
def ialive_pic():
- if dv.getdv("USER_PIC"):
- pic = dv.getdv("USER_PIC")
- elif Config.USER_PIC:
- pic = Config.USER_PIC
- return pic
+ """inline alive pic url"""
+ pic_url = dv.getdv("USER_PIC")
+ data = pic_url if pic_url else Config.USER_PIC
+ return data if data else None