0.0.2
This commit is contained in:
parent
6b5ea57c89
commit
0503eb77bd
594
bot.js
594
bot.js
@ -1,21 +1,12 @@
|
||||
require('dotenv').config()
|
||||
// Подключаем необходимые библиотеки
|
||||
const { Telegraf, Scenes, session, Markup, Stage } = require('telegraf');
|
||||
const { Op } = require('sequelize');
|
||||
const sequelize = require('./db'); // Подключение базы данных
|
||||
// Подключаем обработчики
|
||||
const commands = require('./commands');
|
||||
const utils = require('./utils');
|
||||
const handlers = require('./handlers');
|
||||
const {
|
||||
Telegraf,
|
||||
Scenes,
|
||||
session,
|
||||
Stage,
|
||||
Markup
|
||||
} = require('telegraf')
|
||||
const {
|
||||
weaponshop,
|
||||
slots,
|
||||
rarecars,
|
||||
simplecars,
|
||||
houses,
|
||||
cars,
|
||||
phones,
|
||||
weapons,
|
||||
equipment,
|
||||
UserModel,
|
||||
WorldModel,
|
||||
JobModel,
|
||||
@ -29,80 +20,7 @@ const {
|
||||
WarehouseModel,
|
||||
SaleModel,
|
||||
SkillsModel,
|
||||
mainChat,
|
||||
adminList,
|
||||
expToUp,
|
||||
topSym
|
||||
} = require('./config')
|
||||
const {
|
||||
profile,
|
||||
bonus,
|
||||
pay,
|
||||
getprofile,
|
||||
menu,
|
||||
worldMenu,
|
||||
referal,
|
||||
jobs,
|
||||
chooseJob,
|
||||
casinoMenu,
|
||||
work,
|
||||
top,
|
||||
propertyList,
|
||||
propertyMenu,
|
||||
propertyBuy,
|
||||
propertySell,
|
||||
hatkeisList,
|
||||
organizationMenu,
|
||||
workoff,
|
||||
leaveOrg,
|
||||
leaveOrgAccept,
|
||||
payday,
|
||||
orgMessage,
|
||||
materialsBuy,
|
||||
percentSet,
|
||||
invite,
|
||||
inviteAction,
|
||||
report,
|
||||
slotsMenu,
|
||||
slotsRun,
|
||||
promocodeActivate,
|
||||
carContainers,
|
||||
chooseContainer,
|
||||
reportAnswer,
|
||||
fastblock,
|
||||
createPromo,
|
||||
genPromo,
|
||||
organizationCreate,
|
||||
shot,
|
||||
outmenu,
|
||||
lobbyCreate,
|
||||
lobbyMenu,
|
||||
garage,
|
||||
race
|
||||
} = require('./commands')
|
||||
const {
|
||||
spaces,
|
||||
spacesWithMarkdown,
|
||||
escape,
|
||||
generatePromo,
|
||||
generateVoucher,
|
||||
getCurrentTime,
|
||||
getSlot,
|
||||
giveExp,
|
||||
matPriceUpdate,
|
||||
rand,
|
||||
random,
|
||||
setCooldown,
|
||||
weaponShopUpdate,
|
||||
stats
|
||||
} = require('./utils')
|
||||
const {
|
||||
handleError
|
||||
} = require('./handlers')
|
||||
const sequelize = require('./db');
|
||||
const { Op } = require('sequelize');
|
||||
const fs = require('fs');
|
||||
const { createCanvas, loadImage } = require('canvas');
|
||||
} = global.config
|
||||
const bot = new Telegraf(process.env.BOT_TOKEN)
|
||||
const crime = require('./scenes/crime')
|
||||
const pocketsteal = require('./scenes/pocketsteal')
|
||||
@ -113,26 +31,18 @@ const newpve = require('./scenes/newpve')
|
||||
|
||||
const start = async () => {
|
||||
try {
|
||||
await sequelize.authenticate()
|
||||
await sequelize.sync()
|
||||
// Подключаемся к базе данных
|
||||
await sequelize.authenticate();
|
||||
console.log('Подключение к базе данных успешно!');
|
||||
|
||||
} catch (e) {
|
||||
console.log('Подключение к бд сломалось', e)
|
||||
}
|
||||
try {
|
||||
await sequelize.authenticate()
|
||||
await UserModel.sync({ alter: true })
|
||||
await WorldModel.sync({ alter: true })
|
||||
await JobModel.sync({ alter: true })
|
||||
await PropertyModel.sync({ alter: true })
|
||||
await BusinessModel.sync({ alter: true })
|
||||
await ReportModel.sync({ alter: true })
|
||||
await BlockModel.sync({ alter: true })
|
||||
await PromocodeModel.sync()
|
||||
await SkillsModel.sync({ alter: true })
|
||||
console.log('Синхронизация завершена',)
|
||||
// Синхронизация моделей, если нужно
|
||||
await sequelize.sync({ alter: true });
|
||||
console.log('Синхронизация моделей завершена.');
|
||||
|
||||
// Запуск бота
|
||||
console.log('Бот успешно запущен!');
|
||||
} catch (error) {
|
||||
console.log('Ошибка синхронизации', error)
|
||||
console.error('Ошибка при запуске приложения:', error);
|
||||
}
|
||||
}
|
||||
|
||||
@ -177,7 +87,7 @@ bot.use(
|
||||
})
|
||||
)
|
||||
bot.use(stage)
|
||||
bot.use(stats)
|
||||
bot.use(utils.stats)
|
||||
|
||||
bot.use(async (ctx, next) => {
|
||||
bot.context.config = require('./ctxconfig.json')
|
||||
@ -186,10 +96,10 @@ bot.use(async (ctx, next) => {
|
||||
if(username == null) username = ctx.from.id
|
||||
switch(ctx.updateType){
|
||||
case `message`:
|
||||
console.log(getCurrentTime() + `: ` + username + `: ` + ctx.update.message.text)
|
||||
console.log(utils.getCurrentTime() + `: ` + username + `: ` + ctx.update.message.text)
|
||||
break;
|
||||
case `callback_query`:
|
||||
console.log(getCurrentTime() + `: ${username}: ${ctx.update.callback_query.data}`)
|
||||
console.log(utils.getCurrentTime() + `: ${username}: ${ctx.update.callback_query.data}`)
|
||||
break;
|
||||
default:
|
||||
console.log(ctx)
|
||||
@ -297,15 +207,15 @@ bot.hears('промка', async(ctx) => {
|
||||
generatePromo()
|
||||
});
|
||||
|
||||
bot.hears('▶️ Меню', menu);
|
||||
bot.hears('▶️ Меню', commands.menu);
|
||||
|
||||
bot.hears('Чат', async (ctx) => {
|
||||
ctx.reply(`${ctx.message.chat.id}`)
|
||||
});
|
||||
|
||||
bot.hears('😎 Профиль', profile);
|
||||
bot.hears('😎 Профиль', commands.profile);
|
||||
|
||||
bot.command('getprofile', getprofile);
|
||||
bot.command('getprofile', commands.getprofile);
|
||||
|
||||
bot.hears('Рандом', async (ctx) => {
|
||||
let users = await UserModel.findAll();
|
||||
@ -331,72 +241,72 @@ bot.hears('💳 Баланс', async (ctx) => {
|
||||
`);
|
||||
})
|
||||
|
||||
bot.hears('🎁 Бонус', bonus)
|
||||
bot.hears('🎁 Бонус', commands.bonus)
|
||||
|
||||
bot.hears('Гараж', garage)
|
||||
bot.hears('Гараж', commands.garage)
|
||||
|
||||
bot.hears('Гонка', race)
|
||||
bot.hears('Гонка', commands.race)
|
||||
|
||||
bot.command('pay', pay)
|
||||
bot.command('pay', commands.pay)
|
||||
|
||||
bot.hears('Мир', worldMenu)
|
||||
bot.hears('Мир', commands.worldMenu)
|
||||
|
||||
bot.hears('📞 Пригласить', referal)
|
||||
bot.hears('📞 Пригласить', commands.referal)
|
||||
|
||||
bot.hears('📢 Вакансии', jobs)
|
||||
bot.hears('📢 Вакансии', commands.jobs)
|
||||
|
||||
bot.action(/job_(1|2|3|4|5|6|7|leave)/, chooseJob)
|
||||
bot.action(/job_(1|2|3|4|5|6|7|leave)/, commands.chooseJob)
|
||||
|
||||
bot.hears('🏯 Казино', casinoMenu)
|
||||
bot.hears('🏯 Казино', commands.casinoMenu)
|
||||
|
||||
bot.hears('🗄️ Работать', work)
|
||||
bot.hears('🗄️ Работать', commands.work)
|
||||
|
||||
bot.hears('Топ', top)
|
||||
bot.hears('Топ', commands.top)
|
||||
|
||||
bot.hears('🔵 Имущество', propertyMenu)
|
||||
bot.hears('🔵 Имущество', commands.propertyMenu)
|
||||
|
||||
bot.action('shopmenu', propertyMenu)
|
||||
bot.action('shopmenu', commands.propertyMenu)
|
||||
|
||||
bot.action(/shop_(house|phone|car)/, propertyList)
|
||||
bot.action(/shop_(house|phone|car)/, commands.propertyList)
|
||||
|
||||
bot.action(/{"action": "buy"*/, propertyBuy)
|
||||
bot.action(/{"action": "buy"*/, commands.propertyBuy)
|
||||
|
||||
bot.hears('Поставщик', hatkeisList)
|
||||
bot.hears('Поставщик', commands.hatkeisList)
|
||||
|
||||
bot.command('sell', propertySell)
|
||||
bot.command('sell', commands.propertySell)
|
||||
|
||||
bot.hears('🌐 Организация', organizationMenu)
|
||||
bot.hears('🌐 Организация', commands.organizationMenu)
|
||||
|
||||
bot.action('workoff', workoff)
|
||||
bot.action('workoff', commands.workoff)
|
||||
|
||||
bot.action('покинуть', leaveOrg)
|
||||
bot.action('покинуть', commands.leaveOrg)
|
||||
|
||||
bot.action('cancel', async (ctx) => {
|
||||
await ctx.deleteMessage()
|
||||
await bot.telegram.answerCbQuery(ctx.callbackQuery.id, `Отмена.`)
|
||||
})
|
||||
|
||||
bot.action('user_leave_business', leaveOrgAccept)
|
||||
bot.action('user_leave_business', commands.leaveOrgAccept)
|
||||
|
||||
bot.action('payday', payday)
|
||||
bot.action('payday', commands.payday)
|
||||
|
||||
bot.command('orgmessage', orgMessage)
|
||||
bot.command('orgmessage', commands.orgMessage)
|
||||
|
||||
bot.command('materials', materialsBuy)
|
||||
bot.command('materials', commands.materialsBuy)
|
||||
|
||||
bot.command('percent', percentSet)
|
||||
bot.command('percent', commands.percentSet)
|
||||
|
||||
bot.command('business', organizationCreate)
|
||||
bot.command('business', commands.organizationCreate)
|
||||
|
||||
bot.command('invite', invite)
|
||||
bot.command('invite', commands.invite)
|
||||
|
||||
bot.action(/{"type": "business_invite_(accept|refuse)"*/, inviteAction)
|
||||
bot.action(/{"type": "business_invite_(accept|refuse)"*/, commands.inviteAction)
|
||||
|
||||
bot.command('report', report)
|
||||
bot.command('report', commands.report)
|
||||
|
||||
bot.hears('🎰 Слоты', slotsMenu)
|
||||
bot.hears('🎰 Слоты', commands.slotsMenu)
|
||||
|
||||
bot.action(/slots(1000|5000|25000|50000|100000)/, slotsRun)
|
||||
bot.action(/slots(1000|5000|25000|50000|100000)/, commands.slotsRun)
|
||||
|
||||
bot.hears('Помощь', async (ctx) => {
|
||||
return await ctx.replyWithMarkdownV2(`• [Функционал](https://telegra.ph/CampFire-Bot-Info-09-25)\n• [Правила](https://telegra.ph/PRAVILA-BOTA-09-25)`, {
|
||||
@ -404,11 +314,11 @@ bot.hears('Помощь', async (ctx) => {
|
||||
})
|
||||
})
|
||||
|
||||
bot.command('promocode', promocodeActivate)
|
||||
bot.command('promocode', commands.promocodeActivate)
|
||||
|
||||
bot.hears('📦 Контейнеры', carContainers)
|
||||
bot.hears('📦 Контейнеры', commands.carContainers)
|
||||
|
||||
bot.action(/container_(1|2|3|4|5|6|7|8|9|10)/, chooseContainer)
|
||||
bot.action(/container_(1|2|3|4|5|6|7|8|9|10)/, commands.chooseContainer)
|
||||
|
||||
bot.action(/{"action": "sueta_*/, async (ctx) => {
|
||||
let data = ctx.update.callback_query.data;
|
||||
@ -436,86 +346,114 @@ bot.action(/{"action": "sueta_*/, async (ctx) => {
|
||||
|
||||
/////////////////////////////////////Enterprise Update 20.12.2024//////////////////////////////////////////////////
|
||||
|
||||
// Обновление меню "Предприятия"
|
||||
bot.hears('🏗️ Предприятия', async (ctx) => {
|
||||
return await ctx.reply(`
|
||||
Меню предприятий
|
||||
У вас: нет предприятий.
|
||||
Цены:
|
||||
const user = await UserModel.findByPk(ctx.from.id);
|
||||
const warehouse = await WarehouseModel.findOne({ where: { playerId: user.telegram_id } });
|
||||
|
||||
`, Markup
|
||||
.inlineKeyboard([
|
||||
[
|
||||
{text: 'Мои предприятия', callback_data: `my_enterprises`},
|
||||
{text: 'Построить', callback_data: `build_enterprise`},
|
||||
{text: 'Склад', callback_data: `open_warehouse`},
|
||||
]
|
||||
])
|
||||
.resize())
|
||||
})
|
||||
const enterprises = await EnterpriseModel.findAll({
|
||||
where: { playerId: user.telegram_id }
|
||||
});
|
||||
|
||||
let message = `🏗️ Меню предприятий:\n`;
|
||||
message += `У вас: ${enterprises.length} предприятий.\n`;
|
||||
message += warehouse
|
||||
? `🗄️ Единый склад: Доступен (Ёмкость: ${warehouse.capacity} ед.)\n`
|
||||
: `🗄️ Единый склад: Не построен.\n`;
|
||||
|
||||
bot.action('my_enterprises', async (ctx) => {
|
||||
let user = await UserModel.findByPk(ctx.from.id)
|
||||
let enterprises = await EnterpriseModel.findAll({
|
||||
where: {
|
||||
playerId: user.telegram_id
|
||||
const buttons = [];
|
||||
|
||||
// Добавляем кнопки для предприятий
|
||||
buttons.push([{ text: '🏭 Мои предприятия', callback_data: 'my_enterprises' }]);
|
||||
buttons.push([{ text: '🛠️ Построить предприятие', callback_data: 'build_enterprise' }]);
|
||||
|
||||
// Кнопка для управления или постройки склада
|
||||
if (warehouse) {
|
||||
buttons.push([{ text: '🚛 Управление складом', callback_data: 'manage_warehouse' }]);
|
||||
} else {
|
||||
buttons.push([{ text: '🗄️ Построить склад', callback_data: 'open_warehouse' }]);
|
||||
}
|
||||
})
|
||||
let message = `Ваши предприятия:\n`
|
||||
enterprises.forEach(enterprise => {
|
||||
message += `🏭 ${enterprise.name} (Тип: ${enterprise.resourceType}, Уровень: ${enterprise.level}, Производительность: ${enterprise.efficiency} ед/ч, Склад: ${enterprise.warehouseCapacity} ед.)\n`
|
||||
})
|
||||
if (enterprises.length === 0) {
|
||||
message += 'У вас нет предприятий.\n'
|
||||
}
|
||||
return await ctx.reply(message)
|
||||
})
|
||||
|
||||
// Возвращаем меню с кнопками
|
||||
return await ctx.reply(message, Markup.inlineKeyboard(buttons).resize());
|
||||
});
|
||||
|
||||
|
||||
// Функция для преобразования типа ресурса в эмодзи
|
||||
function getEnterpriseEmoji(resourceType) {
|
||||
const emojis = {
|
||||
wood: '🌳',
|
||||
coal: '⛏️',
|
||||
oil: '🛢️',
|
||||
metall: '⚒️',
|
||||
gold: '💰',
|
||||
diamond: '💎'
|
||||
}
|
||||
return emojis[resourceType] || '🏭'
|
||||
}
|
||||
|
||||
// Построение предприятия
|
||||
bot.action('build_enterprise', async (ctx) => {
|
||||
let user = await UserModel.findByPk(ctx.from.id)
|
||||
let enterprises = await EnterpriseModel.findAll({
|
||||
where: {
|
||||
playerId: user.telegram_id
|
||||
}
|
||||
})
|
||||
if (enterprises.length > 0) return await ctx.reply(`У вас уже есть предприятие.`)
|
||||
const user = await UserModel.findByPk(ctx.from.id);
|
||||
const enterprises = await EnterpriseModel.findAll({
|
||||
where: { playerId: user.telegram_id }
|
||||
});
|
||||
|
||||
let message = `Выберите тип предприятия (цена зависит от ресурса):`
|
||||
let buttons = []
|
||||
let types = ['wood', 'coal', 'oil', 'metall', 'gold', 'diamond']
|
||||
types.forEach(type => {
|
||||
let price = getResourcePrice(type) // Функция для получения стоимости
|
||||
buttons.push({text: `${type} (Цена: ${price} монет)`, callback_data: `build_${type}`})
|
||||
})
|
||||
return await ctx.reply(message, Markup.inlineKeyboard(buttons).resize())
|
||||
})
|
||||
|
||||
function getResourcePrice(resourceType) {
|
||||
const prices = {
|
||||
wood: 100,
|
||||
coal: 200,
|
||||
oil: 500,
|
||||
metall: 1000,
|
||||
gold: 3000,
|
||||
diamond: 5000
|
||||
}
|
||||
return prices[resourceType] || 0
|
||||
if (enterprises.length >= 5) {
|
||||
return await ctx.reply('Вы достигли максимального числа предприятий.');
|
||||
}
|
||||
|
||||
const resourcePrices = {
|
||||
wood: 10000,
|
||||
coal: 20000,
|
||||
oil: 50000,
|
||||
metall: 100000,
|
||||
gold: 300000,
|
||||
diamond: 500000
|
||||
};
|
||||
|
||||
let message = `🛠️ Постройка предприятия:\n`;
|
||||
for (const [resource, price] of Object.entries(resourcePrices)) {
|
||||
const resourceName = getResourceName(resource);
|
||||
message += `${resourceName}: ${price} монет\n`;
|
||||
}
|
||||
message += '\nВыберите тип предприятия:';
|
||||
|
||||
const buttons = [
|
||||
[
|
||||
{ text: '🌲', callback_data: 'build_wood' },
|
||||
{ text: '⛏️', callback_data: 'build_coal' }
|
||||
],
|
||||
[
|
||||
{ text: '🛢️', callback_data: 'build_oil' },
|
||||
{ text: '⚙️', callback_data: 'build_metall' }
|
||||
],
|
||||
[
|
||||
{ text: '🥇', callback_data: 'build_gold' },
|
||||
{ text: '💎', callback_data: 'build_diamond' }
|
||||
]
|
||||
];
|
||||
|
||||
return await ctx.reply(message, Markup.inlineKeyboard(buttons).resize());
|
||||
});
|
||||
|
||||
|
||||
// Построение предприятия по выбранному типу
|
||||
bot.action(/build_(wood|coal|oil|metall|gold|diamond)/, async (ctx) => {
|
||||
let user = await UserModel.findByPk(ctx.from.id)
|
||||
let data = ctx.update.callback_query.data
|
||||
let type = data.split('_')[1]
|
||||
let price = getResourcePrice(type)
|
||||
let price = getEnterprisePrice(type)
|
||||
|
||||
// Проверка, есть ли достаточно денег у пользователя
|
||||
if (user.balance < price) {
|
||||
return await ctx.reply(`У вас недостаточно средств для постройки предприятия. Необходимо ${price} монет.`)
|
||||
return await ctx.reply(`У вас недостаточно средств для постройки предприятия. Необходимо ${price} руб.`)
|
||||
}
|
||||
|
||||
// Строим предприятие
|
||||
let enterpriseName = `${user.username}'s ${getReadableType(type)}` // Название предприятия
|
||||
let enterprise = await EnterpriseModel.create({
|
||||
name: `${type} mine`,
|
||||
name: enterpriseName,
|
||||
resourceType: type,
|
||||
playerId: user.telegram_id,
|
||||
level: 1,
|
||||
@ -524,9 +462,187 @@ bot.action(/build_(wood|coal|oil|metall|gold|diamond)/, async (ctx) => {
|
||||
})
|
||||
|
||||
// Снимаем деньги с баланса
|
||||
await user.update({ balance: user.balance - price })
|
||||
await user.update({ money: user.money - price })
|
||||
|
||||
return await ctx.reply(`Предприятие ${enterprise.name} построено!`)
|
||||
return await ctx.reply(`Предприятие ${enterprise.name} (ID: ${enterprise.id}) построено!`)
|
||||
})
|
||||
|
||||
// Функция для расчета стоимости предприятия
|
||||
function getEnterprisePrice(resourceType) {
|
||||
const prices = {
|
||||
wood: 5000,
|
||||
coal: 10000,
|
||||
oil: 20000,
|
||||
metall: 50000,
|
||||
gold: 150000,
|
||||
diamond: 250000
|
||||
}
|
||||
return prices[resourceType] || 0
|
||||
}
|
||||
|
||||
// Функция для преобразования типа ресурса в читаемое название
|
||||
function getReadableType(type) {
|
||||
const names = {
|
||||
wood: 'Деревообрабатывающее предприятие',
|
||||
coal: 'Угольное предприятие',
|
||||
oil: 'Нефтяное предприятие',
|
||||
metall: 'Металлургическое предприятие',
|
||||
gold: 'Золотое предприятие',
|
||||
diamond: 'Алмазное предприятие'
|
||||
}
|
||||
return names[type] || type
|
||||
}
|
||||
|
||||
bot.action('buy_warehouse', async (ctx) => {
|
||||
let user = await UserModel.findByPk(ctx.from.id)
|
||||
if (user.money < 500000) {
|
||||
return await ctx.reply(`У вас недостаточно средств для покупки склада.`)
|
||||
}
|
||||
|
||||
await WarehouseModel.create({
|
||||
playerId: user.telegram_id,
|
||||
capacity: 1000, // Начальная ёмкость
|
||||
wood: 0,
|
||||
coal: 0,
|
||||
oil: 0,
|
||||
metall: 0,
|
||||
gold: 0,
|
||||
diamond: 0
|
||||
})
|
||||
|
||||
await user.update({ money: user.money - 500000 })
|
||||
return await ctx.reply(`Вы успешно купили единый склад!`)
|
||||
})
|
||||
|
||||
// Управление складом
|
||||
bot.action('manage_warehouse', async (ctx) => {
|
||||
const user = await UserModel.findByPk(ctx.from.id);
|
||||
const warehouse = await WarehouseModel.findOne({ where: { playerId: user.telegram_id } });
|
||||
|
||||
if (!warehouse) {
|
||||
return await ctx.reply('У вас нет склада для управления.');
|
||||
}
|
||||
|
||||
let message = `🚛 Управление складом:\n`;
|
||||
message += `Общая ёмкость: ${warehouse.capacity} ед.\n`;
|
||||
message += `Хранимые ресурсы:\n`;
|
||||
message += `🌲 Дерево: ${warehouse.wood || 0}\n`;
|
||||
message += `⛏️ Уголь: ${warehouse.coal || 0}\n`;
|
||||
message += `🛢️ Нефть: ${warehouse.oil || 0}\n`;
|
||||
message += `⚙️ Металл: ${warehouse.metall || 0}\n`;
|
||||
message += `🥇 Золото: ${warehouse.gold || 0}\n`;
|
||||
message += `💎 Алмазы: ${warehouse.diamond || 0}\n`;
|
||||
|
||||
const buttons = [
|
||||
[{ text: '➕ Перевести ресурсы', callback_data: 'transfer_resources' }],
|
||||
[{ text: '📤 Продать со склада', callback_data: 'sell_from_warehouse' }],
|
||||
[{ text: '🚚 Купить транспорт', callback_data: 'buy_truck' }]
|
||||
];
|
||||
|
||||
return await ctx.reply(message, Markup.inlineKeyboard(buttons).resize());
|
||||
});
|
||||
|
||||
bot.action('warehouse_management', async (ctx) => {
|
||||
let user = await UserModel.findByPk(ctx.from.id)
|
||||
let warehouse = await WarehouseModel.findOne({ where: { playerId: user.telegram_id } })
|
||||
|
||||
if (!warehouse) {
|
||||
return await ctx.reply(`У вас нет склада. Вы можете купить его за 500,000 руб.`, Markup.inlineKeyboard([
|
||||
[{ text: 'Купить склад', callback_data: 'buy_warehouse' }]
|
||||
]).resize())
|
||||
}
|
||||
|
||||
let message = `
|
||||
🏗️ Единый склад
|
||||
Емкость: ${warehouse.capacity} ед.
|
||||
Ресурсы:
|
||||
🌲 Дерево: ${warehouse.wood || 0}
|
||||
⛏️ Уголь: ${warehouse.coal || 0}
|
||||
🛢️ Нефть: ${warehouse.oil || 0}
|
||||
🛠️ Металл: ${warehouse.metall || 0}
|
||||
💰 Золото: ${warehouse.gold || 0}
|
||||
💎 Алмазы: ${warehouse.diamond || 0}
|
||||
`
|
||||
return await ctx.reply(message, Markup.inlineKeyboard([
|
||||
[{ text: 'Управление транспортом', callback_data: 'manage_trucks' }],
|
||||
[{ text: 'Продать ресурсы', callback_data: 'sell_from_warehouse' }]
|
||||
]).resize())
|
||||
})
|
||||
|
||||
// Управление предприятием
|
||||
bot.action(/manage_(\d+)/, async (ctx) => {
|
||||
let enterpriseId = ctx.match[1]
|
||||
let enterprise = await EnterpriseModel.findByPk(enterpriseId)
|
||||
|
||||
if (!enterprise) return await ctx.reply(`Предприятие не найдено.`)
|
||||
|
||||
// Логика управления предприятием (например, прокачка или продажа ресурсов)
|
||||
return await ctx.reply(`Вы управляете предприятием ${enterprise.name} (ID: ${enterprise.id}).`)
|
||||
})
|
||||
bot.action('transfer_resources', async (ctx) => {
|
||||
const user = await UserModel.findByPk(ctx.from.id);
|
||||
const warehouse = await WarehouseModel.findOne({ where: { playerId: user.telegram_id } });
|
||||
|
||||
if (!warehouse) {
|
||||
return await ctx.reply('У вас нет единого склада.');
|
||||
}
|
||||
|
||||
const enterprises = await EnterpriseModel.findAll({
|
||||
where: { playerId: user.telegram_id }
|
||||
});
|
||||
|
||||
let message = `➕ Перевозка ресурсов:\n`;
|
||||
message += `Общая ёмкость склада: ${warehouse.capacity} ед.\n`;
|
||||
message += `Выберите предприятие для перевозки ресурсов:`;
|
||||
|
||||
const buttons = enterprises.map(ent => {
|
||||
return [{ text: `🏭 ${ent.name}`, callback_data: `transfer_from_${ent.id}` }];
|
||||
});
|
||||
|
||||
return await ctx.reply(message, Markup.inlineKeyboard(buttons).resize());
|
||||
});
|
||||
|
||||
// Перевозка с конкретного предприятия
|
||||
bot.action(/transfer_from_(\d+)/, async (ctx) => {
|
||||
const enterpriseId = ctx.match[1];
|
||||
const user = await UserModel.findByPk(ctx.from.id);
|
||||
const warehouse = await WarehouseModel.findOne({ where: { playerId: user.telegram_id } });
|
||||
|
||||
const enterprise = await EnterpriseModel.findByPk(enterpriseId);
|
||||
if (!enterprise) {
|
||||
return await ctx.reply('Предприятие не найдено.');
|
||||
}
|
||||
|
||||
let message = `🚛 Перевозка с предприятия ${enterprise.name}:\n`;
|
||||
message += `🌲 Дерево: ${enterprise.wood || 0}\n`;
|
||||
message += `⛏️ Уголь: ${enterprise.coal || 0}\n`;
|
||||
message += `🛢️ Нефть: ${enterprise.oil || 0}\n`;
|
||||
message += `⚙️ Металл: ${enterprise.metall || 0}\n`;
|
||||
message += `🥇 Золото: ${enterprise.gold || 0}\n`;
|
||||
message += `💎 Алмазы: ${enterprise.diamond || 0}\n`;
|
||||
message += `\nВведите количество ресурса для перевозки.`;
|
||||
|
||||
return await ctx.reply(message);
|
||||
});
|
||||
|
||||
bot.command('ent_rename', async (ctx) => {
|
||||
let args = ctx.message.text.split(' ').slice(1)
|
||||
if (args.length < 2) {
|
||||
return await ctx.reply('Использование: /ent_rename <ID> <Новое название>')
|
||||
}
|
||||
|
||||
let enterpriseId = parseInt(args[0])
|
||||
let newName = args.slice(1).join(' ')
|
||||
|
||||
let enterprise = await EnterpriseModel.findByPk(enterpriseId)
|
||||
if (!enterprise) {
|
||||
return await ctx.reply(`Предприятие с ID ${enterpriseId} не найдено.`)
|
||||
}
|
||||
|
||||
// Переименовываем предприятие
|
||||
await enterprise.update({ name: newName })
|
||||
|
||||
return await ctx.reply(`Предприятие (ID: ${enterprise.id}) переименовано в "${newName}".`)
|
||||
})
|
||||
|
||||
bot.action('upgrade_enterprise', async (ctx) => {
|
||||
@ -620,20 +736,6 @@ bot.action(/sell_(\d+)/, async (ctx) => {
|
||||
return await ctx.reply(`Вы продали все ресурсы с ${enterprise.name} за ${totalSale} монет.`)
|
||||
})
|
||||
|
||||
bot.action('open_warehouse', async (ctx) => {
|
||||
let user = await UserModel.findByPk(ctx.from.id)
|
||||
let warehouse = await WarehouseModel.findOne({ where: { playerId: user.telegram_id } })
|
||||
|
||||
if (warehouse) return await ctx.reply(`У вас уже есть склад.`)
|
||||
|
||||
let newWarehouse = await WarehouseModel.create({
|
||||
playerId: user.telegram_id,
|
||||
capacity: 500 // Начальная ёмкость склада
|
||||
})
|
||||
|
||||
return await ctx.reply(`Вы открыли новый склад!`)
|
||||
})
|
||||
|
||||
bot.action('hire_truck', async (ctx) => {
|
||||
let user = await UserModel.findByPk(ctx.from.id)
|
||||
let warehouse = await WarehouseModel.findOne({ where: { playerId: user.telegram_id } })
|
||||
@ -650,18 +752,54 @@ bot.action('hire_truck', async (ctx) => {
|
||||
return await ctx.reply(`Вы наняли грузовик для транспортировки ресурсов!`)
|
||||
})
|
||||
|
||||
async function initializeResourcePrices() {
|
||||
const resources = [
|
||||
{ resourceType: 'wood', basePrice: 100, recoveryRate: 1 },
|
||||
{ resourceType: 'coal', basePrice: 200, recoveryRate: 2 },
|
||||
{ resourceType: 'oil', basePrice: 500, recoveryRate: 5 },
|
||||
{ resourceType: 'metall', basePrice: 1000, recoveryRate: 10 },
|
||||
{ resourceType: 'gold', basePrice: 3000, recoveryRate: 15 },
|
||||
{ resourceType: 'diamond', basePrice: 5000, recoveryRate: 20 }
|
||||
]
|
||||
|
||||
for (let resource of resources) {
|
||||
await ResourcePriceModel.findOrCreate({
|
||||
where: { resourceType: resource.resourceType },
|
||||
defaults: {
|
||||
currentPrice: resource.basePrice,
|
||||
basePrice: resource.basePrice,
|
||||
recoveryRate: resource.recoveryRate
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
initializeResourcePrices()
|
||||
|
||||
setInterval(async () => {
|
||||
const resources = await ResourcePriceModel.findAll()
|
||||
for (let resource of resources) {
|
||||
if (resource.currentPrice < resource.basePrice) {
|
||||
resource.currentPrice += resource.recoveryRate
|
||||
if (resource.currentPrice > resource.basePrice) {
|
||||
resource.currentPrice = resource.basePrice
|
||||
}
|
||||
await resource.save()
|
||||
}
|
||||
}
|
||||
}, 60000) // Обновляем цены каждые 60 секунд
|
||||
|
||||
/////////////////////////////////////Enterprise Update end//////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////Admin Commands//////////////////////////////////////////////////
|
||||
|
||||
|
||||
bot.command('answer', reportAnswer)
|
||||
bot.command('answer', commands.reportAnswer)
|
||||
|
||||
bot.command('fastblock', fastblock)
|
||||
bot.command('fastblock', commands.fastblock)
|
||||
|
||||
bot.command('createpromocode', createPromo)
|
||||
bot.command('createpromocode', commands.createPromo)
|
||||
|
||||
bot.command('genpromo', genPromo)
|
||||
bot.command('genpromo', commands.genPromo)
|
||||
|
||||
///////////////////////////////////////Functions//////////////////////////////////////////////////////
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
const {
|
||||
UserModel,
|
||||
PromocodeModel
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
const {
|
||||
generateVoucher
|
||||
} = require('/dev/Telegram/CampFireGameBot/utils')
|
||||
} = global.utils
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
let user = await UserModel.findByPk(ctx.from.id)
|
||||
|
@ -5,7 +5,7 @@ const bot = new Telegraf(process.env.BOT_TOKEN)
|
||||
const {
|
||||
UserModel,
|
||||
BlockModel
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
let user = await UserModel.findByPk(ctx.from.id)
|
||||
|
@ -2,10 +2,10 @@ const voucher_codes = require('voucher-code-generator');
|
||||
const {
|
||||
UserModel,
|
||||
PromocodeModel
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
const {
|
||||
generateVoucher
|
||||
} = require('/dev/Telegram/CampFireGameBot/utils')
|
||||
} = global.utils
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
let user = await UserModel.findByPk(ctx.from.id)
|
||||
|
@ -5,7 +5,7 @@ const bot = new Telegraf(process.env.BOT_TOKEN)
|
||||
const {
|
||||
UserModel,
|
||||
ReportModel
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
let user = await UserModel.findByPk(ctx.from.id)
|
||||
|
@ -2,7 +2,7 @@ const {
|
||||
UserModel,
|
||||
WorldModel,
|
||||
BusinessModel
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
const {
|
||||
rand,
|
||||
setCooldown
|
||||
|
@ -3,10 +3,10 @@ const {
|
||||
simplecars,
|
||||
UserModel,
|
||||
PropertyModel
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
const {
|
||||
spaces
|
||||
} = require('/dev/Telegram/CampFireGameBot/utils')
|
||||
} = global.utils
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
let data = ctx.update.callback_query.data;
|
||||
|
@ -1,6 +1,6 @@
|
||||
const {
|
||||
UserModel
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
let user = await UserModel.findByPk(ctx.from.id)
|
||||
|
@ -2,13 +2,13 @@ const {
|
||||
slots,
|
||||
UserModel,
|
||||
WorldModel
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
const {
|
||||
spaces,
|
||||
getSlot,
|
||||
giveExp,
|
||||
setCooldown
|
||||
} = require('/dev/Telegram/CampFireGameBot/utils')
|
||||
} = global.utils
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
let data = ctx.update.callback_query.data;
|
||||
|
@ -3,7 +3,7 @@ const {
|
||||
} = require('telegraf')
|
||||
const {
|
||||
UserModel
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
let user = await UserModel.findByPk(ctx.from.id)
|
||||
|
@ -27,7 +27,7 @@ const {
|
||||
adminList,
|
||||
expToUp,
|
||||
topSym
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
const {
|
||||
spaces,
|
||||
spacesWithMarkdown,
|
||||
@ -43,7 +43,7 @@ const {
|
||||
setCooldown,
|
||||
weaponShopUpdate,
|
||||
stats
|
||||
} = require('/dev/Telegram/CampFireGameBot/utils')
|
||||
} = global.utils
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
// Получаем контекст canvas
|
||||
|
@ -2,7 +2,7 @@ const {
|
||||
UserModel,
|
||||
PropertyModel,
|
||||
expToUp
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
const {
|
||||
spacesWithMarkdown,
|
||||
escape
|
||||
|
@ -2,7 +2,7 @@ const {
|
||||
UserModel,
|
||||
PropertyModel,
|
||||
expToUp
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
const {
|
||||
spacesWithMarkdown,
|
||||
escape
|
||||
|
@ -20,7 +20,7 @@ const {
|
||||
adminList,
|
||||
expToUp,
|
||||
topSym
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
const {
|
||||
spaces,
|
||||
spacesWithMarkdown,
|
||||
|
@ -1,8 +1,3 @@
|
||||
const {
|
||||
UserModel,
|
||||
JobModel
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
let data = ctx.update.callback_query.data;
|
||||
let user = await UserModel.findByPk(ctx.from.id);
|
||||
|
@ -1,13 +1,3 @@
|
||||
const {
|
||||
UserModel,
|
||||
WorldModel,
|
||||
JobModel
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
const {
|
||||
giveExp,
|
||||
setCooldown
|
||||
} = require('/dev/Telegram/CampFireGameBot/utils')
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
let user = await UserModel.findByPk(ctx.from.id);
|
||||
let job = await JobModel.findByPk(user.job);
|
||||
|
@ -5,10 +5,11 @@ const {
|
||||
module.exports = async (ctx) => {
|
||||
return await ctx.reply('Main Menu', Markup
|
||||
.keyboard([
|
||||
['😎 Профиль'],
|
||||
['🗄️ Работать', '🌐 Организация', '🎁 Бонус', '🏯 Казино'],
|
||||
['😎 Профиль'], // Row1 with 2 buttons
|
||||
['🗄️ Работать', '🌐 Организация', '🎁 Бонус', '🏯 Казино'], // Row2 with 2 buttons
|
||||
['🏗️ Предприятия'],
|
||||
['📦 Контейнеры'],
|
||||
['📢 Вакансии', '🔵 Имущество', '📞 Пригласить']
|
||||
['📢 Вакансии', '🔵 Имущество', '📞 Пригласить'] // Row3 with 3 buttons
|
||||
])
|
||||
.resize()
|
||||
)
|
||||
|
@ -6,7 +6,7 @@ const bot = new Telegraf(process.env.BOT_TOKEN)
|
||||
const {
|
||||
UserModel,
|
||||
BusinessModel
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
ctx.args = ctx.update.message.text.split(' ')
|
||||
|
@ -1,9 +1,9 @@
|
||||
const sequelize = require('/workspace/degradin/Dev/Telegram/CampFire Play/db');
|
||||
const sequelize = global.database
|
||||
const { Op } = require('sequelize');
|
||||
const {
|
||||
UserModel,
|
||||
BusinessModel
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
let data = ctx.update.callback_query.data;
|
||||
|
@ -6,7 +6,7 @@ const bot = new Telegraf(process.env.BOT_TOKEN)
|
||||
const {
|
||||
UserModel,
|
||||
BusinessModel
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
let user = await UserModel.findByPk(ctx.from.id)
|
||||
|
@ -5,7 +5,7 @@ const bot = new Telegraf(process.env.BOT_TOKEN)
|
||||
const {
|
||||
UserModel,
|
||||
BusinessModel
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
let data = ctx.update.callback_query.data;
|
||||
|
@ -2,7 +2,7 @@ const {
|
||||
UserModel,
|
||||
WorldModel,
|
||||
BusinessModel
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
ctx.args = ctx.update.message.text.split(' ')
|
||||
|
@ -5,7 +5,7 @@ const bot = new Telegraf(process.env.BOT_TOKEN)
|
||||
const {
|
||||
UserModel,
|
||||
BusinessModel
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
if (!ctx.args[1]) return ctx.reply(`Не указан аргумент.`)
|
||||
|
@ -2,7 +2,7 @@ const {
|
||||
UserModel,
|
||||
WorldModel,
|
||||
BusinessModel
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
let user = await UserModel.findByPk(ctx.from.id)
|
||||
|
@ -4,11 +4,11 @@ const {
|
||||
const {
|
||||
UserModel,
|
||||
BusinessModel
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
const {
|
||||
spaces,
|
||||
escape
|
||||
} = require('/dev/Telegram/CampFireGameBot/utils')
|
||||
} = global.utils
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
let user = await UserModel.findByPk(ctx.from.id)
|
||||
|
@ -6,12 +6,12 @@ const {
|
||||
UserModel,
|
||||
WorldModel,
|
||||
BusinessModel
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
const {
|
||||
spaces,
|
||||
giveExp,
|
||||
rand
|
||||
} = require('/dev/Telegram/CampFireGameBot/utils')
|
||||
} = global.utils
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
let user = null
|
||||
|
@ -1,7 +1,7 @@
|
||||
const {
|
||||
UserModel,
|
||||
BusinessModel
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
ctx.args = ctx.update.message.text.split(' ')
|
||||
|
@ -1,12 +1,12 @@
|
||||
const {
|
||||
UserModel,
|
||||
BusinessModel
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
const {
|
||||
spaces,
|
||||
escape,
|
||||
setCooldown
|
||||
} = require('/dev/Telegram/CampFireGameBot/utils')
|
||||
} = global.utils
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
let user = await UserModel.findByPk(ctx.from.id)
|
||||
|
@ -5,7 +5,7 @@ const bot = new Telegraf(process.env.BOT_TOKEN)
|
||||
const {
|
||||
UserModel,
|
||||
WorldModel
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
ctx.args = ctx.update.message.text.split(' ')
|
||||
|
@ -2,7 +2,7 @@ const {
|
||||
UserModel,
|
||||
PropertyModel,
|
||||
expToUp
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
const {
|
||||
spacesWithMarkdown,
|
||||
escape
|
||||
|
@ -6,7 +6,7 @@ const {
|
||||
UserModel,
|
||||
PromocodeModel,
|
||||
adminList
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
const {
|
||||
spaces
|
||||
} = require('../utils')
|
||||
|
@ -3,12 +3,12 @@ const {
|
||||
} = require('telegraf')
|
||||
const {
|
||||
weaponshop
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
const {
|
||||
spaces,
|
||||
escape,
|
||||
weaponShopUpdate
|
||||
} = require('/dev/Telegram/CampFireGameBot/utils')
|
||||
} = global.utils
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
let text = `[Hatkeis Gunsmith](https://telegra.ph/Hatkeis-Gunsmith-09-27)\n`
|
||||
|
@ -20,7 +20,7 @@ const {
|
||||
adminList,
|
||||
expToUp,
|
||||
topSym
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
const {
|
||||
spaces,
|
||||
spacesWithMarkdown,
|
||||
@ -36,7 +36,7 @@ const {
|
||||
setCooldown,
|
||||
weaponShopUpdate,
|
||||
stats
|
||||
} = require('/dev/Telegram/CampFireGameBot/utils')
|
||||
} = global.utils
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
let data = ctx.update.callback_query.data;
|
||||
|
@ -5,7 +5,7 @@ const {
|
||||
houses,
|
||||
cars,
|
||||
phones
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
let data = ctx.update.callback_query.data;
|
||||
|
@ -3,7 +3,7 @@ const {
|
||||
} = require('telegraf')
|
||||
const {
|
||||
UserModel
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
let user = await UserModel.findByPk(ctx.from.id);
|
||||
|
@ -20,7 +20,7 @@ const {
|
||||
adminList,
|
||||
expToUp,
|
||||
topSym
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
const {
|
||||
spaces,
|
||||
spacesWithMarkdown,
|
||||
@ -36,7 +36,7 @@ const {
|
||||
setCooldown,
|
||||
weaponShopUpdate,
|
||||
stats
|
||||
} = require('/dev/Telegram/CampFireGameBot/utils')
|
||||
} = global.utils
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
ctx.args = ctx.update.message.text.split(' ')
|
||||
|
@ -1,14 +1,14 @@
|
||||
const sequelize = require('/workspace/degradin/Dev/Telegram/CampFire Play/db');
|
||||
const sequelize = global.database
|
||||
const {
|
||||
rarecars,
|
||||
simplecars,
|
||||
UserModel,
|
||||
PropertyModel
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
const {
|
||||
spaces,
|
||||
rand
|
||||
} = require('/dev/Telegram/CampFireGameBot/utils')
|
||||
} = global.utils
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
let user = await UserModel.findByPk(ctx.from.id)
|
||||
|
@ -7,7 +7,7 @@ const {
|
||||
UserModel,
|
||||
ReportModel,
|
||||
adminList
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
const shortid = require('shortid');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
|
@ -1,11 +1,11 @@
|
||||
const {
|
||||
UserModel,
|
||||
topSym
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
const {
|
||||
spaces
|
||||
} = require('/dev/Telegram/CampFireGameBot/utils')
|
||||
const sequelize = require('../db');
|
||||
} = global.utils
|
||||
const sequelize = global.database
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
|
@ -1,6 +1,6 @@
|
||||
const {
|
||||
WorldModel
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
const {
|
||||
spaces
|
||||
} = require('../utils')
|
||||
|
21
db.js
21
db.js
@ -1,13 +1,16 @@
|
||||
const { Sequelize } = require('sequelize');
|
||||
|
||||
module.exports = new Sequelize(
|
||||
'campfire',
|
||||
'bot',
|
||||
'Ka23ds05!',
|
||||
// Использование переменных окружения для конфиденциальных данных
|
||||
const sequelize = new Sequelize(
|
||||
process.env.DB_NAME, // Название базы данных
|
||||
process.env.DB_USER, // Пользователь
|
||||
process.env.DB_PASSWORD, // Пароль
|
||||
{
|
||||
host: 'localhost',
|
||||
port: '5432',
|
||||
dialect: 'postgres',
|
||||
logging: false
|
||||
host: process.env.DB_HOST, // Хост
|
||||
port: process.env.DB_PORT, // Порт
|
||||
dialect: 'postgres', // Диалект базы данных
|
||||
logging: false, // Отключение логирования запросов в консоль
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
module.exports = sequelize;
|
||||
|
11
index.js
11
index.js
@ -1,2 +1,11 @@
|
||||
require('dotenv').config()
|
||||
require('dotenv').config();
|
||||
const sequelize = require('./db'); // Подключение базы данных
|
||||
|
||||
// Настраиваем глобальные переменные (опционально)
|
||||
global.path = require('path');
|
||||
global.config = require('./config'); // Конфигурация
|
||||
global.database = sequelize; // База данных
|
||||
global.utils = require('./utils');
|
||||
|
||||
// Инициализация бота
|
||||
require('./bot')
|
@ -25,7 +25,7 @@ const Enterprise = sequelize.define('enterprise', {
|
||||
playerId: {
|
||||
type: Sequelize.INTEGER,
|
||||
references: {
|
||||
model: 'Users',
|
||||
model: 'users',
|
||||
key: 'telegram_id'
|
||||
}
|
||||
}
|
||||
|
32
models/resourceprice.model.js
Normal file
32
models/resourceprice.model.js
Normal file
@ -0,0 +1,32 @@
|
||||
const sequelize = require('../db');
|
||||
const {DataTypes} = require('sequelize');
|
||||
|
||||
const ResourcePriceModel = sequelize.define('resource_price', {
|
||||
resource: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
unique: true, // Уникальное значение для каждого ресурса
|
||||
},
|
||||
price: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
defaultValue: 0, // Базовая цена
|
||||
},
|
||||
basePrice: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
defaultValue: 0, // Цена, к которой возвращается при восстановлении
|
||||
},
|
||||
fluctuationRate: {
|
||||
type: DataTypes.FLOAT,
|
||||
allowNull: false,
|
||||
defaultValue: 0.1, // Коэффициент изменения цены при продаже
|
||||
},
|
||||
recoveryRate: {
|
||||
type: DataTypes.FLOAT,
|
||||
allowNull: false,
|
||||
defaultValue: 0.01, // Коэффициент восстановления цены
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = ResourcePriceModel;
|
@ -1,31 +1,12 @@
|
||||
const sequelize = require('../db');
|
||||
const {Sequelize} = require('sequelize');
|
||||
const {DataTypes} = require('sequelize');
|
||||
|
||||
const Sale = sequelize.define('sale', {
|
||||
enterpriseId: {
|
||||
type: Sequelize.INTEGER,
|
||||
references: {
|
||||
model: 'Enterprises',
|
||||
key: 'id'
|
||||
}
|
||||
},
|
||||
resourceType: {
|
||||
type: Sequelize.STRING, // тип ресурса
|
||||
allowNull: false
|
||||
},
|
||||
quantity: {
|
||||
type: Sequelize.INTEGER, // количество продаваемого ресурса
|
||||
defaultValue: 0
|
||||
},
|
||||
salePrice: {
|
||||
type: Sequelize.FLOAT, // цена за единицу ресурса
|
||||
defaultValue: 100
|
||||
},
|
||||
time: {
|
||||
type: Sequelize.DATE, // время продажи
|
||||
defaultValue: Sequelize.NOW
|
||||
}
|
||||
});
|
||||
resourceType: DataTypes.STRING,
|
||||
currentPrice: DataTypes.FLOAT,
|
||||
basePrice: DataTypes.FLOAT,
|
||||
recoveryRate: DataTypes.FLOAT // Скорость восстановления цены к базовой
|
||||
})
|
||||
|
||||
|
||||
module.exports = Sale;
|
||||
|
@ -1,40 +1,21 @@
|
||||
const sequelize = require('../db');
|
||||
const {Sequelize} = require('sequelize');
|
||||
const {DataTypes} = require('sequelize');
|
||||
|
||||
const Warehouse = sequelize.define('warehouse', {
|
||||
playerId: {
|
||||
type: Sequelize.INTEGER,
|
||||
references: {
|
||||
model: 'Users',
|
||||
key: 'id'
|
||||
}
|
||||
},
|
||||
capacity: {
|
||||
type: Sequelize.INTEGER, // ёмкость общего склада
|
||||
defaultValue: 500
|
||||
},
|
||||
logisticsLevel: {
|
||||
type: Sequelize.INTEGER, // уровень логистики
|
||||
defaultValue: 1
|
||||
}
|
||||
});
|
||||
playerId: DataTypes.INTEGER,
|
||||
capacity: DataTypes.INTEGER, // Общая ёмкость склада
|
||||
wood: DataTypes.INTEGER,
|
||||
coal: DataTypes.INTEGER,
|
||||
oil: DataTypes.INTEGER,
|
||||
metall: DataTypes.INTEGER,
|
||||
gold: DataTypes.INTEGER,
|
||||
diamond: DataTypes.INTEGER,
|
||||
})
|
||||
|
||||
const Truck = sequelize.define('truck', {
|
||||
warehouseId: {
|
||||
type: Sequelize.INTEGER,
|
||||
references: {
|
||||
model: 'Warehouses',
|
||||
key: 'id'
|
||||
}
|
||||
},
|
||||
capacity: {
|
||||
type: Sequelize.INTEGER, // сколько ресурсов грузовик может вывозить в час
|
||||
defaultValue: 10
|
||||
},
|
||||
efficiency: {
|
||||
type: Sequelize.INTEGER, // эффективность грузовика (на сколько быстрее он может работать)
|
||||
defaultValue: 1
|
||||
}
|
||||
});
|
||||
warehouseId: DataTypes.INTEGER,
|
||||
capacity: DataTypes.INTEGER, // Сколько может перевезти за час
|
||||
efficiency: DataTypes.INTEGER // Частота транспортировки (количество операций в час)
|
||||
})
|
||||
|
||||
module.exports = Warehouse, Truck;
|
||||
|
25
package-lock.json
generated
25
package-lock.json
generated
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "telegram-bot-course",
|
||||
"version": "1.0.0",
|
||||
"name": "campfiregamebot",
|
||||
"version": "0.0.2",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "telegram-bot-course",
|
||||
"version": "1.0.0",
|
||||
"name": "campfiregamebot",
|
||||
"version": "0.0.2",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"dotenv": "^16.4.7",
|
||||
@ -17,6 +17,7 @@
|
||||
"pg-hstore": "^2.3.3",
|
||||
"pm2": "^5.3.0",
|
||||
"sequelize": "^6.6.2",
|
||||
"shortid": "^2.2.16",
|
||||
"telegraf": "^4.13.1",
|
||||
"uuid": "^9.0.1",
|
||||
"voucher-code-generator": "^1.3.0"
|
||||
@ -1158,6 +1159,12 @@
|
||||
"integrity": "sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==",
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/nanoid": {
|
||||
"version": "2.1.11",
|
||||
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-2.1.11.tgz",
|
||||
"integrity": "sha512-s/snB+WGm6uwi0WjsZdaVcuf3KJXlfGl2LcxgwkEwJF0D/BWzVWAZW/XY4bFaiR7s0Jk3FPvlnepg1H1b1UwlA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/needle": {
|
||||
"version": "2.4.0",
|
||||
"resolved": "https://registry.npmjs.org/needle/-/needle-2.4.0.tgz",
|
||||
@ -1883,6 +1890,16 @@
|
||||
"integrity": "sha512-sQTKC1Re/rM6XyFM6fIAGHRPVGvyXfgzIDvzoq608vM+jeyVD0Tu1E6Np0Kc2zAIFWIj963V2800iF/9LPieQw==",
|
||||
"license": "BSD-2-Clause"
|
||||
},
|
||||
"node_modules/shortid": {
|
||||
"version": "2.2.16",
|
||||
"resolved": "https://registry.npmjs.org/shortid/-/shortid-2.2.16.tgz",
|
||||
"integrity": "sha512-Ugt+GIZqvGXCIItnsL+lvFJOiN7RYqlGy7QE41O3YC1xbNSeDGIRO7xg2JJXIAj1cAGnOeC1r7/T9pgrtQbv4g==",
|
||||
"deprecated": "Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"nanoid": "^2.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/signal-exit": {
|
||||
"version": "3.0.7",
|
||||
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz",
|
||||
|
13
package.json
13
package.json
@ -1,14 +1,14 @@
|
||||
{
|
||||
"name": "telegram-bot-course",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"name": "campfiregamebot",
|
||||
"version": "0.0.2",
|
||||
"description": "CampFire Game Telegram Bot",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"dev": "nodemon index.js",
|
||||
"start": "node index.js"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"author": "Degradin",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"dotenv": "^16.4.7",
|
||||
@ -19,8 +19,13 @@
|
||||
"pg-hstore": "^2.3.3",
|
||||
"pm2": "^5.3.0",
|
||||
"sequelize": "^6.6.2",
|
||||
"shortid": "^2.2.16",
|
||||
"telegraf": "^4.13.1",
|
||||
"uuid": "^9.0.1",
|
||||
"voucher-code-generator": "^1.3.0"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://git.campfiregg.ru/degradin/CampFirePlay"
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ const {
|
||||
WorldModel,
|
||||
SkillsModel,
|
||||
PropertyModel
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
const {
|
||||
spaces,
|
||||
getSlot,
|
||||
@ -19,7 +19,7 @@ const {
|
||||
rand,
|
||||
random,
|
||||
setCooldown
|
||||
} = require('/dev/Telegram/CampFireGameBot/utils');
|
||||
} = global.utils;
|
||||
const crime = new Scenes.BaseScene('Crime');
|
||||
|
||||
crime.enter( async (ctx) => {
|
||||
|
@ -11,7 +11,7 @@ UserModel,
|
||||
WorldModel,
|
||||
SkillsModel,
|
||||
PropertyModel
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
const {
|
||||
spaces,
|
||||
getSlot,
|
||||
@ -20,7 +20,7 @@ rand,
|
||||
random,
|
||||
setCooldown,
|
||||
drop
|
||||
} = require('/dev/Telegram/CampFireGameBot/utils');
|
||||
} = global.utils;
|
||||
const newpve = new Scenes.BaseScene('NEWPVE');
|
||||
const resultTier = [
|
||||
{hit: 'Head', droprate: 10},
|
||||
|
@ -11,7 +11,7 @@ UserModel,
|
||||
WorldModel,
|
||||
SkillsModel,
|
||||
PropertyModel
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
const {
|
||||
spaces,
|
||||
getSlot,
|
||||
@ -19,7 +19,7 @@ giveExp,
|
||||
rand,
|
||||
random,
|
||||
setCooldown
|
||||
} = require('/dev/Telegram/CampFireGameBot/utils');
|
||||
} = global.utils;
|
||||
const steal = new Scenes.BaseScene('POCKET_STEAL');
|
||||
|
||||
steal.enter(async (ctx) => {
|
||||
|
@ -11,7 +11,7 @@ UserModel,
|
||||
WorldModel,
|
||||
SkillsModel,
|
||||
PropertyModel
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
const {
|
||||
spaces,
|
||||
getSlot,
|
||||
@ -20,7 +20,7 @@ rand,
|
||||
random,
|
||||
setCooldown,
|
||||
drop
|
||||
} = require('/dev/Telegram/CampFireGameBot/utils');
|
||||
} = global.utils;
|
||||
const pve = new Scenes.BaseScene('PVE');
|
||||
|
||||
pve.enter(async (ctx) => {
|
||||
|
@ -11,7 +11,7 @@ UserModel,
|
||||
WorldModel,
|
||||
SkillsModel,
|
||||
PropertyModel
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
const {
|
||||
spaces,
|
||||
getSlot,
|
||||
@ -19,7 +19,7 @@ giveExp,
|
||||
rand,
|
||||
random,
|
||||
setCooldown
|
||||
} = require('/dev/Telegram/CampFireGameBot/utils');
|
||||
} = global.utils;
|
||||
const shop = new Scenes.BaseScene('SHOP_ROBBERY');
|
||||
|
||||
bot.on('callback_query', (ctx) => {
|
||||
|
@ -5,7 +5,7 @@ const bot = new Telegraf(process.env.BOT_TOKEN)
|
||||
const {
|
||||
PromocodeModel,
|
||||
mainChat
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
const voucher_codes = require('voucher-code-generator');
|
||||
const rand = require('./rand')
|
||||
const generateVoucher = require('./generateVoucher');
|
||||
|
@ -4,7 +4,7 @@ const {
|
||||
const bot = new Telegraf(process.env.BOT_TOKEN)
|
||||
const {
|
||||
expToUp
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
|
||||
|
||||
module.exports = async (user, experience) => {
|
||||
|
@ -1,7 +1,7 @@
|
||||
const rand = require('./rand')
|
||||
const {
|
||||
WorldModel
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
|
||||
module.exports = async () => {
|
||||
let world = await WorldModel.findByPk(1)
|
||||
|
@ -12,7 +12,7 @@ const rtOP = io.metric({
|
||||
})
|
||||
|
||||
// const usersCountIO = io.metric({
|
||||
// name: 'Users count',
|
||||
// name: 'global.User count',
|
||||
// unit: 'user'
|
||||
// })
|
||||
|
||||
|
@ -3,7 +3,7 @@ const {
|
||||
weaponshop,
|
||||
weapons,
|
||||
equipment,
|
||||
} = require('/dev/Telegram/CampFireGameBot/config')
|
||||
} = global.config
|
||||
const fs = require('fs');
|
||||
|
||||
module.exports = () => {
|
||||
|
Loading…
Reference in New Issue
Block a user