hotfixes on release

This commit is contained in:
Degradin 2023-09-21 23:27:06 +03:00
parent f83f8ca0ab
commit 48fd7f232b
9 changed files with 65 additions and 39 deletions

3
db.js
View File

@ -7,6 +7,7 @@ module.exports = new Sequelize(
{
host: 'localhost',
port: '5432',
dialect: 'postgres'
dialect: 'postgres',
logging: false
}
)

View File

@ -21,7 +21,7 @@ const BusinessModel = require('./models/business.model');
const ReportModel = require('./models/report.model');
const BlockModel = require('./models/block.model');
const whitelist = [275416286, 1797342681]
const adminList = [275416286]
const adminList = [`275416286`]
const expToUp = [0, 10, 15, 22, 35, 50, 70, 85, 100, 125, 200]
const start = async () => {
@ -62,18 +62,23 @@ bot.telegram.setMyCommands([{
bot.use(async (ctx, next) => {
let id = ctx.from.id
let username = ctx.from.username
if(ctx.update.message.text){
console.log(username + `: ` + ctx.update.message.text)
}else{
console.log(username + `: ` + ctx)
}
let user = await UserModel.findByPk(id);
let block = await BlockModel.findByPk(id);
let property = await PropertyModel.findByPk(id);
if (!user) ctx.reply(`Первичная регистрация профиля.`);
if (user === null) {
UserModel.create({
await UserModel.create({
telegram_id: id,
username: username,
})
} else {}
if (property === null) {
PropertyModel.create({
await PropertyModel.create({
telegram_id: id
})
} else {}
@ -94,7 +99,7 @@ bot.command('start', async (ctx) => {
if (ctx.payload) {
let id = ctx.from.id
let user = await UserModel.findByPk(id);
if (user === null) {
if (user.level == 1) {
let ref = await UserModel.findByPk(ctx.payload)
let world = await WorldModel.findByPk(1)
world.balance -= 25000
@ -135,8 +140,8 @@ bot.hears('😎 Профиль', async (ctx) => {
let property = await PropertyModel.findByPk(ctx.from.id);
if (!user) return ctx.reply(`Ошибка #1`);
return ctx.reply(`
👤 ${user.username} ${adminList.includes(ctx.from.id)? " ✅" : ""}
🆔 ID: ${ctx.from.id}
👤${user.username} ${adminList.includes(user.telegram_id)? " ✅" : ""}
🆔: ${ctx.from.id}
📶 Уровень: ${user.level} | ${user.exp} / ${expToUp[user.level]}
Повышается за различные действия.
@ -198,7 +203,14 @@ bot.hears('🎁 Бонус', async (ctx) => {
text += `⏩ ¤${money*2}\n`;
}
}
if (user.business.id == 0){
await user.save();
await world.save();
return ctx.reply(`
Из ежечасного бонуса Вам выпало:
${text}
`)
}
let business = await BusinessModel.findOne({
where: {
owner: user.business.id
@ -220,7 +232,7 @@ ${text}
bot.command('pay', async (ctx) => {
ctx.args = ctx.update.message.text.split(' ')
if (!ctx.args[1] || !ctx.args[2]) return ctx.reply(`Не указан аргумент.`)
if (!ctx.args[1] || !ctx.args[2]) return ctx.reply(`/pay [Никнейм] [Сумма]`)
if (!Number(ctx.args[2])) return ctx.reply(`Сумма должна быть числовая.`)
let sender = await UserModel.findByPk(ctx.from.id);
let receiver = await UserModel.findOne({
@ -392,7 +404,7 @@ bot.hears('🗄️ Работать', async (ctx) => {
let job = await JobModel.findByPk(user.job);
let world = await WorldModel.findByPk(1)
let timer = user.jobtime
let cooldown = setCooldown(user, 3600, timer)
let cooldown = setCooldown(user, 1800, timer)
if (user.jobtime > cooldown.currentTime) return ctx.reply(`📛 Работать можно будет через ${cooldown.timeLeftInMinutes} минут(у/ы)`);
if (user.job == 0) {
return await ctx.reply(`Вы безработный.`)
@ -588,7 +600,7 @@ bot.hears('Топ', async (ctx) => {
],
limit: 10
})
if (!topPlayer[9]) {
if (!topPlayer[1]) {
console.log(topPlayer[0])
return await ctx.reply(`
В данный момент недостаточно игроков для составления топ 10, показывается только топ 1.
@ -604,10 +616,10 @@ bot.hears('Топ', async (ctx) => {
4. ${topPlayer[3].username}
5. ${topPlayer[4].username}
6. ${topPlayer[5].username}
7. ${topPlayer[6].username}
8. ${topPlayer[7].username}
9. ${topPlayer[8].username}
10. ${topPlayer[9].username}
7. ${topPlayer[6] ? topPlayer[6].username : `Пока никого`}
8. ${topPlayer[7] ? topPlayer[7].username : `Пока никого`}
9. ${topPlayer[8] ? topPlayer[8].username : `Пока никого`}
10. ${topPlayer[9] ? topPlayer[9].username : `Пока никого`}
`)
}
@ -718,9 +730,10 @@ bot.command('buy', async (ctx) => {
bot.hears('🌐 Организация', async (ctx) => {
let user = await UserModel.findByPk(ctx.from.id)
if (user.business.id == 0) return await ctx.reply(`Вы не состоите в организации.`)
let business = await BusinessModel.findOne({
where: {
owner: ctx.from.id
owner: ctx.from.id.toString()
}
})
if(business === null){
@ -755,7 +768,7 @@ bot.hears('📶 Отработка', async (ctx) => {
})
if (user.business == null) return await ctx.reply(`Вы не работаете в организации.`)
let timer = user.worktime
let cooldown = setCooldown(user, 3600, timer)
let cooldown = setCooldown(user, 1800, timer)
if (user.worktime > cooldown.currentTime) return ctx.reply(`📛 Работа в организации будет доступна через ${cooldown.timeLeftInMinutes} минут(у/ы)`);
if (business.materials < 10) return ctx.reply(`📛 В организации недостаточно материалов для отработки.`);
user.business = {
@ -774,7 +787,7 @@ bot.hears('💸 Payday', async (ctx) => {
let user = null
let business = await BusinessModel.findOne({
where: {
owner: ctx.from.id
owner: ctx.from.id.toString()
}
})
let world = await WorldModel.findByPk(1)
@ -825,10 +838,11 @@ bot.hears('💸 Payday', async (ctx) => {
bot.command('materials', async (ctx) => {
ctx.args = ctx.update.message.text.split(' ')
let user = await UserModel.findByPk(ctx.from.id)
if (user.business.id == 0) return await ctx.reply(`Вы не владеете организацией.`)
let world = await WorldModel.findByPk(1)
let business = await BusinessModel.findOne({
where: {
owner: ctx.from.id
owner: ctx.from.id.toString()
}
})
if (business === null) return await ctx.reply(`У вас нет организации.`)
@ -846,9 +860,10 @@ bot.command('materials', async (ctx) => {
bot.command('percent', async (ctx) => {
ctx.args = ctx.update.message.text.split(' ')
let user = await UserModel.findByPk(ctx.from.id)
if (user.business.id == 0) return await ctx.reply(`Вы не владеете организацией.`)
let business = await BusinessModel.findOne({
where: {
owner: ctx.from.id
owner: ctx.from.id.toString()
}
})
if (business === null) return await ctx.reply(`У вас нет организации.`)
@ -873,15 +888,18 @@ bot.command('percent', async (ctx) => {
bot.command('business', async (ctx) => {
let user = await UserModel.findByPk(ctx.from.id)
if (user.business.id != 0){
let business = await BusinessModel.findOne({
where: {
owner: ctx.from.id
owner: ctx.from.id.toString()
}
})
}
let business = null
let world = await WorldModel.findByPk(1)
ctx.args = ctx.update.message.text.split(' ')
if (business !== null) return await ctx.reply(`У вас уже есть организация.`)
if (!ctx.args[1]) return ctx.reply(`Не указан аргумент.`)
if (business != null) return await ctx.reply(`У вас уже есть организация.`)
if (!ctx.args[1]) return ctx.reply(`/business [Название организации]`)
if (user.money < 100000) return await ctx.reply(`Регистрация организации стоит ¤100.000`)
if (user.level < 5) return await ctx.reply(`Регистрация организации доступна с 5 уровня.`)
user.money -= 100000
@ -912,6 +930,7 @@ bot.command('invite', async (ctx) => {
ctx.args = ctx.update.message.text.split(' ')
if (!ctx.args[1]) return ctx.reply(`/invite [ID]`)
let user = await UserModel.findByPk(ctx.from.id)
if (user.business.id == 0) return await ctx.reply(`У вас нет организации в которую можно пригласить игрока.`)
let invited = await UserModel.findOne({
where: {
username: ctx.args[1]
@ -1081,15 +1100,12 @@ async function matPriceUpdate() {
setInterval(() => {
var today = new Date();
let hours = today.getHours();
if (hours == "0" || hours == "12" || hours == "23") {
if (hours == "0" || hours == "12") {
weaponShopUpdate()
matPriceUpdate()
}
}, 360000);
weaponShopUpdate()
matPriceUpdate()
start()
bot.launch()

View File

@ -1,11 +1,11 @@
{
"0": {
"name": "SCAR-H",
"name": "ТТ",
"price": 1000,
"type": "weapon"
},
"1": {
"name": "Glock",
"name": "ТТ",
"price": 1000,
"type": "weapon"
},
@ -15,17 +15,17 @@
"type": "weapon"
},
"3": {
"name": "Five-Seven",
"name": "Glock",
"price": 1000,
"type": "weapon"
},
"4": {
"name": "Deagle",
"name": "SCAR-H",
"price": 1000,
"type": "weapon"
},
"5": {
"name": "Бронежилет M5",
"name": "Бронежилет M3",
"price": 1000,
"type": "equipment"
},
@ -40,7 +40,7 @@
"type": "equipment"
},
"8": {
"name": "Картонные накладки",
"name": "Бронежилет M4",
"price": 1000,
"type": "equipment"
},

View File

@ -2,7 +2,7 @@ const sequelize = require('../db');
const {DataTypes} = require('sequelize');
const Block = sequelize.define('block', {
telegram_id: {type: DataTypes.INTEGER, primaryKey: true, unique: true}, uid: {type: DataTypes.STRING, unique: true},
telegram_id: {type: DataTypes.BIGINT, primaryKey: true, unique: true}, uid: {type: DataTypes.STRING, unique: true},
isBlocked: {type: DataTypes.BOOLEAN, defaultValue: false},
reason: {type: DataTypes.STRING, defaultValue: "Не указана."},
time: {type: DataTypes.INTEGER, defaultValue: 0}

View File

@ -4,7 +4,7 @@ const {DataTypes} = require('sequelize');
const Business = sequelize.define('business', {
id: {type: DataTypes.INTEGER, primaryKey: true, unique: true, autoIncrement: true},
name: {type: DataTypes.STRING, defaultValue: "Организация не найдена."},
owner: {type: DataTypes.INTEGER, defaultValue: 0},
owner: {type: DataTypes.STRING, defaultValue: 0},
balance: {type: DataTypes.INTEGER, defaultValue: 0},
materials: {type: DataTypes.INTEGER, defaultValue: 0},
users: {type: DataTypes.ARRAY(DataTypes.INTEGER)},

View File

@ -2,7 +2,7 @@ const sequelize = require('../db');
const {DataTypes} = require('sequelize');
const Property = sequelize.define('property', {
telegram_id: {type: DataTypes.INTEGER, primaryKey: true, unique: true},
telegram_id: {type: DataTypes.STRING, primaryKey: true, unique: true},
house: {type: DataTypes.JSON, defaultValue: 0},
car: {type: DataTypes.JSON, defaultValue: 0},
mobile: {type: DataTypes.JSON, defaultValue: 0},

View File

@ -4,7 +4,7 @@ const {DataTypes} = require('sequelize');
const Report = sequelize.define('report', {
id: {type: DataTypes.INTEGER, primaryKey: true, unique: true, autoIncrement: true},
uid: {type: DataTypes.STRING, unique: true},
author: {type: DataTypes.INTEGER, defaultValue: 0},
author: {type: DataTypes.STRING, defaultValue: 0},
text: {type: DataTypes.STRING, defaultValue: 0},
status: {type: DataTypes.INTEGER, defaultValue: 1}
})

View File

@ -2,7 +2,7 @@ const sequelize = require('../db');
const {DataTypes} = require('sequelize');
const User = sequelize.define('user', {
telegram_id: {type: DataTypes.INTEGER, primaryKey: true, unique: true},
telegram_id: {type: DataTypes.STRING, primaryKey: true, unique: true},
username: {type: DataTypes.STRING},
level: {type: DataTypes.INTEGER, defaultValue: 1},
exp: {type: DataTypes.INTEGER, defaultValue: 0},
@ -12,7 +12,12 @@ const User = sequelize.define('user', {
job: {type: DataTypes.INTEGER, defaultValue: 0},
jobcheck: {type: DataTypes.INTEGER, defaultValue: 0},
jobtime: {type: DataTypes.INTEGER, defaultValue: 0},
business: {type: DataTypes.JSON, defaultValue: 0},
business: {type: DataTypes.JSON, defaultValue: {
id: 0,
checks: 0,
percent: 0
}
},
worktime: {type: DataTypes.INTEGER, defaultValue: 0}
})

View File

@ -38,5 +38,9 @@
"10": {
"name": "IPhone 15 Pro Max",
"price": 190000
},
"11": {
"name": "OnePlus 11",
"price": 85000
}
}