def default_test(message): userid = message.from_user.id f_builds('=', userid, "state", "researchers") markup = types.ReplyKeyboardMarkup(resize_keyboard=True) markup.row('me') bot.send_message(message.chat.id, (f""" Напишите сколько людей вы хотите назначить заниматься наукой? """), reply_markup=markup)
def default_test(message): userid = message.from_user.id n_count = f_builds('?', userid, "n", 0) researchers_count = f_builds('?', userid, "researchers", 0) max_researchers = f_builds('?', userid, "max_researchers", 0) markup = types.ReplyKeyboardMarkup(resize_keyboard=True) markup.row('Указать колличество исследователей') markup.row('me') bot.send_message(message.chat.id, (f""" Человек исследуют {researchers_count}/{max_researchers} """), reply_markup=markup)
def default_test(message): t1 = time.time() my_tasks_cron() userid = message.from_user.id markup = types.ReplyKeyboardMarkup(resize_keyboard=True) if (f_builds('?', userid, "n", 0) > 1): exped = "exped" else: exped = "xxxx" if (f_builds('?', userid, "crystal", 0) > 1): research = "research" else: research = "xxxx" markup.row('work', (f"{exped}"), 'laboratory') markup.row('me', 'Город', (f"{research}")) userid = message.from_user.id coin = f_coin('?', userid, 0) n_count = f_builds('?', userid, "n", 0) workers_count = f_builds('?', userid, "workers", 0) warrior_count = f_builds('?', userid, "warrior", 0) people_count = round(f_builds('?', userid, "people", 0), 1) food = round(f_builds('?', userid, "food", 0), 1) population_count = f_builds('?', userid, "population growth", 0) coin = f_coin('?', userid, 0) m_task = my_task(userid) i = 0 if (len(m_task) > 0): task_str = "Задачи:\n" while (i < len(m_task)): task_str += (f"{m_task[i]}\n") i += 1 else: task_str = '' bot.send_message(message.chat.id, (f""" 👥 {people_count} 🍕{food} 💰{coin} {task_str} Постройки: N-центры = {n_count} Прирост населения {population_count}/час Рабочих = {workers_count} Воинов = {warrior_count}"""), reply_markup=markup) print(time.time() - t1)
def defens (userid, mode): warrior_count = f_builds ('?',userid, "warrior", 0) if mode == 'rand': power1 = warrior_count*3 power2 = rand(3,50) if (power1>power2): batl_res = round((power1 - power2*(power2/power1))/3) return ((f""" На крепость напали! Твои воины оказались сильнее Твои Потери: {batl_res} Потери врага: {batl_res} """), batl_res) else: batl_res = warrior_count - power1*(power1/power2) return ("lose", batl_res)
def default_test(message): userid = message.from_user.id markup = types.ReplyKeyboardMarkup(resize_keyboard=True) markup.row('me') if (message.text.isdigit()): max_researchers = f_builds('?', userid, "max_researchers", 0) researchers = f_builds('?', userid, "researchers", 0) change_people = researchers - int(message.text) if ((int(message.text)) <= max_researchers): f_builds('=', userid, "researchers", int(message.text)) f_builds('+', userid, "people", change_people) f_builds('=', userid, "state", 0) else: bot.send_message(message.chat.id, (f""" Вы не можете назначить больше {max_researchers} """), reply_markup=markup) else: bot.send_message(message.chat.id, (f""" Напишите ЧИСЛО людей вы хотите назначить заниматься наукой? """), reply_markup=markup)
def hour_tasks_cron(): conn = psycopg2.connect(DATABASE_URL, sslmode='require') cursor = conn.cursor() cursor.execute(f"select user_id from users where id > 0") for userid in cursor: pop = f_builds('?', userid[0], "population growth", 0) food_count = f_builds('?', userid[0], "food", 0) storage_cap = f_builds('?', userid[0], "storage capacity", 0) people = f_builds('?', userid[0], "people", 0) food_gr = f_builds('?', userid[0], "food growth", 0) food_change = food_gr - (people) * 0.1 if ((people + pop) < storage_cap): f_builds('+', userid[0], "people", pop) else: f_builds('=', userid[0], "people", storage_cap) if ((food_change + food_count) < storage_cap): f_builds('+', userid[0], "food", food_change) print(food_change) else: f_builds('=', userid[0], "food", storage_cap) researchers = f_builds('?', userid[0], "researchers", 0) max_researchers = f_builds('?', userid[0], "max_researchers", 0) cof = researchers / max_researchers n = f_builds('?', userid[0], "n", 0) lvl_exp = random.randint(1, 2) rand = random.randint(1, 100) if (rand < (5 * cof)): n = n + 1 break if (rand < (20 * cof)): f_exp(n, 3) break elif (rand < (50 * cof)): f_exp(n, 2) break else: f_exp(n, 1) break conn.commit() conn.close()
def callback_inline(call): if call.message: userid = call.from_user.id if (f_coin('?', userid, 0) > 40) and (random.randint(0, 100) < 3): #BATLLES bot.send_message(call.message.chat.id, (f"На вас напали")) batl_res, score = defens(userid, "rand") bot.send_message(message.chat.id, (f"{batl_res}")) if call.data == "work": f_coin('+', userid, 1) coin = f_coin('?', userid, 0) str2 = (f"$ = {coin}") keyboard2 = types.InlineKeyboardMarkup() work_button = types.InlineKeyboardButton(text=str2, callback_data="work") keyboard2.add(work_button) bot.edit_message_reply_markup(chat_id=call.message.chat.id, message_id=call.message.message_id, reply_markup=keyboard2) if call.data == "N": coin = f_coin('?', userid, 0) n_count = f_builds('?', userid, "n", 0) n_cost = 100 if int(coin) >= n_cost: f_coin('+', userid, -n_cost) n_count = f_builds('+', userid, "n", 1) keyboard = types.InlineKeyboardMarkup() work_button = types.InlineKeyboardButton( text=(f"Строим еще за {n_cost}?"), callback_data="N") keyboard.add(work_button) bot.edit_message_text( chat_id=call.message.chat.id, message_id=call.message.message_id, text=( f"Есть {n_count} N-центров \nСтроим еще за {n_cost}?"), reply_markup=keyboard) else: bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text="Не хватает монет!") if call.data == "farm": coin = f_coin('?', userid, 0) n_count = f_builds('?', userid, "n", 0) n_cost = 50 if int(coin) >= n_cost: f_coin('+', userid, -n_cost) n_count = f_builds('+', userid, "farm", 1) keyboard = types.InlineKeyboardMarkup() work_button = types.InlineKeyboardButton( text=(f"Строим еще за {n_cost}?"), callback_data="farm") keyboard.add(work_button) bot.edit_message_text( chat_id=call.message.chat.id, message_id=call.message.message_id, text=(f"Есть {n_count} ферм \nСтроим еще за {n_cost}?"), reply_markup=keyboard) else: bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text="Не хватает монет!") if call.data == "workers": coin = f_coin('?', userid, 0) work_count = f_builds('?', userid, "workers", 0) n_cost = 10 p_count = f_builds('?', userid, "people", 0) if (int(coin) >= n_cost) and (int(p_count) >= 1): f_coin('+', userid, -n_cost) f_builds('+', userid, "people", -1) work_count = f_builds('+', userid, "workers", 1) keyboard = types.InlineKeyboardMarkup() work_button = types.InlineKeyboardButton( text=(f"Строим еще за {n_cost}?"), callback_data="workers") keyboard.add(work_button) bot.edit_message_text( chat_id=call.message.chat.id, message_id=call.message.message_id, text=( f"Есть {work_count} рабочих \nСтроим еще за {n_cost}?" ), reply_markup=keyboard) else: bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text="Не хватает монет или людей!") if call.data == "warrior": coin = f_coin('?', userid, 0) n_count = f_builds('?', userid, "warrior", 0) p_count = f_builds('?', userid, "people", 0) n_cost = 50 if int(coin) >= n_cost and p_count >= 1: f_coin('+', userid, -n_cost) f_builds('+', userid, "people", -1) n_count = f_builds('+', userid, "warrior", 1) keyboard = types.InlineKeyboardMarkup() work_button = types.InlineKeyboardButton( text=(f"Строим еще за {n_cost}?"), callback_data="warrior") keyboard.add(work_button) bot.edit_message_text( chat_id=call.message.chat.id, message_id=call.message.message_id, text=(f"Есть {n_count} воинов \nСтроим еще за {n_cost}?"), reply_markup=keyboard) else: bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text="Не хватает монет или людей!") if call.data == "mine": workers_count = f_builds('?', userid, "workers", 0) exped_count = f_builds('?', userid, "exped", 0) if (exped_count < 1): if (workers_count >= 5): f_builds('+', userid, "exped", +1) f_builds('+', userid, "workers", -5) bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text=(f"Рабочие скоро вернутся")) time.sleep(random.randint(15, 50)) f_builds('+', userid, "workers", +5) f_builds('+', userid, "exped", -1) new_coin = round( (abs(round(random.normalvariate(12, 12), -1))) / 2) f_coin('+', userid, new_coin) bot.send_message(call.message.chat.id, (f"Рабочие нашли ${new_coin}")) else: bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text="Не хватает людей!") else: bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text="У вас уже отправленна експедиция!") if call.data == "forest": workers_count = f_builds('?', userid, "workers", 0) exped_count = f_builds('?', userid, "exped", 0) if (exped_count < 1): if (workers_count >= 20): f_builds('+', userid, "exped", +1) f_builds('+', userid, "workers", -20) bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text=(f"Рабочие скоро вернутся")) quality = random.randint(1, 5) time.sleep(random.randint(30, 80) * quality) sid = random.randint(1, 4000) * quality / 3 if (sid > 4000): f_builds('+', userid, "workers", +20) f_builds('+', userid, "crystal", +1) bot.send_message(call.message.chat.id, ( f"Рабочие нашли странный кристал\n нужно бы обследовать его" )) elif (sid < 300): bot.send_message(call.message.chat.id, (f"Все експедиторы погибли в лесу")) else: f_builds('+', userid, "workers", +20) bot.send_message(call.message.chat.id, ( f"В этот раз експедиция вернулась с пустыми руками" )) f_builds('+', userid, "exped", -1) else: bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text="Не хватает людей!") else: bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text="У вас уже отправленна експедиция!") if call.data == "unknown_place": workers_count = f_builds('?', userid, "workers", 0) exped_count = f_builds('?', userid, "exped", 0) if (exped_count < 1): if (workers_count >= 20): f_builds('+', userid, "exped", +1) f_builds('+', userid, "workers", -20) bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text=(f"Рабочие скоро вернутся")) quality = random.randint(1, 5) time.sleep(random.randint(30, 80) * quality) sid = random.randint(1, 4000) * quality / 3 if (sid > 4000): f_builds('+', userid, "workers", +20) f_builds('+', userid, "crystal", +1) bot.send_message(chat_id=message.chat.id, text=(f"""Рабочие нашли: 'Оно [ça] * функционирует повсюду, иногда без остановок, иногда с перерывами. Оно дышит, оно греет, оно ест. Оно испражняется, оно целует. Но какое заблуждение говорить о нем как о чем-то одном и определенном [le ça].' """), parse_mode='Markdown') elif (sid < 300): bot.send_message(call.message.chat.id, (f"Все експедиторы погибли в лесу")) else: f_builds('+', userid, "workers", +20) bot.send_message(call.message.chat.id, ( f"В этот раз експедиция вернулась с пустыми руками" )) f_builds('+', userid, "exped", -1) else: bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text="Не хватает людей!") else: bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text="У вас уже отправленна експедиция!")
@bot.message_handler( func=lambda mess: mess.text == 'Указать колличество исследователей' and mess.content_type == 'text') def default_test(message): userid = message.from_user.id f_builds('=', userid, "state", "researchers") markup = types.ReplyKeyboardMarkup(resize_keyboard=True) markup.row('me') bot.send_message(message.chat.id, (f""" Напишите сколько людей вы хотите назначить заниматься наукой? """), reply_markup=markup) @bot.message_handler(func=lambda message: funs.f_builds( '?', message.chat.id, "state", 0) == "researchers") def default_test(message): userid = message.from_user.id markup = types.ReplyKeyboardMarkup(resize_keyboard=True) markup.row('me') if (message.text.isdigit()): max_researchers = f_builds('?', userid, "max_researchers", 0) researchers = f_builds('?', userid, "researchers", 0) change_people = researchers - int(message.text) if ((int(message.text)) <= max_researchers): f_builds('=', userid, "researchers", int(message.text)) f_builds('+', userid, "people", change_people) f_builds('=', userid, "state", 0) else: bot.send_message(message.chat.id, (f"""