コード例 #1
0
ファイル: commands.py プロジェクト: woolysammoth/coinflow
def commandChat(self, command):
	"""
		Set the self.isChat property to true
		True means that any input test is sent as a chat post
	"""
	if not util.checkLogin(self):
		return
	#send a post to indicate that chat was joined
	try:
		self.agent.post('chatting:True')
	except netvend.NetvendResponseError as e:
		self.writeConsole('Failed to set chat - ' + str(e))
		return False
	self.isChat = True
	#get the list of agents who are currently chatting
	self.writeConsole('\n=== Currently chatting ===')
	chatList = util.getChatters(self)
	for chatter in chatList:
		self.writeConsole(chatter)
	self.writeConsole('\nEnter /chat again to stop chatting\n')
	#get and print the 5 posts previous to our joining
	query = "select post_id, address, data from posts where data like 'chat:%' order by ts desc limit 5"
	posts = util.putQuery(self, query)
	if posts is not False:
		for post in reversed(posts['rows']):
			self.writeConsole(util.getNick(self, post[1]) + ' (' + post[0] + ') >> ' + post[2].split(':',1)[1])
			chatPostId = post[0]
	db.setData(self, 'chat_post_id', chatPostId)
	self.togglePoll(True)
	return True
コード例 #2
0
ファイル: commands.py プロジェクト: woolysammoth/coinflow
def commandHistory(self, command):
	"""
		Display the last ten posts for the specified user
		the users current agents posts are shown if no address/nick is given
	"""
	if not util.checkLogin(self):
		return
	if len(command) < 2:
		address = self.agentAddress
		nick = self.agentNick
	else:
		address = util.getAddressFromNick(command[1])
		if address is False:
			address = command[1]
			nick = command[1]
		else:
			address = address
			nick = command[1]
	self.writeConsole('\n== Last 10 Posts for ' + nick + ' ==\n')
	query = "select posts.post_id, posts.data, history.fee from posts inner join history on posts.history_id = history.history_id where posts.address = '" + str(
		address) + "' order by posts.ts asc limit 10"
	rows = util.putQuery(self, query)
	if rows is False:
		self.writeConsole('No posts to display')
		return
	for row in rows['rows']:
		if 'post:' in row[1]:
			post = row[1].split(':', 1)[1]
		else:
			continue
		self.writeConsole('Post ID: ' + str(row[0]) + ' Fee: ' + str(row[2]) + '\n>> ' + str(post) + '\n')
	return
コード例 #3
0
ファイル: commands.py プロジェクト: woolysammoth/coinflow
def commandWhisper(self, command):
	"""
		Initiate a whisper session with the agent specified
	"""
	if not util.checkLogin(self):
		return
	if len(command) < 2:
		self.writeConsole('You need to supply the detail of the agent or post you wish to whisper to.')
		return
	if self.isWhisper is False:
		address = util.checkAddress(command[1])
		if address is False:
			self.writeConsole('Couldn\'t find the agent specified.')
			return
		query = "select data from posts where address = '" + str(address) + "' and data like 'whisperpubkey:%' order by ts desc limit 1"
		rows = util.putQuery(self, query)
		if rows is False:
			self.writeConsole('Couldn\'t find a Public Key for agent ' + command[1])
			return
		self.whisperBobPubKey = RSA.importKey(str(rows['rows'][0][0].split(':',1)[1]))
		self.whisperBobAddress = address
		self.writeConsole('Whisper session with ' + command[1] + 'has been initiated')
		self.writeConsole('Enter \'/whisper\' again to end this whisper session')
		self.isWhisper = True
		return
