-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(PVQ Panel): add activity #11161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pavl21
wants to merge
12
commits into
PreMiD:main
Choose a base branch
from
pavl21:add-pvq-panel-presence
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
eb3dd1d
feat: add PVQ Panel presence
pavl21 2802954
chore: update author name to Pavl21
pavl21 95aad34
fix: avoid redundant "Server" wording, truncate long names
pavl21 cdd452c
fix(PVQ Panel): address review comments
f4ed55c
style(PVQ Panel): refactor robotic action strings
3fc6f90
chore(PVQ Panel): translate action strings to english
1e4e0ee
fix(PVQ Panel): resolve remaining eslint and schema errors
c246b11
fix: resolve upstream linting errors
58836d4
chore: revert package-lock.json to upstream to fix conflicts
60304b3
chore: merge upstream/main to resolve conflicts
29fe17f
chore(PVQ Panel): update tags
77bd040
chore(PVQ Panel): update thumbnail to landscape image
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| { | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| "$schema": "https://schemas.premid.app/metadata/1.17", | ||
| "apiVersion": 1, | ||
| "author": { | ||
| "name": "Pavl21", | ||
| "id": "289810872396808193" | ||
| }, | ||
| "service": "PVQ Panel", | ||
| "description": { | ||
| "de": "Game-Server-Management-Panel", | ||
| "en": "Game server management panel" | ||
| }, | ||
| "url": "pv-q.de", | ||
| "regExp": "^https?[:][/][/]([a-z0-9-]+[.])*pv-q[.]de[/]", | ||
| "version": "1.0.0", | ||
| "logo": "https://pv-q.de/favicons/pvq-icon-maskable-512x512.png", | ||
| "thumbnail": "https://i.imgur.com/9sGJnp4.png", | ||
| "color": "#3b82f6", | ||
| "category": "other", | ||
| "tags": ["gameserver", "panel"], | ||
| "settings": [ | ||
| { | ||
| "id": "showServerName", | ||
| "icon": "fas fa-server", | ||
| "value": true, | ||
| "title": "Show Server Name", | ||
| "description": "Show the current server name on Discord." | ||
| }, | ||
| { | ||
| "id": "showStatus", | ||
| "icon": "fas fa-signal", | ||
| "value": true, | ||
| "title": "Show Server Status", | ||
| "description": "Show the server status (Online/Offline) on Discord." | ||
| }, | ||
| { | ||
| "id": "showElapsedTime", | ||
| "icon": "fas fa-clock", | ||
| "value": true, | ||
| "title": "Show Elapsed Time", | ||
| "description": "Show how long you've been on the page." | ||
| } | ||
| ] | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,239 @@ | ||
| const presence = new Presence({ clientId: '1509262800776728726' }) | ||
| const startTimestamp = Math.floor(Date.now() / 1000) | ||
|
|
||
| enum ActivityAssets { | ||
| Logo = 'https://pv-q.de/favicons/pvq-icon-maskable-512x512.png', | ||
| } | ||
|
|
||
| // Liest Server-Namen aus PVQ Panel Sidebar DOM. | ||
| // Regulärer Server: <span class="font-semibold text-lg text-gray-50 truncate" title="ServerName"> | ||
| // Node-Server: zwei Spans — "Node 555" + "Germany 1" → "Node 555 - Germany 1" | ||
| function getServerName(): string | null { | ||
| const regularSpan = document.querySelector<HTMLSpanElement>( | ||
| 'span.font-semibold.text-lg.text-gray-50.truncate[title]', | ||
| ) | ||
| if (regularSpan) { | ||
| const name = regularSpan.getAttribute('title')?.trim() | ||
| if (name) | ||
| return name | ||
| } | ||
|
|
||
| const nodeLabel = document.querySelector<HTMLSpanElement>( | ||
| 'span.text-2xl.font-extrabold.text-gray-50', | ||
| )?.textContent?.trim() | ||
| const nodeDesc = document.querySelector<HTMLSpanElement>( | ||
| 'span.text-md.text-gray-300', | ||
| )?.textContent?.trim() | ||
|
|
||
| if (nodeLabel && nodeDesc) | ||
| return `${nodeLabel} - ${nodeDesc}` | ||
| if (nodeLabel) | ||
| return nodeLabel | ||
|
|
||
| return null | ||
| } | ||
|
|
||
| function isNodeServer(name: string): boolean { | ||
| return /^Node \d+ - .+$/.test(name) | ||
| } | ||
|
|
||
| // Kürzt lange Server-/Node-Namen für die kompakte Discord-Anzeige. | ||
| function truncate(text: string, max: number): string { | ||
| return text.length > max ? `${text.slice(0, max - 1).trimEnd()}…` : text | ||
| } | ||
|
|
||
| function isBotPath(subPath: string): boolean { | ||
| return ['/knowledge', '/blacklist', '/channels', '/profile', '/access', '/memory'].some( | ||
| p => subPath.startsWith(p), | ||
| ) | ||
| } | ||
|
|
||
| function isNodeManagerPath(subPath: string): boolean { | ||
| return ['/firewall', '/system-logs', '/node-users', '/api-control'].some( | ||
| p => subPath.startsWith(p), | ||
| ) | ||
| } | ||
|
|
||
| // Liest Server-Status aus aria-label des ServerStatusBadge DOM-Elements. | ||
| // ServerStatusBadge rendert: <div role="img" aria-label="Online|Offline|..."> | ||
| // Panel-Texte sind z.B. "Server läuft" — "Server "-Präfix entfernt, da details | ||
| // bereits mit "Server: <Name>" beginnt (sonst "Server: X · Server läuft"). | ||
| function getServerStatus(): string | null { | ||
| const label = document.querySelector<HTMLElement>('div[role="img"][aria-label]') | ||
| ?.getAttribute('aria-label') | ||
| if (!label) | ||
| return null | ||
| return label.replace(/^Server\s+/i, '') | ||
| } | ||
|
|
||
| // Zählt Server-Rows im Node-Manager-Dashboard. | ||
| // ServerSplitterContainer: <div class="server-list-container"> → Kinder sind motion.div je Server | ||
| function getNodeServerCount(): number { | ||
| const container = document.querySelector('.server-list-container') | ||
| if (!container) | ||
| return 0 | ||
| return container.children.length | ||
| } | ||
|
|
||
| function getServerAction(subPath: string): string { | ||
| if (subPath === '/' || subPath === '') | ||
| return 'Viewing Console' | ||
| if (subPath.startsWith('/files/edit') || subPath.startsWith('/files/new')) | ||
| return 'Editing Files' | ||
| if (subPath.startsWith('/files')) | ||
| return 'Managing Files' | ||
| if (subPath.startsWith('/databases')) | ||
| return 'Managing Databases' | ||
| if (subPath.startsWith('/backups')) | ||
| return 'Managing Backups' | ||
| if (subPath.startsWith('/minecraft-plugins')) | ||
| return 'Installing Plugins' | ||
| if (subPath.startsWith('/modpacks')) | ||
| return 'Browsing Modpacks' | ||
| if (subPath.startsWith('/players')) | ||
| return 'Managing Players' | ||
| if (subPath.startsWith('/minecraft/bedrock-addons')) | ||
| return 'Managing Bedrock Addons' | ||
| if (subPath.startsWith('/minecraft/properties')) | ||
| return 'Configuring Server' | ||
| if (subPath.startsWith('/minecraft/versions')) | ||
| return 'Changing Server Version' | ||
| if (subPath.startsWith('/bedrock-support')) | ||
| return 'Configuring Bedrock' | ||
| if (subPath.startsWith('/network')) | ||
| return 'Managing Ports' | ||
| if (subPath.startsWith('/proxy')) | ||
| return 'Configuring Proxy' | ||
| if (subPath.startsWith('/subdomain')) | ||
| return 'Configuring Subdomains' | ||
| if (subPath.startsWith('/schedules/') && subPath.length > '/schedules/'.length) | ||
| return 'Editing Schedules' | ||
| if (subPath.startsWith('/schedules')) | ||
| return 'Managing Schedules' | ||
| if (subPath.startsWith('/users')) | ||
| return 'Managing Users' | ||
| if (subPath.startsWith('/startup')) | ||
| return 'Configuring Startup' | ||
| if (subPath.startsWith('/settings')) | ||
| return 'Managing Settings' | ||
| if (subPath.startsWith('/Statistics')) | ||
| return 'Viewing Statistics' | ||
| if (subPath.startsWith('/activity')) | ||
| return 'Viewing Activity Logs' | ||
| if (subPath.startsWith('/picoclaw')) | ||
| return 'Managing PicoClaw' | ||
| return 'In Panel' | ||
| } | ||
|
|
||
| function getNodeAction(subPath: string): string { | ||
| if (subPath === '/' || subPath === '') { | ||
| const count = getNodeServerCount() | ||
| return count > 0 ? `Managing ${count} Servers` : 'Managing Node' | ||
| } | ||
| if (subPath.startsWith('/firewall')) | ||
| return 'Configuring Firewall' | ||
| if (subPath.startsWith('/system-logs')) | ||
| return 'Viewing System Logs' | ||
| if (subPath.startsWith('/node-users')) | ||
| return 'Managing Node Users' | ||
| if (subPath.startsWith('/api-control')) | ||
| return 'Managing API Keys' | ||
| return 'Managing Node' | ||
| } | ||
|
|
||
| function getBotAction(subPath: string): string { | ||
| if (subPath === '/' || subPath === '') | ||
| return 'In Bot Overview' | ||
| if (subPath.startsWith('/knowledge')) | ||
| return 'Training Knowledgebase' | ||
| if (subPath.startsWith('/blacklist')) | ||
| return 'Managing Blacklist' | ||
| if (subPath.startsWith('/channels')) | ||
| return 'Configuring Channels' | ||
| if (subPath.startsWith('/profile')) | ||
| return 'Editing Bot Profile' | ||
| if (subPath.startsWith('/logs')) | ||
| return 'Viewing Bot Logs' | ||
| if (subPath.startsWith('/access')) | ||
| return 'Managing Bot Access' | ||
| if (subPath.startsWith('/activity')) | ||
| return 'Viewing Bot Activity' | ||
| if (subPath.startsWith('/memory')) | ||
| return 'Managing Bot Memory' | ||
| if (subPath.startsWith('/settings')) | ||
| return 'Configuring Bot' | ||
| return 'Managing Bot' | ||
| } | ||
|
|
||
| function getAccountAction(pathname: string): string { | ||
| if (pathname.includes('/activity')) | ||
| return 'Viewing Account Logs' | ||
| if (pathname.includes('/snippets')) | ||
| return 'Managing Snippets' | ||
| if (pathname.includes('/data-export')) | ||
| return 'In GDPR Export' | ||
| return 'Managing Account' | ||
| } | ||
|
|
||
| presence.on('UpdateData', async () => { | ||
| const presenceData: PresenceData = { | ||
| largeImageKey: ActivityAssets.Logo, | ||
| buttons: [{ label: 'PVQ Panel öffnen', url: 'https://pv-q.de/auth/login' }], | ||
| } | ||
|
|
||
| const [showServerName, showStatus, showElapsedTime] = await Promise.all([ | ||
| presence.getSetting<boolean>('showServerName'), | ||
| presence.getSetting<boolean>('showStatus'), | ||
| presence.getSetting<boolean>('showElapsedTime'), | ||
| ]) | ||
|
|
||
| if (showElapsedTime) { | ||
| presenceData.startTimestamp = startTimestamp | ||
| } | ||
|
|
||
| const { pathname } = document.location | ||
|
|
||
| const serverMatch = pathname.match(/^\/server\/[a-f0-9-]+(\/.*)?$/i) | ||
|
|
||
| if (serverMatch) { | ||
| const subPath = serverMatch[1] || '/' | ||
| const serverName = getServerName() | ||
|
|
||
| if (isBotPath(subPath)) { | ||
| presenceData.details = showServerName && serverName | ||
| ? `Discord Bot: ${truncate(serverName, 40)}` | ||
| : 'Discord Bot' | ||
| presenceData.state = getBotAction(subPath) | ||
| } | ||
| else if (isNodeManagerPath(subPath) || (serverName !== null && isNodeServer(serverName))) { | ||
| presenceData.details = showServerName && serverName | ||
| ? `Node Manager: ${truncate(serverName, 40)}` | ||
| : 'Node Manager' | ||
| presenceData.state = getNodeAction(subPath) | ||
| } | ||
| else { | ||
| let details = showServerName && serverName | ||
| ? `Server: ${truncate(serverName, 40)}` | ||
| : 'Server' | ||
|
|
||
| if (showStatus && showServerName) { | ||
| const status = getServerStatus() | ||
| if (status) | ||
| details += ` · ${status}` | ||
| } | ||
|
|
||
| presenceData.details = details | ||
| presenceData.state = getServerAction(subPath) | ||
| } | ||
| } | ||
| else if (pathname.startsWith('/account')) { | ||
| presenceData.details = 'PVQ Panel' | ||
| presenceData.state = getAccountAction(pathname) | ||
| } | ||
| else { | ||
| presenceData.details = 'PVQ Panel' | ||
| presenceData.state = 'Dashboard' | ||
| } | ||
|
|
||
| presence.setActivity(presenceData) | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.