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 12bcad1..662b9da 100644 --- a/nadeo_event_api/src/nadeo_event_api/api/endpoints.py +++ b/nadeo_event_api/src/nadeo_event_api/api/endpoints.py @@ -33,5 +33,8 @@ 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 +PASTES_IO_LOGIN_URL = "http://pastesio.com/api/login" +PASTES_IO_CREATE_URL = "http://pastesio.com/api/paste/create" + +PASTEFY_SKIFF_CREATE_URL = "https://pastes.skiff.dev/api/v2/paste" +PASTEFY_SKIFF_RAW_URL_FMT = "https://pastes.skiff.dev/{0}/raw" \ No newline at end of file diff --git a/nadeo_event_api/src/nadeo_event_api/api/pastesio/__init__.py b/nadeo_event_api/src/nadeo_event_api/api/pastefy/__init__.py similarity index 100% rename from nadeo_event_api/src/nadeo_event_api/api/pastesio/__init__.py rename to nadeo_event_api/src/nadeo_event_api/api/pastefy/__init__.py diff --git a/nadeo_event_api/src/nadeo_event_api/api/pastefy/pastefy_api.py b/nadeo_event_api/src/nadeo_event_api/api/pastefy/pastefy_api.py new file mode 100644 index 0000000..e0bd1bf --- /dev/null +++ b/nadeo_event_api/src/nadeo_event_api/api/pastefy/pastefy_api.py @@ -0,0 +1,42 @@ +# Hosted by Matrix, requires dedicated IP whitelist to work. + +import datetime +import json +import requests + +from nadeo_event_api.api.endpoints import PASTEFY_SKIFF_CREATE_URL, PASTEFY_SKIFF_RAW_URL_FMT +from nadeo_event_api.objects.outbound.pastebin.tmwt_2v2 import Tmwt2v2Paste + +def post_tmwt_2v2(tmwt_2v2_pastebin: Tmwt2v2Paste, title: str) -> str: + """Posts a TMWT 2v2 paste to pastes.skiff.dev and returns the URL of the raw paste. Expires in 1 hour. + NOTE: Must have a whitelisted IP -- contact Matrix/Skiff for this if needed. + + Args: + tmwt_2v2_pastebin (Tmwt2v2Pastebin): The TMWT paste. + title (str): The title of the paste. + + Returns: + str: The raw URL of the paste. + """ + content = json.dumps(tmwt_2v2_pastebin.as_jsonable_dict(), indent=4) + expiry_date = datetime.datetime.utcnow() + datetime.timedelta(hours=1) + formatted = expiry_date.strftime('%Y-%m-%d %H:%M:%S') + '.0' + data = { + "type": "PASTE", + "title": title, + "content": content, + "expire_at": formatted, + "visibility": "PUBLIC", + } + + response = requests.post( + url=PASTEFY_SKIFF_CREATE_URL, + data=data, + ) + if response.status_code != 200: + print(response.text) + raise Exception(f"Failed to post to pastes.skiff.dev API.") + + paste_id = response.json()["paste"]["id"] + paste_url = PASTEFY_SKIFF_RAW_URL_FMT.format(paste_id) + return paste_url \ No newline at end of file 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 deleted file mode 100644 index 5c730f2..0000000 --- a/nadeo_event_api/src/nadeo_event_api/api/pastesio/pastesio_api.py +++ /dev/null @@ -1,72 +0,0 @@ -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/sample/tmwt_scrim.py b/sample/tmwt_scrim.py index 39b3e1a..c10b226 100644 --- a/sample/tmwt_scrim.py +++ b/sample/tmwt_scrim.py @@ -25,7 +25,7 @@ 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 Tmwt2v2Paste, Tmwt2v2PasteTeam -from nadeo_event_api.api.pastebin.pastebin_api import post_tmwt_2v2 +from nadeo_event_api.api.pastefy.pastefy_api import post_tmwt_2v2 from nadeo_event_api.objects.outbound.settings.pick_ban_style import PickBanStyle # Event info @@ -37,12 +37,14 @@ # Create teams of two by UID blue_team = Tmwt2v2PasteTeam( team_name="Blue", + team_id="Blue", p1_tm_account_id="febeaf4d-f340-4954-9fe2-88390959ae53", # Charles p2_tm_account_id="6e3bf3f9-7dcb-47d4-bdae-037ab66628f2", # Randomize ) red_team = Tmwt2v2PasteTeam( team_name="Red", + team_id="Red", p1_tm_account_id="2e34c3cb-9548-4815-aee3-c68518a1fd88", # Nixotica p2_tm_account_id="da244fe1-a978-449e-8a06-1362bce8b203", # Slorpie ) @@ -52,7 +54,7 @@ team_b=red_team, ) -# pastebin_url = post_tmwt_2v2(pastebin, os.environ.get("PASTEBIN_API_DEV_KEY")) # type: ignore +teams_url = post_tmwt_2v2(pastebin, "tmwt2025test") now = datetime.utcnow() match_start = now + timedelta(minutes=1) @@ -96,7 +98,7 @@ ), match_points_limit=2, match_info="2025 THE YEAR", - teams_url="https://pastebin.com/raw/hSLVPj1c", + teams_url=teams_url, #"https://pastebin.com/raw/hSLVPj1c", ), map_points_limit=5, loading_screen_image_url="https://download.dashmap.live/6e3bf3f9-7dcb-47d4-bdae-037ab66628f2/AM_Stream_BG_Nologo.png",