Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
K
Koishi Plugin Ygocard
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 Ygocard
Commits
a2f3d08d
Commit
a2f3d08d
authored
Jan 11, 2023
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
put as service
parent
71a2e911
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
11 deletions
+29
-11
src/index.tsx
src/index.tsx
+29
-11
No files found.
src/index.tsx
View file @
a2f3d08d
...
...
@@ -17,6 +17,7 @@ import {
PutSession
,
CommandLocale
,
Inject
,
Provide
,
}
from
'
koishi-thirdeye
'
;
import
{
Logger
,
Random
,
Session
}
from
'
koishi
'
;
import
initSqlJs
from
'
sql.js
'
;
...
...
@@ -26,9 +27,16 @@ import PuppeteerPlugin from 'koishi-plugin-puppeteer';
export
*
from
'
./config
'
;
declare
module
'
koishi
'
{
interface
Context
{
ygocard
:
YGOCardPlugin
;
}
}
const
commonFilter
=
'
datas.type & 0x4000 = 0 and (datas.alias = 0 or datas.id - datas.alias > 10)
'
;
@
Provide
(
'
ygocard
'
)
@
DefinePlugin
({
name
:
'
ygocard
'
,
schema
:
YGOCardConfig
})
export
default
class
YGOCardPlugin
extends
StarterPlugin
(
YGOCardConfig
)
...
...
@@ -73,12 +81,12 @@ export default class YGOCardPlugin
const
[
result
]
=
this
.
queryInDB
(
id
.
toString
(),
db
);
return
result
;
}
private
randomCard
()
{
randomCard
()
{
const
db
=
Random
.
pick
(
this
.
dbs
);
if
(
!
db
)
return
;
return
this
.
randomCardInDB
(
db
);
}
private
queryInAllDBs
(
value
:
string
,
matchCount
?:
number
)
{
queryInAllDBs
(
value
:
string
,
matchCount
?:
number
)
{
return
_
.
sortBy
(
_
.
uniqBy
(
_
.
flatten
(
this
.
dbs
.
map
((
db
)
=>
this
.
queryInDB
(
value
,
db
))),
...
...
@@ -87,7 +95,7 @@ export default class YGOCardPlugin
(
c
)
=>
c
.
getDistanceFrom
(
value
),
).
slice
(
0
,
matchCount
||
this
.
config
.
matchCount
);
}
private
async
loadD
Bs
(
SQL
:
SQL
.
SqlJsStatic
)
{
private
async
loadD
atabases
(
)
{
const
allDatabaseFiles
=
_
.
flatten
(
await
Promise
.
all
(
this
.
config
.
databasePaths
.
map
(
async
(
p
)
=>
...
...
@@ -97,22 +105,32 @@ export default class YGOCardPlugin
),
),
);
this
.
logger
.
info
(
`Will load cards from
${
allDatabaseFiles
.
length
}
databases.`
,
);
const
buffers
=
await
Promise
.
all
(
allDatabaseFiles
.
map
((
f
)
=>
fs
.
readFile
(
f
)),
);
this
.
dbs
=
buffers
.
map
((
b
)
=>
new
SQL
.
Database
(
b
));
this
.
dbs
=
buffers
.
map
((
b
)
=>
new
this
.
SQL
.
Database
(
b
));
this
.
logger
.
info
(
`Loaded cards from
${
allDatabaseFiles
.
length
}
databases.`
);
}
private
SQL
:
initSqlJs
.
SqlJsStatic
;
async
onConnect
()
{
const
SQL
=
await
initSqlJs
();
return
this
.
loadD
Bs
(
SQL
);
this
.
SQL
=
await
initSqlJs
();
return
this
.
loadD
atabases
(
);
}
onDisconnect
()
{
private
disposeDatabase
()
{
this
.
dbs
.
forEach
((
db
)
=>
db
.
close
());
this
.
dbs
=
[];
}
onDisconnect
()
{
this
.
disposeDatabase
();
}
async
reloadDatabase
()
{
this
.
disposeDatabase
();
await
this
.
loadDatabases
();
}
async
renderCard
(
card
:
YGOProCard
)
{
...
...
@@ -183,7 +201,7 @@ export default class YGOCardPlugin
@
UseCommand
(
'
{{commandName}} [query]
'
)
@
CommandLocale
(
'
zh
'
,
localeZh
.
cardCommand
)
@
CommandLocale
(
'
en
'
,
localeEn
.
cardCommand
)
async
onCardCommand
(
private
async
onCardCommand
(
@
PutArg
(
0
)
query
:
string
,
@
PutOption
(
'
random
'
,
'
--random
'
)
random
:
boolean
,
@
PutOption
(
'
count
'
,
'
-c <count:posint>
'
)
count
:
number
,
...
...
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