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/rpc.py

143 lines
5.2 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
import time
import os
import sys
from colors import *
from functions import *
2022-02-01 17:34:08 +02:00
version = '2.6'
import libinstaller
from pypresence import Presence
client_id = '800049969960058882'
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",
"conference": "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"
}
2021-04-30 03:25:36 +03:00
if getConfig("use_rpc") 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
2021-04-30 03:25:36 +03:00
if getConfig("use_rpc") 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():
2021-04-30 03:25:36 +03:00
if getConfig("use_rpc") 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:
2021-04-30 03:25:36 +03:00
if getConfig("use_rpc") 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
def waitLesson(conference, start):
changePresence("waiting", "Ожидание", f"Ждём начала «{conference}»", "Конференция не началась", start=start)
def onLesson(conference, start):
changePresence("conference", "Конференция", f"Слушаем «{conference}»", "Идёт конференция", 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 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 запущен в режиме тестирования", "Режим отладки")