MiraiForum

    • 注册
    • 登录
    • 搜索
    • 热门
    • 最新
    • 未解决
    • 标签
    • 群组
    • 友情链接
    1. 主页
    2. Danile0
    3. 帖子
    D
    • 资料
    • 关注 0
    • 粉丝 0
    • 主题 5
    • 帖子 17
    • 最佳 0
    • 有争议的 0
    • 群组 0

    Danile0 发布的帖子

    • RE: mirai-console怎么发送ShortVideo JAVA

      已经解决了,谢谢

      发布在 开发交流
      D
      Danile0
    • RE: mirai-console怎么发送ShortVideo JAVA

      @cssxsh 这个版本现在可以用么

      发布在 开发交流
      D
      Danile0
    • mirai-console怎么发送ShortVideo JAVA

      如题

      发布在 开发交流
      D
      Danile0
    • 技术交流-如何实现高效率的消息过滤

      各位大佬,官方文档可以通过GlobalEventChannel过滤,但是我觉得比较麻烦,每个都需要去注册单独的事件。

      现在我想像simbot那样,通过自定义注解加AOP去实现消息的过滤,有没有可实现的方法,或者说怎么加载AOP呢?

      发布在 开发交流
      D
      Danile0
    • RE: 配置文件的注释打不出来

      @cssxsh 我只是用kotlin写配置文件,其他都是java

      build.gradle

      plugins {
          id 'org.jetbrains.kotlin.jvm' version '1.9.0'
          id 'org.jetbrains.kotlin.plugin.serialization' version '1.9.0'
          id 'net.mamoe.mirai-console' version '2.15.0'
      }
      
      dependencies {
          implementation 'org.ini4j:ini4j:0.5.4'
          implementation 'com.alibaba.fastjson2:fastjson2:2.0.33'
          implementation 'com.squareup.okhttp3:okhttp:4.11.0'
          implementation 'net.mamoe.yamlkt:yamlkt-jvm:0.13.0'
          implementation 'mysql:mysql-connector-java:8.0.33'
          implementation 'cn.hutool:hutool-all:5.8.21'
      
      }
      
      group = 'com.ayang.plugin'
      version = '1.1.5_bp'
      
      repositories {
          maven { url 'https://maven.aliyun.com/repository/public' }
          mavenCentral()
      }
      
      
      发布在 开发交流
      D
      Danile0
    • RE: 配置文件的注释打不出来

      @cssxsh 是的

      package com.ayang.plugin
      
      import kotlinx.serialization.Serializable
      import net.mamoe.mirai.console.data.ReadOnlyPluginConfig
      import net.mamoe.mirai.console.data.ValueDescription
      import net.mamoe.mirai.console.data.value
      import net.mamoe.yamlkt.Comment
      
      /**
       * @author JinLY
       * @description A3Bot配置文件
       * @date 2023-08-11 13:50:26
       */
      object A3BotConfig : ReadOnlyPluginConfig("A3BotConfig") {
      
          @Serializable
          data class data(
              @Comment("驱动")
              val driver: String,
              @Comment("数据库地址")
              val url: String,
              @Comment("数据库用户名")
              val username: String,
              @Comment("数据库密码")
              val password: String,
          )
      
          @ValueDescription("数据库配置")
          val dataSource: MutableList<data> by value(mutableListOf(
              data(
                  driver = "com.mysql.cj.jdbc.Driver",
                  url = "jdbc:mysql://localhost:3306/a3bot?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai",
                  username = "root",
                  password = "admin"
              )
          ))
      }
      

      配置文件生成后:

      # 数据库配置
      dataSource: 
        - driver: com.mysql.cj.jdbc.Driver
          url: 'jdbc:mysql://localhost:3306/a3bot?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai'
          username: root
          password: admin
      
      发布在 开发交流
      D
      Danile0
    • RE: 配置文件的注释打不出来

      @cssxsh 不好意思

      object A3BotConfig : ReadOnlyPluginConfig("A3BotConfig") {
      
          data class data(
              @Comment("驱动")
              val driver: String,
              @Comment("数据库地址")
              val url: String,
              @Comment("数据库用户名")
              val username: String,
              @Comment("数据库密码")
              val password: String,
          )
      
          @ValueDescription("数据库配置")
          val dataSource: MutableList<data> by value(mutableListOf(
              data(
                  driver = "com.mysql.cj.jdbc.Driver",
                  url = "jdbc:mysql://localhost:3306/a3bot?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai",
                  username = "root",
                  password = "admin"
              )
          ))
      }
      
      发布在 开发交流
      D
      Danile0
    • 配置文件的注释打不出来

      如图所示

      4d443af4-12b0-4f3b-8e82-d5543a67cbf8-image.png

      两种注解都试了,而且还多一条横杠
      4fd7b4f2-4832-4ac8-994c-daf2a97382c0-image.png

      发布在 开发交流
      D
      Danile0
    • RE: 配置文件自动初始化,怎么解决?

      @cssxsh 可以了,谢谢

      发布在 开发交流
      D
      Danile0
    • RE: 配置文件自动初始化,怎么解决?

      @MrXiaoM 如果说,我让用户自己配置,然后我升级版本,增加了配置。怎么把新增的配置写入呢

      发布在 开发交流
      D
      Danile0
    • RE: 配置文件自动初始化,怎么解决?

      @MrXiaoM 好的,我试试

      发布在 开发交流
      D
      Danile0
    • 配置文件自动初始化,怎么解决?

      0329e6ce-9ba0-4ecf-bea2-8bbeb7efbbe8-image.png

      启动后生成的文件:

      c46eea09-d2ab-429a-a2d9-a6384806c024-image.png

      直接修改这个文件的value
      4c4f3373-b815-4b03-be7a-a5e7d3968b38-image.png

      过一会儿自动就恢复成初始状态了

      发布在 开发交流
      D
      Danile0
    • RE: 求助! 发送图片失败

      @Danile0 第5行多了个new FIle(); 忽略就行

      发布在 开发交流
      D
      Danile0
    • RE: 求助! 发送图片失败

      @起舞弄清影
      =。= ,这样就行了吧

      try {
                              byte[] bytes = Base64.getDecoder().decode(stringR.getData());
                              String path = dataFile.getPath().substring(0, dataFile.getPath().length() - 9);
                              File file = new File(path + "serverInfo.png");
                              ImageIO.write(ImageIO.read(new ByteArrayInputStream(bytes)), "png", new File(file.getPath()));
                              ExternalResource resource = ExternalResource.create(file);
                              Image image = event.getGroup().uploadImage(resource);
                              MessageChain messageChain = new MessageChainBuilder()
                                      .append(new At(event.getSender().getId()))
                                      .append("\n")
                                      .append(image)
                                      .build();
                              event.getGroup().sendMessage(messageChain);
                          }catch (Exception e){
                              e.printStackTrace();
                              MessageUtil.sendGroupMessage(event, "获取图片失败!");
                          }
      
      发布在 开发交流
      D
      Danile0
    • RE: 求助! 发送图片失败

      @起舞弄清影 在 求助! 发送图片失败 中说:

      你这明显是上传了不支持的格式
      试试用ImageIO

      我把文件命名为.png了呀

      发布在 开发交流
      D
      Danile0
    • 求助! 发送图片失败

      报错:

      java.lang.IllegalArgumentException: Unsupported image type (mirai) for ExternalResource net.mamoe.mirai.internal.utils.ExternalResourceImplByFile@e44b38d, considering use gif/png/bmp/jpg format. image header:
              at net.mamoe.mirai.internal.message.image.ImageDecoderKt.calculateImageInfo(ImageDecoder.kt:159)
              at net.mamoe.mirai.internal.contact.CommonGroupImpl$uploadImage$lambda-16$$inlined$runBIO$1.invoke(CoroutineUtils.kt:23)
              at kotlinx.coroutines.InterruptibleKt.runInterruptibleInExpectedContext(Interruptible.kt:51)
              at kotlinx.coroutines.InterruptibleKt.access$runInterruptibleInExpectedContext(Interruptible.kt:1)
              at kotlinx.coroutines.InterruptibleKt$runInterruptible$2.invokeSuspend(Interruptible.kt:43)
              at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
              at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
              at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
              at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
              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)
      

      代码:

      byte[] bytes = Base64.getDecoder().decode(stringR.getData());
                          String path = dataFile.getPath().substring(0, dataFile.getPath().length() - 9);
                          File file = FileUtils.byte2image(bytes, path , UUID.randomUUID() + ".png");
      
                          ExternalResource resource = ExternalResource.create(file);
                          Image image = event.getGroup().uploadImage(resource);
                          MessageChain messageChain = new MessageChainBuilder()
                                  .append(new At(event.getSender().getId()))
                                  .append("\n")
                                  .append(image)
                                  .build();
                          event.getGroup().sendMessage(messageChain);
      
      发布在 开发交流
      D
      Danile0
    • 1 / 1