mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-02 03:55:55 +00:00
feat: 添加更多插件示例
This commit is contained in:
@@ -1,6 +1,11 @@
|
|||||||
from pkg.plugin.models import *
|
from pkg.plugin.models import *
|
||||||
from pkg.plugin.host import EventContext
|
from pkg.plugin.host import EventContext
|
||||||
|
|
||||||
|
"""
|
||||||
|
基本命令的中文形式支持
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
__mapping__ = {
|
__mapping__ = {
|
||||||
"帮助": "help",
|
"帮助": "help",
|
||||||
"重置": "reset",
|
"重置": "reset",
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
from pkg.plugin.models import *
|
from pkg.plugin.models import *
|
||||||
from pkg.plugin.host import EventContext
|
from pkg.plugin.host import EventContext
|
||||||
|
|
||||||
|
"""
|
||||||
|
在收到私聊或群聊消息"hello"时,回复"hello, <发送者id>!"或"hello, everyone!"
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
# 注册插件
|
# 注册插件
|
||||||
@register(name="Hello", description="hello world", version="0.1", author="RockChinQ")
|
@register(name="Hello", description="hello world", version="0.1", author="RockChinQ")
|
||||||
|
|||||||
43
tests/plugin_examples/urlikethisijustsix/urlt.py
Normal file
43
tests/plugin_examples/urlikethisijustsix/urlt.py
Normal 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
|
||||||
Reference in New Issue
Block a user