218 lines
7.3 KiB
Python
218 lines
7.3 KiB
Python
# Description: Discord Rich Presence plugin for EU-Utility
|
|
# Author: LemonNexus
|
|
# Version: 1.0.0
|
|
|
|
"""
|
|
Discord Rich Presence plugin for EU-Utility.
|
|
Shows current Entropia Universe activity in Discord.
|
|
"""
|
|
|
|
from PyQt6.QtWidgets import (
|
|
QWidget, QVBoxLayout, QHBoxLayout, QLabel,
|
|
QPushButton, QLineEdit, QCheckBox, QComboBox
|
|
)
|
|
from PyQt6.QtCore import QTimer
|
|
from plugins.base_plugin import BasePlugin
|
|
import time
|
|
import threading
|
|
|
|
|
|
class DiscordPresencePlugin(BasePlugin):
|
|
"""Discord Rich Presence integration for EU-Utility."""
|
|
|
|
name = "Discord Presence"
|
|
version = "1.0.0"
|
|
author = "LemonNexus"
|
|
description = "Show EU activity in Discord status"
|
|
icon = "message-square"
|
|
|
|
def initialize(self):
|
|
"""Initialize Discord RPC."""
|
|
self.enabled = self.load_data("enabled", False)
|
|
self.client_id = self.load_data("client_id", "")
|
|
self.show_details = self.load_data("show_details", True)
|
|
self.rpc = None
|
|
self.connected = False
|
|
|
|
# Try to import pypresence
|
|
try:
|
|
from pypresence import Presence
|
|
self.Presence = Presence
|
|
self.available = True
|
|
except ImportError:
|
|
self.log_warning("pypresence not installed. Run: pip install pypresence")
|
|
self.available = False
|
|
return
|
|
|
|
# Auto-connect if enabled
|
|
if self.enabled and self.client_id:
|
|
self._connect()
|
|
|
|
def get_ui(self):
|
|
"""Create plugin UI."""
|
|
widget = QWidget()
|
|
layout = QVBoxLayout(widget)
|
|
layout.setSpacing(15)
|
|
|
|
# Title
|
|
title = QLabel("Discord Rich Presence")
|
|
title.setStyleSheet("font-size: 18px; font-weight: bold; color: #5865F2;")
|
|
layout.addWidget(title)
|
|
|
|
# Status
|
|
self.status_label = QLabel("Status: " + ("Connected" if self.connected else "Disconnected"))
|
|
self.status_label.setStyleSheet(
|
|
f"color: {'#43b581' if self.connected else '#f04747'}; font-weight: bold;"
|
|
)
|
|
layout.addWidget(self.status_label)
|
|
|
|
# Enable checkbox
|
|
self.enable_checkbox = QCheckBox("Enable Discord Presence")
|
|
self.enable_checkbox.setChecked(self.enabled)
|
|
self.enable_checkbox.toggled.connect(self._on_enable_toggled)
|
|
layout.addWidget(self.enable_checkbox)
|
|
|
|
# Client ID input
|
|
id_layout = QHBoxLayout()
|
|
id_layout.addWidget(QLabel("Client ID:"))
|
|
self.id_input = QLineEdit(self.client_id)
|
|
self.id_input.setPlaceholderText("Your Discord Application Client ID")
|
|
id_layout.addWidget(self.id_input)
|
|
layout.addLayout(id_layout)
|
|
|
|
# Show details
|
|
self.details_checkbox = QCheckBox("Show detailed activity")
|
|
self.details_checkbox.setChecked(self.show_details)
|
|
self.details_checkbox.toggled.connect(self._on_details_toggled)
|
|
layout.addWidget(self.details_checkbox)
|
|
|
|
# Activity type
|
|
layout.addWidget(QLabel("Activity Type:"))
|
|
self.activity_combo = QComboBox()
|
|
self.activity_combo.addItems(["Playing", "Hunting", "Mining", "Crafting", "Trading"])
|
|
self.activity_combo.currentTextChanged.connect(self._update_presence)
|
|
layout.addWidget(self.activity_combo)
|
|
|
|
# Buttons
|
|
btn_layout = QHBoxLayout()
|
|
|
|
connect_btn = QPushButton("Connect")
|
|
connect_btn.clicked.connect(self._connect)
|
|
btn_layout.addWidget(connect_btn)
|
|
|
|
disconnect_btn = QPushButton("Disconnect")
|
|
disconnect_btn.clicked.connect(self._disconnect)
|
|
btn_layout.addWidget(disconnect_btn)
|
|
|
|
update_btn = QPushButton("Update Presence")
|
|
update_btn.clicked.connect(self._update_presence)
|
|
btn_layout.addWidget(update_btn)
|
|
|
|
layout.addLayout(btn_layout)
|
|
|
|
# Info
|
|
info = QLabel(
|
|
"To use this feature:\n"
|
|
"1. Create a Discord app at discord.com/developers\n"
|
|
"2. Copy the Client ID\n"
|
|
"3. Paste it above and click Connect"
|
|
)
|
|
info.setStyleSheet("color: rgba(255,255,255,150); font-size: 11px;")
|
|
layout.addWidget(info)
|
|
|
|
layout.addStretch()
|
|
return widget
|
|
|
|
def _on_enable_toggled(self, checked):
|
|
"""Handle enable toggle."""
|
|
self.enabled = checked
|
|
self.save_data("enabled", checked)
|
|
if checked:
|
|
self._connect()
|
|
else:
|
|
self._disconnect()
|
|
|
|
def _on_details_toggled(self, checked):
|
|
"""Handle details toggle."""
|
|
self.show_details = checked
|
|
self.save_data("show_details", checked)
|
|
self._update_presence()
|
|
|
|
def _connect(self):
|
|
"""Connect to Discord."""
|
|
if not self.available:
|
|
self.log_error("pypresence not installed")
|
|
return
|
|
|
|
client_id = self.id_input.text().strip()
|
|
if not client_id:
|
|
self.log_warning("No Client ID provided")
|
|
return
|
|
|
|
self.client_id = client_id
|
|
self.save_data("client_id", client_id)
|
|
|
|
try:
|
|
self.rpc = self.Presence(client_id)
|
|
self.rpc.connect()
|
|
self.connected = True
|
|
self.status_label.setText("Status: Connected")
|
|
self.status_label.setStyleSheet("color: #43b581; font-weight: bold;")
|
|
self._update_presence()
|
|
self.log_info("Discord RPC connected")
|
|
except Exception as e:
|
|
self.log_error(f"Failed to connect: {e}")
|
|
self.connected = False
|
|
|
|
def _disconnect(self):
|
|
"""Disconnect from Discord."""
|
|
if self.rpc:
|
|
try:
|
|
self.rpc.close()
|
|
except:
|
|
pass
|
|
self.rpc = None
|
|
self.connected = False
|
|
self.status_label.setText("Status: Disconnected")
|
|
self.status_label.setStyleSheet("color: #f04747; font-weight: bold;")
|
|
self.log_info("Discord RPC disconnected")
|
|
|
|
def _update_presence(self):
|
|
"""Update Discord presence."""
|
|
if not self.connected or not self.rpc:
|
|
return
|
|
|
|
activity = self.activity_combo.currentText()
|
|
|
|
try:
|
|
if self.show_details:
|
|
self.rpc.update(
|
|
state=f"In Entropia Universe",
|
|
details=f"Currently {activity}",
|
|
large_image="eu_logo",
|
|
large_text="Entropia Universe",
|
|
small_image="playing",
|
|
small_text=activity,
|
|
start=time.time()
|
|
)
|
|
else:
|
|
self.rpc.update(
|
|
state="Playing Entropia Universe",
|
|
large_image="eu_logo",
|
|
large_text="Entropia Universe"
|
|
)
|
|
self.log_info("Presence updated")
|
|
except Exception as e:
|
|
self.log_error(f"Failed to update presence: {e}")
|
|
|
|
def on_show(self):
|
|
"""Update UI when shown."""
|
|
self.status_label.setText("Status: " + ("Connected" if self.connected else "Disconnected"))
|
|
self.status_label.setStyleSheet(
|
|
f"color: {'#43b581' if self.connected else '#f04747'}; font-weight: bold;"
|
|
)
|
|
|
|
def shutdown(self):
|
|
"""Cleanup on shutdown."""
|
|
self._disconnect()
|