텔레그램 웰컴 봇 시간 대별로 customize 하기

조회수 704회

텔레그램 그룹에 들어오는 사람들을 아침과 저녁 시간 대에 따라 다른 웰컴 메시지를 보내려고 합니다.

morning : 9am - 11pm / overnight : 11pm - 9am

def welcome_morning(update, context, new_member):

    now = datetime.datetime.now()
    if 9 <= now.hour <= 23:

        message = update.message
        chat_id = message.chat.id
        logger.info(
            "%s joined to chat %d (%s)",
            escape(new_member.first_name),
            chat_id,
            escape(message.chat.title),
        )

        # Pull the custom message for this chat from the database
        text = db.get(str(chat_id))

    # Use default message if there's no custom one set

    if text is None:
        text = '아침 시간에 보내는 웰컴 메시지'

    # Replace placeholders and send message
    text = text.replace("$username", new_member.first_name)
    text = text.replace("$title", message.chat.title)
    send_async(context, chat_id=chat_id, text=text, parse_mode=ParseMode.HTML)
def welcome_overnight(update, context, new_member):

    now = datetime.datetime.now()
    if 23 <= now.hour <= 9:

        message = update.message
        chat_id = message.chat.id
        logger.info(
            "%s joined to chat %d (%s)",
            escape(new_member.first_name),
            chat_id,
            escape(message.chat.title),
        )

        # Pull the custom message for this chat from the database
        text = db.get(str(chat_id))

        # Use default message if there's no custom one set

    if text is None:
        text = '새벽 시간에 보내는 웰컴 메시지'

    # Replace placeholders and send message
    text = text.replace("$username", new_member.first_name)
    text = text.replace("$title", message.chat.title)
    send_async(context, chat_id=chat_id, text=text, parse_mode=ParseMode.HTML)

indentation이 잘못된 건지 datetime format이 이상한 건지 모르겠습니다.. 일단 실행해도 아무 메시지가 뜨지 않습니다.

혹시 힌트라도 아시는 분 계시면 답변 감사하겠습니다.

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)