2023-03-18 14:08:49 +00:00
|
|
|
import re
|
|
|
|
|
|
|
|
import ujson as json
|
2023-04-19 07:41:39 +00:00
|
|
|
|
2023-03-18 14:08:49 +00:00
|
|
|
from config import Config
|
|
|
|
from core.builtins import Bot
|
|
|
|
from core.builtins.message import Image
|
2023-04-19 07:41:39 +00:00
|
|
|
from core.component import module
|
2023-07-14 07:59:01 +00:00
|
|
|
from core.dirty_check import check_bool, rickroll
|
2023-04-19 07:41:39 +00:00
|
|
|
from core.utils.http import download_to_cache, get_url
|
2023-03-18 14:08:49 +00:00
|
|
|
|
|
|
|
web_render_local = Config('web_render_local')
|
2023-07-27 14:32:44 +00:00
|
|
|
t = module('tweet', developers=['Dianliang233'], desc='{tweet.help.desc}', alias=['x'])
|
2023-03-18 14:08:49 +00:00
|
|
|
|
|
|
|
|
2023-06-09 10:23:48 +00:00
|
|
|
@t.handle('<tweet> {{tweet.help}}')
|
|
|
|
async def _(msg: Bot.MessageSession, tweet: str):
|
|
|
|
if tweet.isdigit():
|
|
|
|
tweet_id = tweet
|
2023-06-07 05:43:31 +00:00
|
|
|
else:
|
2023-06-09 10:23:48 +00:00
|
|
|
match = re.search(r"status/(\d+)", tweet)
|
2023-06-07 05:51:09 +00:00
|
|
|
if match:
|
|
|
|
tweet_id = match.group(1)
|
|
|
|
else:
|
|
|
|
await msg.finish(msg.locale.t('tweet.message.error'))
|
2023-07-27 14:32:44 +00:00
|
|
|
res = await get_url(f'https://react-tweet.vercel.app/api/tweet/{tweet_id}')
|
2023-03-18 14:08:49 +00:00
|
|
|
res_json = json.loads(res)
|
2023-07-27 14:32:44 +00:00
|
|
|
if not res_json['data']:
|
2023-05-23 05:03:44 +00:00
|
|
|
await msg.finish(msg.locale.t('tweet.message.not_found'))
|
2023-03-18 14:08:49 +00:00
|
|
|
else:
|
2023-07-27 14:32:44 +00:00
|
|
|
if await check_bool(res_json['data']['text'], res_json['data']['user']['name'], res_json['data']['user']['screen_name']):
|
2023-07-27 19:31:53 +00:00
|
|
|
rickroll(msg)
|
2023-03-18 14:08:49 +00:00
|
|
|
else:
|
|
|
|
css = '''
|
|
|
|
main {
|
|
|
|
justify-content: start !important;
|
|
|
|
}
|
|
|
|
|
|
|
|
main > div {
|
|
|
|
margin: 0 !important;
|
|
|
|
border: 0 !important;
|
|
|
|
}
|
|
|
|
|
|
|
|
article {
|
|
|
|
padding: .75rem 1rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
footer {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
#__next > div {
|
|
|
|
height: auto;
|
|
|
|
padding: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
a[href^="https://twitter.com/intent/follow"],
|
|
|
|
a[href^="https://help.twitter.com/en/twitter-for-websites-ads-info-and-privacy"],
|
|
|
|
div[class^="tweet-replies"],
|
|
|
|
button[aria-label="Copy link"],
|
|
|
|
a[aria-label="Reply to this Tweet on Twitter"],
|
|
|
|
span[class^="tweet-header_separator"] {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
'''
|
2023-07-29 12:49:47 +00:00
|
|
|
pic = await download_to_cache(web_render_local + '/element_screenshot', method='POST', headers={
|
2023-04-30 03:30:59 +00:00
|
|
|
'Content-Type': 'application/json',
|
2023-07-27 14:32:44 +00:00
|
|
|
}, post_data=json.dumps({'url': f'https://react-tweet-next.vercel.app/light/{tweet_id}', 'css': css, 'mw': False, 'element': 'article'}), request_private_ip=True)
|
|
|
|
await msg.finish([Image(pic), f"https://twitter.com/{res_json['data']['user']['screen_name']}/status/{tweet_id}"])
|