Skip to content

Commit

Permalink
Twitter fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
the-laziest-coder committed Aug 9, 2024
1 parent ed21292 commit 7a6e92c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 17 deletions.
2 changes: 1 addition & 1 deletion internal/galxe/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ async def _follow_space(self, campaign_id: str, credential_id):

def _default_sync_options(self, credential_id: str):
return {
'address': self.client.address,
'address': self.client.full_address,
'credId': credential_id,
}

Expand Down
2 changes: 1 addition & 1 deletion internal/galxe/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ async def prepare_participate(self, campaign_id, captcha, chain, referral_code=N
'query': 'mutation PrepareParticipate($input: PrepareParticipateInput!) {\n prepareParticipate(input: $input) {\n allow\n disallowReason\n signature\n nonce\n mintFuncInfo {\n funcName\n nftCoreAddress\n verifyIDs\n powahs\n cap\n __typename\n }\n extLinkResp {\n success\n data\n error\n __typename\n }\n metaTxResp {\n metaSig2\n autoTaskUrl\n metaSpaceAddr\n forwarderAddr\n metaTxHash\n reqQueueing\n __typename\n }\n solanaTxResp {\n mint\n updateAuthority\n explorerUrl\n signedTx\n verifyID\n __typename\n }\n aptosTxResp {\n signatureExpiredAt\n tokenName\n __typename\n }\n tokenRewardCampaignTxResp {\n signatureExpiredAt\n verifyID\n __typename\n }\n loyaltyPointsTxResp {\n TotalClaimedPoints\n __typename\n }\n __typename\n }\n}\n',
'variables': {
'input': {
'address': self.address,
'address': self.full_address,
'campaignID': campaign_id,
'captcha': captcha,
'chain': chain,
Expand Down
53 changes: 38 additions & 15 deletions internal/twitter/twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def _get_headers(info: AccountInfo) -> dict:
'accept-language': 'en;q=0.9',
'authorization': 'Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA',
'content-type': 'application/json',
'origin': 'https://mobile.x.com',
'referer': 'https://mobile.x.com/',
'origin': 'https://x.com',
'referer': 'https://x.com/',
'sec-ch-ua': SEC_CH_UA,
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': SEC_CH_UA_PLATFORM,
Expand Down Expand Up @@ -108,6 +108,19 @@ async def _get_ct0(self):
self.account.twitter_error = True
raise Exception(f'Failed to get ct0 for twitter: {reason}{str(e)}')

def check_response_errors(self, resp):
if type(resp) is not dict:
return
errors = resp.get('errors', [])
if type(errors) is not list:
return
if len(errors) == 0:
return
error_msg = ' | '.join([msg for msg in [err.get('message') for err in errors if type(err) is dict] if msg])
if len(error_msg) == 0:
return
raise Exception(error_msg)

async def get_my_profile_info(self):
url = 'https://api.x.com/1.1/account/settings.json'
params = {
Expand Down Expand Up @@ -209,24 +222,32 @@ async def post_tweet(self, text, tweet_id=None) -> str:
dark_request=False
),
features=dict(
freedom_of_speech_not_reach_fetch_enabled=True,
communities_web_enable_tweet_community_results_fetch=True,
c9s_tweet_anatomy_moderator_badge_enabled=True,
tweetypie_unmention_optimization_enabled=True,
responsive_web_edit_tweet_api_enabled=True,
graphql_is_translatable_rweb_tweet_is_translatable_enabled=True,
view_counts_everywhere_api_enabled=True,
longform_notetweets_consumption_enabled=True,
longform_notetweets_inline_media_enabled=True,
responsive_web_twitter_article_tweet_consumption_enabled=True,
tweet_awards_web_tipping_enabled=False,
creator_subscriptions_quote_tweet_preview_enabled=False,
longform_notetweets_rich_text_read_enabled=True,
responsive_web_edit_tweet_api_enabled=True,
responsive_web_enhance_cards_enabled=False,
longform_notetweets_inline_media_enabled=True,
articles_preview_enabled=True,
rweb_video_timestamps_enabled=True,
rweb_tipjar_consumption_enabled=True,
responsive_web_graphql_exclude_directive_enabled=True,
verified_phone_label_enabled=False,
freedom_of_speech_not_reach_fetch_enabled=True,
standardized_nudges_misinfo=True,
tweet_with_visibility_results_prefer_gql_limited_actions_policy_enabled=True,
responsive_web_graphql_skip_user_profile_image_extensions_enabled=False,
responsive_web_graphql_timeline_navigation_enabled=True,
standardized_nudges_misinfo=True,
tweet_awards_web_tipping_enabled=False,
tweet_with_visibility_results_prefer_gql_limited_actions_policy_enabled=False,
tweetypie_unmention_optimization_enabled=True,
verified_phone_label_enabled=False,
view_counts_everywhere_api_enabled=True
responsive_web_enhance_cards_enabled=False,
),
queryId=query_id)
queryId=query_id,
)

if tweet_id:
_json['variables']['reply'] = dict(
Expand Down Expand Up @@ -260,7 +281,9 @@ async def retweet(self, tweet_id):
'queryId': query_id
}
try:
return await self.request('POST', url, json=_json, resp_handler=lambda r: r)
resp = await self.request('POST', url, json=_json, resp_handler=lambda r: r)
self.check_response_errors(resp)
return resp
except Exception as e:
raise Exception(f'Retweet error: {str(e)}')

Expand All @@ -285,7 +308,7 @@ async def like(self, tweet_id) -> bool:

async def find_posted_tweet(self, text_condition_func, count=20) -> str:
action = "UserTweets"
query_id = "QWF3SzpHmykQHsQMixG0cg"
query_id = "V1ze5q3ijDS1VeLwLY0m7g"
params = {
'variables': to_json({
"userId": self.my_user_id,
Expand Down

0 comments on commit 7a6e92c

Please sign in to comment.