Skip to content

Repository files navigation

import random import json import os from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup from telegram.ext import ApplicationBuilder, CommandHandler, CallbackContext

Протеиновые типы

PROTEINS = ["Альфа-протеины", "Бета-протеины", "Гамма-протеины", "Дельта-протеины", "Эпсилон-протеины"]

Путь к файлам профилей пользователей

PROFILE_DIR = "./profiles"

Создание профиля

def create_profile(user_id): if not os.path.exists(PROFILE_DIR): os.makedirs(PROFILE_DIR) profile_path = os.path.join(PROFILE_DIR, f"{user_id}.json")

if not os.path.exists(profile_path):
    profile = {
        "user_id": user_id,
        "proteins": {protein: 0 for protein in PROTEINS},
        "daily_collected": False,
        "capsule_parts": []
    }
    with open(profile_path, 'w') as f:
        json.dump(profile, f)
    return profile
else:
    with open(profile_path, 'r') as f:
        return json.load(f)

Сохранение профиля

def save_profile(user_id, profile): profile_path = os.path.join(PROFILE_DIR, f"{user_id}.json") with open(profile_path, 'w') as f: json.dump(profile, f)

Команда /start

async def start(update: Update, context: CallbackContext): user_id = update.message.from_user.id profile = create_profile(user_id) await update.message.reply_text("Ваш профиль создан! Собирайте протеины и стройте вечную капсулу!")

Команда для сбора протеинов

async def collect_proteins(update: Update, context: CallbackContext): user_id = update.message.from_user.id profile = create_profile(user_id)

if profile['daily_collected']:
    await update.message.reply_text("Вы уже собрали протеины сегодня. Попробуйте завтра.")
    return

collected_proteins = {protein: random.randint(1, 5) for protein in PROTEINS}
for protein, amount in collected_proteins.items():
    profile['proteins'][protein] += amount

profile['daily_collected'] = True
save_profile(user_id, profile)

response = "Вы собрали следующие протеины:\n"
for protein, amount in collected_proteins.items():
    response += f"{protein}: {amount}\n"

await update.message.reply_text(response)

Команда /build для строительства капсулы

async def build_capsule(update: Update, context: CallbackContext): user_id = update.message.from_user.id profile = create_profile(user_id)

# Пример ресурсов, которые нужны для строительства части капсулы
build_requirements = {
    "Модуль управления": {"Альфа-протеины": 5, "Бета-протеины": 3},
    "Энергетический модуль": {"Гамма-протеины": 4, "Дельта-протеины": 2},
}

built_items = []
for part, requirements in build_requirements.items():
    if all(profile['proteins'].get(protein, 0) >= amount for protein, amount in requirements.items()):
        for protein, amount in requirements.items():
            profile['proteins'][protein] -= amount
        profile['capsule_parts'].append(part)
        built_items.append(part)

save_profile(user_id, profile)

if built_items:
    response = "Вы построили следующие части капсулы:\n" + "\n".join(built_items)
else:
    response = "Недостаточно ресурсов для постройки капсулы."

await update.message.reply_text(response)

Команда /compute для выполнения случайного задания

async def compute_task(update: Update, context: CallbackContext): user_id = update.message.from_user.id profile = create_profile(user_id)

tasks = [
    "Орать на форумах о будущем человечества.",
    "Расклеивать листовки о биоинженерии.",
    "Учиться на курсах биоинженерии.",
    "Проходить курсы по иммортализму.",
    "Работать на подработке для закупки материалов."
]

task = random.choice(tasks)
await update.message.reply_text(f"Ваше задание на сегодня: {task}")

Основной запуск бота

async def main(): application = ApplicationBuilder().token("YOUR_BOT_TOKEN").build()

application.add_handler(CommandHandler("start", start))
application.add_handler(CommandHandler("collect", collect_proteins))
application.add_handler(CommandHandler("build", build_capsule))
application.add_handler(CommandHandler("compute", compute_task))

await application.run_polling()

if name == 'main': import asyncio asyncio.run(main())

About

Telegram game bot (protein collector)

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages