use remember_web cookie instead of pterodactyl_session

This commit is contained in:
Joseph Montanaro 2020-10-29 23:10:58 -07:00
parent 38863a92cc
commit c895dc7627
2 changed files with 8 additions and 5 deletions

6
bot.py
View File

@ -15,7 +15,9 @@ import heavynode
DISCORD_TOKEN = os.environ['discord_token']
DISCORD_SERVER_ID = 530446700058509323
HEAVYNODE_TOKEN = os.environ['heavynode_token']
SESSION_COOKIE = os.environ['pterodactyl_session_cookie']
# SESSION_COOKIE = os.environ['pterodactyl_session_cookie']
COOKIE_NAME = 'remember_web_59ba36addc2b2f9401580f014c7f58ea4e30989d'
COOKIE_VALUE = os.environ[COOKIE_NAME]
logging.basicConfig()
@ -24,7 +26,7 @@ intents = discord.Intents.default()
intents.members = True
bot = lib.MineBot(command_prefix='!', intents=intents)
hn = heavynode.Client(HEAVYNODE_TOKEN, SESSION_COOKIE)
hn = heavynode.Client(HEAVYNODE_TOKEN, COOKIE_NAME, COOKIE_VALUE)
bot.add_cleanup(hn.shutdown)

View File

@ -78,9 +78,10 @@ class Socket:
class Client:
def __init__(self, token, session_cookie):
def __init__(self, token, cookie_name, cookie_value):
self.token = token
self.session_cookie = session_cookie
self.cookie_name = cookie_name
self.cookie_value = cookie_value
self.baseurl = 'https://control.heavynode.com/api'
self.stats = []
# global state is icky, but it sure is convenient
@ -148,7 +149,7 @@ class Client:
await self.socket.connect_socket()
async def fetch_daemon_secret(self):
cookie = {'pterodactyl_session': self.session_cookie}
cookie = {self.cookie_name: self.cookie_value}
async with aiohttp.ClientSession(cookies=cookie) as session:
r = await session.get('https://control.heavynode.com/server/' + self.server['identifier'])
m = re.search('"daemonSecret"\s?:\s?"([^"]*)"', await r.text())