31 lines
1019 B
JavaScript
31 lines
1019 B
JavaScript
const {
|
|
Telegraf,
|
|
Markup
|
|
} = require('telegraf')
|
|
const bot = new Telegraf(process.env.BOT_TOKEN)
|
|
const {
|
|
UserModel,
|
|
ReportModel,
|
|
adminList
|
|
} = global.config
|
|
const shortid = require('shortid');
|
|
|
|
module.exports = async (ctx) => {
|
|
let user = await UserModel.findByPk(ctx.from.id)
|
|
ctx.args = ctx.update.message.text.split(' ')
|
|
if (!ctx.args[1]) return ctx.reply(`/report [Текст обращения]`)
|
|
let uID = shortid.generate()
|
|
await ReportModel.create({
|
|
uid: uID,
|
|
author: user.telegram_id,
|
|
text: ctx.payload,
|
|
status: 1
|
|
})
|
|
let report = await ReportModel.findOne({
|
|
where: {
|
|
uid: uID
|
|
}
|
|
})
|
|
await bot.telegram.sendMessage(adminList[0], `Обращение от пользователя ${user.username}\nТекст обращения:\n${ctx.payload}\n\nДля ответа /answer ${report.id} [Ответ]`)
|
|
return await ctx.reply(`Обращение #${report.id}[${report.uid}] создано.`)
|
|
} |