def username(bot, update, args): response = messages.markdown("<u><b>Change username<b><u>\n\n", bot.messenger) userInfo = util.crossMessengerSplit(update) userId = userInfo['user'] if 'user' in userInfo else None #Get the user entry from the user which fired the command user = bot.database.getUser(userId) if user == None: response += messages.nodesRequired(bot.messenger) elif len(args) != 1: response += messages.userNameRequiredError(bot.messenger) elif not util.validateName(args[0]): response += messages.invalidNameError.format(args[0]) else: old = user['name'] bot.database.updateUsername(args[0], user['id']) response += "Username updated from {} to {}".format( messages.removeMarkdown(old), messages.removeMarkdown(args[0])) return response
def me(bot, update): response = messages.markdown("<u><b>User info<b><u>\n\n", bot.messenger) userInfo = util.crossMessengerSplit(update) userId = userInfo['user'] if 'user' in userInfo else None #Get the user entry from the user which fired the command user = bot.database.getUser(userId) if user == None: response += messages.nodesRequired(bot.messenger) else: response += "You are {}\n\n".format( messages.removeMarkdown(user['name'])) response += "Status Notifications " + messages.notificationState( bot.messenger, user['status_n']) response += "\nReward Notifications " + messages.notificationState( bot.messenger, user['reward_n']) response += "\nTimeout Notifications " + messages.notificationState( bot.messenger, user['timeout_n']) response += "\nNetwork Notifications " + messages.notificationState( bot.messenger, user['network_n']) return response
def detail(bot, args): logger.info("detail") response = messages.markdown("<u><b>Proposal detail<b><u>\n\n", bot.messenger) if len(args): proposalIds = [] for arg in args: try: proposalIds.append(int(arg)) except: response += "Invalid argument: {}\n\n".format( messages.removeMarkdown(arg)) for proposalId in proposalIds: proposal = bot.proposals.getProposal(proposalId) if proposal: response += messages.proposalDetail(bot.messenger, proposal) else: response += "There is no info about the ID {}!\n\n".format( proposalId) return response
def top(bot, update, args): response = "<u><b>Top nodes<b><u>\n\n" userInfo = util.crossMessengerSplit(update) userId = userInfo['user'] if 'user' in userInfo else None userName = userInfo['name'] if 'name' in userInfo else None logger.debug("nodes - user: {}".format(userId)) nodesFound = False user = bot.database.getUser(userId) userNodes = bot.database.getAllNodes(userId) if user == None or userNodes == None or len(userNodes) == 0: response += messages.nodesRequired(bot.messenger) else: invalidFilterValueMsg = "<b>ERROR<b>: Invalid filter value: <b>{}<b>! Valid range: 10 - 100\n\n" topPercent = 10 if len(args) >= 1: if util.isInt(args[0]) and\ int(args[0]) >= 10 and int(args[0]) <= 100: topPercent = int(args[0]) else: response += invalidFilterValueMsg.format( messages.removeMarkdown(args[0])) response += "<b>Filter<b> {}%\n\n".format(topPercent) with bot.nodeList as nodeList: topX = nodeList.enabledWithMinProtocol() * (topPercent / 100) collaterals = list(map(lambda x: x['collateral'], userNodes)) nodes = nodeList.getNodes(collaterals) topNodes = list( filter(lambda x: x.position <= topX and x.position > 0, nodes)) minimumUptime = nodeList.minimumUptime() if len(topNodes): for masternode in sorted(topNodes, key=lambda x: x.position if x.position > 0 else 100000): userNode = bot.database.getNodes(masternode.collateral, user['id']) response += "<b>" + userNode['name'] + "<b>" response += "\nPosition " + messages.markdown( masternode.positionString(minimumUptime), bot.messenger) response += "\n" + messages.link( bot.messenger, 'https://explorer3.curium.cc/address/{}'.format( masternode.payee), 'Open the explorer!') response += "\n\n" else: response += "<b>You have currently no nodes in the top {}% of the queue.<b>\n\n".format( topPercent) return messages.markdown(response, bot.messenger)