Skip to content

Commit

Permalink
Fix Images Module
Browse files Browse the repository at this point in the history
  • Loading branch information
SilentDemonSD authored Jun 15, 2023
1 parent 35bb719 commit 5c09799
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions bot/modules/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,28 @@ async def picture_add(_, message):
pic_add = msg_text.strip()
await editMessage(editable, "<b>Adding your Link ...</b>")
elif resm and resm.photo:
if not (resm.photo and resm.photo[-1].file_size <= 5242880*2):
if not (resm.photo and resm.photo.file_size <= 5242880*2):
await editMessage(editable, "This Media is Not Supported! Only Send Photos !!")
return
path = "Thumbnails/"
if not await aiopath.isdir(path):
mkdir(path)
photo_dir = await resm.download()
await editMessage(editable, "<b>Uploading to telegra.ph Server, Please Wait...</b>")
await editMessage(editable, "<b>Uploading to graph.org Server, Please Wait...</b>")
await asleep(1)
try:
pic_add = f'https://graph.org{upload_file(photo_dir)[0]}'
LOGGER.info(f"Telegraph Link : {pic_add}")
except Exception as e:
LOGGER.error(f"Pictures Error: {e}")
LOGGER.error(f"Images Error: {e}")
await editMessage(editable, str(e))
finally:
await aioremove(photo_dir)
else:
help_msg = "<b>By Replying to Link (Telegra.ph or DDL):</b>"
help_msg += f"\n<code>/addpic" + " {link}" + "</code>\n"
help_msg += f"\n<code>/{BotCommands.AddImageCommand}" + " {link}" + "</code>\n"
help_msg += "\n<b>By Replying to Photo on Telegram:</b>"
help_msg += f"\n<code>/addpic" + " {photo}" + "</code>"
help_msg += f"\n<code>/{BotCommands.AddImageCommand}" + " {photo}" + "</code>"
await editMessage(editable, help_msg)
return
config_dict['IMAGES'].append(pic_add)
Expand All @@ -55,7 +55,7 @@ async def picture_add(_, message):
async def pictures(_, message):
user_id = message.from_user.id
if not config_dict['IMAGES']:
await sendMessage(message, "No Photo to Show ! Add by /addpic")
await sendMessage(message, f"No Photo to Show ! Add by /{BotCommands.AddImageCommand}")
else:
to_edit = await sendMessage(message, "Generating Grid of your Images...")
buttons = ButtonMaker()
Expand All @@ -65,7 +65,7 @@ async def pictures(_, message):
buttons.ibutton("Close", f"images {user_id} close")
buttons.ibutton("Remove All", f"images {user_id} removall", 'footer')
await deleteMessage(to_edit)
await sendMessage(message, f'🌄 <b>Picture No. : 1 / {len(config_dict["IMAGES"])}</b>', buttons.build_menu(2), config_dict['IMAGES'][0])
await sendMessage(message, f'🌄 <b>Image No. : 1 / {len(config_dict["IMAGES"])}</b>', buttons.build_menu(2), config_dict['IMAGES'][0])

async def pics_callback(_, query):
message = query.message
Expand All @@ -78,7 +78,7 @@ async def pics_callback(_, query):
await query.answer()
ind = handleIndex(int(data[3]), config_dict['IMAGES'])
no = len(config_dict['IMAGES']) - abs(ind+1) if ind < 0 else ind + 1
pic_info = f'🌄 <b>Picture No. : {no} / {len(config_dict["IMAGES"])}</b>'
pic_info = f'🌄 <b>Image No. : {no} / {len(config_dict["IMAGES"])}</b>'
buttons = ButtonMaker()
buttons.ibutton("<<", f"images {data[1]} turn {ind-1}")
buttons.ibutton(">>", f"images {data[1]} turn {ind+1}")
Expand All @@ -93,25 +93,25 @@ async def pics_callback(_, query):
query.answer("Photo Successfully Deleted", show_alert=True)
if len(config_dict['IMAGES']) == 0:
await query.message.delete()
await sendMessage(message, "No Photo to Show ! Add by /addpic")
await sendMessage(message, f"<b>No Photo to Show !</b> Add by /{BotCommands.AddImageCommand}")
return
ind = int(data[3])+1
ind = len(config_dict['IMAGES']) - abs(ind) if ind < 0 else ind
pic_info = f'🌄 <b>Picture No. : {ind+1} / {len(config_dict["IMAGES"])}</b>'
pic_info = f'🌄 <b>Image No. : {ind+1} / {len(config_dict["IMAGES"])}</b>'
buttons = ButtonMaker()
buttons.ibutton("<<", f"images {data[1]} turn {ind-1}")
buttons.ibutton(">>", f"images {data[1]} turn {ind+1}")
buttons.ibutton("Remove Photo", f"images {data[1]} remov {ind}")
buttons.ibutton("Remove Image", f"images {data[1]} remov {ind}")
buttons.ibutton("Close", f"images {data[1]} close")
buttons.ibutton("Remove All", f"images {data[1]} removall", 'footer')
await editMessage(message, pic_info, buttons.build_menu(2), config_dict['IMAGES'][ind])
elif data[2] == 'removall':
config_dict['IMAGES'].clear()
if DATABASE_URL:
await DbManger().update_config({'IMAGES': config_dict['IMAGES']})
await query.answer("All Photos Successfully Deleted", show_alert=True)
await query.answer("All Images Successfully Deleted", show_alert=True)
await query.message.delete()
await sendMessage("No Photo to Show ! Add by /addpic")
await sendMessage(f"<b>No Images to Show !</b> Add by /{BotCommands.AddImageCommand}")
else:
await query.answer()
await query.message.delete()
Expand All @@ -120,4 +120,4 @@ async def pics_callback(_, query):

bot.add_handler(MessageHandler(picture_add, filters=command(BotCommands.AddImageCommand) & CustomFilters.authorized))
bot.add_handler(MessageHandler(pictures, filters=command(BotCommands.ImagesCommand) & CustomFilters.authorized))
bot.add_handler(CallbackQueryHandler(pics_callback, filters=regex(r'^images')))
bot.add_handler(CallbackQueryHandler(pics_callback, filters=regex(r'^images')))

0 comments on commit 5c09799

Please sign in to comment.