Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
K
Koishi Plugin Order Picker
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 Order Picker
Commits
85fe2f56
Commit
85fe2f56
authored
Aug 14, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
trace last message
parent
938f4dae
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
16 deletions
+57
-16
src/config.ts
src/config.ts
+12
-12
src/index.ts
src/index.ts
+45
-4
No files found.
src/config.ts
View file @
85fe2f56
// import 'source-map-support/register';
import
{
DefineSchema
,
RegisterSchema
}
from
'
koishi-thirdeye
'
;
import
{
MaybeArray
,
Schema
,
segment
,
Session
}
from
'
koishi
'
;
import
{
segment
,
Session
}
from
'
koishi
'
;
@
RegisterSchema
()
export
class
OrderPickerConfig
{
...
...
@@ -25,23 +25,23 @@ export class OrderPickerConfig {
@
DefineSchema
({
description
:
'
抢单的文本。
'
,
default
:
'
我要
'
})
pickWord
:
string
;
isMatchingTarget
(
session
:
Session
)
{
return
(
session
.
content
&&
session
.
guildId
&&
this
.
targetGuilds
.
includes
(
session
.
guildId
.
toString
())
);
}
acceptMessage
(
session
:
Session
)
{
if
(
!
session
.
content
)
{
if
(
!
session
.
userId
||
!
this
.
publishers
.
includes
(
session
.
userId
)
)
{
return
false
;
}
if
(
!
(
session
.
guildId
&&
this
.
targetGuilds
.
includes
(
session
.
guildId
.
toString
())
&&
session
.
userId
&&
this
.
publishers
.
includes
(
session
.
userId
)
)
)
return
false
;
if
(
this
.
blacklistMatchers
.
some
((
matcher
)
=>
session
.
content
.
match
(
matcher
))
)
)
{
return
false
;
}
const
segments
=
segment
.
parse
(
session
.
content
);
if
(
!
segments
.
find
((
s
)
=>
s
.
type
===
'
at
'
&&
s
.
data
.
type
===
'
all
'
))
{
return
false
;
...
...
src/index.ts
View file @
85fe2f56
...
...
@@ -18,7 +18,7 @@ import {
Provide
,
}
from
'
koishi-thirdeye
'
;
export
*
from
'
./config
'
;
import
AragamiPlugin
,
{
CacheKey
}
from
'
koishi-plugin-cache-aragami
'
;
import
AragamiPlugin
,
{
CacheKey
,
CacheTTL
}
from
'
koishi-plugin-cache-aragami
'
;
export
class
SelfOnline
{
@
CacheKey
()
...
...
@@ -27,6 +27,21 @@ export class SelfOnline {
online
:
boolean
;
}
@
CacheTTL
(
60000
)
export
class
LastMessage
{
@
CacheKey
()
guildId
:
string
;
userId
:
string
;
content
:
string
;
fromSession
(
session
:
Session
)
{
this
.
guildId
=
session
.
guildId
;
this
.
userId
=
session
.
userId
;
this
.
content
=
session
.
content
;
return
this
;
}
}
const
base
=
StarterPlugin
(
OrderPickerConfig
);
@
Provide
(
'
utility
'
,
{
immediate
:
true
})
...
...
@@ -43,6 +58,21 @@ class Utility extends base {
async
setOnline
(
selfId
:
string
,
online
:
boolean
)
{
await
this
.
aragami
.
set
(
SelfOnline
,
{
selfId
,
online
});
}
async
saveLastMessage
(
session
:
Session
)
{
const
lastMessage
=
new
LastMessage
().
fromSession
(
session
);
return
this
.
aragami
.
set
(
lastMessage
);
}
async
fetchLastMessage
(
session
:
Session
)
{
const
lastMessage
=
await
this
.
aragami
.
get
(
LastMessage
,
session
.
guildId
);
if
(
lastMessage
)
{
await
this
.
aragami
.
del
(
LastMessage
,
session
.
guildId
);
if
(
lastMessage
.
userId
===
session
.
userId
)
{
return
lastMessage
.
content
;
}
}
}
}
@
DefinePlugin
()
...
...
@@ -101,13 +131,24 @@ export default class OrderPicker extends base {
@
OnGuild
()
@
UseMiddleware
()
async
detectOrder
(
session
:
Session
,
next
:
Next
)
{
if
(
!
this
.
config
.
acceptMessage
(
session
))
return
next
();
if
(
!
this
.
config
.
isMatchingTarget
(
session
))
return
next
();
if
(
!
this
.
config
.
acceptMessage
(
session
))
{
await
this
.
utility
.
saveLastMessage
(
session
);
return
next
();
}
const
lastMessageContent
=
await
this
.
utility
.
fetchLastMessage
(
session
);
if
(
!
(
await
this
.
utility
.
isOnline
(
session
.
selfId
)))
return
next
();
cons
t
description
=
segment
le
t
description
=
segment
.
parse
(
session
.
content
)
.
filter
((
s
)
=>
s
.
type
===
'
text
'
)
.
map
((
s
)
=>
s
.
data
.
content
)
.
join
(
''
);
.
join
(
''
)
.
trim
();
if
(
!
description
)
{
description
=
lastMessageContent
||
''
;
}
await
session
.
bot
.
sendPrivateMessage
(
this
.
config
.
masterId
,
`接到群
${
session
.
guildId
}
的由
${
session
.
userId
}
发布的单:
${
description
}
`
,
...
...
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