• 欢迎加入MineBBS QQ讨论群:点击查看所有的官方讨论群
  • 我们将于近期对服务器进行迁移,服务可能中断至多2日。请各位安排好自己的访问计划,造成不便敬请谅解!
  • MineBBS入站考试已经上线!想要成为【正式会员】解锁更多功能吗?快来参与吧!【点我去看】
资源图标

原创 工具 【Skript扩展】 Ws-plugin 1.0.0

完成注册/登录后下载
版权类型
原创
插件中文名称
Ws-plugin
插件英文名称
Ws-plugin
原帖地址
#
支持的核心(服务端)
  1. Paper
适配版本(Java)
  1. 26.x
代码:
import:
    com.example.wsplugin.WebSocketClientManager
    com.example.wsplugin.event.WsMessageEvent
    com.example.wsplugin.WsPlugin
    cn.hutool.json.JSONObject
    cn.hutool.json.JSONUtil
    cn.hutool.core.util.IdUtil
    java.net.URI
    java.util.Map


function sendGroupMessage(group:number,content:text):
    set {_string1} to JSONUtil.createObj()
    {_string1}.put("text", {_content})
    
    set {_string2} to JSONUtil.createObj()
    {_string2}.put("type", "text").put("data", {_string1})

    set {_string3} to JSONUtil.createArray().put({_string2})

    set {_string4} to JSONUtil.createObj().put("group_id", {_group}).put("message", {_string3})

    set {_string5} to JSONUtil.createObj().put("action", "send_group_msg").put("params", {_string4}).put("echo", IdUtil.randomUUID())

    {BotService::WS}.sendJson({_string5})

function sendPrivateMessage(group:number,content:text):
    set {_string1} to JSONUtil.createObj()
    {_string1}.put("text", {_content})
    
    set {_string2} to JSONUtil.createObj()
    {_string2}.put("type", "text").put("data", {_string1})

    set {_string3} to JSONUtil.createArray().put({_string2})

    set {_string4} to JSONUtil.createObj().put("user_id", {_group}).put("message", {_string3})

    set {_string5} to JSONUtil.createObj().put("action", "send_private_msg").put("params", {_string4}).put("echo", IdUtil.randomUUID())

    {BotService::WS}.sendJson({_string5})


on load:
    set {BotService::WS} to new WebSocketClientManager()
    {BotService::WS}.connect("ws://127.0.0.1:3081")
    # delete {BotService::qqMember::*}
    # delete {BotService::gameID::*}

on join:
    sendGroupMessage(937291459, "%event-player%加入了服务器!")
    if {BotService::List} does not exist:
        set {BotService::List} to " "
    add "%event-player% %nl%" to {BotService::List}


on leave:
    sendGroupMessage(937291459, "%event-player%离开了服务器!")
    remove "%event-player% %nl%" from {BotService::List}
    send {BotService::List} to console

on click:
    if {BotService::List} doesn't contain "%event-player%":
        if {BotService::List} does not exist:
            set {BotService::List} to " "
        add "%event-player% %nl%" to {BotService::List}

on WsMessageEvent:
    set {_msg} to event.getMessage()
    set {_json} to JSONUtil.parseObj({_msg})
    set {_type} to {_json}.getStr("post_type")
    set {_messageType} to {_json}.getStr("message_type")
    # message 是数组,取第一条消息段
    set {_arr} to {_json}.getJSONArray("message")
    set {_seg} to {_arr}.get(0)
    set {_msgType} to {_seg}.getStr("type")
    set {_data} to {_seg}.getJSONObject("data")
    set {_content} to {_data}.getStr("text")
    set {_groupId} to {_json}.getLong("group_id")
    set {_sender} to {_json}.getJSONObject("sender")
    set {_senderQQId} to {_sender}.getLong("user_id")
    set {_senderQQName} to {_sender}.getStr("nickname")

    if {_messageType} is "group":
        if "%{_type}%" is "message":
            if "%{_msgType}%" is "text":
                if {_content} start with "#":
                    if {_content} start with "#list":
                        if online player count is more than 0:
                            sendGroupMessage({_groupId}, "[AgateCraft]%nl%在线玩家数:%nl% - %online player count%名%nl%最大容纳人数:%nl% - %max players count%名%nl%在线玩家列表:%nl%%{BotService::List}%")
                        else:
                            sendGroupMessage({_groupId}, "没有玩家在线〒▽〒")
                    if {_content} start with "#菜单":
                        set {_a} to "[AgateCraft]群服互通机器人%nl%#list    查询玩家列表(群内发送)%nl%%nl%#password <你的新密码>    私信发送,修改忘记的密码%nl%%nl%#bind <游戏id(必须为英文,基岩用户请在前面加“.”)>    将你的游戏账户与qq绑定%nl%%nl%#unbind 解除绑定"
                        sendGroupMessage({_groupId}, {_a})
                    if {_content} start with "#bind":
                        set {_a} to "%{_senderQQId}%"
                        set {_gameId::*} to {_content} parsed as "#bind %text%"
                        if {BotService::qqMember::%{_a}%} exist:
                            sendGroupMessage({_groupId}, "[AgateCraft]%nl%你已经绑定过了!!!")
                        else if {BotService::gameID::%{_gameID::1}%} exist:
                            sendGroupMessage({_groupId}, "[AgateCraft]%nl%该游戏ID已经被绑定了!!!")
                        else:
                            set {BotService::qqMember::%{_a}%} to {_gameID::1}
                            set {BotService::gameID::%{_gameID::1}%} to {_a}
                            sendGroupMessage({_groupId}, "[AgateCraft]%nl%你的QQID:%{BotService::gameID::%{_gameID::1}%}%%nl%你的游戏ID:%{BotService::qqMember::%{_a}%}%")
                    if {_content} start with "#unbind":
                        set {_a} to "%{_senderQQId}%"
                        if {BotService::qqMember::%{_a}%} or {BotService::gameID::%{_gameID::1}%} exist:
                            sendGroupMessage({_groupId}, "[AgateCraft]%nl%解绑中......")
                            delete {BotService::gameID::%{BotService::qqMember::%{_a}%}%}
                            wait 3 seconds
                            delete {BotService::qqMember::%{_a}%}
                            sendGroupMessage({_groupId}, "[AgateCraft]%nl%解绑成功")
                        else:
                            sendGroupMessage({_groupId}, "[AgateCraft]%nl%你还没有绑定,输入#菜单获取帮助吧")
                else if "%{_groupId}%" is "937291459":
                    send "§c[QQ群消息]§a<%{_senderQQName}%>§b%{_content}%" to players
    else if {_messageType} is "private":
        if {_content} start with "#":
            if {_content} start with "#password":
                set {_a} to "%{_senderQQId}%"
                set {_password::*} to {_content} parsed as "#password %text%"
                if {BotService::qqMember::%{_a}%} exist:
                    execute console command "/authme password %{BotService::qqMember::%{_a}%}% %{_password::1}%"
                    sendPrivateMessage({_senderQQId}, "[AgateCraft]%nl%你的密码改为%{_password::1}%,机器人不会储存您的密码!!!")
                else:
                    sendPrivateMessage({_senderQQId}, "[AgateCraft]%nl%你还没有绑定,群内发送#菜单获取帮助!!!")

        

on chat:
    sendGroupMessage(937291459, "[%event-world%]<%event-player%>%chat message%")

on unload:
    {BotService::WS}.disconnect()
    delete {BotService::List}
作者
Zhanan08
下载
2
查看
38
首次发布
最后更新

评分

0.00 星 0 次评分

Zhanan08 的其他资源

后退
顶部 底部