Skip to content

Commit 8d33007

Browse files
authored
23/01/2023
1 parent 5dd1c34 commit 8d33007

File tree

8 files changed

+361
-0
lines changed

8 files changed

+361
-0
lines changed

main.py

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import os
2+
import sys
3+
4+
f = open(os.devnull, 'w')
5+
sys.stdout = f
6+
sys.stderr = f
7+
8+
import eel
9+
from pypresence import Presence
10+
import time
11+
12+
eel.init('web')
13+
14+
rpc = ''
15+
16+
def createPresence(presenceData):
17+
try:
18+
global rpc
19+
rpc = Presence(presenceData['application_id'])
20+
rpc.connect()
21+
eel.consolelog('Connected to Discord.')
22+
except:
23+
eel.consolelog('Not a valid Application ID.')
24+
eel.onError('Not a valid Application ID.')
25+
return
26+
del presenceData['application_id']
27+
rpc.update(**presenceData)
28+
send_data.has_run = True
29+
eel.consolelog('Started Presence!')
30+
eel.onOkay('Started Presence!')
31+
32+
def updatePresence(presenceData):
33+
del presenceData['application_id']
34+
global rpc
35+
rpc.update(**presenceData)
36+
eel.consolelog('Updated Presence!')
37+
eel.onOkay('Updated Presence!')
38+
return
39+
40+
def packPresenceData(application_id, details, state, start, large_image, large_text, small_image, small_text, button1_label, button1_url, button2_label, button2_url):
41+
presenceData = {}
42+
43+
if application_id:
44+
presenceData["application_id"] = application_id
45+
else:
46+
return 0
47+
48+
if details:
49+
presenceData["details"] = details
50+
51+
if state:
52+
presenceData["state"] = state
53+
54+
if start == True:
55+
presenceData["start"] = int(time.time())
56+
57+
if large_image:
58+
presenceData["large_image"] = large_image
59+
60+
if large_image and large_text:
61+
presenceData["large_text"] = large_text
62+
63+
if small_image:
64+
presenceData["small_image"] = small_image
65+
66+
if small_image and small_text:
67+
presenceData["small_text"] = small_text
68+
69+
if (button1_label and button1_url) and (not button2_label or not button2_url):
70+
presenceData["buttons"] = [{"label": button1_label, "url": button1_url}]
71+
72+
elif (button2_label and button2_url) and (not button1_label or not button1_url):
73+
presenceData["buttons"] = [{"label": button2_label, "url": button2_url}]
74+
75+
elif (button1_label and button1_url) and (button2_label and button2_url):
76+
presenceData["buttons"] = [{"label": button1_label, "url": button1_url}, {"label": button2_label, "url": button2_url}]
77+
78+
eel.consolelog(presenceData)
79+
return presenceData
80+
81+
@eel.expose
82+
def send_data(application_id, details, state, start, large_image, large_text, small_image, small_text, button1_label, button1_url, button2_label, button2_url):
83+
presenceData = packPresenceData(application_id = application_id, details = details, state = state, start = start, large_image = large_image, large_text = large_text, small_image = small_image, small_text = small_text, button1_label = button1_label, button1_url = button1_url, button2_label = button2_label, button2_url = button2_url)
84+
85+
if presenceData == 0:
86+
eel.consolelog('No Application ID given.')
87+
eel.onError('No Application ID given.')
88+
return
89+
90+
if getattr(send_data, 'has_run', False):
91+
return updatePresence(presenceData)
92+
93+
return createPresence(presenceData)
94+
95+
eel.consolelog('Started eel.')
96+
eel.start('index.html', size=('1500', '800'))
97+
98+
while True:
99+
eel.sleep(60)
139 KB
Binary file not shown.

web/fonts/Uni Sans SemiBold.otf

132 KB
Binary file not shown.

web/images/example.png

13.5 KB
Loading

web/images/icon.ico

279 KB
Binary file not shown.

