def info(message): if not Senero.is_valid_chat(message): bot.reply_to(message, 'This bot is only available for group https://t.me/senero') return senero.ensure_user(message) bot.send_chat_action(message.chat.id, 'typing') status = Senero.extract_args(message.text) if 1 == len(status): status[0] = status[0].lower() if status[0] in Senero.COINS: bot.send_message(message.chat.id, 'Only cryptocurrency)') return coin = Senero.symbol_to_id(int(bot.get_chat_members_count(message.chat.id)), status[0]) if coin is {} or 1 != len(coin): bot.send_message(message.chat.id, 'Unknown coin(s)') else: coin = coin[status[0]] txt = '<b>' + coin['name'] + ':</b>\n' txt += 'Symbol: ' + coin['symbol'] + '\n' txt += 'Price: ' + coin['price_usd'] + '$ / ' + coin['price_eur'] \ + '€ / '.decode('utf8') + coin['price_btc'] + 'BTC\n' txt += '24 Hours value: ' + coin['24h_volume_usd'] + '$ / ' \ + coin['24h_volume_eur'] + '€\n'.decode('utf8') txt += 'Market cap: ' + coin['market_cap_usd'] + '$ / ' \ + coin['market_cap_eur'] + '€\n'.decode('utf8') txt += '<i>Change:</i>\n' txt += 'Last 1 hour: ' + coin['percent_change_1h'] + '%\n' txt += 'Last 24 hours: ' + coin['percent_change_24h'] + '%\n' txt += 'Last 7 days: ' + coin['percent_change_7d'] + '%\n' bot.reply_to(message, txt, parse_mode='HTML') else: bot.reply_to(message, 'Invalid command format\n/help for more information')
def convert(message): if not Senero.is_valid_chat(message): bot.reply_to(message, 'This bot is only available for group https://t.me/senero') return senero.ensure_user(message) bot.send_chat_action(message.chat.id, 'typing') status = Senero.extract_args(message.text) if 3 == len(status) and isinstance(float(status[0]), numbers.Real): status[1] = status[1].lower() status[2] = status[2].lower() coins = Senero.symbol_to_id(int(bot.get_chat_members_count(message.chat.id)), status[1], status[2]) if coins is {} or 2 != len(coins): bot.send_message(message.chat.id, 'Unknown coin(s)') else: if status[1] in Senero.COINS and status[2] in Senero.COINS: bot.reply_to(message, 'It\'s cryptocurrency converter, why would you want to do that?') return if status[2] in Senero.COINS: value_rate = float(coins[status[1]]['price_' + status[2].lower()]) * float(status[0]) elif status[1] in Senero.COINS: value_rate = (1 / float(coins[status[2]]['price_' + status[1].lower()])) * float(status[0]) else: value_rate = (float(coins[status[1]]['price_usd']) / float( coins[status[2]]['price_usd'])) * float(status[0]) value_rate = ('%.8f' % float(value_rate)) value_rate = value_rate.rstrip('0').rstrip('.') if '.' in value_rate else value_rate bot.reply_to(message, str(status[0]) + ' ' + coins[status[1]]['name'] + ' is ' + value_rate + status[2]) else: bot.reply_to(message, 'Invalid command format\n/help for more information')
def bet(message): if not Senero.is_valid_chat(message): bot.reply_to(message, 'This bot is only available for group https://t.me/senero') return senero.ensure_user(message) status = Senero.extract_args(message.text) user_id = str(message.from_user.id) if 3 == len(status) and status[1].isdigit() \ and ('higher' == status[2].lower() or 'lower' == status[2].lower()): max_points = senero.get_points(message) if int(status[1]) <= max_points: if 0 < int(status[1]): # Check coin symbol coin_symbol = status[0] current_coin = Senero.symbol_to_id(bot.get_chat_members_count(message.chat.id), coin_symbol )[coin_symbol.lower()] if current_coin is {} or 0 == len(current_coin) or 'id' not in current_coin: bot.send_message(message.chat.id, 'Unknown coin \'' + coin_symbol.upper() + '\'') else: if user_id not in senero.users: senero.users[user_id] = Senero.user_to_json(message.from_user) senero.users[user_id]['addedUsers'] = [] if 'bet' not in senero.users[user_id]: senero.users[user_id]['bet'] = {'inBet': False} if senero.users[user_id]['bet']['inBet']: bot.send_message(message.chat.id, 'You already have an active bet!\n' '/mybet - See current bet status,' ' and see results if finished') else: senero.users[user_id]['bet']['inBet'] = True senero.users[user_id]['bet']['oncoin'] = current_coin['id'] senero.users[user_id]['bet']['current_value'] = current_coin['market_cap_usd'] senero.users[user_id]['bet']['points'] = int(status[1]) senero.users[user_id]['bet']['status'] = status[2].lower() senero.users[user_id]['bet']['at'] = int(time.time() * 1000) bot.send_message(message.chat.id, 'Added bet (%s points) for %s\n' 'Currnet market cap: %s$ (predict: %s)' % ( status[1], current_coin['name'], '{:,}'.format(int( str(current_coin['market_cap_usd']).split('.')[0] )), senero.users[user_id]['bet']['status'] )) senero.save_file() else: bot.send_message(message.chat.id, 'Bet amount need to be larger then 0') else: bot.send_message(message.chat.id, 'Insufficient points (' + str(max_points) + ' points available)') else: txt = '<i>This is a function that allow user to bet on Market Cap in 24 hours.</i>\n' txt += '\n<b>Rules:</b>\n' txt += '* All the coin values will be taken from: ' \ '<a href="https://coinmarketcap.com">coinmarketcap.com</a>\n' txt += '* You can cancel your bet only if 10 minutes are not passed since your bet order: /cancelbet\n' txt += '* Only one active bet per user is allowed\n' txt += '\n<b>Format:</b>\n<i>/bet *Coin Symbol* *How much points* *Higher/Lower*</i>\n' txt += 'For example if I have 7 points (/myranking) and I want to bet on ' \ '4 points that the value will be higher:\n' txt += '<i>/bet ltc 4 higher</i>\n' txt += 'Or:\n<i>/bet xmr 1 lower</i>\n' bot.send_message(message.chat.id, txt, parse_mode='HTML', disable_web_page_preview=True)