CuteRPC

CuteRPC est un projet que j'ai fait pour utiliser le Rich Presence de Discord.

Le but recherché ici était de pouvoir utiliser le Rich Presence de Discord avec ses propres paramètres.


Actuellement seulement disponible en lien direct.

import sys
import json
import traceback
from PyQt5 import QtWidgets
from PyQt5.QtCore import Qt
import urllib.request as urllib2
import urllib.error as urllib2_error
import threading
from gui.main import Ui_MainWindow
from RPC_Client import RpcClient
from ErrorHandler import ErrorHandler
class MainWindow(QtWidgets.QMainWindow):
def __init__(self):
QtWidgets.QMainWindow.__init__(self, flags=Qt.FramelessWindowHint)
self.ui = Ui_MainWindow()
self.error_handler = ErrorHandler()
self.ui.setupUi(self)
self.__press_pos = None
self.ui.close.clicked.connect(lambda: self.close())
self.ui.minimize.clicked.connect(lambda: self.showMinimized())
self.ui.rpc_id.textChanged.connect(self.on_change)
self.ui.load_rpc.clicked.connect(self.rpc_clicked)
self.rpc_client = None
def rpc_clicked(self):
images = []
valid_rpc = [False]
def get_images():
url = f"https://discord.com/api/v7/oauth2/applications/{self.ui.rpc_id.text()}/assets"
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)'
' Chrome/78.0.3904.97 Safari/537.36'}
req = urllib2.Request(url, headers=headers)
try:
resp = urllib2.urlopen(req)
except urllib2_error.HTTPError:
self.ui.rpc_id.setText("Invalid Client ID.")
valid_rpc[0] = False
else:
valid_rpc[0] = True
data = json.loads(resp.read().decode(resp.info().get_param('charset') or 'utf-8'))
for item in data:
images.append(item["name"])
return images, valid_rpc
try:
thread = threading.Thread(name='get_images', target=get_images)
thread.start()
thread.join()
if valid_rpc[0] is True:
self.rpc_client = RpcClient(main=self,
client_id=self.ui.rpc_id.text(),
images=images,
error_handler=self.error_handler)
self.hide()
self.rpc_client.show()
except Exception as e:
_ = e
self.error_handler.set_error(traceback.format_exc())
self.error_handler.show()
def on_change(self):
if len(self.ui.rpc_id.text()) > 0 and self.ui.rpc_id.text().isdigit():
self.ui.load_rpc.setEnabled(True)
else:
self.ui.load_rpc.setEnabled(False)
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
self.__press_pos = event.pos()
def mouseReleaseEvent(self, event):
if event.button() == Qt.LeftButton:
self.__press_pos = None
def mouseMoveEvent(self, event):
if self.__press_pos and self.ui.Titlebar.underMouse():
self.move(self.pos() + (event.pos() - self.__press_pos))
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
main = MainWindow()
main.show()
sys.exit(app.exec_())
view raw CuteRPC.py hosted with ❤ by GitHub

cyvax - 2024