Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getUserProperty(userId) {
- const userStatus = {
- mode: 'awaiting',
- obj: ''
- };
- const propertyName = `user_${userId}`
- const scriptProperties = PropertiesService.getScriptProperties();
- let userProperty = scriptProperties.getProperty(propertyName);
- if (!userProperty) {
- scriptProperties.setProperty(propertyName, JSON.stringify(userStatus));
- userProperty = JSON.stringify(userStatus); // Установите userProperty для дальнейшего использования
- }
- let property;
- try {
- property = JSON.parse(userProperty);
- } catch (e) {
- property = null;
- }
- return property;
- }
- function setUserProperty(userId, newMode, newObj) {
- const propertyName = `user_${userId}`
- const scriptProperties = PropertiesService.getScriptProperties();
- let userProperty = scriptProperties.getProperty(propertyName);
- if (!userProperty) {
- throw new Error(`User property for userId ${propertyName} does not exist.`);
- }
- let property;
- try {
- property = JSON.parse(userProperty);
- } catch (e) {
- throw new Error(`Failed to parse user property for userId ${propertyName}.`);
- }
- if (newMode !== undefined) {
- property.mode = newMode;
- }
- if (newObj !== undefined) {
- property.obj = newObj;
- }
- scriptProperties.setProperty(propertyName, JSON.stringify(property));
- }
- ....
- if (msg.chat.type === 'private') {
- const userStatus = getUserProperty(chat_id)
- if (text == "/start") {
- setUserProperty(chat_id, 'awaiting', "")
- Bot.sendMessage({
- chat_id: chat_id,
- text: "Привет! Начнём?",
- reply_markup: {
- keyboard: [
- [{ text: 'НАЧАТЬ сбор фотографий' }],
- ],
- resize_keyboard: true,
- one_time_keyboard: true
- }
- });
- }
- if (text == "НАЧАТЬ сбор фотографий" && userStatus.mode == 'awaiting') {
- setUserProperty(chat_id, 'started', "")
- Bot.sendMessage({
- chat_id: chat_id,
- text: "Хорошо. Режим сбора фотографий запущен.\n\n<b>Введи идентификацию объекта в формате '<i>номер(имя) город</i>'</b>",
- reply_markup: {
- keyboard: [
- [{ text: 'ЗАВЕРШИТЬ сбор фотографий' }],
- ],
- resize_keyboard: true,
- one_time_keyboard: true
- }
- });
- }
- if (text && userStatus.mode == 'started') {
- setUserProperty(chat_id, 'active', text)
- Bot.sendMessage({
- chat_id: chat_id,
- text: "Отлично. Можно приступать к работе. Начинай отправлять фото, а по завершении нажми кноку <i>ЗАВЕРШИТЬ сбор фотографий</i> внизу чата",
- reply_markup: {
- keyboard: [
- [{ text: 'ЗАВЕРШИТЬ сбор фотографий' }],
- ],
- resize_keyboard: true,
- one_time_keyboard: true
- }
- });
- }
- if ((contents.message?.photo || contents.message?.document) && userStatus.mode == 'active') {
- try {
- let objectName = userStatus.obj !== "" ? userStatus.obj : chatTitle;
- let url = msg.photo ? saveFileToDrive(msg.photo[msg.photo.length - 1].file_id, getFolderId(objectName)) : saveFileToDrive(msg.document.file_id, getFolderId(objectName));
- /* let response = Bot.sendMessage({
- chat_id: chat_id,
- text: 'Сохранил 👍',
- disable_notification: true,
- reply_to_message_id: msg.message_id,
- disable_web_page_preview: true
- }) */
- ss.getSheetByName('WorkLog').appendRow([new Date(), url, '', msg.chat.title, msg.from.first_name]);
- } catch (err) {
- betterLog(err, '667yyy');
- }
- };
- if (text == "ЗАВЕРШИТЬ сбор фотографий") {
- setUserProperty(chat_id, 'awaiting', "")
- Bot.sendMessage({
- chat_id: chat_id,
- text: "Режим сбора фотографий отключен.",
- reply_markup: {
- keyboard: [
- [{ text: 'НАЧАТЬ сбор фотографий' }],
- ],
- resize_keyboard: true,
- one_time_keyboard: true
- }
- });
- }
- }
- ....
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement