Exemple #1
0
    def cmd(self,**kwargs):
        serial      = self.serial

        delimiter   = kwargs['delimiter']

        if not util.isDelimiter(delimiter):
            logging.debug("'{0}' is not a proper delimiter character. " \
                    "Please use only \ one of the following characters: $%#@"
                    .format(delimiter))
            return None

        address     = kwargs['address']

        if not util.isAddress(address) and not address == "**":
            logging.debug("{0} must be a two-digit hexadecimal value.".format(
                address))
            return None

        options     = kwargs.get('options', "")
        data        = kwargs.get('data', "")

        command = delimiter + address + options + data
        logging.debug(command)
        self.current["command"] = command

        # clear input buffer of junk
        serial.flushInput()

        # send command
        serial.write(command + "\r")

        # read input buffer for response:
        test, data  = serial.read_until("\r")

        # wait a little...

        if not test:
            raise NameError("ADAM Module from address {0} not found."
                    .format(address))

        delimiter   = data[0]
        data        = data[1:-1]

        if delimiter == "?":
            self.current["response"]    = "ERROR"
        else:
            self.current["response"]    = data

        return delimiter, data
Exemple #2
0
def commandTip(self, command):
    """
		Tip a nickname, address or post_id
		nickname tipping still in progress
	"""
    if self.agent is None:
        self.writeConsole(
            'You don\'t have an active agent.\n/add an agent or /login in order to tip.'
        )
        return
    elif len(command) < 2:
        self.writeConsole(
            'You need to supply the detail of the agent or post you wish to tip.'
        )
        return
    #command[1] could be an address, a nickname or a post id
    #we can identify addresses so do that first
    if util.isAddress(command[1]):
        #we know it's an address
        tipAddress = command[1]
        postId = None
    #otherwise test for nickname
    elif util.getAddressFromNick(command[1]) is not False:
        tipAddress = util.getAddressFromNick(command[1])
        postId = None
    #all it can be after that is a post id
    else:
        tipAddress = util.getAddressFromPostID(self, command[1])
        if tipAddress is False:
            self.writeConsole('Tip Failed - ' + command[1] +
                              ' was not a nickname, address or post id')
            return
        postId = command[1]
    try:
        response = self.agent.tip(tipAddress, int(self.tipAmount), postId)
        if response['success'] == 1:
            try:
                self.agentBalance = self.agent.fetch_balance()
            except netvend.NetvendResponseError as e:
                self.agentBalance = 0
            self.writeConsole('Tip successful.\nTip ID : ' +
                              str(response['command_result']) +
                              ' - New Balance : ' + str(self.agentBalance))
        else:
            self.writeConsole('Tip Failed')
            return
    except netvend.NetvendResponseError as e:
        self.writeConsole('Tip failed - ' + str(e))
    return
Exemple #3
0
def commandFollow(self, command):
    """
		Follow the specified agent
		can specify address or nick
		update the list of nicks first
	"""
    if self.agent is None:
        self.writeConsole(
            'You don\'t have an active agent.\n/add an agent or /login in order to follow agents.'
        )
        return
    if len(command) < 2:
        self.writeConsole('You need to specify an agent to follow')
        return
    #update nicknames
    if util.pollAllPosts(self):
        util.checkNewNicks(self)
    conn = sqlite3.connect('coinflow.db')
    c = conn.cursor()
    if util.isAddress(command[1]):
        query = "select address from accounts where address = '" + command[
            1] + "';"
        rows = util.putQuery(self, query)
        if rows is False:
            self.writeConsole('Couldn\'t find agent ' + command[1])
            return
        address = command[1]
        nick = util.getNick(self, address)
    else:
        c.execute('select address from nicks where nick=?;', (command[1], ))
        address = c.fetchone()
        if address is None:
            self.writeConsole('Couldn\'t find agent ' + command[1])
            return
        address = address[0]
        nick = command[1]
    c.execute("select id from follows where address = ?;", (str(address), ))
    id = c.fetchone()
    if id is None:
        c.execute(
            "insert into follows (nick, address, account) values (?,?,?);",
            (str(nick), str(address), str(self.agentAddress)))
    else:
        c.execute("update follows set nick=? where address=? and account=?;",
                  (str(nick), str(address), str(self.agentAddress)))
    conn.commit()
    conn.close()
    self.writeConsole('You are now following ' + nick)
    return
Exemple #4
0
def commandFollow(self, command):
	"""
		Follow the specified agent
		can specify address or nick
		update the list of nicks first
	"""
	if self.agent is None:
		self.writeConsole('You don\'t have an active agent.\n/add an agent or /login in order to follow agents.') 
		return
	if len(command) < 2:
		self.writeConsole('You need to specify an agent to follow')
		return
	#update nicknames
	if util.pollAllPosts(self):
		util.checkNewNicks(self)
	conn = sqlite3.connect('coinflow.db')
	c = conn.cursor()
	if util.isAddress(command[1]):
		query = "select address from accounts where address = '" + command[1] + "';"
		rows = util.putQuery(self, query)
		if rows is False:
			self.writeConsole('Couldn\'t find agent ' + command[1])
			return
		address = command[1]
		nick = util.getNick(self, address)
	else:
		c.execute('select address from nicks where nick=?;', (command[1],))
		address = c.fetchone()
		if address is None:
			self.writeConsole('Couldn\'t find agent ' + command[1])
			return
		address = address[0]
		nick = command[1]
	c.execute("select id from follows where address = ?;", (str(address),))
	id = c.fetchone() 
	if id is None:
		c.execute("insert into follows (nick, address, account) values (?,?,?);", (str(nick), str(address), str(self.agentAddress)))
	else:
		c.execute("update follows set nick=? where address=? and account=?;", (str(nick), str(address), str(self.agentAddress)))
	conn.commit()
	conn.close()
	self.writeConsole('You are now following ' + nick)
	return
Exemple #5
0
def commandTip(self, command):
	"""
		Tip a nickname, address or post_id
		nickname tipping still in progress
	"""
	if self.agent is None:
		self.writeConsole('You don\'t have an active agent.\n/add an agent or /login in order to tip.')
		return
	elif len(command) < 2:
		self.writeConsole('You need to supply the detail of the agent or post you wish to tip.')
		return
	#command[1] could be an address, a nickname or a post id
	#we can identify addresses so do that first
	if util.isAddress(command[1]):
		#we know it's an address
		tipAddress = command[1]
		postId = None
	#otherwise test for nickname
	elif util.getAddressFromNick(command[1]) is not False:
		tipAddress = util.getAddressFromNick(command[1])
		postId = None
	#all it can be after that is a post id
	else:
		tipAddress = util.getAddressFromPostID(self, command[1])
		if tipAddress is False:
			self.writeConsole('Tip Failed - ' + command[1] + ' was not a nickname, address or post id')
			return
		postId = command[1]
	try:
		response = self.agent.tip(tipAddress, int(self.tipAmount), postId)
		if response['success'] == 1:
			try:
				self.agentBalance = self.agent.fetch_balance()
			except netvend.NetvendResponseError as e:
				self.agentBalance = 0
			self.writeConsole('Tip successful.\nTip ID : ' + str(response['command_result']) + ' - New Balance : ' + str(self.agentBalance))
		else:
			self.writeConsole('Tip Failed')
			return
	except netvend.NetvendResponseError as e:
		self.writeConsole('Tip failed - ' + str(e))
	return