Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
5hojib committed Jul 11, 2024
1 parent 0b0cac0 commit 6bc5ab2
Show file tree
Hide file tree
Showing 17 changed files with 212 additions and 225 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
if git diff-index --quiet HEAD --; then
echo "No changes to commit."
else
git commit -m "Auto-format code using ruff [skip ci]"
git commit -m "Auto-format code using ruff [skip actions]"
git push origin ${{ github.ref }}
fi
env:
Expand Down
23 changes: 5 additions & 18 deletions bot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ async def stats(_, message):
@new_thread
async def start(client, message):
buttons = ButtonMaker()
reply_markup = buttons.build_menu(2)
reply_markup = buttons.menu(2)
if len(message.command) > 1 and message.command[1] == "private":
await deleteMessage(message)
elif len(message.command) > 1 and len(message.command[1]) == 36:
Expand Down Expand Up @@ -185,25 +185,13 @@ def parseline(line):
startLine = "<pre language='python'>"
endLine = "</pre>"
btn = ButtonMaker()
btn.ibutton('Close', f'aeon {user_id} close')
reply_message = await sendMessage(message, startLine + escape(Loglines) + endLine, btn.build_menu(1))
btn.callback('Close', f'aeon {user_id} close')
reply_message = await sendMessage(message, startLine + escape(Loglines) + endLine, btn.menu(1))
await query.edit_message_reply_markup(None)
await deleteMessage(message)
await five_minute_del(reply_message)
except Exception as err:
LOGGER.error(f"TG Log Display : {str(err)}")
elif data[2] == "webpaste":
await query.answer()
async with aiopen('log.txt', 'r') as f:
logFile = await f.read()
cget = create_scraper().request
resp = cget('POST', 'https://spaceb.in/api/v1/documents', data={'content': logFile, 'extension': 'None'}).json()
if resp['status'] == 201:
btn = ButtonMaker()
btn.ubutton('Web paste', f"https://spaceb.in/{resp['payload']['id']}")
await query.edit_message_reply_markup(btn.build_menu(1))
else:
LOGGER.error(f"Web paste failed : {str(err)}")
elif data[2] == "private":
await query.answer(url=f"https://t.me/{bot_name}?start=private")
else:
Expand All @@ -214,9 +202,8 @@ def parseline(line):
@new_task
async def log(_, message):
buttons = ButtonMaker()
buttons.ibutton('Log display', f'aeon {message.from_user.id} logdisplay')
buttons.ibutton('Web paste', f'aeon {message.from_user.id} webpaste')
reply_message = await sendFile(message, 'log.txt', buttons=buttons.build_menu(1))
buttons.callback('Log display', f'aeon {message.from_user.id} logdisplay')
reply_message = await sendFile(message, 'log.txt', buttons=buttons.menu(1))
await deleteMessage(message)
await five_minute_del(reply_message)

Expand Down
26 changes: 13 additions & 13 deletions bot/helper/ext_utils/bot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,21 +143,21 @@ def bt_selection_buttons(id_):
pincode = ''.join([n for n in id_ if n.isdigit()][:4])
buttons = ButtonMaker()
BASE_URL = config_dict['BASE_URL']
buttons.ubutton("Select", f"{BASE_URL}/app/files/{id_}")
buttons.ibutton("Pincode", f"btsel pin {gid} {pincode}")
buttons.ibutton("Cancel", f"btsel rm {gid} {id_}")
buttons.ibutton("Done Selecting", f"btsel done {gid} {id_}")
return buttons.build_menu(2)
buttons.url("Select", f"{BASE_URL}/app/files/{id_}")
buttons.callback("Pincode", f"btsel pin {gid} {pincode}")
buttons.callback("Cancel", f"btsel rm {gid} {id_}")
buttons.callback("Done Selecting", f"btsel done {gid} {id_}")
return buttons.menu(2)


