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
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
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
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
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