コード例 #1
0
    def setlog(bot: Bot, update: Update):

        message = update.effective_message
        chat = update.effective_chat
        if chat.type == chat.CHANNEL:
            message.reply_text("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,
                                 f"This channel has been set as the log channel for {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, "Successfully set log channel!")
                else:
                    LOGGER.exception("ERROR in setting the log channel.")

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

        else:
            message.reply_text("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")
コード例 #2
0
    def setlog(bot: Bot, update: Update):

        message = update.effective_message
        chat = update.effective_chat
        if chat.type == chat.CHANNEL:
            message.reply_text("İndi / setloqu bu kanalı bağlamaq istədiyiniz qrupa yönəldin!")

        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 == "Silmək üçün mesaj tapılmadı":
                    pass
                else:
                    LOGGER.exception("Giriş kanalındakı mesaj silinərkən xəta baş verdi. Hər halda işləməli.")

            try:
                bot.send_message(message.forward_from_chat.id,
                                 f"Bu kanal {chat.title or chat.first_name} üçün log kanalı olaraq təyin edilmişdir.")
            except Unauthorized as excp:
                if excp.message == "Qadağandır: bot kanal söhbətinin üzvü deyil":
                    bot.send_message(chat.id, "Giriş kanalı uğurla quruldu!")
                else:
                    LOGGER.exception("Giriş kanalını qurarkən XƏTA.")

            bot.send_message(chat.id, "Giriş kanalı uğurla quruldu!")

        else:
            message.reply_text("Bir LOG kanalı qurmaq üçün addımlar:\n"
                               " - istənilən kanala botu əlavə edin\n"
                               " - /setlog kanala göndərin\n"
                               " - /setlog-u qrupa yönləndirin\n")