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
62b7ae9f
Commit
62b7ae9f
authored
May 01, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix typing
parent
1aa511d3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
30 deletions
+37
-30
dev/extras.ts
dev/extras.ts
+19
-6
src/config.ts
src/config.ts
+2
-12
src/def.ts
src/def.ts
+4
-0
src/picsource.ts
src/picsource.ts
+12
-12
No files found.
dev/extras.ts
View file @
62b7ae9f
import
{
Schema
}
from
'
koishi
'
;
import
{
Awaitable
,
Context
}
from
'
koishi
'
;
import
{
DefinePlugin
}
from
'
koishi-thirdeye
'
;
import
{
DefinePlugin
,
RegisterSchema
,
SchemaProperty
}
from
'
koishi-thirdeye
'
;
import
{
DefineMultiSourcePlugin
,
PicResult
,
...
...
@@ -8,11 +8,17 @@ import {
PicSourcePlugin
,
}
from
'
../src
'
;
@
DefinePlugin
({
name
:
'
test-source
'
,
schema
:
PicSourceConfig
})
class
TestPicSourcePlugin
extends
PicSourcePlugin
{
@
RegisterSchema
()
class
Config
extends
PicSourceConfig
{
@
SchemaProperty
({
default
:
'
https://cdn02.moecube.com:444
'
})
endpoint
:
string
;
}
@
DefinePlugin
({
name
:
'
test-source
'
,
schema
:
Config
})
class
TestPicSourcePlugin
extends
PicSourcePlugin
<
Config
>
{
randomPic
(
picTags
:
string
[]):
Awaitable
<
PicResult
>
{
return
{
url
:
`
https://cdn02.moecube.com:444
/images/ygopro-images-
${
this
.
name
}
/
${
url
:
`
${
this
.
config
.
endpoint
}
/images/ygopro-images-
${
this
.
name
}
/
${
picTags
[
0
]
||
'
10000
'
}
.jpg`
,
description
:
picTags
[
0
]
||
'
10000
'
,
...
...
@@ -22,7 +28,7 @@ class TestPicSourcePlugin extends PicSourcePlugin {
export
class
TestMultiPicSourcePlugin
extends
DefineMultiSourcePlugin
(
TestPicSourcePlugin
,
PicSource
Config
,
Config
,
)
{}
console
.
log
((
TestMultiPicSourcePlugin
[
'
Config
'
]
as
Schema
).
dict
.
instances
.
type
);
...
...
@@ -30,7 +36,14 @@ console.log((TestMultiPicSourcePlugin['Config'] as Schema).dict.instances.type);
export
default
class
ExtrasInDev
{
constructor
(
ctx
:
Context
)
{
ctx
.
plugin
(
TestMultiPicSourcePlugin
,
{
instances
:
[{
name
:
'
zh-CN
'
,
isDefault
:
true
},
{
name
:
'
en-US
'
}],
instances
:
[
{
name
:
'
zh-CN
'
,
isDefault
:
true
,
endpoint
:
'
https://cdn02.moecube.com:444
'
,
},
{
name
:
'
en-US
'
},
],
});
}
...
...
src/config.ts
View file @
62b7ae9f
// import 'source-map-support/register';
import
{
SchemaProperty
,
RegisterSchema
,
SchemaClass
,
ClassType
,
}
from
'
koishi-thirdeye
'
;
import
{
SchemaProperty
,
RegisterSchema
,
SchemaClass
}
from
'
koishi-thirdeye
'
;
import
{
Quester
}
from
'
koishi
'
;
import
{
Instances
,
PicMiddleware
,
PicMiddlewareInfo
,
PicSourceInfo
,
}
from
'
./def
'
;
import
{
PicMiddleware
,
PicMiddlewareInfo
,
PicSourceInfo
}
from
'
./def
'
;
@
RegisterSchema
()
export
class
PicsPluginConfig
{
...
...
src/def.ts
View file @
62b7ae9f
...
...
@@ -67,3 +67,7 @@ export function ClonePlugin<P extends { new (...args: any[]): any }>(
});
return
clonedPlugin
;
}
export
type
TypeFromClass
<
T
>
=
T
extends
{
new
(...
args
:
any
[]):
infer
U
}
?
U
:
never
;
src/picsource.ts
View file @
62b7ae9f
...
...
@@ -17,6 +17,7 @@ import {
Instances
,
ToInstancesConfig
,
ClonePlugin
,
TypeFromClass
,
}
from
'
./def
'
;
export
class
PicSource
implements
PicSourceInfo
{
...
...
@@ -49,9 +50,7 @@ export class PicSource implements PicSourceInfo {
}
}
export
class
PicSourcePlugin
<
C
extends
PicSourceConfig
=
PicSourceConfig
,
>
extends
PicSource
{
export
class
PicSourcePlugin
<
C
extends
PicSourceConfig
>
extends
PicSource
{
constructor
(
ctx
:
Context
,
config
:
PartialDeep
<
C
>
)
{
super
(
ctx
);
}
...
...
@@ -101,18 +100,19 @@ export class MultiPicSourcePlugin<C extends PicSourceConfig>
}
}
export
function
DefineMultiSourcePlugin
<
C
extends
PicSourceConfig
,
P
extends
PicSourcePlugin
<
C
>
,
>
(
SourcePlugin
:
new
(
ctx
:
Context
,
config
:
C
)
=>
P
,
SourceConfig
:
ClassType
<
C
>
,
export
function
DefineMultiSourcePlugin
<
C
extends
ClassType
<
PicSourceConfig
>>
(
SourcePlugin
:
new
(
ctx
:
Context
,
config
:
TypeFromClass
<
C
>
)
=>
PicSourcePlugin
<
TypeFromClass
<
C
>
>
,
SourceConfig
:
C
,
name
=
SourcePlugin
.
name
,
):
new
(
context
:
Context
,
config
:
Instances
<
PartialDeep
<
C
>>
,
)
=>
MultiPicSourcePlugin
<
C
>
{
const
pluginClass
=
class
SpecificMultiPicSourcePlugin
extends
MultiPicSourcePlugin
<
C
>
{
config
:
Instances
<
PartialDeep
<
TypeFromClass
<
C
>>>
,
)
=>
MultiPicSourcePlugin
<
TypeFromClass
<
C
>>
{
const
pluginClass
=
class
SpecificMultiPicSourcePlugin
extends
MultiPicSourcePlugin
<
TypeFromClass
<
C
>
>
{
getSourcePlugin
()
{
return
SourcePlugin
;
}
...
...
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