예제 #1
0
def sethost():
    global text
    global chat_id
    if not text[:7] == ("http://" or "https:/"):
        return "Address not correct, please follow the example.\nEs: http://myaddress.me"
    else:
        chat_id_host_config.remove(chat_id)
        try:
            user = ClassUsers.load(chat_id)
        except EOFError:
            user = ClassUsers.ChatIDUser()
        user.host = text
        user.dump(chat_id)
        chat_id_config.remove(chat_id)
        bot_logger.debug("set host")
        return "Host address setted"
예제 #2
0
def firstconfig():
    global chat_id
    global text
    bot_logger.debug("FirstConfig")
    if chat_id not in chat_id_f_config:
        chat_id_f_config.append(chat_id)
        answer = "Tell me the host address \n Es: http://myaddress.me"
        # Create user instance
        user = ClassUsers.ChatIDUser()
        user.dump(chat_id)
        writeconfig("0", 0)
        bot_logger.info("Firstconfig " + str(chat_id))
    else:
        user = read_user_info()
        # Set server address
        if user.status == "0":
            if not text[:7] == ("http://" or "https:/"):
                answer = "Address not correct, please follow the example.\nEs: http://myaddress.me"
            else:
                writeconfig("1", 0)
                writeconfig(text, 1)
                answer = "Tell me the host port \n Es: 8080"
        # Set port
        elif user.status == "1":
            if text.isdigit():
                if 65536 >= int(text) > 0:
                    writeconfig(text, 2)
                    writeconfig("2", 0)
                    answer = "Tell me the host username.\nType `NULL` if you haven't a username"
                else:
                    answer = "Out of range.\nMust be between 1 and 65536"
            else:
                answer = "Port not valid.\nEs: 8080"
        # Set username
        elif user.status == "2":
            writeconfig(text, 3)
            writeconfig("3", 0)
            answer = "Tell me the host password\nType `NULL` if you haven't a password"
        # Set password
        elif user.status == "3":
            writeconfig(text, 4)
            writeconfig("4", 0)
            user = read_user_info()
            args_to_func = ["YES"], ["NO"]
            msg = "Correct? \nAddress: " + user.host + "\nPort: " + user.port + "\nUsername: "******"\nPassword: "******""
        # Ask if everything is ok
        elif user.status == "4":
            if text == "YES":
                msg = "All set, have fun and keep seeding!"
                setkeyboard(message=msg, chat_id=chat_id, hide=True)
            elif text == "NO":
                msg = "Write /config to change settings"
                setkeyboard(message=msg, chat_id=chat_id, hide=True)
            else:
                msg = "In order to change settings type /config"
                setkeyboard(message=msg, chat_id=chat_id, hide=True)
            chat_id_f_config.remove(chat_id)
            answer = ""
        else:
            answer = "error"
    return answer