feat: 添加更多插件示例

This commit is contained in:
Rock Chin
2023-01-17 11:17:17 +08:00
parent 41d0082cee
commit b4938ba1fb
4 changed files with 52 additions and 0 deletions

View File

@@ -1,6 +1,11 @@
from pkg.plugin.models import *
from pkg.plugin.host import EventContext
"""
基本命令的中文形式支持
"""
__mapping__ = {
"帮助": "help",
"重置": "reset",

View File

@@ -1,6 +1,10 @@
from pkg.plugin.models import *
from pkg.plugin.host import EventContext
"""
在收到私聊或群聊消息"hello"时,回复"hello, <发送者id>!""hello, everyone!"
"""
# 注册插件
@register(name="Hello", description="hello world", version="0.1", author="RockChinQ")

View File

@@ -0,0 +1,43 @@
import random
from mirai import Plain
from pkg.plugin.models import *
from pkg.plugin.host import EventContext
"""
私聊或群聊消息为以下列出的一些冒犯性词语时自动回复__random_reply__中的一句话
"""
__words__ = ['sb', "傻逼", "dinner", "操你妈", "cnm", "fuck you", "fuckyou",
"f*ck you", "弱智", "若智", "答辩", "依托答辩", "低能儿", "nt", "脑瘫", "闹谈", "老坛"]
__random_reply__ = ['好好好', "啊对对对", "好好好好", "你说得对", "谢谢夸奖"]
@register(name="啊对对对", description="你都这样了,我就顺从你吧", version="0.1", author="RockChinQ")
class AdddPlugin(Plugin):
def __init__(self):
pass
# 绑定私聊消息事件和群消息事件
@on(PersonNormalMessageReceived)
@on(GroupNormalMessageReceived)
def normal_message_received(self, event: EventContext, **kwargs):
msg = kwargs['text_message']
# 如果消息中包含关键词
if msg in __words__:
# 随机一个回复
idx = random.randint(0, len(__random_reply__)-1)
# 返回回复的消息
event.add_return("reply", [Plain(__random_reply__[idx])])
# 阻止向接口获取回复
event.prevent_default()
def __del__(self):
pass