MiraiForum

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

    Mirai-console插件要怎么实现仅靠一张图片实现指令?

    开发交流
    5
    5
    533
    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.
    • D
      Dark_Ghast last edited by

      群员发送一张特定图片(例如“色图来.jpg”),插件根据这张图片作出反应,要如何进行实现?
      mirai-console-example-plugin(https://github.com/Him188/mirai-console-example-plugin/blob/master/src/main/kotlin/org/example/my/plugin/MyPluginMain.kt )中的CommandSender.test需要发送“/指令名 参数 [图片]”才能进行反应,如何通过只发送“[图片]”就进行反应?
      希望能给我参考下代码

      1 Reply Last reply Reply Quote 0
      • Karlatemp
        Karlatemp last edited by

        可以使用直接监听,mirai-console 命令框架不支持直接图片命令的形式

        
            object TesterPlugin : KotlinPlugin(......) {
        
                override fun onEnable() {
                    globalEventChannel().subscribeAlways<MessageEvent> {
                        // do something...
                    }
                }
            }
        
        
        1 Reply Last reply Reply Quote 0
        • Him188
          Him188 last edited by

          Mirai Console 内置的消息解析器不支持通过单个图片触发指令. 若有兴趣, 你可以覆盖默认的 CommandCallParser 来实现自定义的消息到指令的解析. 通常也可以使用 @Karlatemp 提供的方法, 只是没有统一权限管理, 指令列表管理等.

          1 Reply Last reply Reply Quote 0
          • hzm18
            hzm18 last edited by

            你要找的是不是"色图来.jpg"原理....不知道可不可以通过图片md5来判断。mirai-console我不清楚

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

              示例

              // msg 类型为 MessageChain
              for (SingleMessage sm : msg){
                  if(sm instanceof Image){
                      if(checkImage(sm)){
                          //do sth.
                      }
                  }
              }
              

              我忘了图片类型是 OnlineImage 还是啥了,自行寻找吧

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