starting v0.1

Добавлены пресеты имущества
Стоимость материалов отображается в Мире
Прочие исправления и проверки
This commit is contained in:
Degradin 2023-09-21 14:28:55 +03:00
parent bf8d59b0f7
commit f83f8ca0ab
6 changed files with 209 additions and 94 deletions

117
index.js
View File

@ -77,7 +77,7 @@ bot.use(async (ctx, next) => {
telegram_id: id telegram_id: id
}) })
} else {} } else {}
if (whitelist.includes(id) == false) return ctx.reply(`У вас пока нет доступа к боту. Следите за обновлениями в группе: t.me/CampFireGameBotNews`) //if (whitelist.includes(id) == false) return ctx.reply(`У вас пока нет доступа к боту. Следите за обновлениями в группе: t.me/CampFireGameBotNews`)
if (block !== null) { if (block !== null) {
if (block.isBlocked == true && block.time > Date.now() / 1000) return ctx.reply(`У вас активная блокировка по причине: ${block.reason}.\nОставшееся время: ${Math.trunc((block.time - Date.now()/1000)/60)} мин.`) if (block.isBlocked == true && block.time > Date.now() / 1000) return ctx.reply(`У вас активная блокировка по причине: ${block.reason}.\nОставшееся время: ${Math.trunc((block.time - Date.now()/1000)/60)} мин.`)
block.isBlocked = false block.isBlocked = false
@ -110,7 +110,7 @@ bot.command('start', async (ctx) => {
return await ctx.reply('Главное меню', Markup return await ctx.reply('Главное меню', Markup
.keyboard([ .keyboard([
['😎 Профиль', '💳 Баланс'], // Row1 with 2 buttons ['😎 Профиль', '💳 Баланс'], // Row1 with 2 buttons
['🗄️ Работать', '🎁 Бонус'], // Row2 with 2 buttons ['🗄️ Работать', '🌐 Организация', '🎁 Бонус'], // Row2 with 2 buttons
['📢 Вакансии', '🔵 Имущество', '📞 Пригласить'] // Row3 with 3 buttons ['📢 Вакансии', '🔵 Имущество', '📞 Пригласить'] // Row3 with 3 buttons
]) ])
.oneTime() .oneTime()
@ -118,11 +118,11 @@ bot.command('start', async (ctx) => {
) )
}) })
bot.hears('Меню', async (ctx) => { bot.hears('▶️ Меню', async (ctx) => {
return await ctx.reply('Main Menu', Markup return await ctx.reply('Main Menu', Markup
.keyboard([ .keyboard([
['😎 Профиль', '💳 Баланс'], // Row1 with 2 buttons ['😎 Профиль', '💳 Баланс'], // Row1 with 2 buttons
['🗄️ Работать', '🎁 Бонус'], // Row2 with 2 buttons ['🗄️ Работать', '🌐 Организация', '🎁 Бонус'], // Row2 with 2 buttons
['📢 Вакансии', '🔵 Имущество', '📞 Пригласить'] // Row3 with 3 buttons ['📢 Вакансии', '🔵 Имущество', '📞 Пригласить'] // Row3 with 3 buttons
]) ])
.oneTime() .oneTime()
@ -198,7 +198,18 @@ bot.hears('🎁 Бонус', async (ctx) => {
text += `⏩ ¤${money*2}\n`; text += `⏩ ¤${money*2}\n`;
} }
} }
//uplvl(user);
let business = await BusinessModel.findOne({
where: {
owner: user.business.id
}
})
if(business != null){
let mats = rand(3, 10)
text += `${mats} Материалов в организацию\n`
business.materials += mats
business.save()
}
await user.save(); await user.save();
await world.save(); await world.save();
return ctx.reply(` return ctx.reply(`
@ -251,6 +262,7 @@ bot.hears('Мир', async (ctx) => {
let world = await WorldModel.findByPk(1) let world = await WorldModel.findByPk(1)
return ctx.reply(` return ctx.reply(`
Баланс мира: ¤${spaces(world.balance)} Баланс мира: ¤${spaces(world.balance)}
Стоимость материалов: ¤${spaces(world.matPrice)}
`) `)
}) })
@ -270,7 +282,8 @@ bot.hears('📢 Вакансии', async (ctx) => {
.keyboard([ .keyboard([
['Дворник', 'Промоутер'], // Row1 with 2 buttons ['Дворник', 'Промоутер'], // Row1 with 2 buttons
['Официант', 'Бармен'], // Row2 with 2 buttons ['Официант', 'Бармен'], // Row2 with 2 buttons
['Кассир', 'ПВЗ Дикие Ягоды', 'Слесарь'] // Row3 with 3 buttons ['Кассир', 'ПВЗ Дикие Ягоды', 'Слесарь'],
['💤 Уволиться', '▶️ Меню'] // Row3 with 3 buttons
]) ])
.oneTime() .oneTime()
.resize() .resize()
@ -521,7 +534,7 @@ bot.hears('🗄️ Работать', async (ctx) => {
price: 600 price: 600
}, { }, {
name: "Вагиноимитатор", name: "Вагиноимитатор",
price: "600" price: 600
}].random() }].random()
world.balance -= payday world.balance -= payday
world.balance -= Number(stealed.price) world.balance -= Number(stealed.price)
@ -604,7 +617,8 @@ bot.hears('🔵 Имущество', async (ctx) => {
let user = await UserModel.findByPk(ctx.from.id); let user = await UserModel.findByPk(ctx.from.id);
return await ctx.reply(`Места для покупки`, Markup return await ctx.reply(`Места для покупки`, Markup
.keyboard([ .keyboard([
['Жилье', 'Телефоны', 'Автосалон'] // Row3 with 3 buttons ['Жилье', 'Телефоны', 'Автосалон'],
['▶️ Меню'] // Row3 with 3 buttons
]) ])
.oneTime() .oneTime()
.resize()) .resize())
@ -651,6 +665,7 @@ bot.command('buy', async (ctx) => {
if (!ctx.args[1] || !ctx.args[2]) return ctx.reply(`Не указан аргумент.`) if (!ctx.args[1] || !ctx.args[2]) return ctx.reply(`Не указан аргумент.`)
if (!Number(ctx.args[2])) return ctx.reply(`Неверно указан параметр.`) if (!Number(ctx.args[2])) return ctx.reply(`Неверно указан параметр.`)
if (ctx.args[1] == "house") { if (ctx.args[1] == "house") {
if (user.money < houses[ctx.args[2]].price) return await ctx.reply(`У вас недостаточно средств!`)
user.money -= houses[ctx.args[2]].price user.money -= houses[ctx.args[2]].price
world.balance += houses[ctx.args[2]].price world.balance += houses[ctx.args[2]].price
property.house = houses[ctx.args[2]] property.house = houses[ctx.args[2]]
@ -660,6 +675,7 @@ bot.command('buy', async (ctx) => {
return await ctx.reply(`Вы купили ${houses[ctx.args[2]].name}`) return await ctx.reply(`Вы купили ${houses[ctx.args[2]].name}`)
} }
if (ctx.args[1] == "car") { if (ctx.args[1] == "car") {
if (user.money < cars[ctx.args[2]].price) return await ctx.reply(`У вас недостаточно средств!`)
user.money -= cars[ctx.args[2]].price user.money -= cars[ctx.args[2]].price
world.balance += cars[ctx.args[2]].price world.balance += cars[ctx.args[2]].price
property.car = cars[ctx.args[2]] property.car = cars[ctx.args[2]]
@ -669,6 +685,7 @@ bot.command('buy', async (ctx) => {
return await ctx.reply(`Вы купили ${cars[ctx.args[2]].name}`) return await ctx.reply(`Вы купили ${cars[ctx.args[2]].name}`)
} }
if (ctx.args[1] == "phone") { if (ctx.args[1] == "phone") {
if (user.money < phones[ctx.args[2]].price) return await ctx.reply(`У вас недостаточно средств!`)
user.money -= phones[ctx.args[2]].price user.money -= phones[ctx.args[2]].price
world.balance += phones[ctx.args[2]].price world.balance += phones[ctx.args[2]].price
property.mobile = phones[ctx.args[2]] property.mobile = phones[ctx.args[2]]
@ -678,6 +695,7 @@ bot.command('buy', async (ctx) => {
return await ctx.reply(`Вы купили ${phones[ctx.args[2]].name}`) return await ctx.reply(`Вы купили ${phones[ctx.args[2]].name}`)
} }
if (ctx.args[1] == "equipment") { if (ctx.args[1] == "equipment") {
if (user.money < weaponshop[ctx.args[2]].price) return await ctx.reply(`У вас недостаточно средств!`)
if (ctx.args[1] == weaponshop[ctx.args[2]].type) { if (ctx.args[1] == weaponshop[ctx.args[2]].type) {
user.money -= weaponshop[ctx.args[2]].price user.money -= weaponshop[ctx.args[2]].price
world.balance += weaponshop[ctx.args[2]].price world.balance += weaponshop[ctx.args[2]].price
@ -698,26 +716,48 @@ bot.command('buy', async (ctx) => {
return await ctx.reply(`Вы купили.`) return await ctx.reply(`Вы купили.`)
}) })
bot.hears('Организация', async (ctx) => { bot.hears('🌐 Организация', async (ctx) => {
let user = await UserModel.findByPk(ctx.from.id) let user = await UserModel.findByPk(ctx.from.id)
let business = await BusinessModel.findOne({ let business = await BusinessModel.findOne({
where: {
owner: ctx.from.id owner: ctx.from.id
}
}) })
if (business === null) return await ctx.reply(`У вас нет организации.`) if(business === null){
console.log(business) business = await BusinessModel.findOne({
return await ctx.reply(`Ваша организация\n${business.name}\nБаланс: ¤${business.balance}\nСырье: ${business.materials}\nРабочих: ${business.users.length}`) where: {
owner: user.business.id
}
})
return await ctx.reply(`Организация\n${business.name}\nБаланс: ¤${business.balance}\nСырье: ${business.materials}\nРабочих: ${business.users.length}`, Markup.keyboard([
['📶 Отработка'],
['⬅️ Покинуть', '▶️ Меню'] // Row3 with 3 buttons
])
.oneTime()
.resize())
}
if (business.owner == ctx.from.id){
return await ctx.reply(`Ваша организация\n${business.name}\nБаланс: ¤${business.balance}\nСырье: ${business.materials} (Для закупки: [/materials Кол-во])\nРабочих: ${business.users.length} (Для приглашения: [/invite ID])\nОтработок: ${business.checks}`, Markup.keyboard([
['📶 Отработка'],
['💸 Payday', '▶️ Меню']
])
.oneTime()
.resize())
}
}) })
bot.hears('Отработка', async (ctx) => { bot.hears('📶 Отработка', async (ctx) => {
let user = await UserModel.findByPk(ctx.from.id) let user = await UserModel.findByPk(ctx.from.id)
let business = await BusinessModel.findOne({ let business = await BusinessModel.findOne({
where: {
owner: ctx.from.id owner: ctx.from.id
}
}) })
if (user.business == null) return await ctx.reply(`Вы не работаете в организации.`) if (user.business == null) return await ctx.reply(`Вы не работаете в организации.`)
let timer = user.worktime let timer = user.worktime
let cooldown = setCooldown(user, 3600, timer) let cooldown = setCooldown(user, 3600, timer)
if (user.worktime > cooldown.currentTime) return ctx.reply(`📛 Работа в организации будет доступна через ${cooldown.timeLeftInMinutes} минут(у/ы)`); if (user.worktime > cooldown.currentTime) return ctx.reply(`📛 Работа в организации будет доступна через ${cooldown.timeLeftInMinutes} минут(у/ы)`);
if (business.materials <= 10) return ctx.reply(`📛 В организации недостаточно материалов для отработки.`); if (business.materials < 10) return ctx.reply(`📛 В организации недостаточно материалов для отработки.`);
user.business = { user.business = {
id: user.business.id, id: user.business.id,
checks: user.business.checks + 1, checks: user.business.checks + 1,
@ -730,10 +770,12 @@ bot.hears('Отработка', async (ctx) => {
return await ctx.reply(`Вы отработали час на ${business.name}`) return await ctx.reply(`Вы отработали час на ${business.name}`)
}) })
bot.hears('Payday', async (ctx) => { bot.hears('💸 Payday', async (ctx) => {
let user = null let user = null
let business = await BusinessModel.findOne({ let business = await BusinessModel.findOne({
where: {
owner: ctx.from.id owner: ctx.from.id
}
}) })
let world = await WorldModel.findByPk(1) let world = await WorldModel.findByPk(1)
if (business === null) return await ctx.reply(`У вас нет организации.`) if (business === null) return await ctx.reply(`У вас нет организации.`)
@ -753,9 +795,14 @@ bot.hears('Payday', async (ctx) => {
for (i = 0; i < business.users.length; i++) { // Общая внесенная сумма всеми участниками for (i = 0; i < business.users.length; i++) { // Общая внесенная сумма всеми участниками
user = await UserModel.findByPk(business.users[i]) user = await UserModel.findByPk(business.users[i])
profit += user.business.checks * moneyList profit += user.business.checks * moneyList
text += `${user.username} нарабатывает ¤${user.business.checks * moneyList}${moneyList}*${user.business.checks}] в баланс организации.\n` user.business = {
id: user.business.id,
checks: 0,
percent: user.business.percent
} }
text += `Профит: ${profit}\n` user.save()
}
text += `Наработка за текущий период: ${profit}\n`
let profitCheck = profit let profitCheck = profit
for (i = 0; i < business.users.length; i++) { // Процент выплаты участникам for (i = 0; i < business.users.length; i++) { // Процент выплаты участникам
user = await UserModel.findByPk(business.users[i]) user = await UserModel.findByPk(business.users[i])
@ -764,7 +811,7 @@ bot.hears('Payday', async (ctx) => {
user.money += piece user.money += piece
giveExp(user, business.checks) giveExp(user, business.checks)
user.save() user.save()
text += `${user.username} получает ¤${piece}\nОстаток выплат: ¤${profitCheck}\n` text += `${user.username} получает ¤${piece}\n`
} }
if (profitCheck > 0) { if (profitCheck > 0) {
business.balance += profitCheck business.balance += profitCheck
@ -778,30 +825,43 @@ bot.hears('Payday', async (ctx) => {
bot.command('materials', async (ctx) => { bot.command('materials', async (ctx) => {
ctx.args = ctx.update.message.text.split(' ') ctx.args = ctx.update.message.text.split(' ')
let user = await UserModel.findByPk(ctx.from.id) let user = await UserModel.findByPk(ctx.from.id)
let world = await WorldModel.findByPk(1)
let business = await BusinessModel.findOne({ let business = await BusinessModel.findOne({
where: {
owner: ctx.from.id owner: ctx.from.id
}
}) })
if (business === null) return await ctx.reply(`У вас нет организации.`) if (business === null) return await ctx.reply(`У вас нет организации.`)
if (!ctx.args[1]) return ctx.reply(`Не указан аргумент.`) if (!ctx.args[1]) return ctx.reply(`Не указан аргумент.`)
if (!Number(ctx.args[1])) return ctx.reply(`Количество должно быть числом.`) if (!Number(ctx.args[1])) return ctx.reply(`Количество должно быть числом.`)
if (ctx.args[1] < 1) return ctx.reply(`Минимальное количество для покупки - 1`) if (ctx.args[1] < 1) return ctx.reply(`Минимальное количество для покупки - 1`)
business.balance -= Number(world.matPrice*ctx.args[1]) if (ctx.args[1] > business.balance) return ctx.reply(`Недостаточно средств на балансе организации.`)
business.materials += ctx.args[1] let count = Number(ctx.args[1])
business.balance -= world.matPrice*count
business.materials += count
business.save() business.save()
return await ctx.reply(`Закуплено ${ctx.args[1]} материалов для организации`) return await ctx.reply(`Закуплено ${ctx.args[1]} материалов для организации на сумму ${world.matPrice*count}`)
}) })
bot.command('percent', async (ctx) => { bot.command('percent', async (ctx) => {
ctx.args = ctx.update.message.text.split(' ') ctx.args = ctx.update.message.text.split(' ')
let user = await UserModel.findByPk(ctx.from.id) let user = await UserModel.findByPk(ctx.from.id)
let business = await BusinessModel.findOne({ let business = await BusinessModel.findOne({
where: {
owner: ctx.from.id owner: ctx.from.id
}
}) })
if (business === null) return await ctx.reply(`У вас нет организации.`) if (business === null) return await ctx.reply(`У вас нет организации.`)
if (!ctx.args[1] || !ctx.args[2]) return ctx.reply(`Не указан аргумент.`) if (!ctx.args[1] || !ctx.args[2]) return ctx.reply(`Не указан аргумент.`)
if (!Number(ctx.args[2])) return ctx.reply(`Процент должен быть числом от 1 до 100.`) if (!Number(ctx.args[2])) return ctx.reply(`Процент должен быть числом от 1 до 100.`)
if (ctx.args[2] < 1 || ctx.args[2] > 100) return ctx.reply(`Минимальный процент 1 | Максимальный процент 100.`) if (ctx.args[2] < 1 || ctx.args[2] > 100) return ctx.reply(`Минимальный процент 1 | Максимальный процент 100.`)
let change = await UserModel.findByPk(ctx.args[1]) ctx.args[1] = ctx.args[1].slice(1)
console.log(ctx.args)
let change = await UserModel.findOne({
where: {
username: ctx.args[1]
}
})
change.business = { change.business = {
id: change.business.id, id: change.business.id,
checks: change.business.checks, checks: change.business.checks,
@ -814,7 +874,9 @@ bot.command('percent', async (ctx) => {
bot.command('business', async (ctx) => { bot.command('business', async (ctx) => {
let user = await UserModel.findByPk(ctx.from.id) let user = await UserModel.findByPk(ctx.from.id)
let business = await BusinessModel.findOne({ let business = await BusinessModel.findOne({
where: {
owner: ctx.from.id owner: ctx.from.id
}
}) })
let world = await WorldModel.findByPk(1) let world = await WorldModel.findByPk(1)
ctx.args = ctx.update.message.text.split(' ') ctx.args = ctx.update.message.text.split(' ')
@ -897,7 +959,9 @@ bot.on('callback_query', async ctx => {
let user = await UserModel.findByPk(ctx.update.callback_query.from.id) let user = await UserModel.findByPk(ctx.update.callback_query.from.id)
if (data != 0) { if (data != 0) {
let business = await BusinessModel.findOne({ let business = await BusinessModel.findOne({
where: {
owner: data owner: data
}
}) })
user.business = { user.business = {
id: data, id: data,
@ -1007,15 +1071,24 @@ function weaponShopUpdate() {
fs.writeFileSync('json/weaponshop.json', JSON.stringify(weaponshop, null, "\t")) fs.writeFileSync('json/weaponshop.json', JSON.stringify(weaponshop, null, "\t"))
} }
async function matPriceUpdate() {
let world = await WorldModel.findByPk(1)
let price = rand(35, 170)
world.matPrice = price
world.save()
}
setInterval(() => { setInterval(() => {
var today = new Date(); var today = new Date();
let hours = today.getHours(); let hours = today.getHours();
if (hours == "0" || hours == "12" || hours == "23") { if (hours == "0" || hours == "12" || hours == "23") {
weaponShopUpdate() weaponShopUpdate()
matPriceUpdate()
} }
}, 360000); }, 360000);
weaponShopUpdate() weaponShopUpdate()
matPriceUpdate()
start() start()

View File

@ -1,11 +1,11 @@
{ {
"0": { "0": {
"name": "AK-47", "name": "SCAR-H",
"price": 1000, "price": 1000,
"type": "weapon" "type": "weapon"
}, },
"1": { "1": {
"name": "M4A1", "name": "Glock",
"price": 1000, "price": 1000,
"type": "weapon" "type": "weapon"
}, },
@ -20,27 +20,27 @@
"type": "weapon" "type": "weapon"
}, },
"4": { "4": {
"name": "M4A1", "name": "Deagle",
"price": 1000, "price": 1000,
"type": "weapon" "type": "weapon"
}, },
"5": { "5": {
"name": "Картонные накладки",
"price": 1000,
"type": "equipment"
},
"6": {
"name": "Бронежилет M5", "name": "Бронежилет M5",
"price": 1000, "price": 1000,
"type": "equipment" "type": "equipment"
}, },
"6": {
"name": "Бронежилет M3",
"price": 1000,
"type": "equipment"
},
"7": { "7": {
"name": "Бронежилет M6", "name": "Бронежилет M2",
"price": 1000, "price": 1000,
"type": "equipment" "type": "equipment"
}, },
"8": { "8": {
"name": "Кольчуга", "name": "Картонные накладки",
"price": 1000, "price": 1000,
"type": "equipment" "type": "equipment"
}, },

View File

@ -4,7 +4,8 @@ const {DataTypes} = require('sequelize');
const World = sequelize.define('world', { const World = sequelize.define('world', {
id: {type: DataTypes.INTEGER, primaryKey: true, unique: true}, id: {type: DataTypes.INTEGER, primaryKey: true, unique: true},
balance: {type: DataTypes.INTEGER, defaultValue: 50000000}, balance: {type: DataTypes.INTEGER, defaultValue: 50000000},
transactionfee: {type: DataTypes.INTEGER, defaultValue: 1} transactionfee: {type: DataTypes.INTEGER, defaultValue: 1},
matPrice: {type: DataTypes.INTEGER, defaultValue: 100}
}) })
module.exports = World; module.exports = World;

View File

@ -1,42 +1,42 @@
{ {
"1": { "1": {
"name": "Car2", "name": "Электросамокат",
"price": 0 "price": 16000
}, },
"2": { "2": {
"name": "Car3", "name": "ВАЗ 2115",
"price": 10 "price": 90000
}, },
"3": { "3": {
"name": "Car4", "name": "Lada Priora",
"price": 20 "price": 300000
}, },
"4": { "4": {
"name": "Car5", "name": "Renault Logan",
"price": 30 "price": 650000
}, },
"5": { "5": {
"name": "Car6", "name": "Hyundai Solaris",
"price": 40 "price": 800000
}, },
"6": { "6": {
"name": "Car7", "name": "Kia Rio",
"price": 50 "price": 900000
}, },
"7": { "7": {
"name": "Car86", "name": "Ford Focus",
"price": 60 "price": 1100000
}, },
"8": { "8": {
"name": "Car8", "name": "Volkswagen Polo",
"price": 70 "price": 1300000
}, },
"9": { "9": {
"name": "Car9", "name": "Mazda 3",
"price": 80 "price": 1450000
}, },
"10": { "10": {
"name": "Car10", "name": "Mercedes Benz E-200",
"price": 90 "price": 2000000
} }
} }

View File

@ -4,39 +4,39 @@
"price": 100 "price": 100
}, },
"2": { "2": {
"name": "Дом", "name": "Комната в общаге",
"price": 100 "price": 50000
}, },
"3": { "3": {
"name": ом2", "name": "Квартира в малосемейке",
"price": 100 "price": 150000
}, },
"4": { "4": {
"name": ом3", "name": "1-комнатная квартира в сталинке",
"price": 100 "price": 300000
}, },
"5": { "5": {
"name": ом4", "name": "3-комнатная квартира в сталинке",
"price": 100 "price": 500000
}, },
"6": { "6": {
"name": ом5", "name": "Студия с евроремонтом",
"price": 100 "price": 2000000
}, },
"7": { "7": {
"name": ом6", "name": "2-комнатная квартира с евроремонтом в панельке",
"price": 100 "price": 2000000
}, },
"8": { "8": {
"name": ом7", "name": "2-этажный дом",
"price": 100 "price": 5000000
}, },
"9": { "9": {
"name": ом8", "name": "Таунхаус",
"price": 100 "price": 10000000
}, },
"10": { "10": {
"name": ом9", "name": "Дворец",
"price": 100 "price": 50000000
} }
} }

View File

@ -1 +1,42 @@
{} {
"1": {
"name": "Nokia 3310",
"price": 300
},
"2": {
"name": "BQ 6868L",
"price": 4500
},
"3": {
"name": "Realme C21Y",
"price": 7000
},
"4": {
"name": "Xiaomi Redmi 10C",
"price": 10500
},
"5": {
"name": "Samsung Galaxy A13",
"price": 15500
},
"6": {
"name": "Xiaomi Redmi Note 12S",
"price": 22000
},
"7": {
"name": "Nothing Phone 2",
"price": 45000
},
"8": {
"name": "Samsung S23 Ultra",
"price": 109000
},
"9": {
"name": "IPhone 14 Pro Max",
"price": 170000
},
"10": {
"name": "IPhone 15 Pro Max",
"price": 190000
}
}