コード例 #1
0
ファイル: bot3.py プロジェクト: MaksSieve/SomethingX_bot
def gov(m):
    args = extract_arg(m.text)
    cid = m.chat.id
    user = db.get_user(cid)
    if len(args) != 2:  # if wrong number of arguments
        bot.send_message(
            chat_id=cid,
            text=f"Wrong number of arguments!\nUse /gov <password> <point_id>."
        )
    elif args[0] != game['gov_pass']:  # if wrong password
        bot.send_message(chat_id=cid, text=f"Wrong password!")
    elif db.point_has_governor(int(args[1])):
        bot.send_message(chat_id=cid,
                         text=f"This point already have a governor")
    elif user['auth'] == 1:
        bot.send_message(
            chat_id=cid,
            text=
            f"You are already logged in as governor of {game['points'][user['point_id']]['name']}"
        )
    else:
        db.update_user(cid, {"auth": 1, "point_id": int(args[1])})
        bot.send_message(chat_id=cid,
                         text=f"You are successfully logged in as governor!",
                         reply_markup=menu_builder.governor_menu(int(args[1])))
コード例 #2
0
def find_global(message):
    status = util.extract_arg(message.text)

    r = requests.get(reference.link + "global")
    json_data = json.loads(r.text)
    last_update = datetime.fromtimestamp(int(
        json_data['data']['last_updated'])).strftime("%A, %B %d, %Y %I:%M:%S")


    global_stats = 'Cryptocurrencies: ' + str(json_data['data']['active_cryptocurrencies'])+\
                   '\nActive markets: ' + str(json_data['data']['active_markets'])+\
                   '\nBitcoin market percentaje: ' + str(json_data['data']['bitcoin_percentage_of_market_cap'])+ "%" + \
                   '\nMarket capital: ' + str(int(float(json_data['data']['quotes']['USD']['total_market_cap'])))+ "$" + \
                   '\nVolume 24h: ' + str(json_data['data']['quotes']['USD']['total_volume_24h'])+\
                   '\n\nLast update: ' + str(last_update)

    if len(status) == 0:
        bot.send_message(message.chat.id, global_stats)
    elif status[0] == 'f':
        doc = open('global.txt', 'w+')
        doc.write(str(global_stats))
        doc.close
        doc = open('global.txt', 'rb')
        bot.send_document(message.chat.id, doc)
        os.remove('global.txt')
    else:
        bot.send_message(
            message.chat.id, reference.text_messages['wrong_query_global'] +
            reference.text_messages['wrong_query_final'])
コード例 #3
0
def generate_file(message):
    status = util.extract_arg(message.text)

    if len(status) == 0:
        bot.send_message(message.chat.id, reference.text_messages['wrong_query_file']\
                                         +reference.text_messages['wrong_query_final'])
        return

    currency_name = util.concat_arg(status)
    v = find_by_name(str(currency_name), str(message.chat.id))

    if v:
        doc = open(str(v['name']) + '.txt', 'w+')

        coin_data = 'Name: ' + v['name'] + '\n' + \
                    'Symbol: ' + v['symbol'] + '\n' + \
                    'Global rank: '+ str(v['rank']) + '\n' + \
                    'Circulating supply: ' + str(v['circulating_supply']) + '\n' + \
                    'Total supply: '  + str(v['total_supply']) + '\n' + \
                    'Max supply: ' + str(v['max_supply']) + '\n\n' + \
                    'Price \n\n' + \
                    'Price now: ' + str(v['quotes']['USD']['price']) + '$' + '\n' + \
                    'Volume 24h: ' + str(v['quotes']['USD']['volume_24h']) + '\n' + \
                    'Market capital: ' + str(v['quotes']['USD']['market_cap']) + '\n' + \
                    'Percent change 1h: ' + str(v['quotes']['USD']['percent_change_1h']) + '\n' + \
                    'Percent change 24h: ' + str(v['quotes']['USD']['percent_change_24h']) + '\n' + \
                    'Percent change 7d: ' + str(v['quotes']['USD']['percent_change_24h']) + '\n'

        doc.write(coin_data)
        doc.close
        doc = open(str(v['name']) + '.txt', 'rb')
        bot.send_document(message.chat.id, doc)
        os.remove(str(v['name']) + '.txt')
コード例 #4
0
ファイル: bot3.py プロジェクト: MaksSieve/SomethingX_bot
def connected(m):
    cid = m.chat.id
    args = extract_arg(m.text)
    connected_teams = db.get_teams()
    msg = ""
    for c_team in connected_teams:
        if c_team['connected'] == int(args[0]):
            msg = msg + f"{c_team['name']}\n"

    bot.send_message(chat_id=cid, text=msg)
コード例 #5
0
ファイル: bot3.py プロジェクト: MaksSieve/SomethingX_bot
def admin(m):
    args = extract_arg(m.text)
    cid = m.chat.id
    user = db.get_user(cid)
    if len(args) != 1:
        bot.send_message(
            chat_id=cid,
            text=f"Wrong number of arguments!\nUse /admin <password>.")
    elif args[0] != game['adm_pass']:
        bot.send_message(chat_id=cid, text=f"Wrong password!")
    elif user['auth'] == 2:
        bot.send_message(chat_id=cid,
                         text=f"You are already logged in as admin!")
    else:
        db.update_user(cid, {"auth": 2})
        bot.send_message(chat_id=cid,
                         text=f"You are successfully logged in as admin!",
                         reply_markup=menu_builder.admin_menu())
コード例 #6
0
ファイル: bot3.py プロジェクト: MaksSieve/SomethingX_bot
def prices(m):
    cid = m.chat.id
    args = extract_arg(m.text)
    bot.send_message(chat_id=cid,
                     text=get_resources_on_point_string(game, int(args[0])))