async def get_telegraph_list(telegraph_content):
path = [(await telegraph.create_page(title="Drive Search", content=content))["path"] for content in telegraph_content]
if len(path) > 1:
await telegraph.edit_telegraph(path, telegraph_content)
buttons = ButtonMaker()
buttons.ubutton("View", f"https://telegra.ph/{path[0]}")
buttons.url("View", f"https://telegra.ph/{path[0]}")
buttons = extra_btns(buttons)
return buttons.build_menu(1)
return buttons.menu(1)


def handleIndex(index, dic):
Expand Down Expand Up @@ -230,10 +230,10 @@ def get_readable_message():
return None, None
if tasks > STATUS_LIMIT:
buttons = ButtonMaker()
buttons.ibutton("Prev", "status pre")
buttons.ibutton(f"{PAGE_NO}/{PAGES}", "status ref")
buttons.ibutton("Next", "status nex")
button = buttons.build_menu(3)
buttons.callback("Prev", "status pre")
buttons.callback(f"{PAGE_NO}/{PAGES}", "status ref")
buttons.callback("Next", "status nex")
button = buttons.menu(3)
msg += f"<b>• Tasks</b>: {tasks}{bmax_task}"
msg += f"\n<b>• Bot uptime</b>: {currentTime}"
msg += f"\n<b>• Free disk space</b>: {get_readable_file_size(disk_usage('/usr/src/app/downloads/').free)}"
Expand Down Expand Up @@ -449,15 +449,15 @@ async def checking_access(user_id, button=None):
time_str = get_readable_time(token_timeout, True)
if button is None:
button = ButtonMaker()
button.ubutton('Collect token', tinyfy(short_url(f'https://telegram.me/{bot_name}?start={token}')))
button.url('Collect token', tinyfy(short_url(f'https://telegram.me/{bot_name}?start={token}')))
return f'Your token has expired, please collect a new token.\n<b>It will expire after {time_str}</b>!', button
return None, button


def extra_btns(buttons):
if extra_buttons:
for btn_name, btn_url in extra_buttons.items():
buttons.ubutton(btn_name, btn_url)
buttons.url(btn_name, btn_url)
return buttons


