This repository has been archived on 2024-10-14. You can view files and clone it, but cannot push or open issues or pull requests.
AutoZoom/modules/rpc.py

145 lines
5.3 KiB
Python
Raw Permalink Normal View History

# -*- 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 *
2022-04-28 02:18:08 +03:00
version = '2.7'
from pypresence import Presence
client_id = getConfig("rpc_id")
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)
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"
}
if getConfig("rpc_use") and getOS != "android":
try:
RPC.connect()
connected = True
except:
pass
else:
connected = False
def disconnect():
2021-04-07 23:57:02 +03:00
global connected
if getConfig("rpc_use") and getOS != "android":
try:
RPC.close()
connected = False
2021-04-24 03:08:43 +03:00
appendLog('Discord RPC disconnected')
except:
2021-04-24 03:08:43 +03:00
appendLog('Discord RPC failed to disconnect')
def connect():
2021-04-07 23:57:02 +03:00
global connected
try:
RPC.connect()
connected = True
2021-04-24 03:08:43 +03:00
appendLog('Discord RPC connected')
except:
2021-04-24 03:08:43 +03:00
appendLog('Discord RPC failed to connect')
def reset():
if getConfig("rpc_use") and getOS != "android":
RPC.clear()
2021-04-24 03:08:43 +03:00
appendLog('Discord RPC status cleared')
2021-11-05 18:47:43 +02:00
def changePresence(sml_img, sml_txt, stt, dtls, start=None, end=None):
try:
if getConfig("rpc_use") and getOS != "android":
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)})')
except AttributeError:
2021-04-24 03:08:43 +03:00
appendLog('Discord RPC failed to change status')
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)
except AssertionError:
2021-04-24 03:08:43 +03:00
appendLog('Discord RPC failed to change status')
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-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)
def inMenu():
2021-11-05 18:47:43 +02:00
changePresence("menu", "Главное меню", "Открыт список опций", "В главном меню")
def shutdown(end):
2021-11-05 18:47:43 +02:00
changePresence("shutdown", "Выключение", "Отсчёт до авто-выключения", "Выключение ПК", end=end)
def sleepmode(end):
changePresence("shutdown", "Спящий режим", "Отсчёт до авто-засыпания", "Спящий режим ПК", end=end)
def inSettings():
2021-11-05 18:47:43 +02:00
changePresence("settings", "Настройки", "Открыты настройки", "В главном меню")
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
def inEditor():
2021-11-05 18:47:43 +02:00
changePresence("editor", "Редактор", "Открыт редактор", "В главном меню")
def inUpdater():
2021-11-05 18:47:43 +02:00
changePresence("updating", "Обновление", "Открыт центр обновлений", "В главном меню")
def inHelp():
2021-11-05 18:47:43 +02:00
changePresence("support", "Помощь", "Открыта помощь", "В главном меню")
2021-04-24 03:08:43 +03:00
def lessonEnded():
2021-11-05 18:47:43 +02:00
changePresence("waiting", "Ожидание", "Ждём указаний", "Все конференции закончились")
if __name__ == "__main__":
2021-11-05 18:47:43 +02:00
changePresence("settings", "Отладка", "Модуль Discord RPC запущен в режиме тестирования", "Режим отладки")