v5.9
Menu Button Prifile
This commit is contained in:
parent
8f6089b68b
commit
e58bde22bc
2
bot.js
2
bot.js
@ -248,7 +248,7 @@ bot.command('profile', (ctx) => {
|
||||
[
|
||||
{
|
||||
text: "Открыть профиль",
|
||||
web_app: { url: "https://cmpfire.ru:3000/profile" }, // Замените на ваш URL
|
||||
web_app: { url: "https://web-bot.campfiregg.ru/" }, // Замените на ваш URL
|
||||
},
|
||||
],
|
||||
],
|
||||
|
@ -1,65 +1,163 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Профиль</title>
|
||||
<title>Меню игрока</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
text-align: center;
|
||||
font-family: 'Arial', sans-serif;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
background-color: #f4f7fc;
|
||||
color: #333;
|
||||
}
|
||||
.container {
|
||||
max-width: 700px;
|
||||
margin: 30px auto;
|
||||
background: white;
|
||||
padding: 20px;
|
||||
background-color: #f4f4f4;
|
||||
border-radius: 15px;
|
||||
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
|
||||
font-size: 16px;
|
||||
}
|
||||
.profile {
|
||||
background: #fff;
|
||||
padding: 20px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||
.title {
|
||||
font-size: 28px;
|
||||
font-weight: bold;
|
||||
text-align: center;
|
||||
margin-bottom: 20px;
|
||||
color: #4e7dd1;
|
||||
}
|
||||
.profile h1 {
|
||||
margin: 0 0 10px;
|
||||
.section {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.profile p {
|
||||
.section h2 {
|
||||
font-size: 20px;
|
||||
margin-bottom: 10px;
|
||||
color: #4e7dd1;
|
||||
}
|
||||
.section p {
|
||||
margin: 5px 0;
|
||||
}
|
||||
.section span {
|
||||
font-weight: bold;
|
||||
}
|
||||
.button {
|
||||
display: inline-block;
|
||||
background-color: #4e7dd1;
|
||||
color: white;
|
||||
padding: 10px 20px;
|
||||
text-decoration: none;
|
||||
border-radius: 5px;
|
||||
font-size: 16px;
|
||||
margin-top: 20px;
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
}
|
||||
.emoji {
|
||||
font-size: 1.3em;
|
||||
}
|
||||
.resource-icon {
|
||||
font-size: 1.5em;
|
||||
}
|
||||
.enterprise {
|
||||
padding: 15px;
|
||||
background-color: #f9f9f9;
|
||||
border-radius: 10px;
|
||||
margin-top: 10px;
|
||||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
</style>
|
||||
<script src="https://telegram.org/js/telegram-web-app.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="profile">
|
||||
<h1 id="username">Загрузка...</h1>
|
||||
<p>Уровень: <span id="level">—</span></p>
|
||||
<p>Опыт: <span id="exp">—</span> / <span id="expToNextLevel">—</span></p>
|
||||
<p>Баланс: <span id="money">—</span> ₽</p>
|
||||
<p>Дом: <span id="house">—</span></p>
|
||||
<p>Машина: <span id="car">—</span></p>
|
||||
<p>Телефон: <span id="mobile">—</span></p>
|
||||
<div class="container">
|
||||
<div class="title">📜 Меню игрока</div>
|
||||
|
||||
<div class="section">
|
||||
<h2>👤 Личные данные</h2>
|
||||
<p>Имя: <span id="name">—</span></p>
|
||||
<p>Уровень: <span id="level">—</span></p>
|
||||
<p>Опыт: <span id="exp">—</span></p>
|
||||
<p>Здоровье: <span id="hp">—</span> / <span id="max_hp">—</span></p>
|
||||
<p>Деньги: ₽<span id="money">—</span></p>
|
||||
<p>Грязные деньги: ₽<span id="dirtymoney">—</span></p>
|
||||
</div>
|
||||
|
||||
<div class="section">
|
||||
<h2>🏢 Организация</h2>
|
||||
<p>Название: <span id="business-name">—</span></p>
|
||||
<p>Баланс: ₽<span id="business-balance">—</span></p>
|
||||
<p>Материалы: <span id="business-materials">—</span></p>
|
||||
</div>
|
||||
|
||||
<div class="section">
|
||||
<h2>🏭 Предприятия</h2>
|
||||
<div id="enterprises">
|
||||
<p>Нет активных предприятий.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<a href="https://t.me/yourbot" class="button">🏠 Перейти в чат бота</a>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Telegram WebApp API
|
||||
const tg = window.Telegram.WebApp;
|
||||
const playerId = tg.initDataUnsafe.user.id;
|
||||
|
||||
// Получаем ID пользователя
|
||||
const userId = tg.initDataUnsafe.user.id;
|
||||
fetch(`/player/${playerId}`)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
const { user, business, enterprises } = data;
|
||||
|
||||
// Загружаем данные профиля
|
||||
fetch(`/profile/${userId}`)
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
document.getElementById('username').textContent = data.username;
|
||||
document.getElementById('level').textContent = data.level;
|
||||
document.getElementById('exp').textContent = data.exp;
|
||||
document.getElementById('expToNextLevel').textContent = data.expToNextLevel;
|
||||
document.getElementById('money').textContent = data.money;
|
||||
document.getElementById('house').textContent = data.house;
|
||||
document.getElementById('car').textContent = data.car;
|
||||
document.getElementById('mobile').textContent = data.mobile;
|
||||
// Личные данные
|
||||
document.getElementById("name").textContent = user.name || user.username;
|
||||
document.getElementById("level").textContent = user.level;
|
||||
document.getElementById("exp").textContent = user.exp;
|
||||
document.getElementById("hp").textContent = user.hp;
|
||||
document.getElementById("max_hp").textContent = user.max_hp;
|
||||
document.getElementById("money").textContent = user.money;
|
||||
document.getElementById("dirtymoney").textContent = user.dirtymoney;
|
||||
|
||||
// Организация
|
||||
document.getElementById("business-name").textContent = business.name;
|
||||
document.getElementById("business-balance").textContent = business.balance;
|
||||
document.getElementById("business-materials").textContent = business.materials;
|
||||
|
||||
// Предприятия
|
||||
const enterprisesDiv = document.getElementById("enterprises");
|
||||
if (enterprises.length > 0) {
|
||||
enterprisesDiv.innerHTML = "";
|
||||
enterprises.forEach(ent => {
|
||||
const div = document.createElement("div");
|
||||
div.classList.add("enterprise");
|
||||
div.innerHTML = `
|
||||
<strong>${ent.name}</strong><br>
|
||||
Тип ресурса: ${getResourceIcon(ent.resourceType)} ${ent.resourceType}<br>
|
||||
Уровень: ${ent.level}<br>
|
||||
Эффективность: ${ent.efficiency}/час<br>
|
||||
Заполненность склада: ${ent.currentResources}/${ent.warehouseCapacity}
|
||||
`;
|
||||
enterprisesDiv.appendChild(div);
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error('Ошибка загрузки профиля:', err);
|
||||
.catch(err => {
|
||||
console.error("Ошибка загрузки данных:", err);
|
||||
});
|
||||
|
||||
// Функция для конвертации типов ресурсов в эмодзи
|
||||
function getResourceIcon(resource) {
|
||||
switch (resource.toLowerCase()) {
|
||||
case 'дерево': return '🌳';
|
||||
case 'металл': return '🛠️';
|
||||
case 'нефть': return '🛢️';
|
||||
case 'уголь': return '⛏️';
|
||||
case 'золото': return '💰';
|
||||
case 'алмазы': return '💎';
|
||||
default: return '⚙️';
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
31
rpg.js
31
rpg.js
@ -2064,6 +2064,37 @@ rpg.action(/miss_\d+/, async (ctx) => {
|
||||
});
|
||||
|
||||
|
||||
rpg.command("start_battle", async (ctx) => {
|
||||
const character = await CharacterModel.findOne({ where: { telegram_id: ctx.from.id } });
|
||||
|
||||
if (!character) {
|
||||
return ctx.reply("Ваш персонаж не найден. Создайте его, чтобы начать играть!");
|
||||
}
|
||||
|
||||
// Поиск или создание новой битвы
|
||||
const enemy = await Enemy.findByPk(1); // Случайный враг
|
||||
const battle = await Battle.create({
|
||||
character: character.telegram_id,
|
||||
enemy: enemy.id,
|
||||
enemy_hp: enemy.hp,
|
||||
logs: [],
|
||||
status: "active",
|
||||
});
|
||||
|
||||
// Генерация ссылки на Miniapp
|
||||
const miniappUrl = `https://web-bot.campfiregg.ru/battle?battleId=${battle.id}&playerId=${character.telegram_id}`;
|
||||
|
||||
await ctx.reply(
|
||||
`⚔️ Битва началась!\nВаш противник: ${enemy.name}\n🛡️ Уровень: ${enemy.level}\n❤️ Здоровье: ${enemy.hp}\n\nПерейдите в мини-приложение, чтобы продолжить:`,
|
||||
{
|
||||
reply_markup: {
|
||||
inline_keyboard: [
|
||||
[{ text: "Открыть битву", web_app: { url: miniappUrl } }],
|
||||
],
|
||||
},
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
module.exports = rpg;
|
||||
|
56
server.js
56
server.js
@ -1,30 +1,48 @@
|
||||
const express = require('express');
|
||||
const { UserModel, CharacterModel, BusinessModel, EnterpriseModel } = global.config;
|
||||
const app = express();
|
||||
const { UserModel, PropertyModel, expToUp } = global.config;
|
||||
|
||||
// Настраиваем сервер для выдачи статических файлов
|
||||
app.use(express.static('public'));
|
||||
app.use(express.static('public')); // Для выдачи HTML и статики
|
||||
|
||||
// Эндпоинт для получения данных профиля
|
||||
app.get('/profile/:id', async (req, res) => {
|
||||
const id = req.params.id;
|
||||
const user = await UserModel.findByPk(id);
|
||||
const property = await PropertyModel.findByPk(id);
|
||||
// Эндпоинт для получения всех данных игрока
|
||||
app.get('/player/:id', async (req, res) => {
|
||||
const playerId = req.params.id;
|
||||
|
||||
if (!user) return res.status(404).send({ error: 'Пользователь не найден' });
|
||||
try {
|
||||
console.log(playerId)
|
||||
const user = await UserModel.findOne({ where: { telegram_id: req.params.id } });
|
||||
const character = await CharacterModel.findOne({ where: { telegram_id: playerId } });
|
||||
let business = await BusinessModel.findOne({ where: { owner: playerId.toString() } })
|
||||
if(business === null){
|
||||
business = await BusinessModel.findOne( {where: { owner: user.business.id} } )
|
||||
}
|
||||
const enterprises = await EnterpriseModel.findAll({ where: { playerId } });
|
||||
|
||||
res.send({
|
||||
username: user.username,
|
||||
level: user.level,
|
||||
exp: user.exp,
|
||||
expToNextLevel: expToUp[user.level],
|
||||
money: user.money,
|
||||
house: property.house ? property.house.name : "Бездомный",
|
||||
car: property.car1 ? property.car1.name : "Пешком",
|
||||
mobile: property.mobile ? property.mobile.name : "Нет",
|
||||
});
|
||||
if (!user || !character) {
|
||||
return res.status(404).json({ error: "Игрок не найден." });
|
||||
}
|
||||
|
||||
res.json({
|
||||
user: {
|
||||
username: user.username,
|
||||
name: user.name,
|
||||
level: user.level,
|
||||
exp: user.exp,
|
||||
hp: character.hp,
|
||||
max_hp: character.max_hp,
|
||||
money: user.money,
|
||||
dirtymoney: character.dirtymoney,
|
||||
},
|
||||
business: business || { name: "Отсутствует", balance: 0, materials: 0, users: [] },
|
||||
enterprises: enterprises || [],
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
res.status(500).json({ error: 'Ошибка сервера' });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Запуск сервера
|
||||
const PORT = process.env.PORT || 3000;
|
||||
app.listen(PORT, () => console.log(`Сервер запущен на порту ${PORT}`));
|
||||
|
Loading…
Reference in New Issue
Block a user