Skip to content

Commit

Permalink
Add plugin "Rich Discord Status"
Browse files Browse the repository at this point in the history
  • Loading branch information
romanin-rf committed Nov 26, 2023
1 parent 29610db commit 9ad3db8
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
__pycache__/
*.py[cod]
*$py.class
__*.py

# My Python Files
__clean.py

# C extensions
*.so
Expand Down
61 changes: 61 additions & 0 deletions plugins/RichDiscordStatus/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import os
import time
import asyncio
import nest_asyncio
from pypresence import Presence, DiscordNotFound
from seaplayer.plug import PluginBase

# ! Vars
AD_ENABLE = True

# ! Initialization
nest_asyncio.apply()

# ! Main Class
class RichDiscordStatus(PluginBase):
def get_status(self):
data = {
"start": self.start_time,
"large_image": "icon"
}
if AD_ENABLE:
data["buttons"] = [{"label": "GitHub", "url": self.info.url}]
if self.app.currect_sound is not None:
if (self.app.currect_sound.title is not None) and (self.app.currect_sound.artist is not None):
data["details"] = f"{self.app.currect_sound.artist} - {self.app.currect_sound.title}"
else:
data["details"] = os.path.basename(self.app.currect_sound.name)
if self.app.currect_sound.paused:
data["state"] = "Paused"
elif self.app.currect_sound.playing:
data["state"] = "Playing"
else:
data["state"] = "Stopped"
else:
data["details"] = "Sound not selected"
data["state"] = "Waiting"
return data

async def __status__(self) -> None:
while self.running:
try:
rpc = Presence("1178379471124955217")
rpc.connect()
while self.running:
rpc.update(**self.get_status())
await asyncio.sleep(1)
except DiscordNotFound:
await asyncio.sleep(10)

def on_run(self) -> None:
self.start_time = time.time()

async def on_compose(self):
self.running = True
self.app.run_worker(self.__status__, "Discord Rich Status", "seaplayer.plugins.discord.status", thread=True)

async def on_quit(self) -> None:
self.running = False

# ! Registration Plugin Class
plugin_main = RichDiscordStatus
8 changes: 8 additions & 0 deletions plugins/RichDiscordStatus/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "Discord Rich Status",
"name_id": "seaplayer.plugins.discord.status",
"version": "0.1.0",
"author": "Romanin",
"description": "Now what you are listening to will be visible to everyone in Discord.",
"url": "https://github.com/romanin-rf/SeaPlayer"
}
2 changes: 2 additions & 0 deletions plugins/RichDiscordStatus/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nest-asyncio
pypresence

0 comments on commit 9ad3db8

Please sign in to comment.