MiraiForum

    • 注册
    • 登录
    • 搜索
    • 热门
    • 最新
    • 未解决
    • 标签
    • 群组
    • 友情链接

    Shiro 基于OneBot协议的QQ机器人开发框架

    其他项目发布
    1
    1
    468
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • M
      MisakaTAT 最后由 编辑

      About

      一个基于OneBot协议的Java机器人开发框架,支持 mirai-api-http

      仓库:https://github.com/MisakaTAT/Shiro

      QuickStart

      <!-- 导入Maven依赖 -->
      <dependency>
          <groupId>com.mikuac</groupId>
          <artifactId>shiro</artifactId>
          <!-- 请使用最新版本 -->
          <version>1.1.1</version>
      </dependency>
      
      # 修改application.yaml
      server:
        port: 5555
      
      shiro:
        # 全局限速器 (基于令牌桶算法),无需该配置字段可删除,将使用默认值(默认禁用)
        limiter:
          enable: false
          permits-per-second: 1
        # Webscoket连接地址,无需该配置字段可删除,将使用默认值 "/ws/shiro"
        ws-config:
          ws-url: "/ws/shiro"
        # 插件列表 (顺序执行,如果前一个插件返回了MESSAGE_BLOCK,将不会执行后续插件)
        plugin-list:
          - com.mikuac.bot.plugins.ExamplePlugin
      
      // 继承BotPlugin开始编写插件
      @Component
      public class ExamplePlugin extends BotPlugin {
      
          @Override
          public int onPrivateMessage(@NotNull Bot bot, @NotNull PrivateMessageEvent event) {
              // 构建消息
              MsgUtils msgUtils = MsgUtils().builder().face(66).text("Hello, this is shiro demo.");
              // 发送私聊消息
              bot.sendPrivateMsg(event.getUserId(), msgUtils.build(), false);
              // 返回 MESSAGE_IGNORE 插件向下执行,返回 MESSAGE_BLOCK 则不执行下一个插件
              return MESSAGE_IGNORE;
          }
      
          @Override
          public int onGroupMessage(@NotNull Bot bot, @NotNull GroupMessageEvent event) {
              // 构建消息
              MsgUtils msgUtils = MsgUtils().builder().at(event.getUserId()).face(66).text("Hello, this is shiro demo.");
              // 发送群消息
              bot.sendGroupMsg(event.getGroupId(), msgUtils.build(), false);
              // 返回 MESSAGE_IGNORE 插件向下执行,返回 MESSAGE_BLOCK 则不执行下一个插件
              return MESSAGE_IGNORE;
          }
      
      }
      
      1 条回复 最后回复 回复 引用 1
      • 1 / 1
      • First post
        Last post
      Powered by Mamoe Technologies & NodeBB | 友情链接 | 服务监控 | Contact