Пример #1
0
def send(update, message, keyboard, backup_message):
    try:
        update.effective_message.reply_text(message,
                                            parse_mode=ParseMode.MARKDOWN,
                                            reply_markup=keyboard)
    except IndexError:
        update.effective_message.reply_text(
            markdown_parser(backup_message + "\nNote: the current message was "
                            "invalid due to markdown issues. Could be "
                            "due to the user's name."),
            parse_mode=ParseMode.MARKDOWN)
    except KeyError:
        update.effective_message.reply_text(
            markdown_parser(backup_message + "\nNote: the current message is "
                            "invalid due to an issue with some misplaced "
                            "curly brackets. Please update"),
            parse_mode=ParseMode.MARKDOWN)
    except BadRequest as excp:
        if excp.message == "Button_url_invalid":
            update.effective_message.reply_text(markdown_parser(
                backup_message +
                "\nNote: the current message has an invalid url in "
                "one of its buttons. Please update."),
                                                parse_mode=ParseMode.MARKDOWN)
        elif excp.message == "Unsupported url protocol":
            update.effective_message.reply_text(markdown_parser(
                backup_message +
                "\nNote: the current message has buttons which use "
                "url protocols that are unsupported by telegram. "
                "Please update."),
                                                parse_mode=ParseMode.MARKDOWN)
        else:
            raise
Пример #2
0
def send(update, message, keyboard, backup_message):
    try:
        msg = update.effective_message.reply_text(message, parse_mode=ParseMode.MARKDOWN, reply_markup=keyboard)
    except BadRequest as excp:
        if excp.message == "Button_url_invalid":
            msg = update.effective_message.reply_text(markdown_parser(backup_message +
                                                                      "\nNote: the current message has an invalid url "
                                                                      "in one of its buttons. Please update."),
                                                      parse_mode=ParseMode.MARKDOWN)
        elif excp.message == "Unsupported url protocol":
            msg = update.effective_message.reply_text(markdown_parser(backup_message +
                                                                      "\nNote: the current message has buttons which "
                                                                      "use url protocols that are unsupported by "
                                                                      "telegram. Please update."),
                                                      parse_mode=ParseMode.MARKDOWN)
        elif excp.message == "Wrong url host":
            msg = update.effective_message.reply_text(markdown_parser(backup_message +
                                                                      "\nNote: the current message has some bad urls. "
                                                                      "Please update."),
                                                      parse_mode=ParseMode.MARKDOWN)
            LOGGER.warning(message)
            LOGGER.warning(keyboard)
            LOGGER.exception("Could not parse! got invalid url host errors")
        else:
            msg = update.effective_message.reply_text(markdown_parser(backup_message +
                                                                      "\nNote: An error occured when sending the "
                                                                      "custom message. Please update."),
                                                      parse_mode=ParseMode.MARKDOWN)
            LOGGER.exception()

    return msg
Пример #3
0
def send(update, message, keyboard, backup_message):
    chat = update.effective_chat
    cleanserv = sql.clean_service(chat.id)
    reply = update.message.message_id
    # Clean service welcome
    if cleanserv:
        try:
            dispatcher.bot.delete_message(chat.id, update.message.message_id)
        except BadRequest:
            pass
        reply = False
    try:
        msg = update.effective_message.reply_text(
            message,
            parse_mode=ParseMode.MARKDOWN,
            reply_markup=keyboard,
            reply_to_message_id=reply)
    except BadRequest as excp:
        if excp.message == "Button_url_invalid":
            msg = update.effective_message.reply_text(
                markdown_parser(
                    backup_message +
                    "\nNote: the current message has an invalid url "
                    "in one of its buttons. Please update."),
                parse_mode=ParseMode.MARKDOWN,
                reply_to_message_id=reply)
        elif excp.message == "Unsupported url protocol":
            msg = update.effective_message.reply_text(
                markdown_parser(
                    backup_message +
                    "\nNote: the current message has buttons which "
                    "use url protocols that are unsupported by "
                    "telegram. Please update."),
                parse_mode=ParseMode.MARKDOWN,
                reply_to_message_id=reply)
        elif excp.message == "Wrong url host":
            msg = update.effective_message.reply_text(
                markdown_parser(
                    backup_message +
                    "\nNote: the current message has some bad urls. "
                    "Please update."),
                parse_mode=ParseMode.MARKDOWN,
                reply_to_message_id=reply)
            LOGGER.warning(message)
            LOGGER.warning(keyboard)
            LOGGER.exception("Could not parse! got invalid url host errors")
        else:
            msg = update.effective_message.reply_text(
                markdown_parser(backup_message +
                                "\nNote: An error occured when sending the "
                                "custom message. Please update."),
                parse_mode=ParseMode.MARKDOWN,
                reply_to_message_id=reply)
            LOGGER.exception()

    return msg
Пример #4
0
def set_frules(bot: Bot, update: Update, args: List[str]):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    fed_id = sql.get_fed_id(chat.id)

    if is_user_fed_admin(fed_id, user.id) == False:
        update.effective_message.reply_text(
            tld(chat.id, "Only fed admins can do this!"))
        return

    if len(args) >= 1:
        msg = update.effective_message  # type: Optional[Message]
        raw_text = msg.text
        args = raw_text.split(
            None, 1)  # use python's maxsplit to separate cmd and args
        if len(args) == 2:
            txt = args[1]
            offset = len(txt) - len(
                raw_text)  # set correct offset relative to command
            markdown_rules = markdown_parser(txt,
                                             entities=msg.parse_entities(),
                                             offset=offset)
        sql.set_frules(fed_id, markdown_rules)
        update.effective_message.reply_text(
            tld(chat.id, "Successfully set rule's for this fed!"))
    else:
        update.effective_message.reply_text(tld(chat.id,
                                                "Please write rules!"))
Пример #5
0
def set_frules(bot: Bot, update: Update, args: List[str]):
	chat = update.effective_chat  # type: Optional[Chat]
	user = update.effective_user  # type: Optional[User]
	fed_id = sql.get_fed_id(chat.id)

	if not fed_id:
		update.effective_message.reply_text("This chat is not in any federation!")
		return

	if is_user_fed_admin(fed_id, user.id) == False:
		update.effective_message.reply_text("Only federation admins can do this!")
		return

	if len(args) >= 1:
		msg = update.effective_message  # type: Optional[Message]
		raw_text = msg.text
		args = raw_text.split(None, 1)  # use python's maxsplit to separate cmd and args
		if len(args) == 2:
			txt = args[1]
			offset = len(txt) - len(raw_text)  # set correct offset relative to command
			markdown_rules = markdown_parser(txt, entities=msg.parse_entities(), offset=offset)
		x = sql.set_frules(fed_id, markdown_rules)
		if not x:
			update.effective_message.reply_text("Failed to set federation rules. If this persists, reach out to us @tohsakas.")
			return

		rules = sql.get_fed_info(fed_id)['frules']
		update.effective_message.reply_text(f"Rules have been set to :\n{rules}!")
	else:
		update.effective_message.reply_text("Please write the rules!")
Пример #6
0
def save_replied(bot: Bot, update: Update):
    chat_id = update.effective_chat.id
    text = update.effective_message.text
    args = text.split(None, 3)  # use python's maxsplit to separate Cmd, note_name, and data
    if len(args) == 3 and args[1] == "from":
        notename = args[2]
    elif len(args) >= 2:
        notename = args[1]
    else:
        update.effective_message.reply_text("You need to give me a notename to save this message!")
        return

    msg = update.effective_message.reply_to_message  # type: Optional[Message]

    if msg.from_user.is_bot:
        text = extract_text(msg)
        if text:
            sql.add_note_to_db(chat_id, notename, markdown_parser(text), is_reply=False)
            update.effective_message.reply_text("Seems like you're trying to save a message from a bot. Unfortunately, "
                                                "bots can't forward bot messages, so I can't save the exact message. "
                                                "\nI'll save all the text I can, but if you want more, you'll have to "
                                                "forward the message yourself, and then save it.")
        else:
            update.effective_message.reply_text("Bots are kinda handicapped by telegram, making it hard for bots to "
                                                "interract with other bots, so I can't save this message "
                                                "like I usually would - do you mind forwarding it and "
                                                "then saving that new message? Thanks!")
        return

    if MESSAGE_DUMP:
        msg = bot.forward_message(chat_id=MESSAGE_DUMP, from_chat_id=chat_id, message_id=msg.message_id)

    sql.add_note_to_db(chat_id, notename, msg.message_id, is_reply=True)
    update.effective_message.reply_text("Yas! Added replied message {}".format(notename))
Пример #7
0
def set_frules(bot: Bot, update: Update, args: List[str]):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    fed_id = sql.get_fed_id(chat.id)

    if not fed_id:
        update.effective_message.reply_text(tld(chat.id, "This chat is not in any federation!"))
        return

    if is_user_fed_admin(fed_id, user.id) == False:
        update.effective_message.reply_text(tld(chat.id, "Only fed admins can do this!"))
        return

    if len(args) >= 1:
        msg = update.effective_message  # type: Optional[Message]
        raw_text = msg.text
        args = raw_text.split(None, 1)  # use python's maxsplit to separate cmd and args
        if len(args) == 2:
            txt = args[1]
            offset = len(txt) - len(raw_text)  # set correct offset relative to command
            markdown_rules = markdown_parser(txt, entities=msg.parse_entities(), offset=offset)
        x = sql.set_frules(fed_id, markdown_rules)
        if not x:
            update.effective_message.reply_text(tld(chat.id, "Big F! There is an error while setting federation rules! If you wondered why please ask it in support group!"))
            return

        rules = sql.get_fed_info(fed_id).fed_name
        update.effective_message.reply_text(tld(chat.id, f"Rules are set for {rules}!"))
    else:
        update.effective_message.reply_text(tld(chat.id, "Please write rules to set it up!"))
Пример #8
0
def set_frules(bot: Bot, update: Update, args: List[str]):
	spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id)
	if spam == True:
		return update.effective_message.reply_text("Spammer detected! Ignoring user.")

	chat = update.effective_chat  # type: Optional[Chat]
	user = update.effective_user  # type: Optional[User]
	fed_id = sql.get_fed_id(chat.id)

	if not fed_id:
		update.effective_message.reply_text("This chat is not in any federation!")
		return

	if is_user_fed_admin(fed_id, user.id) == False:
		update.effective_message.reply_text("Only fed admins can do this!")
		return

	if len(args) >= 1:
		msg = update.effective_message  # type: Optional[Message]
		raw_text = msg.text
		args = raw_text.split(None, 1)  # use python's maxsplit to separate cmd and args
		if len(args) == 2:
			txt = args[1]
			offset = len(txt) - len(raw_text)  # set correct offset relative to command
			markdown_rules = markdown_parser(txt, entities=msg.parse_entities(), offset=offset)
		x = sql.set_frules(fed_id, markdown_rules)
		if not x:
			update.effective_message.reply_text("Big F! There is an error while setting federation rules! If you wondered why please ask it in @onepunchsupport !")
			return

		rules = sql.get_fed_info(fed_id)['frules']
		update.effective_message.reply_text(f"Rules have been changed to :\n{rules}!")
	else:
		update.effective_message.reply_text("Please write rules to set it up!")
Пример #9
0
def fed_broadcast(bot: Bot, update: Update, args: List[str]):
	msg = update.effective_message  # type: Optional[Message]
	user = update.effective_user  # type: Optional[User]
	if args:
		chat = update.effective_chat  # type: Optional[Chat]
		fed_id = sql.get_fed_id(chat.id)
		fedinfo = sql.get_fed_info(fed_id)
		text = "*New broadcast from the Federation {}*\n".format(fedinfo['fname'])
		# Parsing md
		raw_text = msg.text
		args = raw_text.split(None, 1)  # use python's maxsplit to separate cmd and args
		txt = args[1]
		offset = len(txt) - len(raw_text)  # set correct offset relative to command
		text_parser = markdown_parser(txt, entities=msg.parse_entities(), offset=offset)
		text += text_parser
		try:
			broadcaster = user.first_name
		except:
			broadcaster = user.first_name + " " + user.last_name
		text += "\n\n- {}".format(mention_markdown(user.id, broadcaster))
		chat_list = sql.all_fed_chats(fed_id)
		failed = 0
		for chat in chat_list:
			try:
				bot.sendMessage(chat, text, parse_mode="markdown")
			except TelegramError:
				failed += 1
				LOGGER.warning("Couldn't send broadcast to %s, group name %s", str(chat.chat_id), str(chat.chat_name))

		send_text = "The federation broadcast is complete!"
		if failed >= 1:
			send_text += "{} the group failed to receive the broadcast, probably because they left the federation.".format(failed)
		update.effective_message.reply_text(send_text)
Пример #10
0
def send(update, message, keyboard, backup_message):
    try:
        update.effective_message.reply_text(message,
                                            parse_mode=ParseMode.MARKDOWN,
                                            reply_markup=keyboard)
    except IndexError:
        update.effective_message.reply_text(
            markdown_parser(backup_message + "\nNote: the current message was "
                            "invalid due to markdown issues. Could be "
                            "due to the user's name."),
            parse_mode=ParseMode.MARKDOWN)
    except KeyError:
        update.effective_message.reply_text(
            markdown_parser(backup_message + "\nNote: the current message is "
                            "invalid due to an issue with some misplaced "
                            "curly brackets. Please update"),
            parse_mode=ParseMode.MARKDOWN)
Пример #11
0
def send(update, message, keyboard, backup_message):
    try:
        msg = update.effective_message.reply_text(
            message, parse_mode=ParseMode.MARKDOWN, reply_markup=keyboard)
    except BadRequest as excp:
        if excp.message == "Button_url_invalid":
            msg = update.effective_message.reply_text(
                markdown_parser(
                    backup_message +
                    "\nCatatan: pesan saat ini memiliki url yang tidak valid "
                    "di salah satu tombolnya. Harap perbarui."),
                parse_mode=ParseMode.MARKDOWN,
            )
        elif excp.message == "Unsupported url protocol":
            msg = update.effective_message.reply_text(
                markdown_parser(
                    backup_message +
                    "\nCatatan: pesan saat ini memiliki tombol yang "
                    "gunakan protokol url yang tidak didukung oleh "
                    "telegram. Harap perbarui."),
                parse_mode=ParseMode.MARKDOWN,
            )
        elif excp.message == "Host url salah":
            msg = update.effective_message.reply_text(
                markdown_parser(
                    backup_message +
                    "\nCatatan: pesan saat ini memiliki beberapa url yang buruk. "
                    "Harap perbarui."),
                parse_mode=ParseMode.MARKDOWN,
            )
            LOGGER.warning(message)
            LOGGER.warning(keyboard)
            LOGGER.exception("Could not parse! got invalid url host errors")
        else:
            msg = update.effective_message.reply_text(
                markdown_parser(backup_message +
                                "\nCatatan: Terjadi kesalahan saat mengirim "
                                "pesan khusus. Harap perbarui."),
                parse_mode=ParseMode.MARKDOWN,
            )
            LOGGER.exception()

    return msg
