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
2022-04-28 01:18:08 +02:00

145 lines
5.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- coding: utf-8 -*-
import time
import os
import sys
from modules.colors import *
from modules.functions import *
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
rpc_dict = {
"large_image": "1024_cover",
"small_image": {
"waiting": "status_waiting",
"meeting": "status_lesson",
"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():
global connected
if getConfig("rpc_use") and getOS != "android":
try:
RPC.close()
connected = False
appendLog('Discord RPC disconnected')
except:
appendLog('Discord RPC failed to disconnect')
def connect():
global connected
try:
RPC.connect()
connected = True
appendLog('Discord RPC connected')
except:
appendLog('Discord RPC failed to connect')
def reset():
if getConfig("rpc_use") and getOS != "android":
RPC.clear()
appendLog('Discord RPC status cleared')
def changePresence(sml_img, sml_txt, stt, dtls, start=None, end=None):
try:
if getConfig("rpc_use") and getOS != "android":
if connected == False:
connect()
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:
appendLog('Discord RPC failed to change status')
if getConfig("debug"):
print(f'{RESET}Модуль {BRED}Discord RPC {RESET}не смог подключиться.\nВозможно, ваш {CYAN}Discord {RESET}не открыт.')
time.sleep(1)
except AssertionError:
appendLog('Discord RPC failed to change status')
if getConfig("debug"):
print(f'{RESET}Модуль {BRED}Discord RPC {RESET}не смог подключиться.\nВозможно, ваш {CYAN}Discord {RESET}не открыт.')
time.sleep(1)
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)
def waitLesson(meeting, start):
changePresence("waiting", "Ожидание", f"Ждём начала «{meeting}»", "Конференция не началась", start=start)
def onLesson(meeting, start):
changePresence("meeting", "Конференция", f"Слушаем «{meeting}»", "Идёт конференция", start=start)
def inMenu():
changePresence("menu", "Главное меню", "Открыт список опций", "В главном меню")
def shutdown(end):
changePresence("shutdown", "Выключение", "Отсчёт до авто-выключения", "Выключение ПК", end=end)
def sleepmode(end):
changePresence("shutdown", "Спящий режим", "Отсчёт до авто-засыпания", "Спящий режим ПК", end=end)
def inSettings():
changePresence("settings", "Настройки", "Открыты настройки", "В главном меню")
def inDebug():
changePresence("debug", "Отладка", "Открыто меню отладки", "В меню разработчика")
def inEditor():
changePresence("editor", "Редактор", "Открыт редактор", "В главном меню")
def inUpdater():
changePresence("updating", "Обновление", "Открыт центр обновлений", "В главном меню")
def inHelp():
changePresence("support", "Помощь", "Открыта помощь", "В главном меню")
def lessonEnded():
changePresence("waiting", "Ожидание", "Ждём указаний", "Все конференции закончились")
if __name__ == "__main__":
changePresence("settings", "Отладка", "Модуль Discord RPC запущен в режиме тестирования", "Режим отладки")