Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion nadeo_event_api/src/nadeo_event_api/api/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@
"https://meet.trackmania.nadeo.club/api/competitions/{0}/mode-teams"
)

PASTEBIN_POST_URL = "https://pastebin.com/api/api_post.php"
PASTEBIN_POST_URL = "https://pastebin.com/api/api_post.php"

PASTES_IO_LOGIN_URL = "http://pastes.io/api/login"
PASTES_IO_CREATE_URL = "http://pastes.io/api/paste/create"
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import json
import requests
from nadeo_event_api.api.endpoints import PASTEBIN_POST_URL
from nadeo_event_api.objects.outbound.pastebin.tmwt_2v2 import Tmwt2v2Pastebin
from nadeo_event_api.objects.outbound.pastebin.tmwt_2v2 import Tmwt2v2Paste


def post_tmwt_2v2(tmwt_2v2_pastebin: Tmwt2v2Pastebin, api_dev_key: str) -> str:
def post_tmwt_2v2(tmwt_2v2_pastebin: Tmwt2v2Paste, api_dev_key: str) -> str:
"""Posts a TMWT 2v2 Pastebin and returns the URL of the pastebin.

Args:
Expand Down
Empty file.
72 changes: 72 additions & 0 deletions nadeo_event_api/src/nadeo_event_api/api/pastesio/pastesio_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import json
import requests

from nadeo_event_api.api.endpoints import PASTES_IO_CREATE_URL, PASTES_IO_LOGIN_URL
from nadeo_event_api.objects.outbound.pastebin.tmwt_2v2 import Tmwt2v2Paste


def login(username: str, password: str) -> str:
"""Logs in to the pastes.io API and returns the token.

Args:
username (str): Your username.
password (str): Your password.

Returns:
str: The API token used to authenticate requests.
"""

header = {"Accept": "application/json"}
data = {
"username": username,
"password": password,
}
response = requests.post(
url=PASTES_IO_LOGIN_URL,
headers=header,
data=data,
)

if response.status_code != 200:
error = response.json()["error"]
raise Exception(f"Failed to login to pastes.io API: {error}")

return response.json()["success"]["api_token"]

def post_tmwt_2v2(tmwt_2v2_pastebin: Tmwt2v2Paste, title: str, token: str) -> str:
"""Posts a TMWT 2v2 paste to pastes.io and returns the URL of the raw paste. Expires in 1 hour.

Args:
tmwt_2v2_pastebin (Tmwt2v2Pastebin): The TMWT paste.
title (str): The title of the paste.
token (str): The API token to make the request.

