This repository was archived by the owner on Apr 29, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
60 lines (47 loc) · 2.28 KB
/
Copy pathmain.py
File metadata and controls
60 lines (47 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from pkg.plugin.models import *
from pkg.plugin.context import register, handler, llm_func, BasePlugin, APIHost, EventContext
import json
message_string = ""
file_path = 'plugins/KeywordsReview/keywords.json'
# 注册插件
@register(name="Keyword_active_review", description="关键词主动审查", version="1.0", author="TwperBody")
class KeywordActiveReviewPlugin(BasePlugin):
# 插件加载时触发
def __init__(self, host: APIHost):
pass
async def initialize(self):
pass
# 当收到user消息时触发
@handler(PersonNormalMessageReceived)
async def PersonNormalMessageReceived(self, ctx: EventContext):
with open(file_path, 'r', encoding='utf-8') as file:
data = json.load(file)
keywords = data.get('keywords', [])
msg = ctx.event.text_message # 这里的 event 即为 PersonNormalMessageReceived 的对象
for keyword_dict in keywords:
message_string = keyword_dict.get('keyword', '')
if message_string in msg:
self.ap.logger.debug("{} is trigger keyword".format(ctx.event.sender_id))
ctx.add_return("reply", ["客户端拒绝请求, {}!".format(ctx.event.sender_id)])
# 阻止该事件默认行为(向接口获取回复)
ctx.prevent_default()
break
# 当收到群消息时触发
@handler(GroupNormalMessageReceived)
async def group_normal_message_received(self, ctx: EventContext):
with open(file_path, 'r', encoding='utf-8') as file:
data = json.load(file)
keywords = data.get('keywords', [])
if " " or "@" in msg:
msg = ctx.event.text_message # 这里的 event 即为 GroupMessageReceived 的对象
for keyword_dict in keywords:
message_string = keyword_dict.get('keyword', '')
if message_string in msg:
self.ap.logger.debug("{} is trigger keyword".format(ctx.event.sender_id))
ctx.add_return("reply", ["客户端拒绝请求, {}!".format(ctx.event.sender_id)])
# 阻止该事件默认行为(向接口获取回复)
ctx.prevent_default()
break
# 插件卸载时触发
def __del__(self):
pass