Как сделать проверку discord.js на наличие id пользователя в бд sqlite (ORM)
Как сделать проверку если есть id пользователя в бд sqlite то ему нельзя выдать повторно репутацию?
const { RichEmbed } = require('discord.js')
const Util = require('../../util/Util')
const unixTime = require('../../util/unixTime')
const cfg = require('../../models/BotConfig')
// Models
const users = require('../../models/users')
// Modules
const reput = require('../../modules/economy/reput')
module.exports = {
meta: {
name: 'rep',
aliases: []
},
run: async (bot, msg, args) => {
const { channel, member, guild, mentions } = msg
const Cmds = async () => {
const config = await cfg.findOne();
const target = mentions.members.first() || guild.members.get(args[0])
if(!target) return
users.findOrCreate({
where: {
id: target.id
}
})
.spread(async user => {
const unix = unixTime()
const notify = new RichEmbed()
let mem = user.repmembers
if (mem !== member) return msg.channel.send('вот проверка')
const lastDaily = user.reput
if (lastDaily && unix < lastDaily) {
const time = Util.convertUnixToTime(lastDaily)
let through = ''
if (time.hour >= 1 && time.hour <= 24) through += `${time.hour} ч.`
else if (time.min > 0 && time.min <= 60) through += `${time.min} м.`
else if (time.sec > 0 && time.sec <= 60) through += `${time.sec} с.`
notify
.setColor(member.displayColor)
.setAuthor(member.displayName, member.user.displayAvatarURL)
.setDescription(`Ты уже давал сегодня репутацию, приходи через ${through}.\nИзвини, но быстрее никак`)
.setFooter(`( ͡° ͜ʖ ͡°) Жди...`)
return channel.send(notify).catch(console.error)
} else {
let rep = 1
await reput(user).catch(console.error)
notify
.setColor(member.displayColor)
.setAuthor(member.displayName, member.user.displayAvatarURL)
.setDescription(`Дал ${rep} репутацию пользователю ${target}`)
await users.update({ repmembers: member.id }, { where: { id: target.id }})
return channel.send(notify)
}
})
.catch(console.error)
}
// Права доступа
if (!Util.isOwner(member.id)) {
const requiredChannel = Util.getProp('channels.flood')
if (requiredChannel !== channel.id) return Util.sendError(channel, `Используйте команду в #?flood-chat `)
else return Cmds()
} else {
return Cmds()
}
}
}