def choose_author_size(message): buttons = types.ReplyKeyboardMarkup(row_width=1, one_time_keyboard=True) btn_y = types.KeyboardButton("526") buttons.add(btn_y) if message.content_type == 'text': if util.is_command(message.text) and util.extract_command( message.text) in commands.keys(): command_send(util.extract_command(message.text), message) return if message.text.isdigit(): data['author_y'] = int(message.text) buttons = types.ReplyKeyboardMarkup(row_width=1, one_time_keyboard=True) btn_size = types.KeyboardButton("19") buttons.add(btn_size) msg = bot.send_message(message.chat.id, "Enter author font size: ", reply_markup=buttons) bot.register_next_step_handler(message, gen_img) else: bot.send_message(message.chat.id, "Please enter a valid number!") msg = bot.send_message(message.chat.id, "Enter author y-coordinate: ", reply_markup=buttons) bot.register_next_step_handler(msg, choose_author_size) else: bot.send_message(message.chat.id, "Please enter a valid number!") msg = bot.send_message(message.chat.id, "Enter author y-coordinate: ", reply_markup=buttons) bot.register_next_step_handler(msg, choose_author_size)
def choose_url(message): if message.content_type == 'text': buttons = types.ReplyKeyboardMarkup(row_width=3, one_time_keyboard=True) btn_orange = types.KeyboardButton("Orange") btn_purple = types.KeyboardButton("Purple") btn_green = types.KeyboardButton("Green") buttons.add(btn_orange, btn_purple, btn_green) if util.is_command(message.text) and util.extract_command( message.text) in commands.keys(): command_send(util.extract_command(message.text), message) return if message.text.lower() == 'orange': data['color'] = 'orange' elif message.text.lower() == 'purple': data['color'] = 'purple' elif message.text.lower() == 'green': data['color'] = 'green' else: bot.send_message(message.chat.id, "Please enter a valid option!") msg = bot.send_message(message.chat.id, "Choose the theme color: ", reply_markup=buttons) bot.register_next_step_handler(msg, choose_url) return msg = bot.reply_to(message, "Enter the image URL: ") bot.register_next_step_handler(msg, choose_img_width) else: bot.send_message(message.chat.id, "Please enter a valid option!") msg = bot.send_message(message.chat.id, "Choose the theme color: ", reply_markup=buttons) bot.register_next_step_handler(msg, choose_url) return
def choose_author_x(message): buttons = types.ReplyKeyboardMarkup(row_width=3, one_time_keyboard=True) btn_1 = "- Joe" btn_2 = "- Nidhi" btn_3 = "- Snehal" btn_4 = "- Sarahfin" btn_5 = "- Swapneel" btn_6 = "- Dheeraj" btn_8 = "- Rushi" btn_9 = "- Rijuth" buttons.add(btn_1, btn_2, btn_3, btn_4, btn_5, btn_6, btn_8, btn_9) if message.content_type == 'text': if util.is_command(message.text) and util.extract_command( message.text) in commands.keys(): command_send(util.extract_command(message.text), message) return data['author'] = message.text buttons = types.ReplyKeyboardMarkup(row_width=1, one_time_keyboard=True) btn_x = types.KeyboardButton("488") buttons.add(btn_x) msg = bot.send_message(message.chat.id, "Enter author x-coordinate: ", reply_markup=buttons) bot.register_next_step_handler(msg, choose_author_y) else: bot.send_message(message.chat.id, "Please enter a valid name!") msg = bot.send_message(message.chat.id, "Enter author name: ", reply_markup=buttons) bot.register_next_step_handler(msg, choose_author_x)
def choose_img_x(message): buttons = types.ReplyKeyboardMarkup(row_width=1, one_time_keyboard=True) btn_height = types.KeyboardButton("200") buttons.add(btn_height) if message.content_type == 'text': if util.is_command(message.text) and util.extract_command( message.text) in commands.keys(): command_send(util.extract_command(message.text), message) return if message.text.isdigit(): data['img_height'] = int(message.text) buttons = types.ReplyKeyboardMarkup(row_width=1, one_time_keyboard=True) btn_x = types.KeyboardButton("185") buttons.add(btn_x) msg = bot.send_message(message.chat.id, "Enter image x-coordinate: ", reply_markup=buttons) bot.register_next_step_handler(msg, choose_img_y) else: bot.send_message(message.chat.id, "Please enter a valid number!") msg = bot.send_message(message.chat.id, "Enter image height: ", reply_markup=buttons) bot.register_next_step_handler(msg, choose_img_x) else: bot.send_message(message.chat.id, "Please enter a valid number!") msg = bot.send_message(message.chat.id, "Enter image height: ", reply_markup=buttons) bot.register_next_step_handler(msg, choose_img_x)
def choose_author_quick(message): buttons = types.ReplyKeyboardMarkup(row_width=1, one_time_keyboard=True) btn_y = types.KeyboardButton("25") buttons.add(btn_y) if message.content_type == 'text': if util.is_command(message.text) and util.extract_command( message.text) in commands.keys(): command_send(util.extract_command(message.text), message) return buttons = types.ReplyKeyboardMarkup(row_width=3, one_time_keyboard=True) btn_1 = "- Joe" btn_2 = "- Nidhi" btn_3 = "- Snehal" btn_4 = "- Sarahfin" btn_5 = "- Swapneel" btn_6 = "- Dheeraj" btn_8 = "- Rushi" btn_9 = "- Rijuth" buttons.add(btn_1, btn_2, btn_3, btn_4, btn_5, btn_6, btn_8, btn_9) data['title_size'] = 25 data['title'] = message.text data['title_x'] = 180 data['title_y'] = 455 msg = bot.send_message(message.chat.id, "Enter author name: ", reply_markup=buttons) bot.register_next_step_handler(msg, gen_img_quick) else: bot.send_message(message.chat.id, "Please enter a valid title!") msg = bot.send_message(message.chat.id, "Enter title: ") bot.register_next_step_handler(msg, choose_author_quick)
def handle_message(self, json_string): self.message = types.Message.de_json(json_string) _content_type = self.message.content_type _result_text = None if _content_type == 'text': _text = self.message.text if util.is_command(_text): _cmd = util.extract_command(_text) _agrs = util.extract_arguments(_text) _result_text = self.command_callback(_cmd, _agrs) else: _result_text = self.text_callback(_text) elif _content_type == 'voice': _result_text = self.voice_callback(self.message.voice) elif os.environ.get('DEBUG'): _result_text = 'DEBUG content_type = {0}'.format(_content_type) # Bot always replies with text message return bothelper.new_message(self.message.chat.id, _result_text) if _result_text else None
def gen_img_quick(message): buttons = types.ReplyKeyboardMarkup(row_width=3, one_time_keyboard=True) btn_1 = "- Joe" btn_2 = "- Nidhi" btn_3 = "- Snehal" btn_4 = "- Sarahfin" btn_5 = "- Swapneel" btn_6 = "- Dheeraj" btn_7 = "- Denin" btn_8 = "- Rushi" btn_9 = "- Rijuth" buttons.add(btn_1, btn_2, btn_3, btn_4, btn_5, btn_6, btn_7, btn_8, btn_9) if message.content_type == 'text': if util.is_command(message.text) and util.extract_command( message.text) in commands.keys(): command_send(util.extract_command(message.text), message) return data['author_size'] = 19 data['author'] = message.text data['author_x'] = 488 data['author_y'] = 526 data['img_width'] = 390 data['img_height'] = 200 data['img_x'] = 185 data['img_y'] = 225 data['image'] = resize_img(data['image'], data['img_width'], data['img_height']) data['image'] = make_img(data['image'], data['color'], data['img_x'], data['img_y']) data['image'] = write_title(data['image'], data['title'], data['title_size'], data['title_x'], data['title_y']) data['image'] = write_author(data['image'], data['color'], data['author'], data['author_size'], data['author_x'], data['author_y']) saved_img = save_img(data['image']) img = upload_img(saved_img['directory']) if (img['success'] == True): bot.send_message(message.chat.id, """ <b>IMAGE GENERATED!</b> <i>Uploading...</i> """, parse_mode='HTML') bot.send_message(message.chat.id, img['data']['url']) os.remove(saved_img['directory']) else: bot.send_message(message.chat.id, "<b><u>IMAGE WAS NOT UPLOADED!</u></b>", parse_mode="HTML") else: bot.send_message(message.chat.id, "Please enter a valid name") msg = bot.send_message(message.chat.id, "Enter author name: ", reply_markup=buttons) bot.register_next_step_handler(msg, gen_img_quick)
def choose_img_width(message): if message.content_type == 'text': if util.is_command(message.text) and util.extract_command( message.text) in commands.keys(): command_send(util.extract_command(message.text), message) return if validators.url(message.text): image = get_img(message.text) if (image['status']): data['image'] = image['image'] bot.send_message(message.chat.id, f""" <b>IMAGE FETCHED!</b> <b>WIDTH:</b> {image['width']} <b>HEIGHT:</b> {image['height']} <u><b>RECOMMENDED VALUES</b></u> <b>WIDTH: 512</b> <b>HEIGHT: 288</b> <i>Image size values have to be greater or equal to recommended values. </i> """, reply_to_message_id=message.message_id, parse_mode='HTML') buttons = types.ReplyKeyboardMarkup(row_width=1, one_time_keyboard=True) btn_width = types.KeyboardButton("390") buttons.add(btn_width) msg = bot.send_message(message.chat.id, "Enter image width: ", reply_markup=buttons) bot.register_next_step_handler(msg, choose_img_height) else: bot.send_message(message.chat.id, "Please enter a valid URL!") msg = bot.send_message(message.chat.id, "Enter the image URL: ") bot.register_next_step_handler(msg, choose_img_width) else: bot.send_message(message.chat.id, "Please enter a valid URL!") msg = bot.send_message(message.chat.id, "Enter the image URL: ") bot.register_next_step_handler(msg, choose_img_width) else: bot.send_message(message.chat.id, "Please enter a valid URL!") msg = bot.send_message(message.chat.id, "Enter the image URL: ") bot.register_next_step_handler(msg, choose_img_width)
def gen_img(message): buttons = types.ReplyKeyboardMarkup(row_width=1, one_time_keyboard=True) btn_y = types.KeyboardButton("19") buttons.add(btn_y) if message.content_type == 'text': if util.is_command(message.text) and util.extract_command( message.text) in commands.keys(): command_send(util.extract_command(message.text), message) return if message.text.isdigit(): data['author_size'] = int(message.text) data['image'] = resize_img(data['image'], data['img_width'], data['img_height']) data['image'] = make_img(data['image'], data['color'], data['img_x'], data['img_y']) data['image'] = write_title(data['image'], data['title'], data['title_size'], data['title_x'], data['title_y']) data['image'] = write_author(data['image'], data['color'], data['author'], data['author_size'], data['author_x'], data['author_y']) saved_img = save_img(data['image']) img = upload_img(saved_img['directory']) if (img['success'] == True): bot.send_message(message.chat.id, """ <b>IMAGE GENERATED!</b> <i>Uploading...</i> """, parse_mode='HTML') bot.send_message(message.chat.id, img['data']['url']) os.remove(saved_img['directory']) else: bot.send_message(message.chat.id, "<b><u>IMAGE WAS NOT UPLOADED!</u></b>", parse_mode="HTML") else: bot.send_message(message.chat.id, "Please enter a valid number!") msg = bot.send_message(message.chat.id, "Enter author font size: ", reply_markup=buttons) bot.register_next_step_handler(msg, gen_img) else: bot.send_message(message.chat.id, "Please enter a valid number!") msg = bot.send_message(message.chat.id, "Enter author font size: ", reply_markup=buttons) bot.register_next_step_handler(msg, gen_img)
def choose_title_x(message): if message.content_type == 'text': if util.is_command(message.text) and util.extract_command( message.text) in commands.keys(): command_send(util.extract_command(message.text), message) return data['title'] = message.text buttons = types.ReplyKeyboardMarkup(row_width=1, one_time_keyboard=True) btn_x = types.KeyboardButton("180") buttons.add(btn_x) msg = bot.send_message(message.chat.id, "Enter title x-coordinate: ", reply_markup=buttons) bot.register_next_step_handler(msg, choose_title_y) else: bot.send_message(message.chat.id, "Please enter a valid title!") msg = bot.send_message(message.chat.id, "Enter title: ") bot.register_next_step_handler(msg, choose_title_x)
def choose_title_quick(message): if message.content_type == 'text': if util.is_command(message.text) and util.extract_command( message.text) in commands.keys(): command_send(util.extract_command(message.text), message) return if validators.url(message.text): image = get_img(message.text) if (image['status']): data['image'] = image['image'] bot.send_message(message.chat.id, f""" <b>IMAGE FETCHED!</b> <b>WIDTH:</b> {image['width']} <b>HEIGHT:</b> {image['height']} <u><b>RECOMMENDED VALUES</b></u> <b>WIDTH: 512</b> <b>HEIGHT: 288</b> <i>Image size values have to be greater or equal to recommended values. </i> """, reply_to_message_id=message.message_id, parse_mode='HTML') msg = bot.send_message(message.chat.id, "Enter title: ") bot.register_next_step_handler(msg, choose_author_quick) else: bot.send_message(message.chat.id, "Please enter a valid URL!") msg = bot.send_message(message.chat.id, "Enter the image URL: ") bot.register_next_step_handler(msg, choose_title_quick) else: bot.send_message(message.chat.id, "Please enter a valid URL!") msg = bot.send_message(message.chat.id, "Enter the image URL: ") bot.register_next_step_handler(msg, choose_title_quick) else: bot.send_message(message.chat.id, "Please enter a valid URL!") msg = bot.send_message(message.chat.id, "Enter the image URL: ") bot.register_next_step_handler(msg, choose_title_quick)
def poster(message): if message.chat.id in users: if util.is_command(message.text) and util.extract_arguments( message.text) == 'help': bot.send_message(message.chat.id, """ <u><b> PARAMETERS</b></u> <b>Color : -c</b> <b>Image URL : -u</b> <b>Image Width : -iw</b> <b>Image Height : -ih</b> <b>Image x-coordinate : -ix</b> <b>Image y-coordinate : -iy</b> <b>Author Name : -a</b> <b>Author Size : -as</b> <b>Author x-coordinate : -ax</b> <b>Author y-coordinate : -ay</b> <b>Title Name : -t</b> <b>Title Size : -ts</b> <b>Title x-coordinate : -tx</b> <b>Title y-coordinate : -ty</b> """, reply_to_message_id=message.message_id, parse_mode='HTML') bot.send_message(message.chat.id, """ <u><b>EXAMPLE</b></u> /post -c orange -u https://unsullied.xyz/img/logo/meta.png -iw 390 -ih 200 -ix 185 -iy 225 -t "Testing is fun." -ts 25 -tx 180 -ty 455 -a "- Sarahfin" -as 19 -ax 488 -ay 526 """, reply_to_message_id=message.message_id, parse_mode='HTML') return try: param = message.text.split(' ') if validators.url(param[param.index('-u') + 1]): image = get_img(param[param.index('-u') + 1]) if (image['status']): data['image'] = image['image'] bot.send_message(message.chat.id, f""" <b>IMAGE FETCHED!</b> <b>WIDTH:</b> {image['width']} <b>HEIGHT:</b> {image['height']} <u><b>RECOMMENDED VALUES</b></u> <b>WIDTH: 512</b> <b>HEIGHT: 288</b> <i>Image size values have to be greater or equal to recommended values. </i> """, reply_to_message_id=message.message_id, parse_mode='HTML') title = message.text[message.text. find('-t'):len(message.text) - 1].replace('-t ', '') data['title'] = '' for i in range(1, len(title) - 1): if title[i] == '"': break data['title'] = data['title'] + title[i] data['title_size'] = int(param[param.index('-ts') + 1]) author = message.text[message.text. find('-a'):len(message.text) - 1].replace('-a ', '') data['author'] = '' for i in range(1, len(author) - 1): if author[i] == '"': break data['author'] = data['author'] + author[i] data['author_size'] = int(param[param.index('-as') + 1]) data['img_x'] = int(param[param.index('-ix') + 1]) data['img_y'] = int(param[param.index('-iy') + 1]) data['img_width'] = int(param[param.index('-iw') + 1]) data['img_height'] = int(param[param.index('-ih') + 1]) data['author_x'] = int(param[param.index('-ax') + 1]) data['author_y'] = int(param[param.index('-ay') + 1]) data['title_x'] = int(param[param.index('-tx') + 1]) data['title_y'] = int(param[param.index('-ty') + 1]) data['color'] = param[param.index('-c') + 1].lower() data['image'] = resize_img(data['image'], data['img_width'], data['img_height']) data['image'] = make_img(data['image'], data['color'], data['img_x'], data['img_y']) data['image'] = write_title(data['image'], data['title'], data['title_size'], data['title_x'], data['title_y']) data['image'] = write_author(data['image'], data['color'], data['author'], data['author_size'], data['author_x'], data['author_y']) saved_img = save_img(data['image']) img = upload_img(saved_img['directory']) if (img['success'] == True): bot.send_message(message.chat.id, """ <b>IMAGE GENERATED!</b> <i>Uploading...</i> """, parse_mode='HTML') bot.send_message(message.chat.id, img['data']['url']) os.remove(saved_img['directory']) else: bot.send_message( message.chat.id, "<b><u>IMAGE WAS NOT UPLOADED!</u></b>", parse_mode="HTML") else: bot.send_message(message.chat.id, "Please enter a valid URL!") msg = bot.send_message(message.chat.id, "Enter the image URL: ") bot.register_next_step_handler(msg, choose_img_width) else: bot.send_message(message.chat.id, "Please enter a valid URL!") msg = bot.send_message(message.chat.id, "Enter the image URL: ") bot.register_next_step_handler(msg, choose_img_width) except Exception as e: bot.send_message(message.chat.id, f""" <b>INVALID COMMAND!</b> Run <code>/post help</code> to get the list of accepted arguments <b>Error : {e}</b> """, parse_mode='HTML') else: bot.reply_to(message, """<b>You're not part of unsullied!</b>""", parse_mode='HTML')