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
d21c4229
Commit
d21c4229
authored
May 01, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dev things
parent
3e057beb
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
151 additions
and
94 deletions
+151
-94
dev/extras.ts
dev/extras.ts
+5
-8
src/config.ts
src/config.ts
+12
-15
src/def.ts
src/def.ts
+45
-0
src/index.ts
src/index.ts
+6
-62
src/middleware.ts
src/middleware.ts
+2
-7
src/middlewares/assets.ts
src/middlewares/assets.ts
+2
-1
src/middlewares/download.ts
src/middlewares/download.ts
+2
-1
src/picsource.ts
src/picsource.ts
+77
-0
No files found.
dev/extras.ts
View file @
d21c4229
import
{
Awaitable
,
Context
}
from
'
koishi
'
;
import
{
PicResult
,
PicSource
}
from
'
../src
'
;
import
{
DefinePlugin
}
from
'
koishi-thirdeye
'
;
import
{
PicResult
,
PicSourceConfig
,
PicSourcePlugin
}
from
'
../src
'
;
class
TestPicsource
extends
PicSource
{
constructor
(
ctx
:
Context
,
public
name
:
string
)
{
super
(
ctx
);
}
isDefault
=
true
;
@
DefinePlugin
({
schema
:
PicSourceConfig
})
class
TestPicsource
extends
PicSourcePlugin
{
randomPic
(
picTags
:
string
[]):
Awaitable
<
PicResult
>
{
return
{
url
:
`https://cdn02.moecube.com:444/images/ygopro-images-
${
this
.
name
}
/
${
...
...
@@ -18,8 +16,7 @@ class TestPicsource extends PicSource {
export
default
class
ExtrasInDev
{
constructor
(
ctx
:
Context
)
{
ctx
.
pics
.
addSource
(
new
TestPicsource
(
ctx
,
'
zh-CN
'
));
ctx
.
pics
.
addSource
(
new
TestPicsource
(
ctx
,
'
en-US
'
));
ctx
.
plugin
(
TestPicsource
,
{
name
:
'
zh-CN
'
,
isDefault
:
true
});
}
static
using
=
[
'
pics
'
]
as
const
;
...
...
src/config.ts
View file @
d21c4229
// import 'source-map-support/register';
import
{
SchemaProperty
,
RegisterSchema
,
SchemaClass
}
from
'
koishi-thirdeye
'
;
import
{
SchemaProperty
,
RegisterSchema
,
SchemaClass
,
ClassType
,
}
from
'
koishi-thirdeye
'
;
import
{
Quester
}
from
'
koishi
'
;
import
{
PicMiddleware
}
from
'
./index
'
;
import
{
Instances
,
PicMiddleware
,
PicMiddlewareInfo
,
PicSourceInfo
,
}
from
'
./def
'
;
@
RegisterSchema
()
export
class
PicsPluginConfig
{
...
...
@@ -26,14 +36,6 @@ export type PicsPluginConfigLike = Partial<PicsPluginConfig>;
// For convenience of plugins
export
interface
PicSourceInfo
{
tags
?:
string
[];
weight
?:
number
;
name
:
string
;
description
?:
string
;
isDefault
?:
boolean
;
}
export
class
PicSourceConfig
implements
PicSourceInfo
{
constructor
(
config
:
Partial
<
PicSourceInfo
>
)
{}
...
...
@@ -60,11 +62,6 @@ export class PicSourceConfig implements PicSourceInfo {
export
const
PicSourceSchema
=
SchemaClass
(
PicSourceConfig
);
export
interface
PicMiddlewareInfo
{
name
?:
string
;
prepend
?:
boolean
;
}
export
class
PicMiddlewareConfig
{
constructor
(
config
:
PicMiddlewareInfo
)
{}
@
SchemaProperty
({
description
:
'
中间件名称。
'
})
...
...
src/def.ts
0 → 100644
View file @
d21c4229
import
{
Awaitable
}
from
'
koishi
'
;
import
{
ClassType
,
SchemaProperty
}
from
'
koishi-thirdeye
'
;
export
interface
PicSourceInfo
{
tags
?:
string
[];
weight
?:
number
;
name
:
string
;
description
?:
string
;
isDefault
?:
boolean
;
}
export
interface
PicResult
{
url
:
string
;
description
?:
string
;
}
export
type
PicNext
=
(
url
?:
string
)
=>
Awaitable
<
string
>
;
export
interface
PicMiddleware
extends
PicMiddlewareInfo
{
use
(
url
:
string
,
next
:
PicNext
):
Awaitable
<
string
>
;
}
export
interface
PicMiddlewareInfo
{
name
?:
string
;
prepend
?:
boolean
;
}
export
interface
Instances
<
T
>
{
instances
:
T
[];
}
export
function
ToInstancesConfig
<
T
>
(
instanceConfig
:
ClassType
<
T
>
,
):
new
()
=>
Instances
<
T
>
{
const
instanceConfigClass
=
class
InstancesConfig
{
instances
:
T
[];
};
SchemaProperty
({
type
:
instanceConfig
,
default
:
[]
})(
instanceConfigClass
.
prototype
,
'
instances
'
,
);
return
instanceConfigClass
;
}
src/index.ts
View file @
d21c4229
// import 'source-map-support/register';
import
{
Context
,
Awaitable
,
Random
,
Logger
,
Bot
,
remove
}
from
'
koishi
'
;
import
{
Pic
SourceConfig
,
PicSourceInfo
,
Pic
sPluginConfig
}
from
'
./config
'
;
import
{
Context
,
Random
,
Logger
,
Bot
,
remove
}
from
'
koishi
'
;
import
{
PicsPluginConfig
}
from
'
./config
'
;
import
_
from
'
lodash
'
;
import
{
segment
,
Quester
}
from
'
koishi
'
;
import
{
...
...
@@ -8,18 +8,19 @@ import {
Caller
,
DefinePlugin
,
Inject
,
InjectConfig
,
InjectLogger
,
LifecycleEvents
,
PartialDeep
,
Provide
,
}
from
'
koishi-thirdeye
'
;
import
{
AxiosRequestConfig
}
from
'
axios
'
;
import
{
PicAssetsTransformMiddleware
}
from
'
./middlewares/assets
'
;
import
{
PicDownloaderMiddleware
}
from
'
./middlewares/download
'
;
import
{
PicMiddleware
,
PicNext
}
from
'
./middleware
'
;
import
{
PicMiddleware
,
PicNext
,
PicResult
}
from
'
./def
'
;
import
{
PicSource
}
from
'
./picsource
'
;
export
*
from
'
./config
'
;
export
*
from
'
./middleware
'
;
export
*
from
'
./picsource
'
;
export
*
from
'
./def
'
;
declare
module
'
koishi
'
{
// eslint-disable-next-line @typescript-eslint/no-namespace
...
...
@@ -30,63 +31,6 @@ declare module 'koishi' {
}
}
export
interface
PicResult
{
url
:
string
;
description
?:
string
;
}
export
class
PicSource
implements
PicSourceInfo
{
constructor
(
protected
ctx
:
Context
)
{}
tags
:
string
[]
=
[];
weight
=
1
;
name
=
'
default
'
;
description
=
''
;
isDefault
=
false
;
randomPic
(
picTags
:
string
[]):
Awaitable
<
PicResult
>
{
// For override
throw
new
Error
(
`Not implemented`
);
}
onStartup
():
Awaitable
<
void
>
{
return
;
}
onShutdown
():
Awaitable
<
void
>
{
return
;
}
getDisplayString
()
{
let
pattern
=
this
.
name
;
if
(
this
.
tags
.
length
)
{
pattern
+=
`\t标签:
${
this
.
tags
.
join
(
'
,
'
)}
`
;
}
if
(
this
.
description
)
{
pattern
+=
`\t
${
this
.
description
}
`
;
}
return
pattern
;
}
}
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
...
...
src/middleware.ts
View file @
d21c4229
import
{
Awaitable
,
Logger
}
from
'
koishi
'
;
import
{
PicMiddlewareConfig
,
PicMiddlewareInfo
}
from
'
./config
'
;
import
{
PicMiddlewareConfig
}
from
'
./config
'
;
import
{
BasePlugin
,
Inject
,
...
...
@@ -7,12 +7,7 @@ import {
LifecycleEvents
,
}
from
'
koishi-thirdeye
'
;
import
PicsContainer
from
'
./index
'
;
export
type
PicNext
=
(
url
?:
string
)
=>
Awaitable
<
string
>
;
export
interface
PicMiddleware
extends
PicMiddlewareInfo
{
use
(
url
:
string
,
next
:
PicNext
):
Awaitable
<
string
>
;
}
import
{
PicMiddleware
,
PicNext
}
from
'
./def
'
;
export
class
PicMiddlewareBase
<
C
extends
PicMiddlewareConfig
=
PicMiddlewareConfig
,
...
...
src/middlewares/assets.ts
View file @
d21c4229
import
{
DefinePlugin
,
Inject
}
from
'
koishi-thirdeye
'
;
import
{
Assets
}
from
'
koishi
'
;
import
{
PicMiddlewareBase
,
PicNext
}
from
'
../middleware
'
;
import
{
PicMiddlewareBase
}
from
'
../middleware
'
;
import
{
PicMiddlewareConfig
}
from
'
../config
'
;
import
{
PicNext
}
from
'
../def
'
;
@
DefinePlugin
({
schema
:
PicMiddlewareConfig
})
export
class
PicAssetsTransformMiddleware
extends
PicMiddlewareBase
{
...
...
src/middlewares/download.ts
View file @
d21c4229
import
{
DefinePlugin
}
from
'
koishi-thirdeye
'
;
import
{
PicMiddlewareBase
,
PicNext
}
from
'
../middleware
'
;
import
{
PicMiddlewareBase
}
from
'
../middleware
'
;
import
{
PicMiddlewareConfig
}
from
'
../config
'
;
import
{
PicNext
}
from
'
../def
'
;
@
DefinePlugin
({
schema
:
PicMiddlewareConfig
})
export
class
PicDownloaderMiddleware
extends
PicMiddlewareBase
{
...
...
src/picsource.ts
0 → 100644
View file @
d21c4229
import
{
Context
,
Awaitable
,
Logger
}
from
'
koishi
'
;
import
{
PartialDeep
,
InjectConfig
,
Inject
,
InjectLogger
,
BasePlugin
,
}
from
'
koishi-thirdeye
'
;
import
PicsContainer
from
'
.
'
;
import
{
PicSourceConfig
}
from
'
./config
'
;
import
{
PicSourceInfo
,
PicResult
,
Instances
}
from
'
./def
'
;
export
class
PicSource
implements
PicSourceInfo
{
constructor
(
protected
ctx
:
Context
)
{}
tags
:
string
[]
=
[];
weight
=
1
;
name
=
'
default
'
;
description
=
''
;
isDefault
=
false
;
randomPic
(
picTags
:
string
[]):
Awaitable
<
PicResult
>
{
// For override
throw
new
Error
(
`Not implemented`
);
}
onStartup
():
Awaitable
<
void
>
{
return
;
}
onShutdown
():
Awaitable
<
void
>
{
return
;
}
getDisplayString
()
{
let
pattern
=
this
.
name
;
if
(
this
.
tags
.
length
)
{
pattern
+=
`\t标签:
${
this
.
tags
.
join
(
'
,
'
)}
`
;
}
if
(
this
.
description
)
{
pattern
+=
`\t
${
this
.
description
}
`
;
}
return
pattern
;
}
}
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
);
}
}
export
class
MultiPicSourcePlugin
<
C
extends
PicSourceConfig
=
PicSourceConfig
,
>
extends
BasePlugin
<
Instances
<
C
>>
{
@
Inject
(
true
)
protected
pics
:
PicsContainer
;
@
InjectLogger
()
protected
logger
:
Logger
;
onApply
()
{
const
{
instances
}
=
this
.
config
;
}
}
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