Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
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)
Exemplo n.º 6
0
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)
Exemplo n.º 7
0
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)
Exemplo n.º 8
0
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)
Exemplo n.º 9
0
 def allow_anonymous_filter(message):
     logger.debug("AllowAnonymousMixin::allow_anonymous_filter[allow=%s]" % self.allow_anonymous())
     if not message.content_type == 'text' or extract_command(message.text) not in self.commands_excluded:
         user = TelegramUser.objects.filter(id=message.from_user.id).first()
         if (not user or (user and not user.user)) and not self.allow_anonymous():
             raise NoUserException('Telegram user %s is not associated with an existing User' % message.from_user.id)
     return func(message) if func else True
Exemplo n.º 10
0
 def deep_linking_filter(message):
     logger.debug("DeepLinkingMixin::deep_linking_filter")
     if message.content_type == 'text' and extract_command(
             message.text) == 'start':
         unique_code = self.extract_unique_code(message.text)
         if unique_code:  # if the '/start' command contains a unique_code
             try:
                 deeplink = DeepLinking.objects.valid().get(
                     code=unique_code, bot=self.db_bot)
                 deeplink.used = now()
                 deeplink.save()
                 TelegramUser.objects.get_or_create(
                     id=message.from_user.id,
                     user=deeplink.user,
                     defaults={
                         'first_name':
                         message.from_user.first_name,
                         'last_name':
                         getattr(message.from_user, 'last_name', None),
                         'username':
                         getattr(message.from_user, 'username', None),
                     })
                 # TODO: Associate user to chat,...
                 return True
             except DeepLinking.DoesNotExist as e:
                 raise DeepLinkingException(
                     "Invalid code provided: %s" % str(e))
     return func(message) if func else True
Exemplo n.º 11
0
def handle_start_help(message):
    print("CMD " + message.text)
    command = util.extract_command(message.text)
    if BBRequests.is_photo_cmd(command):
        BBRequests.send_image_by_cmd(command, bot, message.chat.id)
    else:
        bot.send_message(message.chat.id, 'Wrong comand = ' + command)
Exemplo n.º 12
0
    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
Exemplo n.º 13
0
def filter_commands(msg, tgu, filter_value):
    if msg.content_type != 'text':
        return False
    command = telebot_util.extract_command(msg.text)
    if not command:
        return False
    command = str(command).lower()
    return command in map(str.lower, filter_value)
Exemplo n.º 14
0
    def _test_filter(self, filter, filter_value, message):
        test_cases = {
            'content_types': lambda msg: msg.content_type in filter_value,
            'regexp': lambda msg: msg.content_type == 'text' and re.search(filter_value, msg.text),
            'commands': lambda msg: msg.content_type == 'text' and util.extract_command(msg.text) in filter_value,
            'func': lambda msg: filter_value(msg)
        }

        return test_cases.get(filter, lambda msg: False)(message)
Exemplo n.º 15
0
    def _test_filter(self, filter, filter_value, message):
        test_cases = {
            'content_types': lambda msg: msg.content_type in filter_value,
            'regexp': lambda msg: msg.content_type == 'text' and re.search(filter_value, msg.text, re.IGNORECASE),
            'commands': lambda msg: msg.content_type == 'text' and util.extract_command(msg.text) in filter_value,
            'func': lambda msg: filter_value(msg)
        }

        return test_cases.get(filter, lambda msg: False)(message)
Exemplo n.º 16
0
 def _test_filter(filter, filter_value, message):
     if filter == 'content_types':
         return message.content_type in filter_value
     if filter == 'regexp':
         return message.content_type == 'text' and re.search(filter_value, message.text)
     if filter == 'commands':
         return message.content_type == 'text' and util.extract_command(message.text) in filter_value
     if filter == 'lambda':
         return filter_value(message)
     return False
Exemplo n.º 17
0
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)
Exemplo n.º 18
0
 def _test_filter(filter, filter_value, message):
     if filter == "content_types":
         return message.content_type in filter_value
     if filter == "regexp":
         return message.content_type == "text" and re.search(filter_value, message.text)
     if filter == "commands":
         return message.content_type == "text" and util.extract_command(message.text) in filter_value
     if filter == "lambda":
         return filter_value(message)
     return False
Exemplo n.º 19
0
 def _test_filter(filter, filter_value, message):
     if filter == 'content_types':
         return message.content_type in filter_value
     if filter == 'regexp':
         return message.content_type == 'text' and re.search(filter_value, message.text)
     if filter == 'commands':
         return message.content_type == 'text' and util.extract_command(message.text) in filter_value
     if filter == 'lambda':
         return filter_value(message)
     return False