Expand Down
18 changes: 9 additions & 9 deletions bot/helper/listeners/tasks_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,9 @@ async def onUploadComplete(self, link, size, files, folders, mime_type, name, rc
msg += f'<b>• Elapsed: </b>{get_readable_time(time() - self.message.date.timestamp())}\n'
LOGGER.info(f'Task Done: {name}')
buttons = ButtonMaker()
iButton = ButtonMaker()
iButton.ibutton('View in inbox', f"aeon {user_id} private", 'header')
iButton = extra_btns(iButton)
callback = ButtonMaker()
callback.callback('View in inbox', f"aeon {user_id} private", 'header')
callback = extra_btns(callback)
if self.isLeech:
if folders > 1:
msg += f'<b>• Total files: </b>{folders}\n'
Expand Down Expand Up @@ -377,7 +377,7 @@ async def onUploadComplete(self, link, size, files, folders, mime_type, name, rc
await sendMessage(self.botpmmsg, msg + lmsg + fmsg)
await deleteMessage(self.botpmmsg)
if self.isSuperGroup:
await sendMessage(self.message, f'{msg}<b>Files has been sent to your inbox</b>', iButton.build_menu(1))
await sendMessage(self.message, f'{msg}<b>Files has been sent to your inbox</b>', callback.menu(1))
else:
await deleteMessage(self.botpmmsg)
if self.seed:
Expand All @@ -392,22 +392,22 @@ async def onUploadComplete(self, link, size, files, folders, mime_type, name, rc
if mime_type == "Folder":
msg += f'<b>• Total files: </b>{files}\n'
if link:
buttons.ubutton('Cloud link', link)
buttons.url('Cloud link', link)
INDEX_URL = self.index_link if self.drive_id else config_dict['INDEX_URL']
if not rclonePath:
if INDEX_URL:
url_path = rutils.quote(f'{name}')
share_url = f'{INDEX_URL}/{url_path}'
if mime_type == "Folder":
share_url += '/'
buttons.ubutton('Index link', share_url)
buttons.url('Index link', share_url)
buttons = extra_btns(buttons)
button = buttons.build_menu(2)
button = buttons.menu(2)
elif rclonePath:
msg += f'<b>• Path: </b><code>{rclonePath}</code>\n'
button = None
buttons = extra_btns(buttons)
button = buttons.build_menu(2)
button = buttons.menu(2)
msg += f'<b>• User ID: </b><code>{self.message.from_user.id}</code>\n'
msg += f'<b>• By: </b>{self.tag}</blockquote>\n\n'

Expand All @@ -418,7 +418,7 @@ async def onUploadComplete(self, link, size, files, folders, mime_type, name, rc
await sendMessage(self.botpmmsg, msg, button, 'Random')
await deleteMessage(self.botpmmsg)
if self.isSuperGroup:
await sendMessage(self.message, f'{msg} <b>Links has been sent to your inbox</b>', iButton.build_menu(1))
await sendMessage(self.message, f'{msg} <b>Links has been sent to your inbox</b>', callback.menu(1))
else:
await deleteMessage(self.botpmmsg)
if self.seed:
Expand Down
40 changes: 20 additions & 20 deletions bot/helper/mirror_leech_utils/rclone_utils/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,31 +152,31 @@ async def get_path_buttons(self):
else:
ptype = 'fi'
name = f"[{get_readable_file_size(idict['Size'])}] {idict['Path']}"
buttons.ibutton(name, f'rcq pa {ptype} {orig_index}')
buttons.callback(name, f'rcq pa {ptype} {orig_index}')
if items_no > LIST_LIMIT:
for i in [1, 2, 4, 6, 10, 30, 50, 100]:
buttons.ibutton(i, f'rcq ps {i}', position='header')
buttons.ibutton('Previous', 'rcq pre', position='footer')
buttons.ibutton('Next', 'rcq nex', position='footer')
buttons.callback(i, f'rcq ps {i}', position='header')
buttons.callback('Previous', 'rcq pre', position='footer')
buttons.callback('Next', 'rcq nex', position='footer')
if self.list_status == 'rcd':
if self.item_type == '--dirs-only':
buttons.ibutton(
buttons.callback(
'Files', 'rcq itype --files-only', position='footer')
else:
buttons.ibutton(
buttons.callback(
'Folders', 'rcq itype --dirs-only', position='footer')
if self.list_status == 'rcu' or len(self.path_list) > 0:
buttons.ibutton('Choose Current Path',
buttons.callback('Choose Current Path',
'rcq cur', position='footer')
if self.list_status == 'rcu':
buttons.ibutton('Set as Default Path',
buttons.callback('Set as Default Path',
'rcq def', position='footer')
if self.path or len(self.__sections) > 1 or self.__rc_user and self.__rc_owner:
buttons.ibutton('Back', 'rcq back pa', position='footer')
buttons.callback('Back', 'rcq back pa', position='footer')
if self.path:
buttons.ibutton('Back To Root', 'rcq root', position='footer')
buttons.ibutton('Cancel', 'rcq cancel', position='footer')
button = buttons.build_menu(f_cols=2)
buttons.callback('Back To Root', 'rcq root', position='footer')
buttons.callback('Cancel', 'rcq cancel', position='footer')
button = buttons.menu(f_cols=2)
msg = 'Choose Path:' + ('\nTransfer Type: Download' if self.list_status ==
'rcd' else '\nTransfer Type: Upload')
if self.list_status == 'rcu':
Expand Down Expand Up @@ -235,11 +235,11 @@ async def list_remotes(self):
msg += f'\nTimeout: {get_readable_time(self.__timeout-(time()-self.__time))}'
buttons = ButtonMaker()
for remote in self.__sections:
buttons.ibutton(remote, f'rcq re {remote}:')
buttons.callback(remote, f'rcq re {remote}:')
if self.__rc_user and self.__rc_owner:
buttons.ibutton('Back', 'rcq back re', position='footer')
buttons.ibutton('Cancel', 'rcq cancel', position='footer')
button = buttons.build_menu(2)
buttons.callback('Back', 'rcq back re', position='footer')
buttons.callback('Cancel', 'rcq cancel', position='footer')
button = buttons.menu(2)
await self.__send_list_message(msg, button)

async def list_config(self):
Expand All @@ -249,10 +249,10 @@ async def list_config(self):
'rcd' else '\nTransfer Type: Upload')
msg += f'\nTimeout: {get_readable_time(self.__timeout-(time()-self.__time))}'
buttons = ButtonMaker()
buttons.ibutton('Owner Config', 'rcq owner')
buttons.ibutton('My Config', 'rcq user')
buttons.ibutton('Cancel', 'rcq cancel')
button = buttons.build_menu(2)
buttons.callback('Owner Config', 'rcq owner')
buttons.callback('My Config', 'rcq user')
buttons.callback('Cancel', 'rcq cancel')
button = buttons.menu(2)
await self.__send_list_message(msg, button)
else:
self.config_path = 'rcl.conf' if self.__rc_owner else self.user_rcc_path
Expand Down
6 changes: 3 additions & 3 deletions bot/helper/mirror_leech_utils/upload_utils/telegramEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,17 @@ async def __buttons(self, up_path, is_video=False):
buttons = ButtonMaker()
try:
if is_video and bool(self.__files_utils['screenshots']):
buttons.ubutton('SCREENSHOTS', await get_ss(up_path, self.__files_utils['screenshots']))
buttons.url('SCREENSHOTS', await get_ss(up_path, self.__files_utils['screenshots']))
except Exception as e:
LOGGER.error(f"ScreenShots Error: {e}")
try:
if self.__mediainfo:
m = await get_mediainfo_link(up_path)
buttons.ubutton('MediaInfo', m)
buttons.url('MediaInfo', m)
LOGGER.info(m)
except Exception as e:
LOGGER.error(f"MediaInfo Error: {str(e)}")
return buttons.build_menu(1) if self.__has_buttons else None
return buttons.menu(1) if self.__has_buttons else None

async def __copy_file(self):
try:
Expand Down
6 changes: 3 additions & 3 deletions bot/helper/telegram_helper/button_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def __init__(self):
self.__header_button = []
self.__footer_button = []

def ubutton(self, key, link, position=None):
def url(self, key, link, position=None):
if not position:
self.__button.append(InlineKeyboardButton(text=key, url=link))
elif position == 'header':
Expand All @@ -16,7 +16,7 @@ def ubutton(self, key, link, position=None):
self.__footer_button.append(
InlineKeyboardButton(text=key, url=link))

def ibutton(self, key, data, position=None):
def callback(self, key, data, position=None):
if not position:
self.__button.append(InlineKeyboardButton(
text=key, callback_data=data))
Expand All @@ -27,7 +27,7 @@ def ibutton(self, key, data, position=None):
self.__footer_button.append(
InlineKeyboardButton(text=key, callback_data=data))

def build_menu(self, b_cols=1, h_cols=8, f_cols=8):
def menu(self, b_cols=1, h_cols=8, f_cols=8):
menu = [self.__button[i:i+b_cols]
for i in range(0, len(self.__button), b_cols)]
if self.__header_button:
Expand Down
4 changes: 2 additions & 2 deletions bot/helper/telegram_helper/message_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ async def forcesub(message, ids, button=None):
button = ButtonMaker()
_msg = "You haven't joined our channel/group yet!"
for key, value in join_button.items():
button.ubutton(f'Join {key}', value, 'footer')
button.url(f'Join {key}', value, 'footer')
return _msg, button


Expand All @@ -306,5 +306,5 @@ async def BotPm_check(message, button=None):
if button is None:
button = ButtonMaker()
_msg = "You haven't initiated the bot in a private message!"
button.ibutton("Start", f"aeon {user_id} private", 'header')
button.callback("Start", f"aeon {user_id} private", 'header')
return _msg, button
36 changes: 18 additions & 18 deletions bot/modules/bot_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,38 +367,38 @@ async def load_config():
async def get_buttons(key=None, edit_type=None, edit_mode=None, mess=None):
buttons = ButtonMaker()
if key is None:
buttons.ibutton('Config Variables', "botset var")
buttons.ibutton('Private Files', "botset private")
buttons.ibutton('Close', "botset close")
buttons.callback('Config Variables', "botset var")
buttons.callback('Private Files', "botset private")
buttons.callback('Close', "botset close")
msg = 'Bot Settings:'
elif key == 'var':
for k in list(OrderedDict(sorted(config_dict.items())).keys())[START:10+START]:
buttons.ibutton(k, f"botset editvar {k}")
buttons.ibutton('Back', "botset back")
buttons.ibutton('Close', "botset close")
buttons.callback(k, f"botset editvar {k}")
buttons.callback('Back', "botset back")
buttons.callback('Close', "botset close")
for x in range(0, len(config_dict)-1, 10):
buttons.ibutton(f'{int(x/10)+1}', f"botset start var {x}", position='footer')
buttons.callback(f'{int(x/10)+1}', f"botset start var {x}", position='footer')
msg = f'<b>Config Variables<b> | Page: {int(START/10)+1}'
elif key == 'private':
buttons.ibutton('Back', "botset back")
buttons.ibutton('Close', "botset close")
buttons.callback('Back', "botset back")
buttons.callback('Close', "botset close")
msg = "Send private files: config.env, token.pickle, cookies.txt, accounts.zip, terabox.txt, .netrc, or any other files!\n\nTo delete a private file, send only the file name as a text message.\n\n<b>Please note:</b> Changes to .netrc will not take effect for aria2c until it's restarted.\n\n<b>Timeout:</b> 60 seconds"
elif edit_type == 'editvar':
msg = f'<b>Variable:</b> <code>{key}</code>\n\n'
msg += f'<b>Description:</b> {bset_display_dict.get(key, "No Description Provided")}\n\n'
if mess.chat.type == ChatType.PRIVATE:
msg += f'<b>Value:</b> <code>{config_dict.get(key, "None")}</code>\n\n'
elif key not in bool_vars:
buttons.ibutton('View value', f"botset showvar {key}", position="header")
buttons.ibutton('Back', "botset back var", position="footer")
buttons.callback('View value', f"botset showvar {key}", position="header")
buttons.callback('Back', "botset back var", position="footer")
if key not in bool_vars:
if not edit_mode:
buttons.ibutton('Edit Value', f"botset editvar {key} edit")
buttons.callback('Edit Value', f"botset editvar {key} edit")
else:
buttons.ibutton('Stop Edit', f"botset editvar {key}")
buttons.callback('Stop Edit', f"botset editvar {key}")
if key not in ['TELEGRAM_HASH', 'TELEGRAM_API', 'OWNER_ID', 'BOT_TOKEN'] and key not in bool_vars:
buttons.ibutton('Reset', f"botset resetvar {key}")
buttons.ibutton('Close', "botset close", position="footer")
buttons.callback('Reset', f"botset resetvar {key}")
buttons.callback('Close', "botset close", position="footer")
if edit_mode and key in ['CMD_SUFFIX',
'OWNER_ID',
'USER_SESSION_STRING', 'TELEGRAM_HASH',
Expand All @@ -410,10 +410,10 @@ async def get_buttons(key=None, edit_type=None, edit_mode=None, mess=None):
msg += 'Send a valid value for the above Var. <b>Timeout:</b> 60 sec'
if key in bool_vars:
if not (value := config_dict.get(key)):
buttons.ibutton('Make it True', f"botset boolvar {key} on")
buttons.callback('Make it True', f"botset boolvar {key} on")
else:
buttons.ibutton('Make it False', f"botset boolvar {key} off")
button = buttons.build_menu(1) if key is None else buttons.build_menu(2)
buttons.callback('Make it False', f"botset boolvar {key} off")
button = buttons.menu(1) if key is None else buttons.menu(2)
return msg, button


Expand Down
Loading

0 comments on commit 6bc5ab2

Please sign in to comment.