2021-01-21 14:00:58 +02:00
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
import time
|
|
|
|
|
import os
|
|
|
|
|
import sys
|
2022-04-28 02:18:08 +03:00
|
|
|
|
from modules.colors import *
|
|
|
|
|
from modules.functions import *
|
2021-01-21 14:00:58 +02:00
|
|
|
|
|
2022-04-28 02:18:08 +03:00
|
|
|
|
version = '2.7'
|
2021-01-21 14:00:58 +02:00
|
|
|
|
|
|
|
|
|
from pypresence import Presence
|
|
|
|
|
|
2022-02-01 17:38:27 +02:00
|
|
|
|
client_id = getConfig("rpc_id")
|
2021-01-21 14:00:58 +02:00
|
|
|
|
|
2022-02-01 17:32:46 +02:00
|
|
|
|
try:
|
|
|
|
|
RPC = Presence(client_id,pipe=0)
|
|
|
|
|
except Exception as exp:
|
|
|
|
|
appendLog(f'Discord RPC failed to initialize status due to {exp}')
|
|
|
|
|
if getConfig("debug"):
|
|
|
|
|
print(f'{RESET}Модуль {BRED}Discord RPC {RESET}не смог подключиться.\nВозможно, ваш {CYAN}Discord {RESET}не открыт.\nОшибка: {BRED}{exp}{RESET}')
|
|
|
|
|
time.sleep(1)
|
2021-01-21 14:00:58 +02:00
|
|
|
|
|
|
|
|
|
connected = False
|
|
|
|
|
|
2021-11-05 18:47:43 +02:00
|
|
|
|
rpc_dict = {
|
|
|
|
|
"large_image": "1024_cover",
|
|
|
|
|
"small_image": {
|
|
|
|
|
"waiting": "status_waiting",
|
2022-04-28 02:18:08 +03:00
|
|
|
|
"meeting": "status_lesson",
|
2021-11-05 18:47:43 +02:00
|
|
|
|
"menu": "status_menu",
|
|
|
|
|
"shutdown": "status_shutdown",
|
|
|
|
|
"settings": "status_settings",
|
|
|
|
|
"debug": "status_debug",
|
|
|
|
|
"editor": "status_editing",
|
|
|
|
|
"updating": "status_updating",
|
|
|
|
|
"support": "status_support"
|
|
|
|
|
},
|
|
|
|
|
"large_text": "AutoZoom • v%version%\nhttp://bit.ly/auto_zoom"
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-01 17:38:27 +02:00
|
|
|
|
if getConfig("rpc_use") and getOS != "android":
|
2021-01-21 14:00:58 +02:00
|
|
|
|
try:
|
|
|
|
|
RPC.connect()
|
|
|
|
|
connected = True
|
|
|
|
|
except:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
connected = False
|
|
|
|
|
|
|
|
|
|
def disconnect():
|
2021-04-07 23:57:02 +03:00
|
|
|
|
global connected
|
|
|
|
|
|
2022-02-01 17:38:27 +02:00
|
|
|
|
if getConfig("rpc_use") and getOS != "android":
|
2021-01-21 14:00:58 +02:00
|
|
|
|
try:
|
|
|
|
|
RPC.close()
|
|
|
|
|
connected = False
|
2021-04-24 03:08:43 +03:00
|
|
|
|
appendLog('Discord RPC disconnected')
|
2021-01-21 14:00:58 +02:00
|
|
|
|
except:
|
2021-04-24 03:08:43 +03:00
|
|
|
|
appendLog('Discord RPC failed to disconnect')
|
2021-01-21 14:00:58 +02:00
|
|
|
|
|
|
|
|
|
def connect():
|
2021-04-07 23:57:02 +03:00
|
|
|
|
global connected
|
|
|
|
|
|
2021-01-21 14:00:58 +02:00
|
|
|
|
try:
|
|
|
|
|
RPC.connect()
|
|
|
|
|
connected = True
|
2021-04-24 03:08:43 +03:00
|
|
|
|
appendLog('Discord RPC connected')
|
2021-01-21 14:00:58 +02:00
|
|
|
|
except:
|
2021-04-24 03:08:43 +03:00
|
|
|
|
appendLog('Discord RPC failed to connect')
|
2021-01-21 14:00:58 +02:00
|
|
|
|
|
|
|
|
|
def reset():
|
2022-02-01 17:38:27 +02:00
|
|
|
|
if getConfig("rpc_use") and getOS != "android":
|
2021-01-21 14:00:58 +02:00
|
|
|
|
RPC.clear()
|
2021-04-24 03:08:43 +03:00
|
|
|
|
appendLog('Discord RPC status cleared')
|
2021-01-21 14:00:58 +02:00
|
|
|
|
|
|
|
|
|
|
2021-11-05 18:47:43 +02:00
|
|
|
|
def changePresence(sml_img, sml_txt, stt, dtls, start=None, end=None):
|
2021-01-21 14:00:58 +02:00
|
|
|
|
try:
|
2022-02-01 17:38:27 +02:00
|
|
|
|
if getConfig("rpc_use") and getOS != "android":
|
2021-01-21 14:00:58 +02:00
|
|
|
|
if connected == False:
|
|
|
|
|
connect()
|
2021-11-05 18:47:43 +02:00
|
|
|
|
RPC.update(
|
|
|
|
|
large_image=rpc_dict["large_image"],
|
|
|
|
|
small_image=rpc_dict["small_image"][sml_img],
|
|
|
|
|
large_text=rpc_dict["large_text"].replace("%version%", str(version)),
|
|
|
|
|
small_text=sml_txt,
|
|
|
|
|
state=stt,
|
|
|
|
|
details=dtls,
|
|
|
|
|
start=start,
|
|
|
|
|
end=end
|
|
|
|
|
)
|
|
|
|
|
appendLog(f'Discord RPC changed: (Small image: {sml_img}, Small text: {sml_txt}, State: {stt}, Details: {dtls}, Start: {str(start)}, End: {str(end)})')
|
2021-01-21 14:00:58 +02:00
|
|
|
|
except AttributeError:
|
2021-04-24 03:08:43 +03:00
|
|
|
|
appendLog('Discord RPC failed to change status')
|
2021-01-21 14:00:58 +02:00
|
|
|
|
if getConfig("debug"):
|
|
|
|
|
print(f'{RESET}Модуль {BRED}Discord RPC {RESET}не смог подключиться.\nВозможно, ваш {CYAN}Discord {RESET}не открыт.')
|
2021-04-07 23:57:02 +03:00
|
|
|
|
time.sleep(1)
|
2021-01-21 14:00:58 +02:00
|
|
|
|
except AssertionError:
|
2021-04-24 03:08:43 +03:00
|
|
|
|
appendLog('Discord RPC failed to change status')
|
2021-01-21 14:00:58 +02:00
|
|
|
|
if getConfig("debug"):
|
|
|
|
|
print(f'{RESET}Модуль {BRED}Discord RPC {RESET}не смог подключиться.\nВозможно, ваш {CYAN}Discord {RESET}не открыт.')
|
2021-04-07 23:57:02 +03:00
|
|
|
|
time.sleep(1)
|
2021-11-03 09:20:15 +02:00
|
|
|
|
except Exception as exp:
|
|
|
|
|
appendLog(f'Discord RPC failed to change status due to {exp}')
|
|
|
|
|
if getConfig("debug"):
|
|
|
|
|
print(f'{RESET}Модуль {BRED}Discord RPC {RESET}не смог подключиться.\nВозможно, ваш {CYAN}Discord {RESET}не открыт.\nОшибка: {BRED}{exp}{RESET}')
|
|
|
|
|
time.sleep(1)
|
2021-01-21 14:00:58 +02:00
|
|
|
|
|
2021-11-05 18:47:43 +02:00
|
|
|
|
|
2022-04-28 02:18:08 +03:00
|
|
|
|
def waitLesson(meeting, start):
|
|
|
|
|
changePresence("waiting", "Ожидание", f"Ждём начала «{meeting}»", "Конференция не началась", start=start)
|
2021-11-05 18:47:43 +02:00
|
|
|
|
|
2022-04-28 02:18:08 +03:00
|
|
|
|
def onLesson(meeting, start):
|
|
|
|
|
changePresence("meeting", "Конференция", f"Слушаем «{meeting}»", "Идёт конференция", start=start)
|
2021-01-21 14:00:58 +02:00
|
|
|
|
|
2021-04-06 01:32:55 +03:00
|
|
|
|
def inMenu():
|
2021-11-05 18:47:43 +02:00
|
|
|
|
changePresence("menu", "Главное меню", "Открыт список опций", "В главном меню")
|
2021-01-21 14:00:58 +02:00
|
|
|
|
|
|
|
|
|
def shutdown(end):
|
2021-11-05 18:47:43 +02:00
|
|
|
|
changePresence("shutdown", "Выключение", "Отсчёт до авто-выключения", "Выключение ПК", end=end)
|
2021-01-21 14:00:58 +02:00
|
|
|
|
|
2022-02-01 17:38:27 +02:00
|
|
|
|
def sleepmode(end):
|
|
|
|
|
changePresence("shutdown", "Спящий режим", "Отсчёт до авто-засыпания", "Спящий режим ПК", end=end)
|
|
|
|
|
|
2021-01-21 14:00:58 +02:00
|
|
|
|
def inSettings():
|
2021-11-05 18:47:43 +02:00
|
|
|
|
changePresence("settings", "Настройки", "Открыты настройки", "В главном меню")
|
2021-01-21 14:00:58 +02:00
|
|
|
|
|
2021-04-30 03:25:36 +03:00
|
|
|
|
def inDebug():
|
2021-11-05 18:47:43 +02:00
|
|
|
|
changePresence("debug", "Отладка", "Открыто меню отладки", "В меню разработчика")
|
2021-04-30 03:25:36 +03:00
|
|
|
|
|
2021-01-21 14:00:58 +02:00
|
|
|
|
def inEditor():
|
2021-11-05 18:47:43 +02:00
|
|
|
|
changePresence("editor", "Редактор", "Открыт редактор", "В главном меню")
|
2021-01-21 14:00:58 +02:00
|
|
|
|
|
|
|
|
|
def inUpdater():
|
2021-11-05 18:47:43 +02:00
|
|
|
|
changePresence("updating", "Обновление", "Открыт центр обновлений", "В главном меню")
|
2021-01-21 14:00:58 +02:00
|
|
|
|
|
|
|
|
|
def inHelp():
|
2021-11-05 18:47:43 +02:00
|
|
|
|
changePresence("support", "Помощь", "Открыта помощь", "В главном меню")
|
2021-01-21 14:00:58 +02:00
|
|
|
|
|
2021-04-24 03:08:43 +03:00
|
|
|
|
def lessonEnded():
|
2021-11-05 18:47:43 +02:00
|
|
|
|
changePresence("waiting", "Ожидание", "Ждём указаний", "Все конференции закончились")
|
2021-01-21 14:00:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2021-11-05 18:47:43 +02:00
|
|
|
|
changePresence("settings", "Отладка", "Модуль Discord RPC запущен в режиме тестирования", "Режим отладки")
|