|
1 | 1 | from os import stat_result |
2 | 2 | import PySimpleGUI as sg |
3 | 3 | from pypresence import Presence |
4 | | -from pypresence.exceptions import InvalidArgument, InvalidID, InvalidPipe |
| 4 | +from pypresence.exceptions import InvalidArgument, InvalidID, InvalidPipe, ServerError |
5 | 5 | import webbrowser |
6 | | -# Raven's Rich Presence Generator is a free open source program to generate custom discord rich presences. If anyone tries to sell you Raven's Rich Presence Generator, or tries to redistribute it as their own, please report it immediately. You are being scammed" |
| 6 | +import json |
7 | 7 |
|
| 8 | +# Raven's Rich Presence Generator is a free open source program to generate custom discord rich presences. If anyone tries to sell you Raven's Rich Presence Generator, or tries to redistribute it as their own, please report it immediately. You are being scammed" |
| 9 | +theme_choice = 'DarkGrey5' |
| 10 | +sg.theme(theme_choice) |
8 | 11 | # All the stuff inside the window. |
9 | | -layout = [ [sg.Text("Raven\'s Rich Presence Generator")], |
10 | | - [sg.Text(" ", key="ERROR", text_color="red")], #This string is long. |
11 | | - [sg.Text('Enter your client ID', key="~CLIENTID~"), |
12 | | - sg.InputText()], |
13 | | - [sg.Text('Large Image ID:', key="~LIMAGEID~"), |
14 | | - sg.InputText()], |
15 | | - [sg.Text('Small Image ID:', key="~SIMAGEID~"), |
16 | | - sg.InputText()], |
17 | | - [sg.Text('Enter state of Rich Presence (Top text)', key="~RPCSTATE~"), |
18 | | - sg.InputText()], |
19 | | - [sg.Text('Enter details of Rich Presence (2nd to bottom text)', key="~RPCDETAILS~"), |
20 | | - sg.InputText()], |
21 | | - [sg.Text('(Optional) First button text', key="~firstbuttontext~", visible = True), |
22 | | - sg.InputText()], |
23 | | - [sg.Text('(Mandatory if you put text for first button) First button URL', key="~firstbuttonurl~", visible = True), |
24 | | - sg.InputText()], |
25 | | - [sg.Button('Run!'), sg.Button('Cancel'), sg.Button('Join Discord!'), sg.Button('Help'),], |
26 | | - [sg.Text('Ravens Rich Presence Generator is a free open source program to generate custom discord rich presences. \n If anyone tries to sell you Ravens Rich Presence Generator, or tries to redistribute it as their own, please report it immediately.\n You are being scammed', justification='center')] |
| 12 | +layout = [ [sg.Text("Raven\'s Rich Presence Generator", background_color="#212835")], |
| 13 | + [sg.Text(" ", key="ERROR", text_color="red", background_color="#212835")], #This string is long. |
| 14 | + [sg.Text('Enter your client ID', key="~CLIENTID~", background_color="#212835", ), |
| 15 | + sg.InputText(key="CLIENTIDBOX")], |
| 16 | + [sg.Text('Large Image ID:', key="~LIMAGEID~", background_color="#212835"), |
| 17 | + sg.InputText(key="LARGEIMAGEKEY")], |
| 18 | + [sg.Text('Small Image ID:', key="~SIMAGEID~", background_color="#212835"), |
| 19 | + sg.InputText(key="SMALLiMAGEKEY")], |
| 20 | + [sg.Text('Enter top line of text', key="~RPCDETAILS~", background_color="#212835"), |
| 21 | + sg.InputText(key="DETAILS")], |
| 22 | + [sg.Text('Enter bottom line of text', key="~RPCSTATE~", background_color="#212835"), |
| 23 | + sg.InputText(key="STATE")], |
| 24 | + [sg.Text('(Optional) First button text', key="~firstbuttontext~", visible = True, background_color="#212835", ), |
| 25 | + sg.InputText(key="BUTTONLABEL")], |
| 26 | + [sg.Text('(Mandatory if you put text for first button) First button URL', key="~firstbuttonurl~", visible = True, background_color="#212835"), |
| 27 | + sg.InputText(key="BUTTONURL")], |
| 28 | + [sg.Button('Run!', button_color="#d764f9"), sg.Button("Load from config.json", button_color="#d764f9"), sg.Button("Save to config.json", button_color="#d764f9"), sg.Button('Client ID', button_color="#d764f9"), sg.Button('Join Discord!', button_color="#d764f9"), sg.Button('Help', button_color="#d764f9"),], |
| 29 | + [sg.Text('Raven\'s Rich Presence Generator is a free open source program to generate custom discord rich presences. \n If anyone tries to sell you Ravens Rich Presence Generator, or tries to redistribute it as their own, please report it immediately.\n You are being scammed', justification='center', background_color="#212835", )] |
27 | 30 | ] |
28 | 31 |
|
29 | 32 |
|
30 | 33 |
|
31 | 34 | # Create the Window |
32 | | -window = sg.Window('Rich Presence', layout, icon="test.png", element_justification='c') |
| 35 | +window = sg.Window('Rich Presence', layout, icon="test.png", element_justification='c', background_color="#212835") |
33 | 36 |
|
34 | 37 | # Event Loop to process "events" and get the "values" of the inputs |
35 | 38 | while True: |
36 | 39 | event, values = window.read() |
37 | | - if event == sg.WIN_CLOSED or event == 'Cancel': # if user closes window or clicks cancel |
38 | | - break |
| 40 | + |
| 41 | + |
39 | 42 |
|
| 43 | + if event == sg.WIN_CLOSED : # if user closes window or clicks cancel |
| 44 | + break |
| 45 | + |
| 46 | + elif event == "Client ID": |
| 47 | + webbrowser.open("https://discord.com/developers/applications") |
| 48 | + |
40 | 49 | elif event == 'Join Discord!': |
41 | 50 | webbrowser.open("https://discord.gg/MwmnXNsjsj") |
42 | 51 | elif event == 'Help': |
|
49 | 58 | Button Text: The label text shown on the button\n |
50 | 59 | Button URL: The URL that will be opened when a user clicks on the button''') |
51 | 60 |
|
| 61 | + elif event == "Save to config.json": |
| 62 | + |
| 63 | + data = { |
| 64 | + "ClientID": values["CLIENTIDBOX"], |
| 65 | + "LargeImageKey": values["LARGEIMAGEKEY"], |
| 66 | + "SmallImageKey": values["SMALLiMAGEKEY"], |
| 67 | + "State": values["STATE"], |
| 68 | + "Details": values["DETAILS"], |
| 69 | + "ButtonLabel": values["BUTTONLABEL"], |
| 70 | + "ButtonUrl": values["BUTTONURL"] |
| 71 | + |
| 72 | + } |
| 73 | + json_object = json.dumps(data, indent = 4) |
| 74 | + |
| 75 | + |
| 76 | + with open("config.json", "w") as f: |
| 77 | + f.write(json_object) |
| 78 | + |
| 79 | + |
| 80 | + |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | + elif event == "Load from config.json": |
| 87 | + config = None |
| 88 | + largeimage = None |
| 89 | + smallimagekey = None |
| 90 | + state = None |
| 91 | + details = None |
| 92 | + buttonurl = None |
| 93 | + buttonlabel = None |
| 94 | + |
| 95 | + try : |
| 96 | + config = json.load(open("config.json")) |
| 97 | + |
| 98 | + except FileNotFoundError : |
| 99 | + window.Element("ERROR").Update("Error occured! The config.json file does not exist. Make sure it is in the folder of ez-rp.exe") |
| 100 | + |
| 101 | + try : |
| 102 | + cid = str(config["ClientID"]) |
| 103 | + window.Element("CLIENTIDBOX").Update(cid) |
| 104 | + |
| 105 | + except KeyError : |
| 106 | + sg.Popup("Error occured! Client ID Value does not exist.") |
| 107 | + |
| 108 | + try : |
| 109 | + largeimage = str(config["LargeImageKey"]) |
| 110 | + window.Element("LARGEIMAGEKEY").Update(largeimage) |
| 111 | + |
| 112 | + except KeyError: |
| 113 | + print("No Large Iage") |
| 114 | + |
| 115 | + try : |
| 116 | + smallimage = str(config["SmallImageKey"]) |
| 117 | + window.Element("SMALLiMAGEKEY").Update(smallimage) |
| 118 | + |
| 119 | + except KeyError : |
| 120 | + print("No small image") |
| 121 | + |
| 122 | + try : |
| 123 | + |
| 124 | + state = str(config["State"]) |
| 125 | + print(state) |
| 126 | + window.Element("STATE").Update(state) |
| 127 | + |
| 128 | + except KeyError : |
| 129 | + print("No state in config.json") |
| 130 | + |
| 131 | + try : |
| 132 | + details = str(config["Details"]) |
| 133 | + window.Element("DETAILS").Update(details) |
| 134 | + |
| 135 | + except KeyError : |
| 136 | + print("No details in config.json") |
| 137 | + |
| 138 | + try : |
| 139 | + buttonlabel = str(config["ButtonLabel"]) |
| 140 | + window.Element("BUTTONLABEL").Update(buttonlabel) |
| 141 | + |
| 142 | + except KeyError : |
| 143 | + print("No button label in config.json") |
| 144 | + |
| 145 | + try : |
| 146 | + buttonurl = str(config["ButtonURL"]) |
| 147 | + window.Element("BUTTONURL").Update(buttonurl) |
| 148 | + |
| 149 | + except KeyError : |
| 150 | + print("No state in config.json") |
| 151 | + |
| 152 | + |
| 153 | + |
| 154 | + |
| 155 | + |
| 156 | + |
| 157 | + |
| 158 | + |
| 159 | + |
| 160 | + |
| 161 | + |
52 | 162 |
|
53 | 163 | elif window["~firstbuttontext~"] == None and not window["~firstbuttonurl~"] == None: |
54 | 164 | window.Element("ERROR").Update("An error occured! Please make sure to add a URL!") |
55 | 165 |
|
56 | 166 | elif window["~firstbuttonurl~"] == None and not window["~firstbuttontext~"] == None: |
57 | 167 | window.Element("ERROR").Update("An error occured! Make sure to add a label for your button!") |
58 | | - |
| 168 | + |
59 | 169 | else: |
60 | 170 |
|
61 | 171 | try : |
62 | | - |
63 | | - RPC = Presence(values[0]) |
| 172 | + |
| 173 | + print(values["BUTTONLABEL"]) |
| 174 | + print("bruh moment") |
| 175 | + RPC = Presence(values["CLIENTIDBOX"]) |
64 | 176 | RPC.connect() |
65 | | - RPC.update(state=values[3], details=values[4],large_image=values[1],small_image=values[2], buttons=[ |
66 | | - { |
67 | | - "label": values[5], |
68 | | - "url": values[6] |
69 | 177 |
|
70 | | - } |
71 | | - ]) # Set the presence |
| 178 | + print(RPC.update(state=values["STATE"], details=values["DETAILS"], buttons=[{"label": values["BUTTONLABEL"], "url": values["BUTTONURL"]}])) |
| 179 | + |
| 180 | + |
| 181 | + print("Ran this function") |
72 | 182 | window.Element("ERROR").Update("Success! Your rich presence is now up! Make sure to leave this window open.", text_color="green") |
| 183 | + window.TKroot.title("ez-rp Custom Rich Presence. Currently Running!") |
73 | 184 |
|
74 | 185 |
|
75 | 186 | except InvalidID : |
|
78 | 189 | except : |
79 | 190 | try : |
80 | 191 |
|
81 | | - RPC = Presence(values[0]) |
| 192 | + RPC = Presence(values["CLIENTIDBOX"]) |
82 | 193 | RPC.connect() |
83 | | - RPC.update(state=values[3], details=values[4], large_image=values[1], small_image=values[2]) |
| 194 | + RPC.update(state=values["STATE"], details=values["DETAILS"], large_image=values["LARGEIMAGEKEY"], small_image=values["LARGEIMAGEKEY"]) |
84 | 195 | window.Element("ERROR").Update("Success! Your rich presence is now up! Make sure to leave this window open.", text_color="green") |
| 196 | + window.TKroot.title("ez-rp Custom Rich Presence. Currently Running!") |
| 197 | + except ServerError: |
| 198 | + try: |
| 199 | + RPC = Presence(values["CLIENTIDBOX"]) |
| 200 | + RPC.connect() |
| 201 | + RPC.update(state=values["STATE"], details=values["DETAILS"], large_image=values["LARGEIMAGEKEY"]) |
| 202 | + window.Element("ERROR").Update("Success! Your rich presence is now up! Make sure to leave this window open.", text_color="green") |
| 203 | + window.TKroot.title("ez-rp Custom Rich Presence. Currently Running!") |
| 204 | + except ServerError: |
| 205 | + try: |
| 206 | + RPC = Presence(values["CLIENTIDBOX"]) |
| 207 | + RPC.connect() |
| 208 | + RPC.update(state=values["STATE"], details=values["DETAILS"], small_image=values["SMALLiMAGEKEY"]) |
| 209 | + window.Element("ERROR").Update("Success! Your rich presence is now up! Make sure to leave this window open.", text_color="green") |
| 210 | + window.TKroot.title("ez-rp Custom Rich Presence. Currently Running!") |
| 211 | + except ServerError: |
| 212 | + RPC = Presence(values["CLIENTIDBOX"]) |
| 213 | + RPC.connect() |
| 214 | + RPC.update(state=values["STATE"], details=values["DETAILS"]) |
| 215 | + window.Element("ERROR").Update("Success! Your rich presence is now up! Make sure to leave this window open.", text_color="green") |
| 216 | + window.TKroot.title("ez-rp Custom Rich Presence. Currently Running!") |
85 | 217 |
|
86 | | - |
| 218 | + |
| 219 | + except ServerError: |
| 220 | + window.Element("ERROR").Update("An error occured! Please make sure you entered everything required!") |
87 | 221 | except InvalidID : |
88 | | - window.Element("ERROR").Update("An error occured! Please correct your Client ID!") |
| 222 | + sg.Popup("You entered an invalid Client ID! Client IDs are not user IDs, you must obtain them by making an app in the discord developer portal. Click the Client ID Button below to go to the discord developer portal") |
89 | 223 |
|
90 | 224 |
|
91 | 225 |
|
|
0 commit comments