예제 #1
0
def commandAdd(self, command):
	"""
		Add a new agent
		display the address and balance
		add the agent to the profiles
	"""
	if len(command) < 2:
		self.writeConsole('You need to supply a seed value')
		return
	self.agentSeed = command[1]
	util.getAgent(self)
	util.getAddress(self)
	util.initialTip(self)
	util.getBalance(self)
	self.agentNick = util.getNick(self, self.agentAddress)
	conn = db.open()
	c = conn.cursor()
	c.execute('select id from profiles where seed=?;', (command[1],))
	id = c.fetchone()
	if id is None:
		c.execute('insert into profiles (nick, seed) values (?,?);', (str(self.agentNick), str(self.agentSeed)))
	else:
		c.execute('update profiles set nick=? where seed=?;', (str(self.agentNick), str(self.agentSeed)))
	db.close(conn)
	self.writeConsole('Agent created.\nAddress is ' + str(self.agentAddress) + '\nBalance is ' + str(self.agentBalance) + ' ' + str(self.unit))
	#check for new nicknames
	if util.pollAllPosts(self):
		util.checkNewNicks(self)
	#generate a new public/private key pair
	self.whisperAlicePubKey = util.genPubKey(self)
	if self.whisperAlicePubKey is False:
		self.writeConsole('Unable to post your Public Key')
	self.togglePoll(True)
	return
예제 #2
0
def commandListProfiles(self, command):
	"""
		list the profiles of the current user
		each profile has been logged into at least once
		you don't need to be logged in to view profiles 
	"""
	conn = db.open()
	c = conn.cursor()
	c.execute('select nick from profiles;')
	profiles = c.fetchall()
	db.close(conn)
	if not profiles:
		self.writeConsole('You don\'t have any profiles.\nAdd an agent to add a profile.')
		return
	self.writeConsole('\n== Profiles ==\n')
	for profile in profiles:
		self.writeConsole(profile[0])
	return
예제 #3
0
def commandFollow(self, command):
	"""
		Follow the specified agent
		can specify address or nick
		update the list of nicks first
	"""
	if not util.checkLogin(self):
		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 = db.open()
	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, profile) values (?,?,?);",
				  (str(nick), str(address), str(self.agentAddress)))
	else:
		c.execute("update follows set nick=? where address=? and profile=?;",
				  (str(nick), str(address), str(self.agentAddress)))
	db.close(conn)
	self.writeConsole('You are now following ' + nick)
	return
예제 #4
0
def commandLogin(self, command):
	"""
		Login as an existing agent
		can login using nick, address or seed.
		display the nickname (if present), address and balance
		check profiles and update or insert
	"""
	if len(command) < 2:
		self.writeConsole('You need to supply some detail for the agent you want to login as.\nCould be the agents nickname, address or seed')
		return
	seed = util.getSeedFromNick(command[1])
	if seed is False:
		self.agentSeed = command[1]
	else:
		self.agentSeed = seed
	util.getAgent(self)
	util.getAddress(self)
	util.getBalance(self)
	self.agentNick = util.getNick(self, self.agentAddress)
	conn = db.open()
	c = conn.cursor()
	c.execute('select id from profiles where seed=?;', (str(self.agentSeed),))
	id = c.fetchone()
	if id is None:
		c.execute('insert into profiles (nick, seed) values (?,?);', (str(self.agentNick), str(self.agentSeed)))
	else:
		c.execute('update profiles set nick=? where seed=?;', (str(self.agentNick), str(self.agentSeed)))
	db.close(conn)
	self.writeConsole((('Logged in as ' + str(self.agentNick)) if len(self.agentNick) > 0 else (
		'Logged in')) + '.\nAddress is ' + str(self.agentAddress) + '\nBalance is ' + str(self.agentBalance) + ' ' + str(
		self.unit))
	#check for new nicknames
	if util.pollAllPosts(self):
		util.checkNewNicks(self)
	#check for new posts from follows
	commandFeed(self, command)
	#generate a new public/private key pair
	self.whisperAlicePubKey = util.genPubKey(self)
	if self.whisperAlicePubKey is False:
		self.writeConsole('Unable to post your Public Key')
	self.togglePoll(True)
	return
예제 #5
0
def commandNick(self, command):
	"""
		set a nickname for the user
		nickname needs to be unique
		update profile
		update the list of nicks first
	"""
	if not util.checkLogin(self):
		return
	if len(command) < 2:
		self.writeConsole('You need to specify a nickname')
		return
	#update nicknames
	if util.pollAllPosts(self):
		util.checkNewNicks(self)
	util.getAllNicks(self)
	if command[1] in self.allNicks:
		self.writeConsole(command[1] + ' is already taken as a nickname.')
		return
	try:
		response = self.agent.post('nick:' + command[1])
		if response['success'] == 1:
			self.writeConsole('(' + str(response['command_result']) + ') >> Set nickname to ' + str(command[1]))
			self.agentNick = command[1]
			conn = db.open()
			c = conn.cursor()
			c.execute('select id from profiles where seed=?;', (str(self.agentSeed),))
			id = c.fetchone()
			if id is None:
				c.execute('insert into profiles (nick, seed) values (?,?);', (str(self.agentNick), str(self.agentSeed)))
			else:
				c.execute('update profiles set nick=? where seed=?;', (str(self.agentNick), str(self.agentSeed)))
			db.close(conn)
		else:
			self.writeConsole('Setting nick failed')
	except netvend.NetvendResponseError as e:
		self.writeConsole('Setting nick failed - ' + str(e))
	return