Skip to content

Commit

Permalink
sed s/twitter.com/x.com/g
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed May 17, 2024
1 parent 8f9c86d commit 4ed14fa
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions mautrix_twitter/commands/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ async def login_cookie(evt: CommandEvent) -> None:
"auth_token": None,
}
await evt.reply(
"1. Log in to [Twitter](https://www.twitter.com/) in a private/incognito window.\n"
"1. Log in to [Twitter](https://www.x.com/) in a private/incognito window.\n"
"2. Press `F12` to open developer tools.\n"
'3. Select the "Application" (Chrome) or "Storage" (Firefox) tab.\n'
'4. In the sidebar, expand "Cookies" and select `https://twitter.com`.\n'
'4. In the sidebar, expand "Cookies" and select `https://x.com`.\n'
"5. In the cookie list, find the `auth_token` row and double click on the value"
r", then copy the value and send it here."
)
Expand Down
2 changes: 1 addition & 1 deletion mautrix_twitter/commands/conn.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async def ping(evt: CommandEvent) -> None:
user_info = await evt.sender.get_info()
await evt.reply(
f"You're logged in as {user_info.name} "
f"([@{evt.sender.username}](https://twitter.com/{evt.sender.username}), "
f"([@{evt.sender.username}](https://x.com/{evt.sender.username}), "
f"user ID: {evt.sender.twid})"
)

Expand Down
2 changes: 1 addition & 1 deletion mautrix_twitter/portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def deterministic_event_id(self, msg_id: str, part: str) -> EventID:
hash_content = f"{self.mxid}/twitter/{msg_id}/{part}"
hashed = hashlib.sha256(hash_content.encode("utf-8")).digest()
b64hash = base64.urlsafe_b64encode(hashed).decode("utf-8").rstrip("=")
return EventID(f"${b64hash}:twitter.com")
return EventID(f"${b64hash}:x.com")

async def _convert_twitter_message(
self, source: u.User, sender: p.Puppet, message: MessageData
Expand Down
8 changes: 4 additions & 4 deletions mautwitdm/streamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class TwitterStreamer(TwitterDispatcher):
via ``/live_pipeline/events``.
"""

pipeline_url = URL("https://api.twitter.com/live_pipeline/events")
pipeline_update_url = URL("https://api.twitter.com/1.1/live_pipeline/update_subscriptions")
pipeline_url = URL("https://api.x.com/live_pipeline/events")
pipeline_update_url = URL("https://api.x.com/1.1/live_pipeline/update_subscriptions")

log: logging.Logger
loop: asyncio.AbstractEventLoop
Expand All @@ -44,8 +44,8 @@ async def _stream(self) -> AsyncGenerator[StreamEvent, None]:
"Accept": "text/event-stream",
"Accept-Language": "en-US,en;q=0.5",
"DNT": "1",
"Origin": "https://twitter.com",
"Referer": "https://twitter.com/messages",
"Origin": "https://x.com",
"Referer": "https://x.com/messages",
"Pragma": "no-cache",
}
empty_bytes = b""
Expand Down
16 changes: 8 additions & 8 deletions mautwitdm/twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
Tokens = NamedTuple("Tokens", auth_token=str, csrf_token=str)
DownloadResp = NamedTuple("DownloadResp", data=bytes, mime_type=str)

twitter_com = URL("https://twitter.com/")
twitter_com = URL("https://x.com/")


class TwitterAPI(TwitterUploader, TwitterStreamer, TwitterPoller):
"""The main entrypoint for using the internal Twitter DM API."""

base_url: URL = URL("https://api.twitter.com/1.1")
base_url: URL = URL("https://api.x.com/1.1")
dm_url: URL = base_url / "dm"

loop: asyncio.AbstractEventLoop
Expand Down Expand Up @@ -76,9 +76,9 @@ def set_tokens(self, auth_token: str, csrf_token: str) -> None:
"""
cookie = SimpleCookie()
cookie["auth_token"] = auth_token
cookie["auth_token"].update({"domain": "twitter.com", "path": "/"})
cookie["auth_token"].update({"domain": "x.com", "path": "/"})
cookie["ct0"] = csrf_token
cookie["ct0"].update({"domain": "twitter.com", "path": "/"})
cookie["ct0"].update({"domain": "x.com", "path": "/"})
self.http.cookie_jar.update_cookies(cookie, twitter_com)

def mark_typing(self, conversation_id: str | None) -> None:
Expand All @@ -93,7 +93,7 @@ def mark_typing(self, conversation_id: str | None) -> None:

@property
def tokens(self) -> Tokens | None:
cookies = self.http.cookie_jar.filter_cookies(URL("https://twitter.com/"))
cookies = self.http.cookie_jar.filter_cookies(URL("https://x.com/"))
try:
return Tokens(auth_token=cookies["auth_token"].value, csrf_token=cookies["ct0"].value)
except KeyError:
Expand All @@ -118,8 +118,8 @@ def headers(self) -> dict[str, str]:
"Accept": "*/*",
"Accept-Language": "en-US,en;q=0.5",
"DNT": "1",
"Origin": "https://twitter.com",
"Referer": "https://twitter.com/messages",
"Origin": "https://x.com",
"Referer": "https://x.com/messages",
"x-twitter-auth-type": "OAuth2Session",
"x-twitter-client-language": "en",
"x-twitter-active-user": "yes",
Expand All @@ -130,7 +130,7 @@ async def download_media(self, url: str) -> DownloadResp:
headers = {
"Accept": "*/*",
"DNT": "1",
"Referer": "https://twitter.com/messages",
"Referer": "https://x.com/messages",
"User-Agent": self.user_agent,
}
async with self.http.get(url, headers=headers) as resp:
Expand Down
2 changes: 1 addition & 1 deletion mautwitdm/uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


class TwitterUploader:
upload_url: URL = URL("https://upload.twitter.com/i/media/upload.json")
upload_url: URL = URL("https://upload.x.com/i/media/upload.json")

http: ClientSession
log: logging.Logger
Expand Down

0 comments on commit 4ed14fa

Please sign in to comment.