def listener(messages): for m in messages: if not Senero.is_valid_chat(m): continue adding_or_removing_user = Senero.user_to_json(m.from_user) added_user = Senero.user_to_json(m.new_chat_member) left_user = Senero.user_to_json(m.left_chat_member) if adding_or_removing_user is not None: if added_user is not None: # User added print json.dumps(adding_or_removing_user) + ' added ' + json.dumps(added_user) if adding_or_removing_user['id'] not in senero.users: senero.users[adding_or_removing_user['id']] = adding_or_removing_user senero.users[adding_or_removing_user['id']]['addedUsers'] = [] if added_user not in senero.users[adding_or_removing_user['id']]['addedUsers']: senero.users[adding_or_removing_user['id']]['addedUsers'].append(added_user) if added_user['id'] not in senero.users: senero.users[added_user['id']] = added_user senero.users[added_user['id']]['addedUsers'] = [] senero.save_file() bot.send_message(m.chat.id, 'Senero Community Token Bot: Welcome ' + added_user['first_name'] + '! Type /help to see how you can earn some tokens for helping Senero') if left_user is not None: # User left or removed print json.dumps(left_user) + ' left or removed' for user in senero.users: senero.users[user]['addedUsers'].remove(left_user) senero.save_file()
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)