web/index.html

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<head>
2+
<link rel="stylesheet" href="style.css">
3+
<title>Nao_RPC</title>
4+
<link rel="icon" href="images/icon.ico">
5+
</head>
6+
7+
<body>
8+
<div class="section1">
9+
<div>
10+
<h1>Nao_RPC</h1>
11+
<p>Thank you for using Nao_RPC, make sure you have the latest version by visting the download link <a href="https://nao.gg/rpc">here.</a><br>To get started, head over to the <a href="https://discord.com/developers/applications">Discord Developer Portal</a> and create an application. This is so we can use <br>the ID to spin up our RPC. Make sure you chose a name you want for the application, because that is what is used <br> as the main, top line of text. Also, upload any images to "Art Assets" under "Rich Presence" which you will use the name later.</p>
12+
<img src="images/example.png" alt="example">
13+
</div>
14+
</div>
15+
<div class="section2">
16+
<div style="grid-area: applicationId;">
17+
<h2>Application ID</h2>
18+
<p>You can not edit this once the RPC has established a successful connection with Discord. If you want to edit it after, please restart the app. (required)</p>
19+
<br>
20+
<br>
21+
<p>Aplication ID :</p><input type="text" id="applicationId">
22+
</div>
23+
<div style="grid-area: details;">
24+
<h2>Details</h2>
25+
<p>The 2nd line of text. (optional)</p>
26+
<br>
27+
<br>
28+
<p>Details :</p><input type="text" id="details">
29+
</div>
30+
<div style="grid-area: state;">
31+
<h2>State</h2>
32+
<p>The 3rd line of text. (optional)</p>
33+
<br>
34+
<br>
35+
<p>State :</p><input type="text" id="state">
36+
</div>
37+
<div style="grid-area: start;">
38+
<h2>Start Timer</h2>
39+
<p>Timer that keeps track of how long you have had the RPC active. (Optional)</p>
40+
<br>
41+
<br>
42+
<p>Active :</p><input type="checkbox" id="start">
43+
</div>
44+
<div style="grid-area: largeImage;">
45+
<h2>Large Image</h2>
46+
<p>The main image, in the example it is the red one. (Optional)</p>
47+
<br>
48+
<br>
49+
<p>Image Name :</p><input type="text" id="largeImage">
50+
<br>
51+
<p>Image Hover Text :</p> <input type="text" id="largeText">
52+
</div>
53+
<div style="grid-area: smallImage;">
54+
<h2>Small Image</h2>
55+
<p>The corner image, in the example it is the green one. (Optional)</p>
56+
<br>
57+
<br>
58+
<p>Image Name :</p><input type="text" id="smallImage">
59+
<br>
60+
<p>Image Hover Text :</p><input type="text" id="smallText">
61+
</div>
62+
<div style="grid-area: button1;">
63+
<h2>Button 1</h2>
64+
<p>The 1st button. (Optional)</p>
65+
<br>
66+
<br>
67+
<p>Button Label :</p><input type="text" id="button1Label">
68+
<br>
69+
<p>Button Url :</p><input type="text" id="button1Url">
70+
<br>
71+
<p>Note: If this button fails, the 2nd button will take it's place, if you have provided the details for the 2nd button, if not, there will be no buttons.</p>
72+
</div>
73+
<div style="grid-area: button2;">
74+
<h2>Button 2</h2>
75+
<p>The 2nd button. (Optional)</p>
76+
<br>
77+
<br>
78+
<p>Button Label :</p><input type="text" id="button2Label">
79+
<br>
80+
<p>Button Url :</p><input type="text" id="button2Url">
81+
<br>
82+
<p>Note: If the 1st button fails, only this button will be displayed, that is if you have provided details for this button, if not, there will be no buttons.</p>
83+
</div>
84+
<div style="grid-area: sendButton;">
85+
<h2>Start / Update RPC</h2>
86+
<p>Make sure you have included a valid Application ID otherwise nothing will happen.</p>
87+
<br>
88+
<br>
89+
<p>Start / Update the RPC :</p><button id="sendButton">Submit</button>
90+
<br>
91+
<br>
92+
<p id="status"></p>
93+
</div>
94+
</div>
95+
</body>
96+
97+
<script type="text/javascript" src="/eel.js"></script>
98+
<script src="script.js"></script>
99+
100+
</html>