Exemplo n.º 20
0
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)
Exemplo n.º 21
0
    def _test_filter(self, filter, filter_value, message):
        test_cases = {
            'state': lambda msg: self.storage.get_state(msg.chat.id, msg.from_user.id, default='') == filter_value
            if msg.from_user else self.storage.get_state(msg.chat.id, default='') == filter_value,
            'content_types': lambda msg: msg.content_type in filter_value,
            'regexp': lambda msg: msg.content_type == 'text' and re.search(filter_value, msg.text, re.IGNORECASE),
            'commands': lambda msg: msg.content_type == 'text' and util.extract_command(msg.text) in filter_value,
            'func': lambda msg: filter_value(msg)
        }

        return test_cases.get(filter, lambda msg: False)(message)
Exemplo n.º 22
0
 def wait_reply(answer):
     logger.debug("NeutronBot::wait_reply_for_word")
     if answer.content_type == 'text':
         command = extract_command(answer.text)
         if not command:
             logger.debug('Answer for %s: %s' % (meaning.word, answer.text))
             if answer.text in ['ok', 'unknown']:
                 use = WordUse.USES.ok if answer.text == 'ok' else WordUse.USES.unrecognized
                 WordUse.objects.create(meaning=meaning,
                                        use=use,
                                        interface=self.interface,
                                        informer=informer)
                 # Ask for another word
             self.on_word(answer)
Exemplo n.º 23
0
 def wait_reply(answer):
     logger.debug("NeutronBot::wait_reply_for_coarse")
     if answer.content_type == 'text':
         command = extract_command(answer.text)
         if not command:
             logger.debug('Answer for %s: %s' % (meaning.word, answer.text))
             if answer.text in alternates:
                 profane = (answer.text != alternates[0])
                 CoarseWord.objects.create(word=meaning.word,
                                           profane=profane,
                                           interface=self.interface,
                                           informer=informer)
             # Ask for another word
             self.on_coarse(answer)
Exemplo n.º 24
0
 def allow_anonymous_filter(message):
     logger.debug(
         "AllowAnonymousMixin::allow_anonymous_filter[allow=%s]" %
         self.allow_anonymous())
     if not message.content_type == 'text' or extract_command(
             message.text) not in self.commands_excluded:
         user = TelegramUser.objects.filter(
             id=message.from_user.id).first()
         if (not user or
             (user and not user.user)) and not self.allow_anonymous():
             raise NoUserException(
                 'Telegram user %s is not associated with an existing User'
                 % message.from_user.id)
     return func(message) if func else True
Exemplo n.º 25
0
 def wait_reply(answer):
     logger.debug("NeutronBot::wait_reply_for_coarse")
     if answer.content_type == 'text':
         command = extract_command(answer.text)
         if not command:
             logger.debug('Answer for %s: %s' %
                          (meaning.word, answer.text))
             if answer.text in alternates:
                 profane = (answer.text != alternates[0])
                 CoarseWord.objects.create(word=meaning.word,
                                           profane=profane,
                                           interface=self.interface,
                                           informer=informer)
             # Ask for another word
             self.on_coarse(answer)
Exemplo n.º 26
0
 def wait_reply(answer):
     logger.debug("NeutronBot::wait_reply_for_word")
     if answer.content_type == 'text':
         command = extract_command(answer.text)
         if not command:
             logger.debug('Answer for %s: %s' %
                          (meaning.word, answer.text))
             if answer.text in ['ok', 'unknown']:
                 use = WordUse.USES.ok if answer.text == 'ok' else WordUse.USES.unrecognized
                 WordUse.objects.create(meaning=meaning,
                                        use=use,
                                        interface=self.interface,
                                        informer=informer)
                 # Ask for another word
             self.on_word(answer)
Exemplo n.º 27
0
 def deep_linking_filter(message):
     logger.debug("DeepLinkingMixin::deep_linking_filter")
     if message.content_type == 'text' and extract_command(message.text) == 'start':
         unique_code = self.extract_unique_code(message.text)
         if unique_code:  # if the '/start' command contains a unique_code
             try:
                 deeplink = DeepLinking.objects.valid().get(code=unique_code, bot=self.db_bot)
                 deeplink.used = now()
                 deeplink.save()
                 TelegramUser.objects.get_or_create(id=message.from_user.id,
                                                    user=deeplink.user,
                                                    defaults={'first_name': message.from_user.first_name,
                                                              'last_name': getattr(message.from_user, 'last_name', None),
                                                              'username': getattr(message.from_user, 'username', None),
                                                             })
                 # TODO: Associate user to chat,...
                 return True
             except DeepLinking.DoesNotExist as e:
                 raise DeepLinkingException("Invalid code provided: %s" % str(e))
     return func(message) if func else True