|
@@ -0,0 +1,88 @@
|
|
|
|
+import json
|
|
|
|
+import requests
|
|
|
|
+import config
|
|
|
|
+from BotClass import JabberBot
|
|
|
|
+import hashlib
|
|
|
|
+from datetime import datetime
|
|
|
|
+import time
|
|
|
|
+import threading
|
|
|
|
+import jsonAndRequest as jsreq
|
|
|
|
+
|
|
|
|
+global ticketlist
|
|
|
|
+
|
|
|
|
+botname = "st_request_in_process"
|
|
|
|
+JID = botname + "@" + config.JSERVER
|
|
|
|
+PORT = config.PORT
|
|
|
|
+PASSWORD = hashlib.md5((botname + config.PASSWORD).encode('utf-8')).hexdigest()
|
|
|
|
+
|
|
|
|
+listen_to = ["st_request_wontfix@ej.sharix-app.org"]
|
|
|
|
+proceed_to = ["numbers"]
|
|
|
|
+
|
|
|
|
+# Новые параметры
|
|
|
|
+IS_INFINITE_REMINDER = False
|
|
|
|
+DEFAULT_REMINDER_INTERVAL = 30 * 60 # 30 минут в секундах
|
|
|
|
+MAX_REMINDERS = 3 # Максимальное количество напоминаний
|
|
|
|
+DEFAULT_CHECK_INTERVAL = 5 * 60 # Проверка тикетов каждые 5 минут
|
|
|
|
+
|
|
|
|
+# Параметры для тестирования
|
|
|
|
+# MAX_REMINDERS = 2
|
|
|
|
+# DEFAULT_REMINDER_INTERVAL = 5
|
|
|
|
+# DEFAULT_CHECK_INTERVAL = 7
|
|
|
|
+
|
|
|
|
+tickets_nt = {}
|
|
|
|
+
|
|
|
|
+def send_reminder_notification(user, ticket):
|
|
|
|
+ message = f"Напоминание: необходимо принять решение по тикету {ticket.id}"
|
|
|
|
+
|
|
|
|
+ bot.send_notification("st_request_in_process@ej.sharix-app.org", message)
|
|
|
|
+
|
|
|
|
+ print(f"Отправлено напоминание пользователю {user} о тикете {ticket.id}")
|
|
|
|
+
|
|
|
|
+def send_wontfix_notification(user, ticket):
|
|
|
|
+ message = f"Уведомление: тикет {ticket.id} был отмечен как WONTFIX из-за отсутствия действий"
|
|
|
|
+
|
|
|
|
+ bot.send_notification("st_request_in_process@ej.sharix-app.org", message)
|
|
|
|
+
|
|
|
|
+ print(f"Отправлено уведомление пользователю {user} о WONTFIX для тикета {ticket.id}")
|
|
|
|
+
|
|
|
|
+def ticket_worker(ticket, start_time):
|
|
|
|
+ if ticket.id not in tickets_nt:
|
|
|
|
+ tickets_nt[ticket.id] = {
|
|
|
|
+ "reminders": 0,
|
|
|
|
+ "last_date_reminder": start_time
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ dtime_notification = start_time - tickets_nt[ticket.id]["last_date_reminder"]
|
|
|
|
+
|
|
|
|
+ if dtime_notification.seconds > DEFAULT_REMINDER_INTERVAL:
|
|
|
|
+ tickets_nt[ticket.id]["reminders"] += 1
|
|
|
|
+ tickets_nt[ticket.id]["last_date_reminder"] = start_time
|
|
|
|
+
|
|
|
|
+ if IS_INFINITE_REMINDER or tickets_nt[ticket.id]['reminders'] <= MAX_REMINDERS:
|
|
|
|
+ send_reminder_notification("TEST_USER", ticket)
|
|
|
|
+ else:
|
|
|
|
+ del tickets_nt[ticket.id]
|
|
|
|
+ jsreq.requestPatchTicketUser(token, config.API_URL+f"tickets/api/ticket/{ticket.id}/status", { "status": 149 })
|
|
|
|
+ send_wontfix_notification("TEST_USER", ticket)
|
|
|
|
+
|
|
|
|
+def ticket_list_worker(ticket_list, start_time):
|
|
|
|
+ tickets=jsreq.requestGetTicket_user(token, config.API_URL+f"tickets/api/ticket_list/{ticket_list.id}")
|
|
|
|
+ for ticket in tickets:
|
|
|
|
+ if ticket.status == 131:
|
|
|
|
+ ticket_worker(ticket, start_time)
|
|
|
|
+
|
|
|
|
+def status_changer():
|
|
|
|
+ while True:
|
|
|
|
+ ticket_lists = jsreq.requestGetList(token, config.API_URL + "tickets/api/ticket_list/")
|
|
|
|
+ for ticket_list in ticket_lists:
|
|
|
|
+ start_time = datetime.now()
|
|
|
|
+ # bot.bot_log(f"{botname} {start_time.strftime('%Y-%m-%d')} Тикет {ticketlist.id} в обработке\n")
|
|
|
|
+ t1 = threading.Thread(target=ticket_list_worker, args=(ticket_list, start_time))
|
|
|
|
+ t1.start()
|
|
|
|
+ t1.join() # Ожидаем завершения обработки тикета
|
|
|
|
+ time.sleep(DEFAULT_CHECK_INTERVAL)
|
|
|
|
+
|
|
|
|
+# Инициализация и запуск бота
|
|
|
|
+token = jsreq.requestGetToken(config.API_URL + "api/v1/auth/token/login/")
|
|
|
|
+bot = JabberBot(JID, PASSWORD, PORT)
|
|
|
|
+bot.start(status_changer)
|