Returns:
str: The raw URL of the paste.
"""
content = json.dumps(tmwt_2v2_pastebin.as_jsonable_dict(), indent=4)
data = {
"content": content,
"status": 1, # 0 = public, 1 = unlisted, 2 = private
"expire": "1H", # 1H = 1 hour
"title": title,
}
headers = {
"Accept": "application/json",
"Authorization": "Bearer " + token,
}

response = requests.post(
url=PASTES_IO_CREATE_URL,
headers=headers,
data=data,
)
if response.status_code != 200:
error = response.json()["error"]
raise Exception(f"Failed to post to pastes.io API: {error}")

print(response.json())
paste_url = response.json()["success"]["paste_url"]

raw_url = paste_url.replace("https://pastes.io/", "https://pastes.io/raw/")
return raw_url
Original file line number Diff line number Diff line change
@@ -1,206 +1,34 @@
PASTEBIN_TEMPLATE_DICT = [
{
"Id": "one",
{
"Id": "",
"Name": "",
"Players": [
{
"AccountId": "",
"Name": "",
"PhotoUrl": ""
},
{
"AccountId": "",
"Name": "",
"LogoUrl": "",
"Sign2x3Url": "",
"Sign16x9Url": "",
"Sign64x10Url": "",
"Messages": {
"Ace": {
"Customize": [],
"VideoUrl": "",
"VideoResolution": [0, 0],
"VideoDelay": 0,
"SoundUrl": "",
"SoundDelay": 0,
"Message": "",
"MessageDuration": 0,
"MessageDelay": 0
},
"Victory": {
"Customize": [],
"VideoUrl": "",
"VideoResolution": [0, 0],
"VideoDelay": 0,
"SoundUrl": "",
"SoundDelay": 0,
"Message": "",
"MessageDuration": 0,
"MessageDelay": 0
},
"Draw": {
"Customize": [],
"VideoUrl": "",
"VideoResolution": [0, 0],
"VideoDelay": 0,
"SoundUrl": "",
"SoundDelay": 0,
"Message": "",
"MessageDuration": 0,
"MessageDelay": 0
},
"Overtime": {
"Customize": [],
"VideoUrl": "",
"VideoResolution": [0, 0],
"VideoDelay": 0,
"SoundUrl": "",
"SoundDelay": 0,
"Message": "",
"MessageDuration": 0,
"MessageDelay": 0
},
"TrackPoint": {
"Customize": ["SoundUrl", "MessageDelay"],
"VideoUrl": "",
"VideoResolution": [0, 0],
"VideoDelay": 0,
"SoundUrl": "",
"SoundDelay": 0,
"Message": "",
"MessageDuration": 0,
"MessageDelay": 700
},
"MatchPoint": {
"Customize": [],
"VideoUrl": "",
"VideoResolution": [0, 0],
"VideoDelay": 0,
"SoundUrl": "",
"SoundDelay": 0,
"Message": "",
"MessageDuration": 0,
"MessageDelay": 0
},
"TrackWin": {
"Customize": ["SoundUrl", "VideoDelay"],
"VideoUrl": "",
"VideoResolution": [0, 0],
"VideoDelay": 500,
"SoundUrl": "",
"SoundDelay": 0,
"Message": "",
"MessageDuration": 0,
"MessageDelay": 0
},
"MatchWin": {
"Customize": [],
"VideoUrl": "",
"VideoResolution": [0, 0],
"VideoDelay": 0,
"SoundUrl": "",
"SoundDelay": 0,
"Message": "",
"MessageDuration": 0,
"MessageDelay": 0
}
},
"Players": [
{"AccountId": "", "Name": "", "PhotoUrl": ""},
{"AccountId": "6e3bf3f9-7dcb-47d4-bdae-037ab66628f2", "Name": "", "PhotoUrl": ""}
]
},
"PhotoUrl": ""
}
]
},
{
"Id": "two",
"Id": "",
"Name": "",
"Players": [
{
"AccountId": "",
"Name": "",
"PhotoUrl": ""
},
{
"AccountId": "",
"Name": "",
"LogoUrl": "",
"Sign2x3Url": "",
"Sign16x9Url": "",
"Sign64x10Url": "",
"Messages": {
"Ace": {
"Customize": [],
"VideoUrl": "",
"VideoResolution": [0, 0],
"VideoDelay": 0,
"SoundUrl": "",
"SoundDelay": 0,
"Message": "",
"MessageDuration": 0,
"MessageDelay": 0
},
"Victory": {
"Customize": [],
"VideoUrl": "",
"VideoResolution": [0, 0],
"VideoDelay": 0,
"SoundUrl": "",
"SoundDelay": 0,
"Message": "",
"MessageDuration": 0,
"MessageDelay": 0
},
"Draw": {
"Customize": [],
"VideoUrl": "",
"VideoResolution": [0, 0],
"VideoDelay": 0,
"SoundUrl": "",
"SoundDelay": 0,
"Message": "",
"MessageDuration": 0,
"MessageDelay": 0
},
"Overtime": {
"Customize": [],
"VideoUrl": "",
"VideoResolution": [0, 0],
"VideoDelay": 0,
"SoundUrl": "",
"SoundDelay": 0,
"Message": "",
"MessageDuration": 0,
"MessageDelay": 0
},
"TrackPoint": {
"Customize": ["SoundUrl", "MessageDelay"],
"VideoUrl": "",
"VideoResolution": [0, 0],
"VideoDelay": 0,
"SoundUrl": "",
"SoundDelay": 0,
"Message": "",
"MessageDuration": 0,
"MessageDelay": 700
},
"MatchPoint": {
"Customize": [],
"VideoUrl": "",
"VideoResolution": [0, 0],
"VideoDelay": 0,
"SoundUrl": "",
"SoundDelay": 0,
"Message": "",
"MessageDuration": 0,
"MessageDelay": 0
},
"TrackWin": {
"Customize": ["SoundUrl", "VideoDelay"],
"VideoUrl": "",
"VideoResolution": [0, 0],
"VideoDelay": 500,
"SoundUrl": "",
"SoundDelay": 0,
"Message": "",
"MessageDuration": 0,
"MessageDelay": 0
},
"MatchWin": {
"Customize": [],
"VideoUrl": "",
"VideoResolution": [0, 0],
"VideoDelay": 0,
"SoundUrl": "",
"SoundDelay": 0,
"Message": "",
"MessageDuration": 0,
"MessageDelay": 0
}
},
"Players": [
{"AccountId": "", "Name": "", "PhotoUrl": ""},
{"AccountId": "", "Name": "", "PhotoUrl": ""}
]
}
]
"PhotoUrl": ""
}
]
}
]
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
import json
import os
from typing import List

from nadeo_event_api.objects.outbound.pastebin.pastebin_2v2_template import PASTEBIN_TEMPLATE_DICT


class Tmwt2v2PastebinTeam:
class Tmwt2v2PasteTeam:
def __init__(
self,
team_id: str,
team_name: str,
p1_tm_account_id: str,
p2_tm_account_id: str,
):
self.team_id = team_id
self.team_name = team_name
self.p1_tm_account_id = p1_tm_account_id
self.p2_tm_account_id = p2_tm_account_id

def members(self) -> List[str]:
return [self.p1_tm_account_id, self.p2_tm_account_id]

class Tmwt2v2Pastebin:
class Tmwt2v2Paste:
def __init__(
self,
team_a: Tmwt2v2PastebinTeam,
team_b: Tmwt2v2PastebinTeam,
team_a: Tmwt2v2PasteTeam,
team_b: Tmwt2v2PasteTeam,
):
self.team_a = team_a
self.team_b = team_b

def as_jsonable_dict(self):
pastebin_json = PASTEBIN_TEMPLATE_DICT

pastebin_json[0]["Id"] = self.team_a.team_id
pastebin_json[0]["Name"] = self.team_a.team_name
pastebin_json[0]["Players"][0]["AccountId"] = self.team_a.p1_tm_account_id
pastebin_json[0]["Players"][1]["AccountId"] = self.team_a.p2_tm_account_id
pastebin_json[1]["Id"] = self.team_b.team_id
pastebin_json[1]["Name"] = self.team_b.team_name
pastebin_json[1]["Players"][0]["AccountId"] = self.team_b.p1_tm_account_id
pastebin_json[1]["Players"][1]["AccountId"] = self.team_b.p2_tm_account_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"S_PickBanUseGamepadVersion": false,
"S_PickBanStartAuto": false,
"S_PickBanOrder": "",
"S_EnableReadyManager": true,
"S_EnableReadyManager": false,
"S_UseAutoReady": true,
"S_ReadyStartRatio": 1,
"S_MessageTimer": ""
Expand Down
Loading