diff --git a/nadeo_event_api/src/nadeo_event_api/api/endpoints.py b/nadeo_event_api/src/nadeo_event_api/api/endpoints.py index 341266f..12bcad1 100644 --- a/nadeo_event_api/src/nadeo_event_api/api/endpoints.py +++ b/nadeo_event_api/src/nadeo_event_api/api/endpoints.py @@ -31,4 +31,7 @@ "https://meet.trackmania.nadeo.club/api/competitions/{0}/mode-teams" ) -PASTEBIN_POST_URL = "https://pastebin.com/api/api_post.php" \ No newline at end of file +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" \ No newline at end of file diff --git a/nadeo_event_api/src/nadeo_event_api/api/pastebin/pastebin_api.py b/nadeo_event_api/src/nadeo_event_api/api/pastebin/pastebin_api.py index 5af9e4c..0a53c97 100644 --- a/nadeo_event_api/src/nadeo_event_api/api/pastebin/pastebin_api.py +++ b/nadeo_event_api/src/nadeo_event_api/api/pastebin/pastebin_api.py @@ -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: diff --git a/nadeo_event_api/src/nadeo_event_api/api/pastesio/__init__.py b/nadeo_event_api/src/nadeo_event_api/api/pastesio/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/nadeo_event_api/src/nadeo_event_api/api/pastesio/pastesio_api.py b/nadeo_event_api/src/nadeo_event_api/api/pastesio/pastesio_api.py new file mode 100644 index 0000000..5c730f2 --- /dev/null +++ b/nadeo_event_api/src/nadeo_event_api/api/pastesio/pastesio_api.py @@ -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 \ No newline at end of file diff --git a/nadeo_event_api/src/nadeo_event_api/objects/outbound/pastebin/pastebin_2v2_template.py b/nadeo_event_api/src/nadeo_event_api/objects/outbound/pastebin/pastebin_2v2_template.py index 6e158aa..afdf3ae 100644 --- a/nadeo_event_api/src/nadeo_event_api/objects/outbound/pastebin/pastebin_2v2_template.py +++ b/nadeo_event_api/src/nadeo_event_api/objects/outbound/pastebin/pastebin_2v2_template.py @@ -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": "" + } + ] + } +] \ No newline at end of file diff --git a/nadeo_event_api/src/nadeo_event_api/objects/outbound/pastebin/tmwt_2v2.py b/nadeo_event_api/src/nadeo_event_api/objects/outbound/pastebin/tmwt_2v2.py index ffdf591..7c81d84 100644 --- a/nadeo_event_api/src/nadeo_event_api/objects/outbound/pastebin/tmwt_2v2.py +++ b/nadeo_event_api/src/nadeo_event_api/objects/outbound/pastebin/tmwt_2v2.py @@ -1,17 +1,17 @@ -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 @@ -19,11 +19,11 @@ def __init__( 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 @@ -31,9 +31,11 @@ def __init__( 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 diff --git a/nadeo_event_api/test/api/structure/resources/basic_event.json b/nadeo_event_api/test/api/structure/resources/basic_event.json index 6f7e746..6b84ef4 100644 --- a/nadeo_event_api/test/api/structure/resources/basic_event.json +++ b/nadeo_event_api/test/api/structure/resources/basic_event.json @@ -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": "" diff --git a/sample/scratchboard.py b/sample/scratchboard.py index f683eaa..e91d89d 100644 --- a/sample/scratchboard.py +++ b/sample/scratchboard.py @@ -18,30 +18,33 @@ # print(match_results) -# from nadeo_event_api.api.pastebin.pastebin_api import post_tmwt_2v2 -# from nadeo_event_api.objects.outbound.pastebin.tmwt_2v2 import Tmwt2v2Pastebin, Tmwt2v2PastebinTeam +# from nadeo_event_api.api.pastesio.pastesio_api import login, post_tmwt_2v2 +# from nadeo_event_api.objects.outbound.pastebin.tmwt_2v2 import Tmwt2v2Paste, Tmwt2v2PasteTeam -# blue_team = Tmwt2v2PastebinTeam( +# blue_team = Tmwt2v2PasteTeam( +# team_id="blue", # team_name="Blue", # p1_tm_account_id="2e34c3cb-9548-4815-aee3-c68518a1fd88", # Nixotica # p2_tm_account_id="6e3bf3f9-7dcb-47d4-bdae-037ab66628f2", # Randomize # ) -# red_team = Tmwt2v2PastebinTeam( +# red_team = Tmwt2v2PasteTeam( +# team_id="red", # team_name="Red", # p1_tm_account_id="c7818ba0-5e85-408e-a852-f658e8b90eec", # Dummy # p2_tm_account_id="551dd1f5-2380-417d-98a5-8e2244f9287f", # Revants # ) -# pastebin = Tmwt2v2Pastebin( +# paste = Tmwt2v2Paste( # team_a=blue_team, # team_b=red_team, # ) -# url = post_tmwt_2v2(pastebin, os.environ.get("PASTEBIN_API_DEV_KEY")) # type: ignore +# token = login("User", "Pass") +# url = post_tmwt_2v2(paste, "test_paste", token) # print(url) -from nadeo_event_api.api.event_api import get_event_teams, get_event_participants +# from nadeo_event_api.api.event_api import get_event_teams, get_event_participants -print(get_event_teams(24706)) -print(get_event_participants(24706, 4, 0)) \ No newline at end of file +# print(get_event_teams(24706)) +# print(get_event_participants(24706, 4, 0)) \ No newline at end of file diff --git a/sample/tmwt_scrim.py b/sample/tmwt_scrim.py index 2ee8a4e..39b3e1a 100644 --- a/sample/tmwt_scrim.py +++ b/sample/tmwt_scrim.py @@ -24,7 +24,7 @@ from nadeo_event_api.api.structure.round.round import Round, RoundConfig from nadeo_event_api.api.structure.settings.plugin_settings import TMWTPluginSettings from nadeo_event_api.api.structure.settings.script_settings import TMWT2025ScriptSettings, TMWC2023ScriptSettings, BaseTMWTScriptSettings, BaseScriptSettings -from nadeo_event_api.objects.outbound.pastebin.tmwt_2v2 import Tmwt2v2Pastebin, Tmwt2v2PastebinTeam +from nadeo_event_api.objects.outbound.pastebin.tmwt_2v2 import Tmwt2v2Paste, Tmwt2v2PasteTeam from nadeo_event_api.api.pastebin.pastebin_api import post_tmwt_2v2 from nadeo_event_api.objects.outbound.settings.pick_ban_style import PickBanStyle @@ -35,19 +35,19 @@ campaign_id = 81781 # "NAC #3 Campaign" # Create teams of two by UID -blue_team = Tmwt2v2PastebinTeam( +blue_team = Tmwt2v2PasteTeam( team_name="Blue", p1_tm_account_id="febeaf4d-f340-4954-9fe2-88390959ae53", # Charles p2_tm_account_id="6e3bf3f9-7dcb-47d4-bdae-037ab66628f2", # Randomize ) -red_team = Tmwt2v2PastebinTeam( +red_team = Tmwt2v2PasteTeam( team_name="Red", p1_tm_account_id="2e34c3cb-9548-4815-aee3-c68518a1fd88", # Nixotica p2_tm_account_id="da244fe1-a978-449e-8a06-1362bce8b203", # Slorpie ) -pastebin = Tmwt2v2Pastebin( +pastebin = Tmwt2v2Paste( team_a=blue_team, team_b=red_team, )