v0.4
This commit is contained in:
parent
3e7c7942ce
commit
2aef26854f
129
bot.js
129
bot.js
@ -22,6 +22,7 @@ const {
|
||||
SaleModel,
|
||||
ResourcePriceModel,
|
||||
SkillsModel,
|
||||
DailyModel
|
||||
} = global.config
|
||||
const bot = new Telegraf(process.env.BOT_TOKEN)
|
||||
const crime = require('./scenes/crime')
|
||||
@ -357,6 +358,105 @@ bot.action(/{"action": "sueta_*/, async (ctx) => {
|
||||
property.save()
|
||||
})
|
||||
|
||||
bot.action(/dissolve_organization_(\d+)/, async (ctx) => {
|
||||
try {
|
||||
const businessId = parseInt(ctx.match[1], 10);
|
||||
const business = await BusinessModel.findByPk(businessId);
|
||||
console.log(businessId + " " + business.owner)
|
||||
if (!business) {
|
||||
return ctx.answerCbQuery('Организация не найдена.', { show_alert: true });
|
||||
}
|
||||
|
||||
const user = await UserModel.findByPk(ctx.from.id);
|
||||
|
||||
if (business.owner != ctx.from.id) {
|
||||
return ctx.answerCbQuery('Только владелец может ликвидировать организацию.', { show_alert: true });
|
||||
}
|
||||
|
||||
// Расчет и передача 25% от баланса владельцу
|
||||
const payout = Math.floor(business.balance * 0.25);
|
||||
user.money += payout;
|
||||
user.business = { id: 0, checks: 0, percent: 0 };
|
||||
await user.save();
|
||||
|
||||
// Сброс бизнес-данных у участников
|
||||
const members = await UserModel.findAll({
|
||||
where: {
|
||||
'business.id': businessId,
|
||||
},
|
||||
});
|
||||
|
||||
for (const member of members) {
|
||||
member.business = { id: 0, checks: 0, percent: 0 };
|
||||
await member.save();
|
||||
}
|
||||
|
||||
// Удаление организации
|
||||
await business.destroy();
|
||||
|
||||
await ctx.reply(`❌ Организация "${business.name}" ликвидирована. Вы получили ₽${spaces(payout)}.`);
|
||||
} catch (error) {
|
||||
console.error('Ошибка при ликвидации организации:', error);
|
||||
return ctx.reply('Произошла ошибка. Попробуйте снова.');
|
||||
}
|
||||
});
|
||||
|
||||
bot.command('daily_bonus', async (ctx) => {
|
||||
try {
|
||||
const user = await UserModel.findByPk(ctx.from.id);
|
||||
const currentDate = new Date();
|
||||
const day = currentDate.getDate();
|
||||
|
||||
// Проверяем, заходил ли пользователь сегодня
|
||||
const lastLoginDate = new Date(user.lastLogin);
|
||||
if (
|
||||
lastLoginDate.getFullYear() === currentDate.getFullYear() &&
|
||||
lastLoginDate.getMonth() === currentDate.getMonth() &&
|
||||
lastLoginDate.getDate() === day
|
||||
) {
|
||||
return ctx.reply('Вы уже получили награду за сегодня! Возвращайтесь завтра.');
|
||||
}
|
||||
|
||||
// Получение награды из базы
|
||||
const reward = await DailyModel.findOne({ where: { day } });
|
||||
if (!reward) {
|
||||
return ctx.reply('На сегодня награды не настроены. Обратитесь к администратору.');
|
||||
}
|
||||
|
||||
// Обработка награды
|
||||
let totalMoney = reward.money;
|
||||
let message = `🎉 Награда за ${day} число:\n`;
|
||||
|
||||
if (reward.experience > 0) {
|
||||
user.exp += reward.experience;
|
||||
message += `✨ Опыт: ${reward.experience}\n`;
|
||||
}
|
||||
|
||||
if (user.business.id > 0) {
|
||||
user.materials += reward.materials;
|
||||
message += `🏗 Материалы: ${reward.materials}\n`;
|
||||
} else {
|
||||
totalMoney += reward.materials; // Материалы заменяются на деньги
|
||||
}
|
||||
|
||||
// Добавляем деньги
|
||||
user.money += totalMoney;
|
||||
message += `💰 Деньги: ${totalMoney}\n`;
|
||||
|
||||
// Обновляем прогресс
|
||||
//user.lastLogin = currentDate;
|
||||
user.loginStreak = (lastLoginDate.getDate() === day - 1) ? user.loginStreak + 1 : 1;
|
||||
await user.save();
|
||||
|
||||
// Отправляем сообщение
|
||||
await ctx.reply(`${message}\n🔥 Ваша серия входов: ${user.loginStreak} дней.`);
|
||||
} catch (error) {
|
||||
console.error('Ошибка при выдаче ежедневного бонуса:', error);
|
||||
return ctx.reply('Произошла ошибка. Попробуйте снова.');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/////////////////////////////////////Enterprise Update 20.12.2024//////////////////////////////////////////////////
|
||||
|
||||
// Обновление меню "Предприятия"
|
||||
@ -1326,24 +1426,9 @@ bot.command('force_mat', async (ctx) => {
|
||||
/////////////////////////////////////Enterprise Update end//////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////Casino Update//////////////////////////////////////////////////
|
||||
// Функция для игры в слоты
|
||||
const spinSlots = async (ctx, bet, user) => {
|
||||
const slotIcons = ['🔥', '⚡', '⭐', '💀']; // Иконки для слотов
|
||||
const spinSpeed = 500; // Скорость анимации (мс)
|
||||
const spinRounds = 8; // Количество вращений
|
||||
|
||||
let slotMessage = await ctx.reply('🎰 Слот-машина крутится...');
|
||||
|
||||
// Генерация случайного отображения для анимации
|
||||
const getRandomIcons = () => {
|
||||
return `${slotIcons[Math.floor(Math.random() * slotIcons.length)]} | ${slotIcons[Math.floor(Math.random() * slotIcons.length)]} | ${slotIcons[Math.floor(Math.random() * slotIcons.length)]}`;
|
||||
};
|
||||
|
||||
// Анимация вращения
|
||||
for (let i = 0; i < spinRounds; i++) {
|
||||
await new Promise((resolve) => setTimeout(resolve, spinSpeed));
|
||||
const uniqueTag = `[${Date.now()}]`; // Уникальный тег для предотвращения ошибок Telegram
|
||||
await ctx.telegram.editMessageText(ctx.chat.id, slotMessage.message_id, null, `🎰 ${getRandomIcons()} ${uniqueTag}`);
|
||||
}
|
||||
|
||||
// Определяем результат игры
|
||||
const winMultiplier = determineWin();
|
||||
@ -1362,8 +1447,8 @@ const spinSlots = async (ctx, bet, user) => {
|
||||
resultMessage += `💔 Вы проиграли ₽${spaces(bet)}. Попробуйте ещё раз!`;
|
||||
}
|
||||
|
||||
// Финальный результат
|
||||
await ctx.telegram.editMessageText(ctx.chat.id, slotMessage.message_id, null, resultMessage);
|
||||
// Отправляем результат
|
||||
await ctx.reply(resultMessage);
|
||||
};
|
||||
|
||||
// Функция для определения выигрыша
|
||||
@ -1409,11 +1494,6 @@ bot.action(/slots\d+/, async (ctx) => {
|
||||
|
||||
const user = await UserModel.findByPk(ctx.from.id);
|
||||
|
||||
// Проверка на текущую игру
|
||||
if (user.isPlayingCasino) {
|
||||
return ctx.answerCbQuery('⏳ Ваша ставка уже обрабатывается. Подождите!', { show_alert: true });
|
||||
}
|
||||
|
||||
if (!user || user.money < bet) {
|
||||
return ctx.answerCbQuery('💸 У вас недостаточно средств для ставки.', { show_alert: true });
|
||||
}
|
||||
@ -1446,9 +1526,8 @@ const spaces = (number) => {
|
||||
return number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ' ');
|
||||
};
|
||||
|
||||
|
||||
bot.hears('🎰 Рулетка', async (ctx) => {
|
||||
return ctx.reply('Закрыто на ремонт')
|
||||
return ctx.reply('Закрыто')
|
||||
const user = await UserModel.findByPk(ctx.from.id);
|
||||
if (user.money <= 0) {
|
||||
return await ctx.telegram.answerCbQuery(ctx.callbackQuery.id, `У вас недостаточно средств для игры.`, { show_alert: true });
|
||||
|
@ -49,6 +49,9 @@ module.exports = async (ctx) => {
|
||||
}, {
|
||||
text: `💸 Payday`,
|
||||
callback_data: "payday"
|
||||
},
|
||||
{ text: '❌ Ликвидировать организацию',
|
||||
callback_data: `dissolve_organization_${business.id}`
|
||||
}]
|
||||
])
|
||||
.oneTime()
|
||||
|
@ -24,6 +24,7 @@ module.exports = {
|
||||
TruckModel: require('../models/truck.model'),
|
||||
ResourcePriceModel: require('../models/resourceprice.model'),
|
||||
SaleModel: require('../models/sales.model'),
|
||||
DailyModel: require('../models/daily.model'),
|
||||
mainChat : -1001895132127,
|
||||
adminList : [275416286],
|
||||
promoTopicId: 1807,
|
||||
|
12
models/daily.model.js
Normal file
12
models/daily.model.js
Normal file
@ -0,0 +1,12 @@
|
||||
const sequelize = require('../db');
|
||||
const {DataTypes} = require('sequelize');
|
||||
|
||||
const DailyReward = sequelize.define('dailyreward', {
|
||||
day: { type: DataTypes.INTEGER, allowNull: false }, // День месяца
|
||||
money: { type: DataTypes.INTEGER, defaultValue: 0 }, // Деньги
|
||||
experience: { type: DataTypes.INTEGER, defaultValue: 0 }, // Опыт
|
||||
materials: { type: DataTypes.INTEGER, defaultValue: 0 } // Материалы
|
||||
});
|
||||
|
||||
|
||||
module.exports = DailyReward;
|
@ -28,7 +28,15 @@ const User = sequelize.define('user', {
|
||||
slottime: {type: DataTypes.INTEGER, defaultValue: 0},
|
||||
shoprobcd: {type: DataTypes.INTEGER, defaultValue: 0},
|
||||
pocketstealcd: {type: DataTypes.INTEGER, defaultValue: 0},
|
||||
isPlayingCasino: {type: DataTypes.BOOLEAN, defaultValue: false}
|
||||
isPlayingCasino: {type: DataTypes.BOOLEAN, defaultValue: false},
|
||||
lastLogin: {
|
||||
type: DataTypes.DATE,
|
||||
defaultValue: null,
|
||||
},
|
||||
loginStreak: {
|
||||
type: DataTypes.INTEGER,
|
||||
defaultValue: 0,
|
||||
}
|
||||
})
|
||||
|
||||
module.exports = User;
|
||||
|
Loading…
Reference in New Issue
Block a user