Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
K
koishi-plugin-pics
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-pics
Commits
3e057beb
Commit
3e057beb
authored
May 01, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
single picsource base plugin
parent
4d9ec83b
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
103 additions
and
106 deletions
+103
-106
CONTRIBUTING.md
CONTRIBUTING.md
+3
-16
package-lock.json
package-lock.json
+73
-73
package.json
package.json
+1
-1
src/index.ts
src/index.ts
+26
-16
No files found.
CONTRIBUTING.md
View file @
3e057beb
...
...
@@ -52,6 +52,8 @@ export class PicSource {
#### 单图源
对于单图源的插件,我们提供了
`PicSourcePlugin`
基类,只需要集成该类即可快速开发单图源插件。
```
ts
import
{
Context
}
from
"
koishi
"
;
import
{
DefinePlugin
,
RegisterSchema
,
SchemaProperty
,
LifecycleEvents
}
from
"
koishi-thirdeye
"
;
...
...
@@ -65,25 +67,10 @@ export class Config extends PicSourceConfig {
@
DefinePlugin
({
name
:
'
my-picsource
'
,
schema
:
Config
})
export
default
class
MyPicSource
extends
PicSource
implements
LifecycleEvents
{
constructor
(
ctx
:
Context
,
config
:
Partial
<
Config
>
)
{
super
(
ctx
);
}
@
InjectConfig
()
private
config
:
Config
;
@
Inject
(
true
)
private
pics
:
PicsContainer
;
export
default
class
MyPicSource
extends
PicSourcePlugin
<
Config
>
{
async
randomPic
(
tags
:
string
[])
{
return
{
url
:
`https://cdn02.moecube.com:444/images/ygopro-images-zh-CN/
${
this
.
config
.
code
}
.jpg`
,
description
:
`
${
this
.
config
.
code
}
`
};
}
onApply
()
{
this
.
config
.
applyTo
(
this
);
this
.
pics
.
addSource
(
this
);
}
}
```
...
...
package-lock.json
View file @
3e057beb
This diff is collapsed.
Click to expand it.
package.json
View file @
3e057beb
...
...
@@ -57,7 +57,7 @@
"
ws
"
:
"
^8.3.0
"
},
"peerDependencies"
:
{
"koishi"
:
"^4.6.
0
"
"koishi"
:
"^4.6.
1
"
},
"jest"
:
{
"moduleFileExtensions"
:
[
...
...
src/index.ts
View file @
3e057beb
// import 'source-map-support/register';
import
{
Context
,
Assets
,
Awaitable
,
Random
,
Logger
,
Bot
,
remove
,
}
from
'
koishi
'
;
import
{
PicMiddlewareConfig
,
PicMiddlewareInfo
,
PicSourceInfo
,
PicsPluginConfig
,
}
from
'
./config
'
;
import
{
Context
,
Awaitable
,
Random
,
Logger
,
Bot
,
remove
}
from
'
koishi
'
;
import
{
PicSourceConfig
,
PicSourceInfo
,
PicsPluginConfig
}
from
'
./config
'
;
import
_
from
'
lodash
'
;
import
{
segment
,
Quester
}
from
'
koishi
'
;
import
{
BasePlugin
,
Caller
,
ClassType
,
DefinePlugin
,
Inject
,
InjectConfig
,
InjectLogger
,
LifecycleEvents
,
PartialDeep
,
Provide
,
}
from
'
koishi-thirdeye
'
;
import
{
AxiosRequestConfig
}
from
'
axios
'
;
...
...
@@ -77,6 +65,28 @@ export class PicSource implements PicSourceInfo {
}
}
export
class
PicSourcePlugin
<
C
extends
PicSourceConfig
=
PicSourceConfig
,
>
extends
PicSource
{
constructor
(
ctx
:
Context
,
config
:
PartialDeep
<
C
>
)
{
super
(
ctx
);
}
@
InjectConfig
()
protected
config
:
C
;
@
Inject
(
true
)
protected
pics
:
PicsContainer
;
@
InjectLogger
()
protected
logger
:
Logger
;
onApply
()
{
this
.
config
.
applyTo
(
this
);
this
.
pics
.
addSource
(
this
);
}
}
@
Provide
(
'
pics
'
,
{
immediate
:
true
})
@
DefinePlugin
({
name
:
'
pics
'
,
schema
:
PicsPluginConfig
})
export
default
class
PicsContainer
...
...
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