async def inline_buttons(message: Message): if Config.BOT_TOKEN is None: await message.err( "First Create a Inline Bot via @Botfather to Create Buttons...") return replied = message.reply_to_message if not (replied and (replied.text or replied.caption)): await message.err("Reply a text Msg") return await message.edit("<code>Creating an inline button...</code>") if replied.caption: text = replied.caption text = check_brackets(text) dls_loc = await down_image(message) photo_url = str(upload_image(dls_loc)) BUTTON_BASE.insert_one({'msg_data': text, 'photo_url': photo_url}) os.remove(dls_loc) else: text = replied.text text = check_brackets(text) BUTTON_BASE.insert_one({'msg_data': text}) bot = await userge.bot.get_me() x = await userge.get_inline_bot_results(bot.username, "buttonnn") await userge.send_inline_bot_result(chat_id=message.chat.id, query_id=x.query_id, result_id=x.results[0].id) await BUTTON_BASE.drop() await message.delete()
async def ph_comment(message: Message): """ Create P*rnhub Comment for Replied User """ replied = message.reply_to_message if replied: if "|" in message.input_str: u_name, msg_text = message.input_str.split('|') name = u_name.strip() comment = msg_text or replied.text else: if replied.from_user.last_name: name = replied.from_user.first_name + " " + replied.from_user.last_name else: name = replied.from_user.first_name comment = message.input_str or replied.text else: await message.err("```Input not found!...```", del_in=3) return await message.delete() await message.edit("```Creating A PH Comment 😜```", del_in=1) if replied.from_user.photo: pfp_photo = replied.from_user.photo.small_file_id file_name = os.path.join(Config.DOWN_PATH, "profile_pic.jpg") picture = await userge.download_media(pfp_photo, file_name=file_name) loc_f = upload_image(picture) os.remove(picture) else: loc_f = "https://telegra.ph/file/9844536dbba404c227181.jpg" path = await phcomment(loc_f, comment, name) if path == "ERROR": return await message.edit("😔 Something Wrong see Help!", del_in=2) chat_id = message.chat.id await message.delete() await message.client.send_photo(chat_id=chat_id, photo=path, reply_to_message_id=replied.message_id)
def test_upload_from_file_object(self): b64file = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+ip1sAAAAASUVORK5CYII=' from io import BytesIO from base64 import b64decode with BytesIO(b64decode(b64file)) as file_to_upload: # emulate filename for mimetype detection file_to_upload.name = 'sample.png' telegraph_image_url = upload_image(file_to_upload) self.assertIn('http://telegra.ph/file/', telegraph_image_url)
async def phcomment(event): try: await event.edit("`Proccessing..`") text = event.pattern_match.group(1) reply = await event.get_reply_message() if reply: user = await get_user_from_event(event) if user.id == 628766129: return await event.edit("`hoho this is my master`") if user.last_name: name = user.first_name + " " + user.last_name else: name = user.first_name if text: text = text else: text = str(reply.message) elif text: user = await bot.get_me() if user.last_name: name = user.first_name + " " + user.last_name else: name = user.first_name text = text else: return await event.edit("`Give text..`") try: photo = await event.client.download_profile_photo( user.id, str(user.id) + ".png", download_big=False, ) uplded = upload_image(photo) except BaseException: uplded = "https://telegra.ph/file/7d110cd944d54f72bcc84.jpg" except BaseException as e: await purge() return await event.edit(f"`Error: {e}`") img = await phss(uplded, text, name) try: await event.client.send_file( event.chat_id, img, reply_to=event.reply_to_msg_id, ) except BaseException: await purge() return await event.edit("`Reply message has no text!`") await event.delete() await purge()
async def phcomment(event): try: await event.edit("`Sedang memproses...`") text = event.pattern_match.group(1) reply = await event.get_reply_message() if reply: user = await get_user_from_event(event) if user.last_name: name = user.first_name + " " + user.last_name else: name = user.first_name if text: text = text else: text = str(reply.message) elif text: user = await bot.get_me() if user.last_name: name = user.first_name + " " + user.last_name else: name = user.first_name text = text else: return await event.edit("`Berikan teks...`") try: photo = await event.client.download_profile_photo( user.id, str(user.id) + ".png", download_big=False, ) uplded = upload_image(photo) except BaseException: uplded = "https://telegra.ph/file/7d110cd944d54f72bcc84.jpg" except BaseException as e: await purge() return await event.edit(f"**Kesalahan** : `{e}`") img = await phss(uplded, text, name) try: await event.client.send_file( event.chat_id, img, reply_to=event.reply_to_msg_id, ) except BaseException: await purge() return await event.edit("`Pesan balasan tidak memiliki teks!`") await event.delete() await purge()
def save_img(url): raw_url = url res = db.lookup_pic(raw_url) if res != "": print(f"Reusing {res} for {raw_url}…") return res print("Saving " + url) global fformat find_hash = re.findall(r"\/[a-zA-Z0-9_-]+\.jpe?g$", url) filename = 'temp_' + id_generator(5) + '.jpg' if "video.twimg" in url: filename = 'temp_' + id_generator(5) + '.mp4' fformat = 'mp4' filename = url.split('/')[-1].split("?")[0] if url.endswith('.png'): filename = url.split(r"/")[-1] fformat = "png" if find_hash != []: global use_png if use_png: url = url.replace(".jpg", ".png", 1) fformat = "png" else: fformat = "jpg" # +"?format=jpg&name=orig" filename = find_hash[0].replace(r'/', "").replace(".jpg", ".png", 1) print(r'/' + filename) filename = temp_dir + "/" + filename if os.path.exists(filename): print("Duplicate " + url) request = requests.get(url.replace(r"http://", r"https://"), stream=True) if request.status_code == 200: with open(filename, 'wb') as image: for chunk in request: image.write(chunk) else: print(f"Download {url} failed.") return "" try: graphfileurl = upload_image(filename) except: print(f"Upload {filename} failed.") return "" else: db.associate_pic(raw_url, graphfileurl) return graphfileurl
def old_save_imgs(imgurls): print("Saving " + ", ".join(imgurls)) graphPicUrls = [] for pic in imgurls: global fformat find_hash = re.findall(r"\/[a-zA-Z0-9_-]+\.jpe?g$", pic) filename = 'temp_' + id_generator(5) + '.jpg' if "video.twimg" in pic: filename = 'temp_' + id_generator(5) + '.mp4' fformat = 'mp4' filename = pic.split('/')[-1].split("?")[0] if pic.endswith('.png'): filename = pic.split(r"/")[-1] fformat = "png" if find_hash != []: if use_png: pic = pic.replace(".jpg", ".png", 1) fformat = "png" else: fformat = "jpg" # +"?format=jpg&name=orig" filename = find_hash[0].replace(r'/', "").replace(".jpg", ".png", 1) print(r'/' + filename) filename = temp_dir + "/" + filename if os.path.exists(filename): print("Duplicate " + pic) request = requests.get(pic.replace(r"http://", r"https://"), stream=True) if request.status_code == 200: with open(filename, 'wb') as image: for chunk in request: image.write(chunk) graphfileurl = upload_image(filename) graphPicUrls.append(graphfileurl) #os.remove(filename) fsize = os.path.getsize(filename) db.logimg(pic, graphfileurl, "CALCULATED_HASH", "UNKNOWN", fformat, fsize) return graphPicUrls
def gban(update, context): message = update.effective_message chat = update.effective_chat args = context.args user_id, reason = extract_user_and_text(message, args) if message.reply_to_message.photo: photo = context.bot.get_file( update.message.reply_to_message.photo[-1].file_id) evidence_img = photo.download( f'{str(update.message.from_user.id)}.jpg') evidence_img = upload_image(evidence_img) else: evidence = message.reply_to_message.text if not user_id: message.reply_text("You don't seem to be referring to a user.") return if user_id == OWNER_ID: message.reply_text("Nice try -_- but I'm never gonna gban him.") return if int(user_id) in SUDO_USERS: message.reply_text( "I spy, with my little eye... a sudo user war! Why are you guys turning on each other?" ) return if int(user_id) in SUPPORT_USERS: message.reply_text( "OOOH someone's trying to gban a support user! *grabs popcorn*") return if user_id == context.bot.id: message.reply_text( "-_- So funny, lets gban myself why don't I? Nice try.") return try: user_chat = context.bot.get_chat(user_id) except BadRequest as excp: message.reply_text(excp.message) return if user_chat.type != "private": message.reply_text("That's not a user!") return if user_chat.first_name == "": message.reply_text( "This is a deleted account! no point to gban them...") return if not reason: message.reply_text( "Global Ban requires a reason to do so, why not send me one?") return if sql.is_user_gbanned(user_id): if not reason: message.reply_text( "This user is already gbanned; I'd change the reason, but you haven't given me one..." ) return old_reason = sql.update_gban_reason( user_id, user_chat.username or user_chat.first_name, reason) user_id, new_reason = extract_user_and_text(message, args) if old_reason: banner = update.effective_user # type: Optional[User] bannerid = banner.id bannername = banner.first_name new_reason = ( f"{new_reason} // GBanned by {bannername} id {bannerid}") context.bot.sendMessage( GBAN_DUMP, "<b>Global Ban Reason Update</b>" "\n<b>Sudo Admin:</b> {}" "\n<b>User:</b> {}" "\n<b>ID:</b> <code>{}</code>" "\n<b>Previous Reason:</b> {}" "\n<b>New Reason:</b> {}".format( mention_html(banner.id, banner.first_name), mention_html(user_chat.id, user_chat.first_name or "Deleted Account"), user_chat.id, old_reason, new_reason, ), parse_mode=ParseMode.HTML, ) message.reply_text( "This user is already gbanned, for the following reason:\n" "<code>{}</code>\n" "I've gone and updated it with your new reason!".format( html.escape(old_reason)), parse_mode=ParseMode.HTML, ) else: message.reply_text( "This user is already gbanned, but had no reason set; I've gone and updated it!" ) return banner = update.effective_user bannerid = banner.id bannername = banner.first_name reason = f"{reason} // GBanned by {bannername} id {bannerid}" if chat.type != 'private': chat_origin = "<b>{} ({})</b>".format(html.escape(chat.title), chat.id) else: chat_origin = "<b>{}</b>".format(chat.id) if message.reply_to_message.photo: evidence = f"<img src='{evidence_img}'>" else: evidence = evidence EVIDENSE_NEW_GBAN = f"<strong>New Global Ban</strong> \ \n<strong>Originated from:</strong> <code>{chat_origin}</code> \ \n<strong>Sudo Admin:</strong> {mention_html(banner.id, banner.first_name)} \ \n<strong>User:</strong> {mention_html(user_chat.id, user_chat.first_name)} \ \n<strong>ID:</strong> <code>{user_chat.id}</code> \ \n<strong>Reason:</strong> {reason} \ \n\n<strong>Evidence:</strong> <br>\n{evidence}" page = Shoko_gban.post(title=f"Erina-gban-{user_chat.id}", author=f"{banner.first_name} ({banner.id})", text=EVIDENSE_NEW_GBAN) evidence_link = page.get('url') evidence_link = "<a href='{}'>{}</a>".format( evidence_link, f"Erina GBanned // user_id: {user_chat.id}") message.reply_text( f"<b>Beginning of Global Ban for</b> {mention_html(user_chat.id, user_chat.first_name)}" f"\n<b>With ID</b>: <code>{user_chat.id}</code>" f"\n<b>Reason</b>: <code>{reason}</code>" f"\n<b>Evidence:</b> {evidence_link}", parse_mode=ParseMode.HTML, disable_web_page_preview=True, ) starting_usermsg = f"""<b>You've been globally banned</b>\n<b>Reason:</b> {reason}\n<b>Global Ban log:</b> <a href="https://t.me/gban_dump">here</a>\n<b>Appeal:</b> <a href="https://t.me/AmSuraj">here</a>""" try: if chat.type != 'private': chat_origin = "<b>{} ({})</b>".format(html.escape(chat.title), chat.id) else: chat_origin = "<b>{}</b>".format(chat.id) context.bot.sendMessage( GBAN_DUMP, "<b>New Global Ban</b>" f"\n<b>Originated from:</b> <code>{chat_origin}</code>" "\n<b>Sudo Admin:</b> {}" "\n<b>User:</b> {}" "\n<b>ID:</b> <code>{}</code>" "\n<b>Reason:</b> {}" "\n<b>Evidence:</b> {}".format( mention_html(banner.id, banner.first_name), mention_html(user_chat.id, user_chat.first_name), user_chat.id, reason, evidence_link, ), parse_mode=ParseMode.HTML, disable_web_page_preview=True, ) except Exception: context.bot.send_message(ERROR_DUMP, "<b>[Error]</b>" "\nFailed to Log gban user.") try: context.bot.send_message(user_chat.id, starting_usermsg, parse_mode=ParseMode.HTML, disable_web_page_preview=True) except Exception: context.bot.send_message(ERROR_DUMP, f"<b>[Error]</b>\n" f"Failed to send Gban message to this user." f"\nID: <code>{user_chat.id}</code>", parse_mode=ParseMode.HTML) try: context.bot.kick_chat_member(chat.id, user_chat.id) except BadRequest as excp: if excp.message in GBAN_ERRORS: pass sql.gban_user(user_id, user_chat.username or user_chat.first_name, reason)
def test_upload(self): telegraph_url = upload_image('http://httpbin.org/image/jpeg') self.assertIn('http://telegra.ph/file/', telegraph_url)
def gban(update, context): message = update.effective_message chat = update.effective_chat args = context.args user_id, reason = extract_user_and_text(message, args) if message.reply_to_message.photo: photo = context.bot.get_file( update.message.reply_to_message.photo[-1].file_id) evidence_img = photo.download( f'{str(update.message.from_user.id)}.jpg') evidence_img = upload_image(evidence_img) else: evidence = message.reply_to_message.text if not user_id: message.reply_text("You don't seem to be referring to a user.") return if user_id == OWNER_ID: return if int(user_id) in DEV_USERS: return if int(user_id) in SUDO_USERS: return if int(user_id) in SUPPORT_USERS: return if int(user_id) in WHITELIST_USERS: return if user_id == context.bot.id: return try: user_chat = context.bot.get_chat(user_id) except BadRequest as excp: message.reply_text(excp.message) return if user_chat.type != "private": message.reply_text("That's not a user!") return if user_chat.first_name == "": message.reply_text( "This is a deleted account! no point to gban them...") return if not reason: message.reply_text( "Global Ban requires a reason to do so, why not send me one?") return if sql.is_user_gbanned(user_id): if not reason: message.reply_text( "This user is already gbanned; I'd change the reason, but you haven't given me one..." ) return old_reason = sql.update_gban_reason( user_id, user_chat.username or user_chat.first_name, reason) user_id, new_reason = extract_user_and_text(message, args) if old_reason: banner = update.effective_user # type: Optional[User] bannerid = banner.id bannername = banner.first_name new_reason = (f"{new_reason}") context.bot.sendMessage( GBAN_DUMP, "<b>Global Ban Reason Update</b>" "\n<b>Officer:</b> {}" "\n\n<b>User:</b> {}" "\n<b>ID:</b> <code>{}</code>" "\n<b>Previous Reason:</b> {}" "\n<b>New Reason:</b> {}".format( mention_html(banner.id, banner.first_name), mention_html(user_chat.id, user_chat.first_name or "Deleted Account"), user_chat.id, old_reason, new_reason, ), parse_mode=ParseMode.HTML, ) message.reply_text( "This user is already gbanned, for the following reason:\n" "<code>{}</code>\n" "I've gone and updated it with your new reason!".format( html.escape(old_reason)), parse_mode=ParseMode.HTML, ) else: message.reply_text( "This user is already gbanned, but had no reason set; I've gone and updated it!" ) return banner = update.effective_user bannerid = banner.id bannername = banner.first_name reason = f"{reason}" officer = f"{bannername}" officerid = f"{bannerid}" if chat.type != 'private': chat_origin = "<b>{} ({})</b>".format(html.escape(chat.title), chat.id) else: chat_origin = "<b>{}</b>".format(chat.id) if message.reply_to_message.photo: evidence = f"<img src='{evidence_img}'>" else: evidence = evidence EVIDENSE_NEW_GBAN = f"<strong>New Global Ban</strong> \ \n<strong>Originated from:</strong> <code>{chat_origin}</code> \ \n<strong>Officer:</strong> {mention_html(banner.id, banner.first_name)} \n\ \n<strong>User:</strong> {mention_html(user_chat.id, user_chat.first_name)} \ \n<strong>ID:</strong> <code>{user_chat.id}</code> \ \n<strong>Reason:</strong> {reason} \ \n\n<strong>Evidence:</strong> <br>\n{evidence}" page = Chizuru_Gban.post(title=f"Chizuru-Gban-{user_chat.id}", author=f"{banner.first_name} ({banner.id})", text=EVIDENSE_NEW_GBAN) evidence_link = page.get('url') evidence_link = "<a href='{}'>{}</a>".format(evidence_link, f"Chizuru Evidence") message.reply_text( f"<b>Beginning of Global Ban For</b> {mention_html(user_chat.id, user_chat.first_name)}" f"\n<b>With ID</b>: <code>{user_chat.id}</code>" f"\n\n<b>Officer</b>: {banner.first_name}" f"\n<b>Officer ID</b>: <code>{banner.id}</code>" f"\n\n<b>Reason</b>: <code>{reason}</code>" f"\n<b>Evidence:</b> {evidence_link}", parse_mode=ParseMode.HTML, disable_web_page_preview=True, ) starting_usermsg = f"""#Event\n<b>You've Been Globally Banned</b>\n<b>Reason:</b> {reason}\n<b>Global Ban Log:</b> <a href="https://t.me/ElitesOfLogs">LOGS</a>\n<b>Appeal:</b> @{SUPPORT_CHAT}""" try: if chat.type != 'private': chat_origin = "<b>{} ({})</b>".format(html.escape(chat.title), chat.id) else: chat_origin = "<b>{}</b>".format(chat.id) context.bot.sendMessage( GBAN_DUMP, "#GBANNED" f"\n<b>Originated from:</b> <code>{chat_origin}</code>" "\n<b>Officer:</b> {}" "\n\n<b>User:</b> {}" "\n<b>ID:</b> <code>{}</code>" "\n<b>Reason:</b> {}" "\n<b>Evidence:</b> {}".format( mention_html(banner.id, banner.first_name), mention_html(user_chat.id, user_chat.first_name), user_chat.id, reason, evidence_link, ), parse_mode=ParseMode.HTML, disable_web_page_preview=True, ) except Exception: context.bot.send_message(ERROR_DUMP, "<b>[Error]</b>" "\nFailed to Log gban user.") try: context.bot.send_message(user_chat.id, starting_usermsg, parse_mode=ParseMode.HTML, disable_web_page_preview=True) except Exception: context.bot.send_message(ERROR_DUMP, f"<b>[Error]</b>\n" f"Failed to send Gban message to this user." f"\nID: <code>{user_chat.id}</code>", parse_mode=ParseMode.HTML) try: context.bot.kick_chat_member(chat.id, user_chat.id) except BadRequest as excp: if excp.message in GBAN_ERRORS: pass sql.gban_user(user_id, user_chat.username or user_chat.first_name, reason)
def test_upload_return_json(self): telegraph_response = upload_image('http://httpbin.org/image/jpeg', return_json=True) self.assertIsInstance(telegraph_response, list) self.assertTrue(len(telegraph_response), 1) self.assertNotEqual(telegraph_response[0].get('src'), None)
def _upload(): upload_image('http://httpbin.org/delay/3', return_json=True, get_timeout=(2, 2))