Ejemplo n.º 1
0
    def setlog(bot: Bot, update: Update):
        message = update.effective_message  # type: Optional[Message]
        chat = update.effective_chat  # type: Optional[Chat]
        if chat.type == chat.CHANNEL:
            message.reply_text(tld(chat.id, "Now, forward the /setlog to the group you want to tie this channel to!"))

        elif message.forward_from_chat:
            sql.set_chat_log_channel(chat.id, message.forward_from_chat.id)
            try:
                message.delete()
            except BadRequest as excp:
                if excp.message == "Message to delete not found":
                    pass
                else:
                    LOGGER.exception("Error deleting message in log channel. Should work anyway though.")

            try:
                bot.send_message(message.forward_from_chat.id, tld(chat.id, 
                                 "This channel has been set as the log channel for {}.").format(
                                     chat.title or chat.first_name))
            except Unauthorized as excp:
                if excp.message == "Forbidden: bot is not a member of the channel chat":
                    bot.send_message(chat.id, tld(chat.id, "Successfully set log channel!"))
                else:
                    LOGGER.exception("ERROR in setting the log channel.")

            bot.send_message(chat.id, tld(chat.id, "Successfully set log channel!"))

        else:
            message.reply_text(tld(chat.id, "*The steps to set a log channel are:*\n"
                               " • add bot to the desired channel\n"
                               " • send /setlog to the channel\n"
                               " • forward the /setlog to the group\n"), ParseMode.MARKDOWN)
Ejemplo n.º 2
0
def setlog(bot: Bot, update: Update):
    message = update.effective_message  # type: Optional[Message]
    chat = update.effective_chat  # type: Optional[Chat]
    if chat.type == chat.CHANNEL:
        message.reply_text(tld(chat.id, "log_channel_fwd_cmd"))

    elif message.forward_from_chat:
        sql.set_chat_log_channel(chat.id, message.forward_from_chat.id)
        try:
            message.delete()
        except BadRequest as excp:
            if excp.message == "Message to delete not found":
                pass
            else:
                LOGGER.exception(
                    "Error deleting message in log channel. Should work anyway though."
                )

        try:
            bot.send_message(
                message.forward_from_chat.id,
                tld(chat.id,
                    "log_channel_chn_curr_conf").format(chat.title
                                                        or chat.first_name))
        except Unauthorized as excp:
            if excp.message == "Forbidden: bot is not a member of the channel chat":
                bot.send_message(chat.id,
                                 tld(chat.id, "log_channel_link_success"))
            else:
                LOGGER.exception("ERROR in setting the log channel.")

        bot.send_message(chat.id, tld(chat.id, "log_channel_link_success"))

    else:
        message.reply_text(tld(chat.id, "log_channel_invalid_message"),
                           ParseMode.MARKDOWN)