Ejemplo n.º 1
0
 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')
Ejemplo n.º 2
0
        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')
Ejemplo n.º 3
0
 def slap(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)
     if message.from_user.username is not None:
         if '@senero_bot' == status[0].lower():
             bot.send_message(message.chat.id, '@senero_bot slaps @' + str(message.from_user.username))
             return
         bot.send_message(message.chat.id, '@' + str(message.from_user.username) + ' slaps ' + status[0])
     else:
         if '@senero_bot' == status[0].lower():
             bot.send_message(message.chat.id, '@senero_bot slaps ' + str(message.from_user.first_name))
             return
         bot.send_message(message.chat.id, '@' + str(message.from_user.first_name) + ' slaps ' + status[0])
Ejemplo n.º 4
0
        def vote(message):
            if not Senero.is_valid_chat(message):
                bot.reply_to(message, 'This bot is only available for group https://t.me/senero')
                return
            status = Senero.extract_args(message.text)
            if 2 == len(status) and status[0].isdigit() and status[1].isdigit():
                if status[1] in senero.data['polls'] and \
                        int(status[0]) <= len(senero.data['polls'][status[1]]['poll']['options']):

                    if str(message.from_user.id) not in senero.data['polls'][status[1]]['voters']:
                        senero.data['polls'][status[1]]['poll']['options'][int(status[0]) - 1]['votes'] += 1
                        senero.data['polls'][status[1]]['voters'].append(str(message.from_user.id))
                        bot.reply_to(message, 'Vote added to option number ' + status[0])
                        senero.save_file()
                    else:
                        bot.reply_to(message, 'You already voted for this')
                else:
                    bot.reply_to(message, 'Please use options from the keyboard')
            else:
                bot.reply_to(message, 'Please use options from the keyboard')
Ejemplo n.º 5
0
 def reduce_points(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)
     if senero.is_admin(message):
         if 2 == len(status) and status[1].isdigit():
             user_id = senero.user_id_by_name(status[0])
             if user_id is None:
                 bot.reply_to(message, 'User not found\nAsk ' + status[0]
                              + ' to write /addme and then try again')
             else:
                 senero.reduce_points(user_id, status[1])
                 bot.reply_to(message, 'Reduced ' + str(status[1]) + ' point(s) for ' + status[0])
                 senero.save_file()
         else:
             bot.reply_to(message, 'Invalid command format\n/help for more information')
     else:
         bot.reply_to(message, 'Sorry, but you are not an admin!')
Ejemplo n.º 6
0
        def poll(message):
            if not Senero.is_valid_chat(message):
                bot.reply_to(message, 'This bot is only available for group https://t.me/senero')
                return
            status = Senero.extract_args(message.text)
            if 0 == len(status):
                senero.ensure_user(message)
                options_select = types.ReplyKeyboardMarkup(one_time_keyboard=True)
                options_select.add('/newpoll', '/deletepoll', '/polls', 'Cancel')
                bot.send_message(message.chat.id, '<b>Poll manager</b>\n'
                                                  '/newpoll - Create new poll '
                                                  '(admin only - remove last poll for user)\n'
                                                  '/deletepoll - Delete the user poll (admin only)\n'
                                                  '/polls - See current polls',
                                 parse_mode='HTML', reply_markup=options_select)
            else:
                if status[0] in senero.data['polls']:
                    poll_obj = senero.data['polls'][status[0]]['poll']
                    votes = []
                    index = 1
                    for option in poll_obj['options']:
                        if 'text' == option['type']:
                            votes.append('/vote ' + str(index) + ' ' + status[0])
                            bot.send_message(message.chat.id, 'Option number ' + str(index) + ':\n'
                                             + option['val'] + '(' + str(option['votes']) + ' votes)')
                        elif 'image' == option['type']:
                            votes.append('/vote ' + str(index) + ' ' + status[0])
                            bot.send_photo(message.chat.id, open(option['val'], 'rb'),
                                           caption='Option number ' + str(index)
                                                   + '(' + str(option['votes']) + ' votes)')
                        index += 1

                    votes.append('Cancel')
                    options_select = types.ReplyKeyboardMarkup(one_time_keyboard=True)
                    options_select.add(*votes)
                    bot.send_message(message.chat.id, 'Choose an option', reply_markup=options_select)
                else:
                    bot.reply_to(message, 'Unknown poll')
Ejemplo n.º 7
0
        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)