Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
K
koishi-schedule-send
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-schedule-send
Commits
fc6672a4
Commit
fc6672a4
authored
May 04, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add randomInterval
parent
6cc7e356
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
6 deletions
+36
-6
dev/extras.ts
dev/extras.ts
+1
-1
src/config.ts
src/config.ts
+35
-5
No files found.
dev/extras.ts
View file @
fc6672a4
...
...
@@ -27,7 +27,7 @@ export default class ExtrasInDev {
instances
:
[
{
message
:
'
dress
'
,
interval
:
5000
,
randomInterval
:
{
max
:
10000
,
min
:
5000
}
,
immediate
:
true
,
targets
:
[
{
...
...
src/config.ts
View file @
fc6672a4
// import 'source-map-support/register';
import
{
Context
}
from
'
koishi
'
;
import
{
Context
,
Random
}
from
'
koishi
'
;
import
{
SendTarget
}
from
'
koishi-target-def
'
;
import
{
SchemaProperty
}
from
'
koishi-thirdeye
'
;
import
{
RegisterSchema
,
SchemaProperty
}
from
'
koishi-thirdeye
'
;
import
{
scheduleJob
}
from
'
node-schedule
'
;
@
RegisterSchema
()
export
class
RandomInterval
{
@
SchemaProperty
({
step
:
1
,
default
:
0
})
max
:
number
;
@
SchemaProperty
({
step
:
1
,
default
:
0
})
min
:
number
;
getInterval
()
{
return
Random
.
int
(
this
.
min
,
this
.
max
+
1
);
}
isAvailable
()
{
return
!!
this
.
max
&&
!!
this
.
min
;
}
processRandom
(
ctx
:
Context
,
callback
:
()
=>
void
)
{
ctx
.
setTimeout
(()
=>
{
callback
();
this
.
processRandom
(
ctx
,
callback
);
},
this
.
getInterval
());
}
}
export
class
SchedulePluginConfig
{
@
SchemaProperty
({
description
:
'
cron 时间
'
})
@
SchemaProperty
({
description
:
'
cron 时间
。
'
})
cron
:
string
;
@
SchemaProperty
({
description
:
'
执行的间隔 ms
'
,
step
:
1
})
@
SchemaProperty
({
description
:
'
执行的间隔 ms
。
'
,
step
:
1
})
interval
:
number
;
@
SchemaProperty
({
description
:
'
随机间隔。
'
})
randomInterval
:
RandomInterval
;
@
SchemaProperty
({
default
:
false
,
description
:
'
插件启动时是否立即运行一遍。
'
,
...
...
@@ -30,11 +57,14 @@ export class SchedulePluginConfig {
if
(
this
.
cron
)
{
const
job
=
scheduleJob
(
this
.
cron
,
callback
);
ctx
.
on
(
'
dispose
'
,
()
=>
{
job
.
cancel
()
job
.
cancel
()
;
});
}
if
(
this
.
interval
)
{
ctx
.
setInterval
(
callback
,
this
.
interval
);
}
if
(
this
.
randomInterval
?.
isAvailable
())
{
this
.
randomInterval
.
processRandom
(
ctx
,
callback
);
}
}
}
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