Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
K
koishi-plugin-retweet-notifier
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
3rdeye
koishi-plugin-retweet-notifier
Commits
07bf3210
Commit
07bf3210
authored
Jan 31, 2023
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add retry
parent
5bb88798
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
5 deletions
+20
-5
src/config.ts
src/config.ts
+6
-0
src/index.ts
src/index.ts
+14
-5
No files found.
src/config.ts
View file @
07bf3210
...
...
@@ -41,6 +41,12 @@ export class RetweetNotifierPluginConfig {
description
:
'
是否在截图失败时放弃发送。需要使用 Puppeteer。
'
,
})
safe
:
boolean
;
@
SchemaProperty
({
description
:
'
Twitter 截图默认重试次数。
'
,
default
:
3
,
})
retryCount
:
number
;
}
export
type
RetweetNotifierPluginConfigLike
=
...
...
src/index.ts
View file @
07bf3210
...
...
@@ -103,9 +103,18 @@ export default class RetweetNotifierPlugin extends SchedulePlugin(
return
!
existing
?.
length
;
}
private
async
renderTweet
(
url
:
string
)
{
private
async
renderTweet
(
url
:
string
,
retry
=
0
)
{
if
(
!
this
.
ctx
.
puppeteer
)
return
url
;
this
.
logger
.
info
(
`Rendering tweet
${
url
}
...`
);
if
(
retry
>
this
.
config
.
retryCount
)
{
this
.
logger
.
error
(
`Failed to render tweet
${
url
}
after
${
this
.
config
.
retryCount
}
retries`
,
);
return
url
;
}
else
if
(
retry
>
0
)
{
this
.
logger
.
warn
(
`Retrying to render tweet
${
url
}
...`
);
}
else
{
this
.
logger
.
info
(
`Rendering tweet
${
url
}
...`
);
}
const
page
=
await
this
.
ctx
.
puppeteer
.
page
();
try
{
await
page
.
goto
(
url
,
{
timeout
:
300000
,
waitUntil
:
'
networkidle2
'
});
...
...
@@ -115,14 +124,14 @@ export default class RetweetNotifierPlugin extends SchedulePlugin(
// const tweetComponent = page;
if
(
!
tweetComponent
)
{
this
.
logger
.
warn
(
`Component not found for tweet
${
url
}
`
);
return
url
;
return
this
.
renderTweet
(
url
,
retry
+
1
)
;
}
this
.
logger
.
info
(
`Taking screenshot of
${
url
}
...`
);
const
screenshot
=
await
tweetComponent
.
screenshot
({
fullPage
:
false
});
return
segment
.
image
(
screenshot
,
'
image/png
'
).
toString
();
}
catch
(
e
)
{
this
.
logger
.
error
(
`Failed to render tweet
${
url
}
:
${
e
}
`
);
return
url
;
this
.
logger
.
warn
(
`Failed to render tweet
${
url
}
:
${
e
}
`
);
return
this
.
renderTweet
(
url
,
retry
+
1
)
;
}
finally
{
await
page
.
close
();
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment