def btc_balance(bot, update, args): try: btc_id = args[0] # todo add db storage balance = requests.get('https://blockchain.info/address/' + btc_id + '?format=json') bot.sendMessage(update.message.chat_id, text = 'Your balance is: ' + parse_blockchain_info(balance) + emoji.emojize(' :b: ', use_aliases=True)) except: bot.sendMessage(update.message.chat_id, text = "Something went wrong. Did you /dota_register ?")
def dota_LM(bot, update): global dota_history, _db try: user = get_db_user(_db, "telegram_id='%s'" % update.message.from_user.id) last_match = dota_history.matches(account_id = user['steam_id'], matches_requested = 1) bot.sendMessage(update.message.chat_id, text = 'http://www.dotabuff.com/matches/' + str(last_match[0].match_id)) except: bot.sendMessage(update.message.chat_id, text = "Something went wrong. Did you /dota_register ?")
def newYak(bot, update): print update if update.message.text == "SUPPANDI" or update.message.text == "SECRETSUPPANDI": create(bot, update) else: name = update.message.from_user.username text = update.message.text sendText = '@' + name + ": " + text for i in chatIDs: bot.sendMessage(i, sendText)
def eth_cap(bot, update): try: data = requests.get('https://api.coinmarketcap.com/v1/ticker/ethereum') data = json.loads(data.text) cap_usd = data[0]['market_cap_usd'] if cap_usd [-2:] == '.0': cap_usd = cap_usd[:-2] cap_usd = humanize.intcomma(cap_usd) bot.sendMessage(update.message.chat_id, text = emoji.emojize("$" + str(cap_usd), use_aliases=True)) except: bot.sendMessage(update.message.chat_id, text = "Something went wrong. Did you /dota_register ?")
def btc_price(bot, update): try: data = requests.get('https://api.coinmarketcap.com/v1/ticker/bitcoin') data = json.loads(data.text) price_usd = data[0]['price_usd'] price_change = data[0]['percent_change_24h'] if price_change.find('-') < 0: emote = ' :arrow_upper_right: ' else: emote = ' :arrow_lower_right: ' bot.sendMessage(update.message.chat_id, text = emoji.emojize("$" + str(price_usd) + emote + price_change + '%', use_aliases=True)) except: bot.sendMessage(update.message.chat_id, text = "Something went wrong. Did you /dota_register ?")
def handle(msg): """ Receive message and pass the command to call the corresponding function. :param msg: Message received by the bot """ content_type, chat_type, chat_id = telepot.glance(msg) # you can add more content type, like if someone send a picture if msg.get('text'): bot.sendMessage(chat_id, msg.get('text')) if msg.get('entities'): for ent in msg.get('entities'): if ent.get('type') == 'url': bot.sendMessage(chat_id, ent)
def eth_balance(bot, update, args): try: ether_id = args[0] # todo add db storage data = { 'module': 'account', 'action': 'balance', 'address': ether_id, 'tag': 'latest', 'apikey': _etherscan_key } balance = requests.get('https://api.etherscan.io/api/', params=data) bot.sendMessage(update.message.chat_id, text = 'Your balance is: ' + parse_etherscan(balance) + ' Ether') except: bot.sendMessage(update.message.chat_id, text = "Send me wallet ID you'ld like to leard balance of")
def register_alert(bot, update, args): global _alerts, _ticker_events, _db try: event = args[0] threshold = args[1] if event not in _ticker_events: bot.sendMessage(update.message.chat_id, text='Oops, I dont work with this event. Try one of those: ' + ', '.join(_ticker_events)) return; user = get_db_user(_db, "telegram_id='%s'" % update.message.from_user.id) if not user: add_db_user(_db, "telegram_id='%s'" % update.message.from_user.id) user = get_db_user(_db, "telegram_id='%s'" % update.message.from_user.id) if not add_alert(user, event, threshold): return bot.sendMessage(update.message.chat_id, text='You are already subscribed to this event') bot.sendMessage(update.message.chat_id, text='You\'ll be notified when %s reaches %s' %(event, threshold)) except (IndexError, ValueError): bot.sendMessage(update.message.chat_id, text='This command needs your steam ID after space. You can obtain it like this http://dl2.joxi.net/drive/2016/07/13/0013/2351/911663/63/e2a5d4a5b9.png') return False
def help(bot, update): bot.sendMessage(update.message.chat_id, text="/ethprice - Get latest Ether price\n/ethbalance - Get Ether wallet balance\n/ethcap - Get latest Ether capitalization\n" + "/btcprice - Get latest Bitcoin price\n/btcbalance - Get Bitcoin wallet balance\n/btccap - Get latest Bitcoin capitalization\n\n"+ "Have any questions or suggestions? Contact us ASAP at [email protected]\n\nCheck out our channel @cryptoportfolio")