Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
K
koishi-plugin-hisoutensoku-jammer
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
nanahira
koishi-plugin-hisoutensoku-jammer
Commits
879ed119
Commit
879ed119
authored
Mar 04, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use recursiveMatch
parent
4990bdd8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
6 deletions
+15
-6
src/index.ts
src/index.ts
+4
-6
src/utils.ts
src/utils.ts
+11
-0
No files found.
src/index.ts
View file @
879ed119
...
...
@@ -15,6 +15,7 @@ import moment from 'moment';
import
{
chineseCharacterList
}
from
'
./chinese-replace
'
;
import
{
Worker
}
from
'
tesseract.js
'
;
import
_
from
'
lodash
'
;
import
{
recursiveMatch
}
from
'
./utils
'
;
export
*
from
'
./config
'
;
declare
module
'
koishi
'
{
...
...
@@ -26,8 +27,6 @@ declare module 'koishi' {
}
}
const
matcherGlobal
=
/
(
0*
[^\d]
*
)
*
([
1-2
]?[^\d\.]?\d{0,2})(([^\d]
+
[
1-2
]?\d{1,2}){3,}?)
.+
?([
1-6
]([^\d]
*
\d){4})(
.*
[\+\-]\d{1,5})
*/g
;
const
matcherSingle
=
/
(
0*
[^\d]
*
)
*
([
1-2
]?[^\d\.]?\d{0,2})(([^\d]
+
[
1-2
]?\d{1,2}){3,}?)
.+
?([
1-6
]([^\d]
*
\d){4})(
.*
[\+\-]\d{1,5})
*/
;
...
...
@@ -151,7 +150,7 @@ export default class HisoutensokuJammerPlugin
this
.
log
.
info
(
`Parsing message from
${
sender
}
:
${
receivedMessage
}
`
);
let
messageMatch
=
rec
eivedMessage
.
match
(
matcherGlobal
);
let
messageMatch
=
rec
ursiveMatch
(
receivedMessage
,
matcherSingle
);
if
(
useCache
)
{
const
lastMessage
=
await
this
.
cache
.
get
(
'
lastMessages
'
,
sender
);
const
currentMessage
=
receivedMessage
;
...
...
@@ -159,7 +158,7 @@ export default class HisoutensokuJammerPlugin
receivedMessage
=
`
${
lastMessage
}
${
receivedMessage
}
`
;
this
.
log
.
info
(
`Merged message from
${
sender
}
:
${
receivedMessage
}
`
);
if
(
!
messageMatch
)
{
messageMatch
=
rec
eivedMessage
.
match
(
matcherGlobal
);
messageMatch
=
rec
ursiveMatch
(
receivedMessage
,
matcherSingle
);
}
}
if
(
!
messageMatch
)
{
...
...
@@ -171,8 +170,7 @@ export default class HisoutensokuJammerPlugin
return
;
}
const
results
:
{
address
:
string
;
port
:
number
}[]
=
[];
for
(
const
pattern
of
messageMatch
)
{
const
patternMatch
=
pattern
.
match
(
matcherSingle
);
for
(
const
patternMatch
of
messageMatch
)
{
if
((
patternMatch
?.
length
||
0
)
<=
6
)
{
continue
;
}
...
...
src/utils.ts
0 → 100644
View file @
879ed119
export
function
recursiveMatch
(
content
:
string
,
regex
:
string
|
RegExp
,
):
RegExpMatchArray
[]
|
null
{
const
match
=
content
.
match
(
regex
);
if
(
!
match
)
return
null
;
const
remainingContent
=
content
.
slice
(
match
.
index
+
match
[
0
].
length
);
if
(
!
remainingContent
)
return
[
match
];
const
remainingMatches
=
recursiveMatch
(
remainingContent
,
regex
)
||
[];
return
[
match
,
...
remainingMatches
];
}
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