Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
nil2bot
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Iori Ichinose
nil2bot
Commits
eee97715
Commit
eee97715
authored
3 years ago
by
Iori Ichinose
Browse files
Options
Downloads
Patches
Plain Diff
add grep
parent
41634e60
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/plugins/record/__init__.py
+23
-0
23 additions, 0 deletions
src/plugins/record/__init__.py
src/plugins/record/grep.py
+22
-0
22 additions, 0 deletions
src/plugins/record/grep.py
src/utils/recorder.py
+0
-2
0 additions, 2 deletions
src/utils/recorder.py
with
45 additions
and
2 deletions
src/plugins/record/__init__.py
+
23
−
0
View file @
eee97715
...
...
@@ -7,9 +7,12 @@ from nonebot.permission import SUPERUSER
from
src.utils.recorder
import
recorder
from
src.utils.message
import
Message
from
.grep
import
at_re
,
count
record
=
on_message
(
priority
=
5
)
log
=
on_command
(
'
log
'
,
permission
=
SUPERUSER
,
priority
=
1
,
block
=
True
)
rank
=
on_command
(
'
rank
'
,
priority
=
1
,
block
=
True
)
grep
=
on_command
(
'
grep
'
,
priority
=
1
,
block
=
True
)
@record.handle
()
...
...
@@ -71,3 +74,23 @@ async def handle_count(bot: Bot, event: Event, state: T_State):
async
def
handle_rank
(
bot
:
Bot
,
event
:
Event
,
state
:
T_State
):
group_id
=
event
.
dict
()[
'
group_id
'
]
await
rank
.
finish
(
recorder
.
get_recent_rank
(
group_id
))
@grep.handle
()
async
def
handle_grep
(
bot
:
Bot
,
event
:
Event
,
state
:
T_State
):
group_id
=
event
.
dict
()[
'
group_id
'
]
text
=
event
.
dict
()[
'
raw_message
'
]
print
(
text
)
if
m
:
=
at_re
.
findall
(
text
):
user_id
=
int
(
m
[
0
])
else
:
await
grep
.
finish
()
keyword
=
text
.
split
(
maxsplit
=
2
)[
-
1
]
state
[
'
args
'
]
=
(
user_id
,
group_id
,
keyword
)
@grep.got
(
'
args
'
)
async
def
handle_args
(
bot
:
Bot
,
event
:
Event
,
state
:
T_State
):
uid
,
gid
,
keyword
=
state
[
'
args
'
]
print
(
state
[
'
args
'
])
await
grep
.
finish
(
count
(
gid
,
uid
,
keyword
))
This diff is collapsed.
Click to expand it.
src/plugins/record/grep.py
0 → 100644
+
22
−
0
View file @
eee97715
from
src.utils.recorder
import
recorder
import
re
import
random
at_re
=
re
.
compile
(
r
'
\[CQ:at,qq=(\d+)\]
'
)
def
count
(
gid
:
int
,
uid
:
int
,
keyword
:
str
)
->
str
:
group_id
=
str
(
gid
)
user_id
=
str
(
uid
)
messages
=
recorder
.
messages
if
group_id
not
in
messages
or
user_id
not
in
messages
[
group_id
]:
return
'
grep: no matches found
'
greped
=
[
m
for
m
in
messages
[
group_id
][
user_id
]
if
keyword
in
m
]
count
=
len
(
greped
)
if
count
!=
0
:
ret
=
[
f
'
您在本群的语料中共出现
{
count
}
次
{
keyword
}
:
'
]
count
=
min
(
5
,
count
)
ret
+=
random
.
sample
(
greped
,
k
=
count
)
return
'
\n
'
.
join
(
ret
)
else
:
return
'
grep: no matches found
'
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/utils/recorder.py
+
0
−
2
View file @
eee97715
...
...
@@ -117,8 +117,6 @@ class Recorder:
for
user
,
count
in
sorted
(
ret
.
items
(),
key
=
lambda
x
:
x
[
1
],
reverse
=
True
)[:
10
]:
strs
.
append
(
f
'
{
user
}
:
{
count
}
条
'
)
print
(
messages
)
print
(
strs
)
return
'
\n
'
.
join
(
strs
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment