Skip to content
Merged

u #94

Show file tree
Hide file tree
Changes from all commits
Commits
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
29 changes: 12 additions & 17 deletions tronx/helpers/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
ReplyKeyboardMarkup,
Update
)
from config import Config
from tronx.database.postgres.dv_sql import DVSQL

dv = DVSQL()


# custom regex filter
Expand All @@ -38,6 +34,13 @@ async def func(flt, client: Client, update: Update):
if update.from_user and not (update.from_user.is_self or update.from_user.id in client.SudoUsers()):
return False

# allow some specific commands to sudos
if update.from_user and update.from_user.id in client.SudoUsers():
if update.text or update.caption and not "full" in client.SudoCmds():
for x in pattern.split(): # list of texts
if not x in client.SudoCmds():
return False

# work only for -> bot owner if not sudo
elif not "sudo" in allow:
if update.from_user and not update.from_user.is_self:
Expand Down Expand Up @@ -80,21 +83,11 @@ async def func(flt, client: Client, update: Update):



def MyPrefix():
"""Multiple prefix support function"""
return dv.getdv("PREFIX").split() or Config.PREFIX.split() or "."

def SudoCmds():
"""commands which are in this variable will work for sudo users, `full` to allow all commands"""
return dv.getdv("SUDO_CMDS").split() or []




# custom command filter
def gen(
commands: Union[str, List[str]],
prefixes: Union[str, List[str]] = MyPrefix(),
prefixes: Union[str, List[str]] = [],
case_sensitive: bool = True,
allow: list = []
):
Expand Down Expand Up @@ -123,9 +116,9 @@ async def func(flt, client: Client, message: Message):

# allow some specific commands to sudos
if message.from_user and message.from_user.id in client.SudoUsers():
if not "full" in SudoCmds():
if not "full" in client.SudoCmds():
for x in raw_commands:
if not x in SudoCmds():
if not x in client.SudoCmds():
return False

# work only for -> bot owner if not sudo
Expand All @@ -148,6 +141,8 @@ async def func(flt, client: Client, message: Message):
if message.edit_date:
return False

flt.prefixes = client.MyPrefix() # workaround

for prefix in flt.prefixes:
if not text.startswith(prefix):
continue
Expand Down
8 changes: 4 additions & 4 deletions tronx/helpers/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,12 +622,12 @@ def get_file_id(self, message):
media = ["photo", "video", "audio", "document", "sticker", "animation"]

for x in media:
if hasattr(message, x):
if hasattr(message, "caption"):
if message and message[x]:
if message["caption"]:
return {"data":(message[x]).file_id, "caption":message.caption, "type":x}
else:
return {"data":(messsge[x]).file_id, "caption":None, "type":x}
elif hasattr(message, "text"):
elif message["text"]:
return {"data":messsge.text, "caption":None, "type":"text"}


Expand Down Expand Up @@ -769,7 +769,7 @@ def import_module(self, path, exclude=[], display_module=True):
if display_module:
data = sorted(bin)
for x in data:
self.log.info(x + " Loaded !")
print(x + " Loaded !")
return count


Expand Down
16 changes: 15 additions & 1 deletion tronx/helpers/others.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,52 @@
class Others(object):
def NoLoad(self):
""" Get your No load module list """
noloadvar = self.getdv("NO_LOAD")
data_list = noloadvar.split() if noloadvar else False
return data_list or self.NO_LOAD or []


def SudoUsers(self):
""" Get sudo users """
sudovar = self.getdv("SUDO_USERS")
data_list = [int(x) for x in sudovar.split()] if sudovar else False
return data_list or self.SUDO_USERS or []


def Pmpermit(self):
""" Check whether pmpermit is on | off """
return self.getdv("PMPERMIT") or self.PMPERMIT or None


def PmpermitLimit(self):
""" Check the number of warns, defaults to 4 """
return self.getdv("PM_LIMIT") or self.PM_LIMIT or 4


def PmpermitPic(self):
""" Check whether you have added a pic in your pmpermit or not """
return self.getdv("PMPERMIT_PIC") or self.PMPERMIT_PIC or None


def PmpermitText(self):
""" Get the pmpermit text """
return self.getdv("PMPERMIT_TEXT") or self.PMPERMIT_TEXT or None


def MyPrefix(self):
""" Get list of prefixes (command handlers) """
return self.getdv("PREFIX").split() or self.PREFIX.split() or "."


def HelpEmoji(self):
""" This will return the emoji which will be used in helpdex """
return self.getdv("HELP_EMOJI") or self.HELP_EMOJI or ""



def SudoCmds(self):
""" returns a list of command names """
return self.getdv("SUDO_CMDS").split() or []




49 changes: 25 additions & 24 deletions tronx/modules/notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,22 @@


@app.on_message(gen("save", allow = ["sudo"]))
async def save_note(_, m: Message):
async def savenote_hanlder(_, m: Message):
if len(m.command) < 2:
return await app.send_edit(m, "A note name is required with command to save notes ...", mono=True)
return await app.send_edit(m, "A note name is required with command to save a note.", mono=True)

if len(m.command) < 3:
return await app.send_edit(m, "A note name & content is required to save a note.", mono=True)

note_name, text, message_type, content = app.GetNoteType(m)
if not note_name:
return await app.send_edit(m, "A name is necessary for a note !", mono=True)
return await app.send_edit(m, "A note name is necessary to save a note !", mono=True)

if message_type == app.TEXT:
file_id = None
teks, button = app.ParseButton(text)
if not teks:
await app.send_edit(m, f"`{m.text}`\n\nError: There is no text in here !")
await app.send_edit(m, f"Text: `{m.text}`\n\nError: There is no text in here !")

app.save_selfnote(m.from_user.id, note_name, text, message_type, content)
await app.send_edit(m, "Saved note = **[ `{}` ]**".format(note_name))
Expand All @@ -71,21 +74,21 @@ async def save_note(_, m: Message):


@app.on_message(regex(">"))
async def get_note(_, m: Message):
async def getnote_handler(_, m: Message):
reply = m.reply_to_message
if m.text and m.text.startswith(">"):
if len(m.text.split()) == 1:
if app.long(m) == 1:
note = m.text.replace(">", "")
else:
return
return # no response

getnotes = app.get_selfnote(m.from_user.id, note)

if not getnotes:
return await app.send_edit(m, "This note does not exist !")

msg_id = None # message.message_id
if reply:
mdg_id = reply.message_id
msg_id = reply.message_id if reply else None

if getnotes['type'] == app.TEXT:
teks, button = app.ParseButton(getnotes.get('value'))
button = app.BuildKeyboard(button)
Expand Down Expand Up @@ -125,8 +128,9 @@ async def get_note(_, m: Message):
else:
teks = False
button = False

if button:
return await app.send_edit(m, "Inline button not supported in this userbot version :(\nSee @tronuserbot for more information")
return await app.send_edit(m, "Inline button not supported in this userbot.")
else:
try:
if msg_id:
Expand All @@ -148,32 +152,29 @@ async def get_note(_, m: Message):


@app.on_message(gen("notes", allow = ["sudo"]))
async def notes_list(_, m: Message):
async def notelist_handler(_, m: Message):
getnotes = app.get_all_selfnotes(m.from_user.id)
if not getnotes:
return await app.send_edit(m, "There are no saved notes !")
return await app.send_edit(m, "There are no saved notes !", mono=True, delme=4)

notelist = "**Notebook:**\n\n"
notelist = "**NOTEBOOK:**\n\n"
for x in getnotes:
if len(notelist) >= 1800:
await app.send_edit(m, notebook)
notelist = "**Notebook:**\n\n"
notelist += "`>{}`\n".format(x)
notelist += f"`>{x}`\n"

await app.send_edit(m, notelist)




@app.on_message(gen("clear"))
async def clear_note(client, m: Message):
async def clearnote_handler(_, m: Message):
if app.long(m) <= 1:
return await app.send_edit(m, f"Sir, give note name after command, Ex: `{app.PREFIX}clear cat`")
return await app.send_edit(m, f"Sir, give me a note name after command, Ex: `{app.PREFIX}clear cat`")

note = m.text.split()[1]
getnote = app.rm_selfnote(m.from_user.id, note)
if not getnote:
notename = m.text.split()[1]
getnotes = app.rm_selfnote(m.from_user.id, notename)
if not getnotes:
return await app.send_edit(m, "This note does not exist!")
else:
await app.send_edit(m, "Deleted note = **[ `{}` ]**".format(note),parse_mode="markdown")
await app.send_edit(m, f"Deleted note = **[ `{notename}` ]**")

4 changes: 3 additions & 1 deletion tronx/modules/pmpermit.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,20 @@ async def send_warn(m: Message, user):
pic,
caption=text
)
app.set_msgid(user, msg.message_id)
return True
elif not pic:
msg = await app.send_message(
m.chat.id,
text,
disable_web_page_preview=True
)
app.set_msgid(user, msg.message_id)
return True
else:
return print("The bot didn't send pmpermit warning message.")
return False
app.set_msgid(user, msg.message_id)




Expand Down