ajout du code pour l'api REST et discord oauth. Refacto
This commit is contained in:
33
src/tools/discord_tools.py
Normal file
33
src/tools/discord_tools.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import psutil
|
||||
|
||||
from pypresence import Presence
|
||||
from get_server_token import GetServerTokenForDiscord
|
||||
from constants import Urls
|
||||
|
||||
class DiscordToken:
|
||||
@staticmethod
|
||||
def decode_discord_token():
|
||||
discord_token = GetServerTokenForDiscord.get_token(GetServerTokenForDiscord.authenticate(Urls.API_URL.value))
|
||||
return discord_token
|
||||
|
||||
class CheckDiscord:
|
||||
|
||||
@staticmethod
|
||||
def isdiscordrunning() -> bool:
|
||||
for process in psutil.process_iter(["name"]):
|
||||
if process.info["name"].lower() == "discord.exe":
|
||||
return True
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def isuserconnected(clientid: str) -> bool:
|
||||
rpc = Presence(clientid)
|
||||
try:
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
finally:
|
||||
try:
|
||||
rpc.close()
|
||||
except Exception:
|
||||
pass
|
||||
Reference in New Issue
Block a user