web/script.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
eel.expose(consolelog);
2+
function consolelog(msg) {
3+
console.log(msg);
4+
}
5+
6+
eel.expose(onError);
7+
function onError(msg) {
8+
document.getElementById("status").classList.add('statusr');
9+
document.getElementById("status").classList.remove('statusg');
10+
document.getElementById('applicationId').readOnly = false;
11+
document.getElementById('status').innerText = msg
12+
}
13+
14+
eel.expose(onOkay);
15+
function onOkay(msg) {
16+
document.getElementById("status").classList.add('statusg');
17+
document.getElementById("status").classList.remove('statusr');
18+
document.getElementById('applicationId').readOnly = true;
19+
document.getElementById('status').innerText = msg
20+
}
21+
22+
document.getElementById('sendButton').addEventListener('click', async() => {
23+
applicationId = document.getElementById("applicationId").value;
24+
details = document.getElementById("details").value;
25+
state = document.getElementById("state").value;
26+
start = document.getElementById("start").checked;
27+
largeImage = document.getElementById("largeImage").value;
28+
largeText = document.getElementById("largeText").value;
29+
smallImage = document.getElementById("smallImage").value;
30+
smallText = document.getElementById("smallText").value;
31+
button1Label = document.getElementById("button1Label").value;
32+
button1Url = document.getElementById("button1Url").value;
33+
button2Label = document.getElementById("button2Label").value;
34+
button2Url = document.getElementById("button2Url").value;
35+
36+
await eel.send_data(application_id = applicationId, details = details, state = state, start = start, large_image = largeImage, large_image_text = largeText, small_image = smallImage, small_image_text = smallText, button1_label = button1Label, button1_url = button1Url, button2_label = button2Label, button2_url = button2Url);
37+
38+
})

web/style.css

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
@font-face {
2+
font-family: Uni Sans;
3+
src: url("fonts/Uni Sans SemiBold.otf") format("opentype");
4+
}
5+
6+
@font-face {
7+
font-family: Uni Sans;
8+
font-style: italic;
9+
src: url("fonts/Uni Sans SemiBold Italic.otf") format("opentype");
10+
}
11+
12+
* {
13+
box-sizing: border-box;
14+
border-width: 0px;
15+
border-color: greenyellow;
16+
border-style: solid;
17+
}
18+
19+
body {
20+
margin-top: 1rem;
21+
margin-bottom: 1rem;
22+
margin-left: 5rem;
23+
margin-right: 5rem;
24+
background-color: #202225;
25+
font-family: Uni Sans;
26+
}
27+
28+
body a {
29+
text-decoration: underline;
30+
color: rgb(37, 106, 255);
31+
}
32+
33+
.section1 {
34+
height: fit-content;
35+
width: 100%;
36+
text-align: center;
37+
background-color: #2F3136;
38+
border-radius: 1rem;
39+
display: inline-block;
40+
}
41+
42+
.section1 div {
43+
text-align: center;
44+
background-color: #36393F;
45+
border-radius: 1rem;
46+
margin: 2rem;
47+
}
48+
49+
.section1 div h1 {
50+
color: #96989D;
51+
text-align: center;
52+
font-size: 4rem;
53+
padding-top: 2rem;
54+
}
55+
56+
.section1 div p {
57+
padding-bottom: 1rem;
58+
color: #DCDDDE;
59+
font-style: italic;
60+
text-align: center;
61+
font-size: 1rem;
62+
}
63+
64+
65+
.section1 div img {
66+
padding-bottom: 2rem;
67+
}
68+
69+
.section2 {
70+
margin-top: 4rem;
71+
height: fit-content;
72+
width: 100%;
73+
display: grid;
74+
grid-template-areas:
75+
"applicationId details state"
76+
"start largeImage smallImage"
77+
"button1 button2 sendButton";
78+
grid-template-columns: 1fr 1fr 1fr;
79+
grid-template-rows: 1fr 1fr 1fr;
80+
background-color: #2F3136;
81+
border-radius: 1rem;
82+
}
83+
84+
.section2 div {
85+
display: inline;
86+
text-align: center;
87+
background-color: #36393F;
88+
border-radius: 1rem;
89+
margin: 2rem;
90+
}
91+
92+
.section2 div h2 {
93+
color: #96989D;
94+
text-align: center;
95+
font-size: 2rem;
96+
}
97+
98+
.section2 div p {
99+
margin-right: .5rem;
100+
margin-bottom: 1rem;
101+
color: #DCDDDE;
102+
font-style: italic;
103+
text-align: center;
104+
font-size: 1rem;
105+
display: inline;
106+
}
107+
108+
.section2 div input {
109+
margin-bottom: 1rem;
110+
text-align: center;
111+
}
112+
113+
.section2 div img {
114+
width: 15rem;
115+
padding-bottom: 1rem;
116+
}
117+
118+
.statusr {
119+
color: #ff0000!important;
120+
}
121+
122+
.statusg {
123+
color: #00ff00!important;
124+
}

0 commit comments

Comments
 (0)