Example #1
0
def addmagnet(torrent, chat_id):
    try:
        user = ClassUsers.load(chat_id)
        # http://pazpi.ecc to replace with the setting from the user
        url = user.host + ":" + user.port + '/ruTorrent/php/addtorrent.php?url=' + torrent
        if not (user.username == "NULL" or user.password == "NULL"):
            try:
                respond = requests.post(url, auth=HTTPBasicAuth(user.username, user.password))
                # If server answer correctly answer successfully
                if respond.status_code == 200:
                    return 'Magnet added successfully!'
                else:
                    return 'Error communicating with server Error ' + str(respond.status_code)
            except requests.exceptions.ConnectionError:
                return 'Host not reachable'
        else:
            try:
                respond = requests.post(url)
                if respond.status_code == 200:
                    return 'Magnet added successfully!'
                else:
                    return 'Error communicating with server. Error ' + str(respond.status_code)
            except requests.exceptions.ConnectionError:
                return 'Host not reachable'
    except EOFError:
        return 'Host not set, type /start to config your user'
Example #2
0
def addmagnet(torrent, chat_id):
    try:
        user = ClassUsers.load(chat_id)
        # http://pazpi.ecc to replace with the setting from the user
        url = user.host + ":" + user.port + '/php/addtorrent.php?url=' + torrent
        if not (user.username == "NULL" or user.password == "NULL"):
            try:
                respond = requests.post(url,
                                        auth=HTTPBasicAuth(
                                            user.username, user.password))
                # If server answer correctly answer successfully
                if respond.status_code == 200:
                    return 'Magnet added successfully!'
                else:
                    return 'Error communicating with server Error ' + str(
                        respond.status_code)
            except requests.exceptions.ConnectionError:
                return 'Host not reachable'
        else:
            try:
                respond = requests.post(url)
                if respond.status_code == 200:
                    return 'Magnet added successfully!'
                else:
                    return 'Error communicating with server. Error ' + str(
                        respond.status_code)
            except requests.exceptions.ConnectionError:
                return 'Host not reachable'
    except EOFError:
        return 'Host not set, type /start to config your user'
Example #3
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"
Example #4
0
def setpassword():
    global text
    global chat_id
    chat_id_password_config.remove(chat_id)
    user = ClassUsers.load(chat_id)
    user.password = text
    user.dump(chat_id)
    chat_id_config.remove(chat_id)
    bot_logger.debug("set password")
    return "Password setted"
Example #5
0
def setusername():
    global text
    global chat_id
    chat_id_user_config.remove(chat_id)
    user = ClassUsers.load(chat_id)
    user.username = text
    user.dump(chat_id)
    chat_id_config.remove(chat_id)
    bot_logger.debug("set username")
    return "Hostname setted"
Example #6
0
def setpassword():
    global text
    global chat_id
    chat_id_password_config.remove(chat_id)
    user = ClassUsers.load(chat_id)
    user.password = text
    user.dump(chat_id)
    chat_id_config.remove(chat_id)
    bot_logger.debug("set password")
    return "Password setted"
Example #7
0
def setusername():
    global text
    global chat_id
    chat_id_user_config.remove(chat_id)
    user = ClassUsers.load(chat_id)
    user.username= text
    user.dump(chat_id)
    chat_id_config.remove(chat_id)
    bot_logger.debug("set username")
    return "Hostname setted"
Example #8
0
def setport():
    global text
    global chat_id
    if not text.isdigit:
        return "Port not correct, make sure is a number.\nEs: 80, 8080"
    else:
        chat_id_port_config.remove(chat_id)
        user = ClassUsers.load(chat_id)
        user.port = text
        user.dump(chat_id)
        chat_id_config.remove(chat_id)
        bot_logger.debug("set port")
        return "Port setted"
Example #9
0
def setport():
    global text
    global chat_id
    if not text.isdigit:
        return "Port not correct, make sure is a number.\nEs: 80, 8080"
    else:
        chat_id_port_config.remove(chat_id)
        user = ClassUsers.load(chat_id)
        user.port = text
        user.dump(chat_id)
        chat_id_config.remove(chat_id)
        bot_logger.debug("set port")
        return "Port setted"
Example #10
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"
Example #11
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
Example #12
0
def read_user_info():
    global chat_id
    user = ClassUsers.load(chat_id)
    bot_logger.debug("Read user")
    return user
Example #13
0
def read_user_info():
    global chat_id
    user = ClassUsers.load(chat_id)
    bot_logger.debug("Read user")
    return user