MiraiForum

    • Register
    • Login
    • Search
    • Popular
    • Recent
    • Unsolved
    • Tags
    • Groups
    • 友情链接

    CommandYouWant —— 重定向其他插件的命令

    插件发布
    kotlin plugin xxxyouwant 命令
    7
    22
    3565
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • MrXiaoM
      MrXiaoM 童心未泯 last edited by MrXiaoM

      CommandYouWant

      项目地址:https://github.com/MrXiaoM/CommandYouWant

      「你想要的插件」系列作品

      重定向命令,统一机器人命令格式。

      灵感来源于 Minecraft 服务端插件 OhMyCmd

      经济系统支持

      本插件支持使用经济系统(可选) Mirai Economy Core,
      如有需要使用金钱功能,请自行安装。若不需要金钱功能可不安装,不影响使用。

      简介

      各大插件作者对于机器人命令的命名方式各不相同,
      同时,有的插件年久失修,且没有提供命令修改方法。
      这时,CommandYouWant 派上了用场,你可以逐一部署
      各个命令的别名,将这个命令的参数任意映射到另一个命令上。

      安装

      到 Releases 下载插件并放入 plugins 文件夹进行安装

      安装完毕后,编辑配置文件作出你想要的修改。在控制台执行 /cmduw reload 重载配置即可~

      使用方法和示例

      以调用 cssxsh 大佬的 NovelAi Helper 为例,先到文件夹 config/top.mrxiaom.commandyouwant/commands,第一次启动这个插件会创建这个文件夹并把示例配置 sample.yml 放进去。首先把 sample.yml 复制一份,取任意名放在同一文件夹中。然后打开编辑:

      perm: test
      perm-desc: 获取图片
      deny-tips: '权限不足'
      keyword: '{at:bot}画画 {next}'
      keywords-list: []
      # 参数屏蔽词
      keyword-block:
        # 第二个参数 {next} 中禁止出现的字符列表
        1: 
          - '#'
      keyword-block-tips: 你输入的参数不合规
      actions: 
        - 'cmd:/nai {1}'
        - 'send:可以像这样一次执行多条指令'
      # false 的时候忽略执行以上两条命令的权限检查
      is-action-check-perm: false
      

      首先我们设置权限,比如将 perm 设为 test,填写后用户需要有权限 top.mrxiaom.commandyouwant:command.test 才能执行这个命令。

      然后,我们需要定义用户要怎样才能触发这个命令,将格式写到 keyword 里。如果需要更多命令别名,加到 keywords-list 里,格式与 keyword 一致。

      在 keyword 中插入 {} 包围的内容作为命令参数,如图中的例子,有两个参数 {at:bot} 和 {next} (都能填什么参数可以在后面的表格看到),用户需要发「@机器人 画画 初音未来 可爱(任意字符都行)」,插件就会把其中的参数提取出来,按顺序排好,这里的参数是

      索引 内容
      0 @机器人
      1 "初音未来 可爱(任意字符都行)"

      然后,插件会将这些参数替换掉 actions 里的 {索引} 然后模拟用户执行命令。

      说白了,就是给其他插件的命令套壳。
      写要执行的命令到 actions 之前,需要添加前缀。不添加前缀将默认以 cmd: 方式执行。

      前缀 说明
      cmd: 使用 mirai-console 的命令系统执行命令
      msg: 模拟消息事件,触发其他插件收到群消息/好友消息
      send: 发送消息,后面填写的内容即发送的内容

      在 actions 中,你可以使用这些基础变量,如有需要其他变量,欢迎 PR。

      变量(不区分大小写) 说明
      {at} @发送命令的人,好友消息时将为空白
      {quote} 回复消息
      {botId} 机器人QQ号
      {groupId} 群号,好友消息时将为空白
      {friendId} 好友QQ号,群消息时将为空白
      {senderId} 命令发送者QQ号
      {subjectId} 好友消息时为QQ号,群消息时为群号

      如果无法通过索引补充参数到要模拟执行的命令里,将会在后台报错。如果你有特别需求忽略这个错误,请在后面再加个 ?,如 {0}?

      在完成了命令的基础设置后,你可以更改一些进阶设置,注释在默认配置文件里都有。

      keyword/keywords 所有可用的参数如下

      内容 解释
      {arg} 单个文字参数,识别到空格就终止
      {next} 长段文字参数,识别到其他类型的消息元素或消息末尾就终止
      {at} @某人,@所有人都可以
      {at:QQ号} @某人,只能@特定某个人
      {at:bot} @机器人
      {img} 图片
      {face} 表情

      希望你能看懂这份教程。

      捐助

      前往 爱发电 捐助我。

      来自群组: SkyNet1748

      1 Reply Last reply Reply Quote 0
      • T
        TNTobsidian last edited by

        您好,感谢您提供这么好的插件!但不过打扰一下,帖子中Releases的github链接是不是粘错了😂少了个You

        1 Reply Last reply Reply Quote 1
        • X
          xing99 last edited by

          你成功了吗

          1 Reply Last reply Reply Quote 0
          • S
            SyuueenN last edited by SyuueenN

            请问需要多种触发方式时,直接在keyword里填多个值可以吗

            MrXiaoM 1 Reply Last reply Reply Quote 0
            • MrXiaoM
              MrXiaoM 童心未泯 @SyuueenN last edited by

              @SyuueenN 目前不能,虽然可以改成一个命令多种触发方式,但目前我没有时间进行开发,所有项目停更。

              要加这个功能也要等我解决完这个插件里还存在的一些逻辑错误才能加了

              S 1 Reply Last reply Reply Quote 0
              • S
                SyuueenN @MrXiaoM last edited by

                @MrXiaoM 十分感谢

                1 Reply Last reply Reply Quote 0
                • S
                  SyuueenN last edited by

                  请问这样的报错是什么问题?
                  其实从安装开始就无法让这个插件起任何反应,甚至尝试用别名执行 /help 都办不到。不过偶然尝试导致了如下的报错,也是头一次见到插件有反应。
                  MiraiConsole v2.13.0 CommandYouWant v0.1.0

                  2022-12-03 18:47:27 E/CommandYouWant: Exception in coroutine Plugin top.mrxiaom.commandyouwant of CommandYouWant
                  java.lang.IllegalStateException: Cannot find MessageSource from message
                          at net.mamoe.mirai.event.events.GroupMessageEvent.<init>(MessageEvent.kt:190)
                          at CommandYouWant-0.1.1.mirai2.jar//top.mrxiaom.commandyouwant.CommandYouWantKt.rebuildMessageEvent(CommandYouWant.kt:136)
                          at CommandYouWant-0.1.1.mirai2.jar//top.mrxiaom.commandyouwant.CommandYouWant.processCommand(CommandYouWant.kt:105)
                          at CommandYouWant-0.1.1.mirai2.jar//top.mrxiaom.commandyouwant.CommandYouWant.access$processCommand(CommandYouWant.kt:29)
                          at CommandYouWant-0.1.1.mirai2.jar//top.mrxiaom.commandyouwant.CommandYouWant$onEnable$1.invokeSuspend(CommandYouWant.kt:59)
                          at CommandYouWant-0.1.1.mirai2.jar//top.mrxiaom.commandyouwant.CommandYouWant$onEnable$1.invoke(CommandYouWant.kt)
                          at CommandYouWant-0.1.1.mirai2.jar//top.mrxiaom.commandyouwant.CommandYouWant$onEnable$1.invoke(CommandYouWant.kt)
                          at net.mamoe.mirai.event.EventChannel$subscribeAlways$1.invokeSuspend(EventChannel.kt:506)
                          at net.mamoe.mirai.event.EventChannel$subscribeAlways$1.invoke(EventChannel.kt)
                          at net.mamoe.mirai.event.EventChannel$subscribeAlways$1.invoke(EventChannel.kt)
                          at net.mamoe.mirai.internal.event.SafeListener$onEvent$2.invokeSuspend(SafeListener.kt:58)
                          at net.mamoe.mirai.internal.event.SafeListener$onEvent$2.invoke(SafeListener.kt)
                          at net.mamoe.mirai.internal.event.SafeListener$onEvent$2.invoke(SafeListener.kt)
                          at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:89)
                          at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:169)
                          at kotlinx.coroutines.BuildersKt.withContext(Unknown Source)
                          at net.mamoe.mirai.internal.event.SafeListener.onEvent(SafeListener.kt:58)
                          at net.mamoe.mirai.internal.event.EventListeners.process(EventListeners.kt:120)
                          at net.mamoe.mirai.internal.event.EventListeners.access$process(EventListeners.kt:28)
                          at net.mamoe.mirai.internal.event.EventListeners$callListeners$2$1.invokeSuspend(EventListeners.kt:85)
                          at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
                          at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
                          at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
                          at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
                          at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
                          at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
                  
                  S 1 Reply Last reply Reply Quote 0
                  • S
                    SyuueenN @SyuueenN last edited by

                    @SyuueenN 虽然查询显示插件版本为 0.1.0,不过文件确实是最新的 0.1.1 版本。

                    MrXiaoM 1 Reply Last reply Reply Quote 0
                    • MrXiaoM
                      MrXiaoM 童心未泯 @SyuueenN last edited by

                      @SyuueenN 找不到消息源。消息事件我还没测试过,一会我推个更新修复

                      1 Reply Last reply Reply Quote 0
                      • S
                        SyuueenN last edited by

                        辛苦

                        MrXiaoM 1 Reply Last reply Reply Quote 0
                        • MrXiaoM
                          MrXiaoM 童心未泯 @SyuueenN last edited by

                          @SyuueenN 0.1.2 已更新

                          1 Reply Last reply Reply Quote 0
                          • S
                            SyuueenN last edited by

                            请问如何在 action 里获取接收命令的群聊或用户?例如设置 Mirai-Admin 插件的 /send to (目标) 发送消息指令时会需要一个目的群号。

                            MrXiaoM 1 Reply Last reply Reply Quote 0
                            • MrXiaoM
                              MrXiaoM 童心未泯 @SyuueenN last edited by

                              @SyuueenN 目前没有这个功能,最近我补课,有空再更新

                              S 1 Reply Last reply Reply Quote 0
                              • S
                                SyuueenN @MrXiaoM last edited by

                                @MrXiaoM 大佬三次元也很忙啊,抽时间做程序辛苦了
                                现阶段这个插件已经有太多可能性了,忍不住妄想一下,如果有回复消息、延时功能、简单的 if 判断的话岂不是直接升维变成插件里的快捷指令了啊

                                MrXiaoM 1 Reply Last reply Reply Quote 0
                                • Ndsanes
                                  Ndsanes last edited by

                                  好东西!收藏了!谢谢大佬!

                                  1 Reply Last reply Reply Quote 0
                                  • MrXiaoM
                                    MrXiaoM 童心未泯 @SyuueenN last edited by

                                    @SyuueenN https://github.com/MrXiaoM/CommandYouWant/releases/tag/0.2.0
                                    已更新

                                    1 Reply Last reply Reply Quote 0
                                    • S
                                      SyuueenN last edited by

                                      辛苦了,感谢

                                      1 Reply Last reply Reply Quote 0
                                      • V
                                        vynoca last edited by

                                        请问如何在LuckPerm里面设置权限呢?弄不明白了呜呜呜

                                        我发现发对应的消息,都是回复无权限的提示;

                                        有所有权限的机器人管理员发送消息,没有回复,会在控制台报错(mirai-hibernate-plugin 相关的?
                                        mirai-hibernate-plugin: Exception in Recorder
                                        kotlinx.serialization.SerializationException: Class 'MetaNoCommand' is not registered for polymorphic serialization in the scope of 'SingleMessage'.
                                        Mark the base class as 'sealed' or register the serializer explicitly.

                                        1 Reply Last reply Reply Quote 0
                                        • S
                                          SyuueenN last edited by

                                          再次表示感谢
                                          电脑被勒索病毒搞了之后不得不手动重做所有 bot 配置,cmduw 神奇地帮我省下巨多事

                                          1 Reply Last reply Reply Quote 0
                                          • L
                                            lunailoli last edited by

                                            This post is deleted!
                                            1 Reply Last reply Reply Quote 0
                                            • 1
                                            • 2
                                            • 1 / 2
                                            • First post
                                              Last post
                                            Powered by Mamoe Technologies & NodeBB | 友情链接 | 服务监控 | Contact