コード例 #4
0
ファイル: commands.py プロジェクト: woolysammoth/coinflow
def commandSendChat(self, message):
	"""
		send the message as a chat post
		check to see if the message is '/chat' and end the chat session if it is
	"""
	if not util.checkLogin(self):
		return
	if message == '/chat':
		#send a post to indicate that chat was left
		try:
			self.agent.post('chatting:True')
		except netvend.NetvendResponseError as e:
			self.writeConsole('Failed to leave chat - ' + str(e))
			return False
		self.isChat = False
		self.writeConsole('Chat is disabled')
		return
	try:
		response = self.agent.post('chat:' + str(message))
		if response['success'] == 1:
			self.writeConsole('(' + str(response['command_result']) + ') >> ' + str(message))
		else:
			self.writeConsole('Chat failed')
	except netvend.NetvendResponseError as e:
		self.writeConsole('Chat failed - ' + str(e))
	return
コード例 #5
0
ファイル: commands.py プロジェクト: woolysammoth/coinflow
def commandFeed(self, command):
	"""
		Display any new posts from your followed agents
	"""
	if not util.checkLogin(self):
		return
	if util.pollFollowsPosts(self):
		util.displayFollowsPosts(self)
	return
コード例 #6
0
ファイル: commands.py プロジェクト: woolysammoth/coinflow
def commandBalance(self, command):
	"""
		display the balance of the currently logged in agent
	"""
	if not util.checkLogin(self):
		return
	util.getBalance(self)
	self.writeConsole('Balance is ' + str(self.agentBalance) + ' ' + str(self.unit))
	return
コード例 #7
0
ファイル: commands.py プロジェクト: woolysammoth/coinflow
def commandGetUnit(self, command):
	"""
		display the current display unit
		stored in the settings table and unique to each profile
	"""
	if not util.checkLogin(self):
		return
	self.unit = db.getSetting(self, 'unit', 'satoshi')
	self.writeConsole('Current display unit is ' + str(self.unit))
	return
コード例 #8
0
ファイル: commands.py プロジェクト: woolysammoth/coinflow
def commandGetTipAmount(self, command):
	"""
		display the current tip amount
		stored in the settings table and unique to each profile
	"""
	if not util.checkLogin(self):
		return
	self.tipAmount = db.getSetting(self, 'tipAmount', 1)
	self.writeConsole('Current Tip Amount is ' + str(self.tipAmount) + ' ' + str(self.unit))
	return
コード例 #9
0
ファイル: commands.py プロジェクト: woolysammoth/coinflow
def commandSetTipAmount(self, command):
	"""
		set the current tip amount
		save to the settings table
	"""
	if not util.checkLogin(self):
		return
	if len(command) < 2:
		self.writeConsole('You need to supply the new tip amount in ' + str(self.unit))
		return
	self.tipAmount = command[1]
	db.setSetting(self, 'tipAmount', self.tipAmount)
	self.writeConsole('Tip amount has been set to ' + str(self.tipAmount) + ' ' + str(self.unit))
	return
コード例 #10
0
ファイル: commands.py プロジェクト: woolysammoth/coinflow
def commandListFollows(self, command):
	"""
		List all the agents you are following
		update the list of nicks first
	"""
	if not util.checkLogin(self):
		return
	follows = util.getFollows(self)
	if not follows:
		self.writeConsole('You don\'t follow anyone yet')
		return
	self.writeConsole('\n== Following ==\n')
	for follow in follows:
		self.writeConsole(follow[0])
	return
コード例 #11
0
ファイル: commands.py プロジェクト: woolysammoth/coinflow
def commandListAgents(self, command):
	"""
		List all users in the system
		update the list of nicks first
	"""
	if not util.checkLogin(self):
		return
	#update nicknames
	if util.pollAllPosts(self):
		util.checkNewNicks(self)
	self.writeConsole('\n== Agents ==\n')
	util.getAllNicks(self)
	for nick in self.allNicks:
		self.writeConsole(nick)
	return
