Bot.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:tinder-telegram-bot 作者: arthurdk 项目源码 文件源码
def set_timeout(bot: Bot, update: Update, args):
    """
    Handles /timeout command
    :param bot:
    :param update:
    :param args:
    :return:
    """
    global data
    chat_id = update.message.chat_id
    if chat_id in data.conversations:
        if len(args) != 1:
            timeout = str(data.conversations[chat_id].timeout)
            message = "Current timeout %s seconds." % timeout
            send_custom_message(bot, chat_id, message=message)
        else:
            try:
                timeout = int(args[0])
                settings = data.conversations[chat_id].settings

                if int(settings.get_setting("min_timeout")) <= timeout <= int(
                        settings.get_setting("max_timeout")):
                    data.conversations[chat_id].timeout = timeout
                    message = "Timeout updated to %d seconds." % data.conversations[chat_id].timeout
                    send_custom_message(bot, chat_id, message=message)
                else:
                    send_custom_message(bot, chat_id, "Timeout out of range: "
                                        + str(settings.get_setting("min_timeout")) + "-"
                                        + str(settings.get_setting("max_timeout")))
            except AttributeError:
                message = "An error happened."
                send_custom_message(bot, chat_id, message=message)
            except BaseException:
                message = "An error happened."
                send_custom_message(bot, chat_id, message=message)
    else:
        send_error(bot=bot, chat_id=chat_id, name="account_not_setup")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号