Пример #12
0
def send(update, message, keyboard, backup_message):
    try:
        msg = update.effective_message.reply_text(message, parse_mode=ParseMode.MARKDOWN, reply_markup=keyboard)
    except IndexError:
        msg = update.effective_message.reply_text(markdown_parser(backup_message +
                                                                  "\nසටහන: වත්මන් පණිවිඩය විය"
                                                                  "සලකුණු කිරීමේ ගැටළු හේතුවෙන් අවලංගුය. වෙන්න පුළුවන් "
                                                                  "පරිශීලකයාගේ නම නිසා."),
                                                  parse_mode=ParseMode.MARKDOWN)
    except KeyError:
        msg = update.effective_message.reply_text(markdown_parser(backup_message +
                                                                  "\nසටහන: වත්මන් පණිවිඩය "
                                                                  "සමහර අස්ථානගත වී ඇති ගැටලුවක් හේතුවෙන් වලංගු නොවේ "
                                                                  "කැරලි වරහන්. කරුණාකර යාවත්කාලීන කරන්න"),
                                                  parse_mode=ParseMode.MARKDOWN)
    except BadRequest as excp:
        if excp.message == "Button_url_invalid":
            msg = update.effective_message.reply_text(markdown_parser(backup_message +
                                                                      "\nසටහන: වත්මන් පණිවිඩයේ වලංගු නොවන url එකක් ඇත"
                                                                      "එහි එක් බොත්තමක් තුළ. කරුණාකර යාවත්කාලීන කරන්න."),
                                                      parse_mode=ParseMode.MARKDOWN)
        elif excp.message == "Unsupported url protocol":
            msg = update.effective_message.reply_text(markdown_parser(backup_message +
                                                                      "\nසටහන: වත්මන් පණිවිඩයේ බොත්තම් ඇත"
                                                                      "සහාය නොදක්වන url ප්‍රොටෝකෝල භාවිතා කරන්න"
                                                                      "telegram. කරුණාකර යාවත්කාලීන කරන්න."),
                                                      parse_mode=ParseMode.MARKDOWN)
        elif excp.message == "Wrong url host":
            msg = update.effective_message.reply_text(markdown_parser(backup_message +
                                                                      "\nසටහන: වත්මන් පණිවිඩයේ නරක url කිහිපයක් ඇත. "
                                                                      "කරුණාකර යාවත්කාලීන කරන්න."),
                                                      parse_mode=ParseMode.MARKDOWN)
            LOGGER.warning(message)
            LOGGER.warning(keyboard)
            LOGGER.exception("Could not parse! got invalid url host errors")
        else:
            msg = update.effective_message.reply_text(markdown_parser(backup_message +
                                                                      "\nසටහන: යවන විට දෝෂයක් ඇතිවිය "
                                                                      "අභිරුචි පණිවිඩය. කරුණාකර යාවත්කාලීන කරන්න.),
                                                      parse_mode=ParseMode.MARKDOWN)
            LOGGER.exception()

    return msg
Пример #13
0
def set_rules(bot: Bot, update: Update):
    chat_id = update.effective_chat.id
    msg = update.effective_message  # type: Optional[Message]
    raw_text = msg.text
    args = raw_text.split(None, 1)  # use python's maxsplit to separate cmd and args
    if len(args) == 2:
        txt = args[1]
        offset = len(txt) - len(raw_text)  # set correct offset relative to command
        markdown_rules = markdown_parser(txt, entities=msg.parse_entities(), offset=offset)

        sql.set_rules(chat_id, markdown_rules)
        update.effective_message.reply_text("Successfully set rules for this group.")
Пример #14
0
def send(update, message, keyboard, backup_message):
    msg = None
    try:
        msg = update.effective_message.reply_text(
            message,
            parse_mode=ParseMode.MARKDOWN,
            reply_markup=keyboard,
            api_kwargs={"allow_sending_without_reply": True})
    except IndexError:
        msg = update.effective_message.reply_text(
            markdown_parser(backup_message + "\nNote: the current message was "
                            "invalid due to markdown issues. Could be "
                            "due to the user's name."),
            parse_mode=ParseMode.MARKDOWN)
    except KeyError:
        msg = update.effective_message.reply_text(
            markdown_parser(backup_message + "\nNote: the current message is "
                            "invalid due to an issue with some misplaced "
                            "curly brackets. Please update"),
            parse_mode=ParseMode.MARKDOWN)
    except BadRequest as excp:
        if excp.message == "Button_url_invalid":
            msg = update.effective_message.reply_text(
                markdown_parser(
                    backup_message +
                    "\nNote: the current message has an invalid url "
                    "in one of its buttons. Please update."),
                parse_mode=ParseMode.MARKDOWN)
        elif excp.message == "Unsupported url protocol":
            msg = update.effective_message.reply_text(
                markdown_parser(
                    backup_message +
                    "\nNote: the current message has buttons which "
                    "use url protocols that are unsupported by "
                    "telegram. Please update."),
                parse_mode=ParseMode.MARKDOWN)
        elif excp.message == "Wrong url host":
            msg = update.effective_message.reply_text(
                markdown_parser(
                    backup_message +
                    "\nNote: the current message has some bad urls. "
                    "Please update."),
                parse_mode=ParseMode.MARKDOWN)
            LOGGER.warning(message)
            LOGGER.warning(keyboard)
            LOGGER.exception("Could not parse! got invalid url host errors")
        elif excp.message == "Replied message not found":
            LOGGER.warning("Original message deleted")
        elif excp.message == "Have no rights to send a message":
            LOGGER.warning("Muted in below chat")
            print(update.effective_message.chat.id)
        else:
            msg = update.effective_message.reply_text(
                markdown_parser(backup_message +
                                "\nNote: An error occured when sending the "
                                "custom message. Please update."),
                parse_mode=ParseMode.MARKDOWN)
            LOGGER.exception()

    return msg
Пример #15
0
def send(update, message, keyboard, backup_message):
    try:
        msg = update.effective_message.reply_text(
            message, parse_mode=ParseMode.MARKDOWN, reply_markup=keyboard)
    except IndexError:
        msg = update.effective_message.reply_text(
            markdown_parser(
                backup_message + "\nNotka: obecna wiadomość była "
                "nieprawidłowa z powodu problemów z markdown. Może to "
                "wynikać z nazwy użytkownika."),
            parse_mode=ParseMode.MARKDOWN)
    except KeyError:
        msg = update.effective_message.reply_text(markdown_parser(
            backup_message + "\nNotka: obecna wiadomość jest "
            "nieprawidłowa z powodu problemu z niektórymi źle umieszczonymi "
            "nawiasami klamrowymi. Proszę poprawić."),
                                                  parse_mode=ParseMode.MARKDOWN
                                                  )
    except BadRequest as excp:
        if excp.message == "Button_url_invalid":
            msg = update.effective_message.reply_text(
                markdown_parser(
                    backup_message +
                    "\nNotka: obecna wiadomość ma nieprawidłowy link  "
                    "w jednym z swoich przycisków. Proszę poprawić."),
                parse_mode=ParseMode.MARKDOWN)
        elif excp.message == "Unsupported url protocol":
            msg = update.effective_message.reply_text(
                markdown_parser(
                    backup_message +
                    "\nNotka: obecna wiadomość posiad przyciski które "
                    "protokoły adresów URL są nieobsługiwane przez "
                    "Telegrama. Proszę poprawić."),
                parse_mode=ParseMode.MARKDOWN)
        elif excp.message == "Wrong url host":
            msg = update.effective_message.reply_text(
                markdown_parser(
                    backup_message +
                    "\nNotka: obecna wiadomość ma kilka złych adresów URL. "
                    "Proszę poprawić."),
                parse_mode=ParseMode.MARKDOWN)
            LOGGER.warning(message)
            LOGGER.warning(keyboard)
            LOGGER.exception(
                "Nie można sparsować! Otrzymano nieprawidłowe błędy hosta adresu URL"
            )
        else:
            msg = update.effective_message.reply_text(
                markdown_parser(
                    backup_message +
                    "\nNotka: Wystąpił błąd podczas wysyłania "
                    "niestandardowej wiadomości. Proszę poprawić."),
                parse_mode=ParseMode.MARKDOWN)
            LOGGER.exception()

    return msg
Пример #16
0
def send(update, message, keyboard, backup_message):
    try:
        msg = update.effective_message.reply_text(
            message, parse_mode=ParseMode.MARKDOWN, reply_markup=keyboard)
    except IndexError:
        msg = update.effective_message.reply_text(markdown_parser(
            backup_message + "\nNota: Il messaggio corrente è "
            "invalido a causa di problemi di markdown. Potrebbe essere a causa del "
            "nome dell'utente."),
                                                  parse_mode=ParseMode.MARKDOWN
                                                  )
    except KeyError:
        msg = update.effective_message.reply_text(
            markdown_parser(backup_message + "\nNote: the current message is "
                            "invalid due to an issue with some misplaced "
                            "curly brackets. Please update"),
            parse_mode=ParseMode.MARKDOWN)
    except BadRequest as excp:
        if excp.message == "Button_url_invalid":
            msg = update.effective_message.reply_text(
                markdown_parser(
                    backup_message +
                    "\nNota: Il messaggio corrente ha un url non valido "
                    "in uno dei bottoni. Per favore, aggiornarlo."),
                parse_mode=ParseMode.MARKDOWN)
        elif excp.message == "Unsupported url protocol":
            msg = update.effective_message.reply_text(
                markdown_parser(
                    backup_message +
                    "\nNota: il messaggio corrente ha bottoni che "
                    "usano un protocollo per gli url non supportato da "
                    "Telegram. Per favore, aggiornarlo."),
                parse_mode=ParseMode.MARKDOWN)
        elif excp.message == "Wrong url host":
            msg = update.effective_message.reply_text(
                markdown_parser(
                    backup_message +
                    "\nNota: il messaggio corrente ha degli url difettosi. "
                    "Per favore, aggiornarlo.."),
                parse_mode=ParseMode.MARKDOWN)
            LOGGER.warning(message)
            LOGGER.warning(keyboard)
            LOGGER.exception(
                "Impossibile parsarlo! Ci sono degli url non validi.")
        else:
            msg = update.effective_message.reply_text(markdown_parser(
                backup_message +
                "\nNota: un errore si è verificato quando ho provato  "
                "a inviare il messaggio customizzato. Per favore, risolvere l'errore."
            ),
                                                      parse_mode=ParseMode.
                                                      MARKDOWN)
            LOGGER.exception()

    return msg
Пример #17
0
def set_rules(update: Update, context: CallbackContext):
    chat_id = update.effective_chat.id
    msg = update.effective_message  # type: Optional[Message]
    raw_text = msg.text
    args = raw_text.split(None,
                          1)  # use python's maxsplit to separate cmd and args
    if len(args) == 2:
        txt = args[1]
        offset = len(txt) - len(
            raw_text)  # set correct offset relative to command
        markdown_rules = markdown_parser(txt,
                                         entities=msg.parse_entities(),
                                         offset=offset)

        sql.set_rules(chat_id, markdown_rules)
        update.effective_message.reply_text("이 그룹에 성공적으로 규칙을 적용했어요!")
Пример #18
0
def send(update, message, keyboard, backup_message):
    try:
        msg = update.effective_message.reply_text(
            message,
            parse_mode=ParseMode.MARKDOWN,
            reply_markup=keyboard,
            disable_web_page_preview=True)
    except IndexError:
        msg = update.effective_message.reply_text(
            markdown_parser(backup_message + "\nNote: the current message was "
                            "invalid due to markdown issues. Could be "
                            "due to the user's name."),
            parse_mode=ParseMode.MARKDOWN)
    except KeyError:
        msg = update.effective_message.reply_text(
            markdown_parser(backup_message + "\nNote: the current message is "
                            "invalid due to an issue with some misplaced "
                            "curly brackets. Please update"),
            parse_mode=ParseMode.MARKDOWN)
    except BadRequest as excp:
        if excp.message == "Button_url_invalid":
            msg = update.effective_message.reply_text(
                markdown_parser(
                    backup_message +
                    "\nNote: the current message has an invalid url "
                    "in one of its buttons. Please update."),
                parse_mode=ParseMode.MARKDOWN)
        elif excp.message == "Unsupported url protocol":
            msg = update.effective_message.reply_text(
                markdown_parser(
                    backup_message +
                    "\nNote: the current message has buttons which "
                    "use url protocols that are unsupported by "
                    "telegram. Please update."),
                parse_mode=ParseMode.MARKDOWN)
        elif excp.message == "Wrong url host":
            msg = update.effective_message.reply_text(
                markdown_parser(
                    backup_message +
                    "\nNote: the current message has some bad urls. "
                    "Please update."),
                parse_mode=ParseMode.MARKDOWN)
            LOGGER.warning(message)
            LOGGER.warning(keyboard)
            LOGGER.exception("Could not parse! got invalid url host errors")
        else:
            msg = update.effective_message.reply_text(
                markdown_parser(backup_message +
                                "\nNote: An error occured when sending the "
                                "custom message. Please update."),
                parse_mode=ParseMode.MARKDOWN)
            LOGGER.exception()

    return msg
Пример #19
0
def send(update, message, keyboard, backup_message):
    try:
        msg = update.effective_message.reply_text(
            message, parse_mode=ParseMode.MARKDOWN, reply_markup=keyboard)
    except IndexError:
        msg = update.effective_message.reply_text(
            markdown_parser(
                backup_message + "\nNota: a mensagem atual foi "
                "inválido devido a problemas de remarcação. Poderia ser "
                "devido ao nome do usuário."),
            parse_mode=ParseMode.MARKDOWN)
    except KeyError:
        msg = update.effective_message.reply_text(
            markdown_parser(
                backup_message + "\n Nota: a mensagem atual é "
                "inválido devido a um problema com alguns extraviados "
                "chaves. Por favor atualize"),
            parse_mode=ParseMode.MARKDOWN)
    except BadRequest as excp:
        if excp.message == "Button_url_invalid":
            msg = update.effective_message.reply_text(
                markdown_parser(backup_message +
                                "\nNota: a mensagem atual tem um URL inválido "
                                "em um de seus botões. Por favor atualize."),
                parse_mode=ParseMode.MARKDOWN)
        elif excp.message == "Unsupported url protocol":
            msg = update.effective_message.reply_text(
                markdown_parser(
                    backup_message + "\nNote: a mensagem atual tem botões que "
                    "usar protocolos de URL que não são suportados por "
                    "telegram. Por favor atualize."),
                parse_mode=ParseMode.MARKDOWN)
        elif excp.message == "Wrong url host":
            msg = update.effective_message.reply_text(
                markdown_parser(
                    backup_message +
                    "\nNota: a mensagem atual tem alguns URLs inválidos. "
                    "Por favor atualize."),
                parse_mode=ParseMode.MARKDOWN)
            LOGGER.warning(message)
            LOGGER.warning(keyboard)
            LOGGER.exception(
                "Não foi possível analisar! tem erros de host de URL inválidos"
            )
        else:
            msg = update.effective_message.reply_text(
                markdown_parser(backup_message +
                                "\observação: ocorreu um erro ao enviar o "
                                "mensagem personalizada. Por favor atualize."),
                parse_mode=ParseMode.MARKDOWN)
            LOGGER.exception()

    return msg
Пример #20
0
def save_replied(bot: Bot, update: Update):
    chat_id = update.effective_chat.id
    text = update.effective_message.text
    args = text.split(
        None, 3)  # use python's maxsplit to separate Cmd, note_name, and data
    if len(args) == 3 and args[1] == "from":
        notename = args[2]
    elif len(args) >= 2:
        notename = args[1]
    else:
        update.effective_message.reply_text(
            "Bu mesajı kaydetmek için bana bir isim vermelisin.!")
        return

    msg = update.effective_message.reply_to_message  # type: Optional[Message]

    if msg.from_user.is_bot:
        text = extract_text(msg)
        if text:
            sql.add_note_to_db(chat_id,
                               notename,
                               markdown_parser(text),
                               is_reply=False)
            update.effective_message.reply_text(
                "Bir bottan mesaj kaydetmeye çalışıyor gibisin. "
                "Botlar, bot mesajlarını iletemez, dolayısıyla tam mesajı kaydedemiyorum. "
                "\nYapabileceğim tüm metni kaydedeceğim, ama daha fazlasını istiyorsanız, "
                "iletiyi kendiniz iletmeniz ve sonra kaydetmeniz gerekir..")
        else:
            update.effective_message.reply_text(
                "Bots are kinda handicapped by telegram, making it hard for bots to "
                "Botlar, telegram tarafından engelleniyor ve robotların diğer botlarla etkileşime "
                "girmesini zorlaştırıyor, bu yüzden bu mesajı kaydedemiyorum "
                "iletiyi kendiniz iletmeniz ve sonra kaydetmeniz gerekir")
        return

    if MESSAGE_DUMP:
        msg = bot.forward_message(chat_id=MESSAGE_DUMP,
                                  from_chat_id=chat_id,
                                  message_id=msg.message_id)

    sql.add_note_to_db(chat_id, notename, msg.message_id, is_reply=True)
    update.effective_message.reply_text(
        "Evet! {} İçin yanıtlama mesajı eklendi".format(notename))
Пример #21
0
def send(update, message, keyboard, backup_message):
    try:
        msg = update.effective_message.reply_text(
            message, parse_mode=ParseMode.MARKDOWN, reply_markup=keyboard)
    except IndexError:
        msg = update.effective_message.reply_text(
            markdown_parser(backup_message + "\nNot: mevcut mesaj "
                            "indirim sorunları nedeniyle geçersiz. Olabilirdi "
                            "kullanıcının adı nedeniyle."),
            parse_mode=ParseMode.MARKDOWN)
    except KeyError:
        msg = update.effective_message.reply_text(
            markdown_parser(backup_message + "\nNote: the current message is "
                            "invalid due to an issue with some misplaced "
                            "curly brackets. Please update"),
            parse_mode=ParseMode.MARKDOWN)
    except BadRequest as excp:
        if excp.message == "Button_url_invalid":
            msg = update.effective_message.reply_text(
                markdown_parser(
                    backup_message +
                    "\nNote: the current message has an invalid url "
                    "düğmelerinden birinde. Lütfen güncelle."),
                parse_mode=ParseMode.MARKDOWN)
        elif excp.message == "Unsupported url protocol":
            msg = update.effective_message.reply_text(
                markdown_parser(
                    backup_message + "\n Not: mevcut mesajda, "
                    "tarafından desteklenmeyen url protokollerini kullanın "
                    "telegram. Please update."),
                parse_mode=ParseMode.MARKDOWN)
        elif excp.message == "Wrong url host":
            msg = update.effective_message.reply_text(
                markdown_parser(
                    backup_message +
                    "\nNote: mevcut mesajda bazı hatalı URL'ler var. "
                    "Please update."),
                parse_mode=ParseMode.MARKDOWN)
            LOGGER.warning(message)
            LOGGER.warning(keyboard)
            LOGGER.exception(
                "Ayrıştırılamadı! geçersiz url ana bilgisayar hataları aldı")
        else:
            msg = update.effective_message.reply_text(
                markdown_parser(backup_message +
                                "\nNote: Gönderirken bir hata oluştu  "
                                "custom message. Please update."),
                parse_mode=ParseMode.MARKDOWN)
            LOGGER.exception()

    return msg
Пример #22
0
def send(update, message, keyboard, backup_message):
    try:
        msg = update.effective_message.reply_text(
            message, parse_mode=ParseMode.MARKDOWN, reply_markup=keyboard)
    except IndexError:
        msg = update.effective_message.reply_text(
            markdown_parser(backup_message + "\nQeyd: Cari mesaj "
                            "qeyd işarələri səbəbindən etibarsızdır. ola bilər"
                            "istifadəçi adı səbəbiylə."),
            parse_mode=ParseMode.MARKDOWN)
    except KeyError:
        msg = update.effective_message.reply_text(
            markdown_parser(backup_message + "\nQeyd: cari mesaj "
                            "bəzi yerlər səhv olduğu üçün etibarsızdır"
                            "buruq mötərizələr. Xahiş edirəm yeniləyin"),
            parse_mode=ParseMode.MARKDOWN)
    except BadRequest as excp:
        if excp.message == "Button_url_invalid":
            msg = update.effective_message.reply_text(
                markdown_parser(
                    backup_message + "\nQeyd: cari mesajın səhv URL'si var "
                    "düymələrindən birində. Xahiş edirəm yeniləyin."),
                parse_mode=ParseMode.MARKDOWN)
        elif excp.message == "Unsupported url protocol":
            msg = update.effective_message.reply_text(markdown_parser(
                backup_message + "\nQeyd: cari mesajın düymələri var "
                "tərəfindən dəstəklənməyən url protokollarından istifadə edin"
                "telegram. Zəhmət olmasa yeniləyin."),
                                                      parse_mode=ParseMode.
                                                      MARKDOWN)
        elif excp.message == "Wrong url host":
            msg = update.effective_message.reply_text(
                markdown_parser(backup_message +
                                "\nQeyd: cari mesajda səhv URL var. "
                                "Xahiş edirəm yeniləyin."),
                parse_mode=ParseMode.MARKDOWN)
            LOGGER.warning(message)
            LOGGER.warning(keyboard)
            LOGGER.exception(
                "Təhlil edilə bilmədi! etibarsız url host səhvləri var")
        else:
            msg = update.effective_message.reply_text(markdown_parser(
                backup_message +
                "\nQeyd: Xüsusi mesaj göndərilərkən bir səhv meydana gəldi. Zəhmət olmasa yeniləyin."
            ),
                                                      parse_mode=ParseMode.
                                                      MARKDOWN)
            LOGGER.exception()

    return msg
Пример #23
0
def send(update, message, keyboard, backup_message):
    try:
        msg = update.effective_message.reply_text(
            message, parse_mode=ParseMode.MARKDOWN, reply_markup=keyboard)
    except IndexError:
        msg = update.effective_message.reply_text(
            markdown_parser(backup_message + "\nنکته: پیغام فعلی  "
                            "بخاطر مشکلات کد موشن قابل استفاده نیست "
                            "ممکنه از قسمت اسم شخص باشه."),
            parse_mode=ParseMode.MARKDOWN)
    except KeyError:
        msg = update.effective_message.reply_text(
            markdown_parser(backup_message + "\nنکته:پیغام فعلی "
                            "بخاطر بد جایگذاری دستورات قابل استفاده نیس "
                            "لطفا دوباره چک کن!"),
            parse_mode=ParseMode.MARKDOWN)
    except BadRequest as excp:
        if excp.message == "Button_url_invalid":
            msg = update.effective_message.reply_text(
                markdown_parser(backup_message +
                                "\nنکته : دکمه ایی که طراحی کردی  "
                                "لینکش ایراد داره لطفا چک کن."),
                parse_mode=ParseMode.MARKDOWN)
        elif excp.message == "Unsupported url protocol":
            msg = update.effective_message.reply_text(
                markdown_parser(backup_message +
                                "\nنکته: دکمه ایی که طراحی کردی"
                                "شامل لینکی هست که تلگرام  "
                                "ساپورت نمیکنه،لطفا چک کن."),
                parse_mode=ParseMode.MARKDOWN)
        elif excp.message == "Wrong url host":
            msg = update.effective_message.reply_text(
                markdown_parser(backup_message +
                                "\nنکته: لینکی که وارد کردی خرابه. "
                                "لطفا چک کن."),
                parse_mode=ParseMode.MARKDOWN)
            LOGGER.warning(message)
            LOGGER.warning(keyboard)
            LOGGER.exception("Could not parse! got invalid url host errors")
        else:
            msg = update.effective_message.reply_text(
                markdown_parser(backup_message +
                                "\nنکته : یه ارور ناشناخته ثبت شد برام "
                                "لطفا دوباره چک کن."),
                parse_mode=ParseMode.MARKDOWN)
            LOGGER.exception()

    return msg
Пример #24
0
def send(update, message, keyboard, backup_message):
    try:
        msg = update.effective_message.reply_text(
            message, parse_mode=ParseMode.MARKDOWN, reply_markup=keyboard)
    except IndexError:
        msg = update.effective_message.reply_text(
            markdown_parser(backup_message + "\nNot: Mevcut mesaj "
                            "indirim sorunları nedeniyle geçersiz. "
                            "kullanıcının adından kaynaklanıyor olabilir."),
            parse_mode=ParseMode.MARKDOWN)
    except KeyError:
        msg = update.effective_message.reply_text(
            markdown_parser(backup_message + "\nNot: Mevcut mesaj "
                            "bazı yanlış yerleştirmeler nedeniyle geçersiz "
                            "Küme parantezleri. Lütfen güncelle"),
            parse_mode=ParseMode.MARKDOWN)
    except BadRequest as excp:
        if excp.message == "Button_url_invalid":
            msg = update.effective_message.reply_text(
                markdown_parser(backup_message + "\nNot: Geçersiz url "
                                "Butonların birinde. Lütfen güncelle."),
                parse_mode=ParseMode.MARKDOWN)
        elif excp.message == "Unsupported url protocol":
            msg = update.effective_message.reply_text(
                markdown_parser(backup_message +
                                "\nNot: Butonlarda yanlış protokole sahip "
                                "url var. Telegram desteklemiyor "
                                "Güncelle."),
                parse_mode=ParseMode.MARKDOWN)
        elif excp.message == "Wrong url host":
            msg = update.effective_message.reply_text(
                markdown_parser(
                    backup_message +
                    "\nNot: Mevcut mesajda bazı hatalı URL'ler var. "
                    "Güncelle."),
                parse_mode=ParseMode.MARKDOWN)
            LOGGER.warning(message)
            LOGGER.warning(keyboard)
            LOGGER.exception("Could not parse! got invalid url host errors")
        else:
            msg = update.effective_message.reply_text(
                markdown_parser(backup_message +
                                "\nNote: Gönderirken bir hata oluştu "
                                "Güncelle."),
                parse_mode=ParseMode.MARKDOWN)
            LOGGER.exception()

    return msg
Пример #25
0
def send(update, message, keyboard, backup_message):
    try:
        msg = update.effective_message.reply_text(
            message, parse_mode=ParseMode.MARKDOWN, reply_markup=keyboard)
    except IndexError:
        msg = update.effective_message.reply_text(
            markdown_parser(backup_message + "\n메모: 현재 메시지가 표시 문제로 인해 "
                            "유효하지 않습니다. 사용자 "
                            "이름 때문일 수 있어요."),
            parse_mode=ParseMode.MARKDOWN)
    except KeyError:
        msg = update.effective_message.reply_text(
            markdown_parser(backup_message + "\n메모: 중괄호가 잘못 배치되어 현재 메시지가 "
                            "유효하지 않아요. "
                            "업데이트하세요"),
            parse_mode=ParseMode.MARKDOWN)
    except BadRequest as excp:
        if excp.message == "Button_url_invalid":
            msg = update.effective_message.reply_text(
                markdown_parser(backup_message +
                                "\n메모: 현재 메시지의 버튼 중 하나에 잘못된 URL 이 "
                                "있어요. 업데이트하세요."),
                parse_mode=ParseMode.MARKDOWN)
        elif excp.message == "Unsupported url protocol":
            msg = update.effective_message.reply_text(
                markdown_parser(backup_message +
                                "\n메모: 현재 메시지에는 Telegram 에서 지원하지 "
                                "않는 URL 프로토콜을 사용하는 버튼이 "
                                "있어요. 업데이트하세요."),
                parse_mode=ParseMode.MARKDOWN)
        elif excp.message == "Wrong url host":
            msg = update.effective_message.reply_text(
                markdown_parser(backup_message +
                                "\n메모: 현재 메시지에 잘못된 URL 들이 있어요. "
                                "업데이트하세요."),
                parse_mode=ParseMode.MARKDOWN)
            LOGGER.warning(message)
            LOGGER.warning(keyboard)
            LOGGER.exception("구문을 분석할 수 없어요! 잘못된 URL 호스트 오류가 발생했어요.")
        else:
            msg = update.effective_message.reply_text(
                markdown_parser(backup_message +
                                "\n메모: 사용자 지정 메시지를 보낼 때 오류가 발생했어요. "
                                "업데이트하세요."),
                parse_mode=ParseMode.MARKDOWN)
            LOGGER.exception()

    return msg
Пример #26
0
def send(update, message, keyboard, backup_message):
    try:
        msg = update.effective_message.reply_text(message, parse_mode=ParseMode.MARKDOWN, reply_markup=keyboard)
    except IndexError:
        msg = update.effective_message.reply_text(markdown_parser(backup_message +
                                                                  "\nHinweis: Die aktuelle Willkommensnachricht "
                                                                  "ist aus Textbearbeitungsgründen nicht möglich. Das kann an dem "
                                                                  "Nutzername liegen."),
                                                  parse_mode=ParseMode.MARKDOWN)
    except KeyError:
        msg = update.effective_message.reply_text(markdown_parser(backup_message +
                                                                  "\nHinweis: Die aktuelle Willkommensnachricht "
                                                                  "Ist aufgrund von Platzhaltern nicht "
                                                                  "möglich. Bitte den Text prüfen und verbessern"),
                                                  parse_mode=ParseMode.MARKDOWN)
    except BadRequest as excp:
        if excp.message == "Button_url_invalid":
            msg = update.effective_message.reply_text(markdown_parser(backup_message +
                                                                      "\nHinweis: Die aktuelle Nachricht beinhaltet"
                                                                      "eine falsche URL in einem der Knöpfe. Bitte prüfen und verbessern."),
                                                      parse_mode=ParseMode.MARKDOWN)
        elif excp.message == "Unsupported url protocol":
            msg = update.effective_message.reply_text(markdown_parser(backup_message +
                                                                      "\nHinweis: Die aktuelle Nachricht beinhaltet Knöpfe, "
                                                                      "die von Telegram nicht unterstützte URL- Protokolle "
                                                                      "nutzen. Bitte überprüfen und updaten."),
                                                      parse_mode=ParseMode.MARKDOWN)
        elif excp.message == "Wrong url host":
            msg = update.effective_message.reply_text(markdown_parser(backup_message +
                                                                      "\nHinweis: Die aktuelle Nachricht beinhaltet falsche Links. "
                                                                      "Bitte überprüfen und verbessern."),
                                                      parse_mode=ParseMode.MARKDOWN)
            LOGGER.warning(message)
            LOGGER.warning(keyboard)
            LOGGER.exception("Parsen nicht möglich! Ungültiger URL Port gefunden!")
        else:
            msg = update.effective_message.reply_text(markdown_parser(backup_message +
                                                                      "\nHinweis: Bei dem Versuch, die neue Willkommenensnachricht zu senden, "
                                                                      "trat ein Fehler auf. Bitte den Text auf Fehler überprüfen und verbessern."),
                                                      parse_mode=ParseMode.MARKDOWN)
            LOGGER.exception()

    return msg
Пример #27
0
def send(update, message, keyboard, backup_message):
    try:
        msg = update.effective_message.reply_text(message, parse_mode=ParseMode.MARKDOWN, reply_markup=keyboard)
    except IndexError:
        msg = update.effective_message.reply_text(markdown_parser(backup_message +
                                                                  "\nMarkdown xətası "
                                                                  "invalid due to markdown issues. Could be "
                                                                  "due to the user's name."),
                                                  parse_mode=ParseMode.MARKDOWN)
    except KeyError:
        msg = update.effective_message.reply_text(markdown_parser(backup_message +
                                                                  "\nNote: the current message is "
                                                                  "invalid due to an issue with some misplaced "
                                                                  "curly brackets. Please update"),
                                                  parse_mode=ParseMode.MARKDOWN)
    except BadRequest as excp:
        if excp.message == "Button_url_invalid":
            msg = update.effective_message.reply_text(markdown_parser(backup_message +
                                                                      "\nXəta: qeyd etdiyiniz link səhvdir. "
                                                                      "Zəhmət olmasa linki yeniləyin."),
                                                      parse_mode=ParseMode.MARKDOWN)
        elif excp.message == "Unsupported url protocol":
            msg = update.effective_message.reply_text(markdown_parser(backup_message +
                                                                      "\nXəta: qeyd etdiyiniz linkdə problem var. "
                                                                      "yazdığınız link telegram tərəfindən "
                                                                      "qadağa olunmuş linkdir. Zəhmət olmasa linki yeniləyin."),
                                                      parse_mode=ParseMode.MARKDOWN)
        elif excp.message == "Wrong url host":
            msg = update.effective_message.reply_text(markdown_parser(backup_message +
                                                                      "\nXəta: qeyd etdiyiniz linkdə səhv var. "
                                                                      "Zəhmət olmasa linki yeniləyin."),
                                                      parse_mode=ParseMode.MARKDOWN)
            LOGGER.warning(message)
            LOGGER.warning(keyboard)
            LOGGER.exception("Could not parse! got invalid url host errors")
        else:
            msg = update.effective_message.reply_text(markdown_parser(backup_message +
                                                                      "\nNote: An error occured when sending the "
                                                                      "custom message. Please update."),
                                                      parse_mode=ParseMode.MARKDOWN)
            LOGGER.exception()

    return msg
Пример #28
0
def new_member(bot, update):
    chat = update.effective_chat

    should_welc, cust_welcome, welc_type = sql.get_welc_pref(chat.id)
    if should_welc:
        new_members = update.effective_message.new_chat_members
        for new_mem in new_members:
            # Give the owner a special welcome
            if new_mem.id == OWNER_ID:
                update.effective_message.reply_text(
                    "Master is in the houseeee, let's get this party started!")
                continue
            # Don't welcome yourself
            elif not new_mem.id == bot.id:
                if welc_type != sql.Types.TEXT and welc_type != sql.Types.BUTTON_TEXT:
                    ENUM_FUNC_MAP[welc_type](chat.id, cust_welcome)
                    return

                first_name = new_mem.first_name or "PersonWithNoName"  # edge case of empty name - occurs for some bugs.
                if cust_welcome:
                    if new_mem.last_name:
                        fullname = "{} {}".format(first_name,
                                                  new_mem.last_name)
                    else:
                        fullname = first_name
                    count = chat.get_members_count()
                    mention = "[{}](tg://user?id={})".format(
                        first_name, new_mem.id)
                    if new_mem.username:
                        username = "******" + escape_markdown(new_mem.username)
                    else:
                        username = mention

                    valid_format = escape_invalid_curly_brackets(
                        cust_welcome, VALID_WELCOME_FORMATTERS)
                    res = valid_format.format(
                        first=escape_markdown(first_name),
                        last=escape_markdown(new_mem.last_name or first_name),
                        fullname=escape_markdown(fullname),
                        username=username,
                        mention=mention,
                        count=count,
                        chatname=escape_markdown(chat.title),
                        id=new_mem.id)
                else:
                    res = sql.DEFAULT_WELCOME.format(first=first_name)

                buttons = sql.get_welc_buttons(chat.id)
                keyb = [[InlineKeyboardButton(btn.name, url=btn.url)]
                        for btn in buttons]
                keyboard = InlineKeyboardMarkup(keyb)

                try:
                    update.effective_message.reply_text(
                        res,
                        parse_mode=ParseMode.MARKDOWN,
                        reply_markup=keyboard)
                except IndexError:

                    update.effective_message.reply_text(
                        markdown_parser(
                            sql.DEFAULT_WELCOME.format(first=first_name) +
                            "\nNote: the current welcome message was "
                            "invalid due to markdown issues. Could be "
                            "due to the user's name."),
                        parse_mode=ParseMode.MARKDOWN)
                except KeyError:
                    update.effective_message.reply_text(
                        markdown_parser(
                            sql.DEFAULT_WELCOME.format(first=first_name) +
                            "\nNote: the current welcome message is "
                            "invalid due to an issue with some misplaced "
                            "curly brackets. Please update"),
                        parse_mode=ParseMode.MARKDOWN)
Пример #29
0
def left_member(bot, update):
    chat = update.effective_chat
    should_welc, cust_leave, leave_type = sql.get_leave_pref(chat.id)
    if should_welc:
        left_mem = update.effective_message.left_chat_member
        if left_mem:
            # Ignore bot being kicked
            if left_mem.id == bot.id:
                return

            # Give the owner a special goodbye
            if left_mem.id == OWNER_ID:
                update.effective_message.reply_text("RIP Master")
                return

            if leave_type != sql.Types.TEXT and leave_type != sql.Types.BUTTON_TEXT:
                ENUM_FUNC_MAP[leave_type](chat.id, cust_leave)
                return

            first_name = left_mem.first_name or "PersonWithNoName"  # edge case of empty name - occurs for some bugs.
            if cust_leave:
                if left_mem.last_name:
                    fullname = "{} {}".format(first_name, left_mem.last_name)
                else:
                    fullname = first_name
                count = chat.get_members_count()
                mention = "[{}](tg://user?id={})".format(
                    first_name, left_mem.id)
                if left_mem.username:
                    username = "******" + escape_markdown(left_mem.username)
                else:
                    username = mention

                valid_format = escape_invalid_curly_brackets(
                    cust_leave, VALID_WELCOME_FORMATTERS)
                res = valid_format.format(
                    first=escape_markdown(first_name),
                    last=escape_markdown(left_mem.last_name or first_name),
                    fullname=escape_markdown(fullname),
                    username=username,
                    mention=mention,
                    count=count,
                    chatname=escape_markdown(chat.title),
                    id=left_mem.id)
            else:
                res = sql.DEFAULT_LEAVE

            buttons = sql.get_leave_buttons(chat.id)
            keyb = [[InlineKeyboardButton(btn.name, url=btn.url)]
                    for btn in buttons]
            keyboard = InlineKeyboardMarkup(keyb)

            try:
                update.effective_message.reply_text(
                    res, parse_mode=ParseMode.MARKDOWN, reply_markup=keyboard)
            except IndexError:
                update.effective_message.reply_text(
                    markdown_parser(sql.DEFAULT_LEAVE +
                                    "\nNote: the current leave "
                                    "message is invalid due to "
                                    "markdown issues. "
                                    " Please update."),
                    parse_mode=ParseMode.MARKDOWN)
            except KeyError:
                update.effective_message.reply_text(
                    markdown_parser(sql.DEFAULT_LEAVE +
                                    "\nNote: the current leave "
                                    "message is invalid due to "
                                    "misplaced curly brackets. "
                                    " Please update."),
                    parse_mode=ParseMode.MARKDOWN)
Пример #30
0
def import_rules(chatid, rules):
    markdown_rules = markdown_parser(rules)
    rules_sql.set_rules(chatid, markdown_rules)