コード例 #12
0
ファイル: commands.py プロジェクト: kewinwang/coinflow
def commandWhisper(self, command):
	"""
		Initiate a whisper session with the agent specified
	"""
	if not util.checkLogin(self):
		return
	if len(command) < 2:
		self.writeConsole('You need to supply the detail of the agent or post you wish to whisper to.')
		return
	if self.isWhisper is False:
		#generate a new private/public key pair
		self.whisperAlicePubKey = util.genPubKey(self)
		if self.whisperAlicePubKey is False:
			self.writeConsole('Unable to post your Public Key')
			return False
		#fetch the specified agents public key
		address = util.checkAddress(command[1])
		if address is False:
			self.writeConsole('Couldn\'t find the agent specified.')
			return
		query = "select data from posts where address = '" + str(address) + "' and data like 'whisperpubkey:%' order by ts desc limit 1"
		rows = util.putQuery(self, query)
		if rows is False:
			self.writeConsole('Couldn\'t find a Public Key for agent ' + command[1])
			return
		self.whisperBobPubKey = RSA.importKey(str(rows['rows'][0][0].split(':',1)[1]))
		self.whisperBobAddress = address
		self.writeConsole('The next thing you type into the input box will be encrypted and sent to ' + command[1])
		self.isWhisper = True
		return
	if self.isWhisper is True:
		cipher = PKCS1_OAEP.new(self.whisperBobPubKey)
		message = cipher.encrypt(command)
		#the post contains the public key we used so that the correct private key can be identified by Bob
		#self.writeConsole('whisper >> ' + str(self.whisperBobPubKey) + '|' + message)
		try:
			response = self.agent.post('whisper:' + str(self.whisperBobPubKey.exportKey(passphrase=self.password)) + '|' + message.encode('base64','strict'))
		except netvend.NetvendResponseError as e:
			self.writeConsole('whisper failed - ' + str(e))
		#tip the agent to alert them to the whisper
		if response['success'] == 1:
			try:
				self.agent.tip(self.whisperBobAddress, 1, response['command_result'])
			except netvend.NetvendResponseError as e:
				self.writeConsole('whisper failed - ' + str(e))
		self.writeConsole('whisper sent')
		self.isWhisper = False
		return
コード例 #13
0
ファイル: commands.py プロジェクト: woolysammoth/coinflow
def commandSetUnit(self, command):
	"""
		set the current display unit
		save to the settings table
	"""
	if not util.checkLogin(self):
		return
	if len(command) < 2:
		self.writeConsole('You need to supply the new display unit.')
		return
	availableUnits = ['btc', 'mbit', 'ubit', 'satoshi', 'msat', 'usat']
	if command[1].lower() not in availableUnits:
		self.writeConsole('The unit you entered is not known.\nAcceptable values are ' + str(availableUnits))
		return
	self.unit = command[1].lower()
	db.setSetting(self, 'unit', self.unit)
	self.writeConsole('Display unit has been set to ' + str(self.unit))
	return
コード例 #14
0
ファイル: commands.py プロジェクト: woolysammoth/coinflow
def commandPost(self, command):
	"""
		Post a message to netvend
	"""
	if not util.checkLogin(self):
		return
	if len(command) < 2:
		self.writeConsole('You need to supply the message to post.')
		return
	try:
		response = self.agent.post('post:' + command[1])
		if response['success'] == 1:
			self.writeConsole('(' + str(response['command_result']) + ') >> ' + str(command[1]))
		else:
			self.writeConsole('Post failed')
	except netvend.NetvendResponseError as e:
		self.writeConsole('Post failed - ' + str(e))
	return
コード例 #15
0
ファイル: commands.py プロジェクト: woolysammoth/coinflow
def commandTip(self, command):
	"""
		Tip a nickname, address or post_id
		nickname tipping still in progress
	"""
	if not util.checkLogin(self):
		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, netvend.convert_value(int(self.tipAmount), str(self.unit), 'usat'), 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
コード例 #16
0
ファイル: commands.py プロジェクト: woolysammoth/coinflow
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
コード例 #17
0
ファイル: commands.py プロジェクト: woolysammoth/coinflow
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