Skip to content

Commit

Permalink
🎉 Recreated repositorie
Browse files Browse the repository at this point in the history
  • Loading branch information
MisakaTAT committed Aug 26, 2021
0 parents commit 14f1e23
Show file tree
Hide file tree
Showing 63 changed files with 4,722 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
.DS_Store
/.mvn/
/mvnw
/mvnw.bat
mvnw.cmd

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/
661 changes: 661 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

118 changes: 118 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<div align="center">

# Shiro

_✨ 基于 [OneBot](https://github.com/howmanybots/onebot/blob/master/README.md) 协议的 QQ机器人 快速开发框架 ✨_

</div>

<p align="center">
<a href="https://search.maven.org/search?q=com.mikuac.shiro"><img src="https://img.shields.io/maven-central/v/com.mikuac/shiro.svg?label=Maven%20Central&style=flat-square" alt="maven" /></a>
<a href="https://github.com/MisakaTAT/Shiro/issues"><img src="https://img.shields.io/github/issues/MisakaTAT/Shiro?style=flat-square" alt="issues" /></a>
<a href="https://github.com/MisakaTAT/Shiro/blob/main/LICENSE"><img src="https://img.shields.io/github/license/MisakaTAT/Shiro?style=flat-square" alt="license"></a>
<img src="https://img.shields.io/badge/JDK-15+-brightgreen.svg?style=flat-square" alt="jdk-version">
<a href="https://qm.qq.com/cgi-bin/qm/qr?k=Fl3-G9irYp84ng7LAFlTvqrOGIFHdufR&jump_from=webapi"><img src="https://img.shields.io/badge/QQ群-204219849-brightgreen.svg?style=flat-square" alt="qq-group"></a>
<a href="https://github.com/howmanybots/onebot"><img src="https://img.shields.io/badge/OneBot-v11-blue?style=flat-square&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABABAMAAABYR2ztAAAAIVBMVEUAAAAAAAADAwMHBwceHh4UFBQNDQ0ZGRkoKCgvLy8iIiLWSdWYAAAAAXRSTlMAQObYZgAAAQVJREFUSMftlM0RgjAQhV+0ATYK6i1Xb+iMd0qgBEqgBEuwBOxU2QDKsjvojQPvkJ/ZL5sXkgWrFirK4MibYUdE3OR2nEpuKz1/q8CdNxNQgthZCXYVLjyoDQftaKuniHHWRnPh2GCUetR2/9HsMAXyUT4/3UHwtQT2AggSCGKeSAsFnxBIOuAggdh3AKTL7pDuCyABcMb0aQP7aM4AnAbc/wHwA5D2wDHTTe56gIIOUA/4YYV2e1sg713PXdZJAuncdZMAGkAukU9OAn40O849+0ornPwT93rphWF0mgAbauUrEOthlX8Zu7P5A6kZyKCJy75hhw1Mgr9RAUvX7A3csGqZegEdniCx30c3agAAAABJRU5ErkJggg==" alt="cqhttp"></a>
</p>

# QuickStart

```xml
<!-- 导入Maven依赖 -->
<dependency>
<groupId>com.mikuac</groupId>
<artifactId>shiro</artifactId>
<version>1.1.1</version>
</dependency>
```

```yaml
# 修改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
```
```java
// 继承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;
}

}
```

# Client

Shiro 以 [OneBot-v11](https://github.com/howmanybots/onebot/tree/master/v11/specs) 标准协议进行开发,兼容所有支持反向WebSocket的OneBot协议客户端

| 项目地址 | 平台 | 核心作者 | 备注 |
| --- | --- | --- | --- |
| [Yiwen-Chan/OneBot-YaYa](https://github.com/Yiwen-Chan/OneBot-YaYa) | [先驱](https://www.xianqubot.com/) | kanri | |
| [richardchien/coolq-http-api](https://github.com/richardchien/coolq-http-api) | CKYU | richardchien | 可在 Mirai 平台使用 [mirai-native](https://github.com/iTXTech/mirai-native) 加载 |
| [Mrs4s/go-cqhttp](https://github.com/Mrs4s/go-cqhttp) | [MiraiGo](https://github.com/Mrs4s/MiraiGo) | Mrs4s | |
| [yyuueexxiinngg/cqhttp-mirai](https://github.com/yyuueexxiinngg/cqhttp-mirai) | [Mirai](https://github.com/mamoe/mirai) | yyuueexxiinngg | |
| [takayama-lily/onebot](https://github.com/takayama-lily/onebot) | [OICQ](https://github.com/takayama-lily/oicq) | takayama | |

# Feature

完善中···

目前已实现绝大部分Event,Action,CQCode,请自行查看源码

# Credits

* [OneBot](https://github.com/botuniverse/onebot)
* [pbbot-spring-boot-starter](https://github.com/ProtobufBot/pbbot-spring-boot-starter)
Shiro开发时的参考实现,感谢 [lz1998](https://github.com/lz1998) 大佬的开源项目,本项目众多灵感正来源于此。

# License

This product is licensed under the GNU General Public License version 3. The license is as published by the Free
Software Foundation published at https://www.gnu.org/licenses/gpl-3.0.html.

Alternatively, this product is licensed under the GNU Lesser General Public License version 3 for non-commercial use.
The license is as published by the Free Software Foundation published at https://www.gnu.org/licenses/lgpl-3.0.html.

Feel free to contact us if you have any questions about licensing or want to use the library in a commercial closed
source product.

# Thanks

Thanks [JetBrains](https://www.jetbrains.com/?from=mirai) Provide Free License Support OpenSource Project

[<img src="https://mikuac.com/images/jetbrains-variant-3.png" width="200"/>](https://www.jetbrains.com/?from=mirai)

## Stargazers over time

[![Stargazers over time](https://starchart.cc/MisakaTAT/Shiro.svg)](https://starchart.cc/MisakaTAT/Shiro)
150 changes: 150 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.mikuac</groupId>
<artifactId>shiro</artifactId>
<version>1.1.1</version>
<name>Shiro</name>
<url>https://mikuac.com</url>
<description>基于OneBot协议的QQ机器人快速开发框架</description>

<properties>
<java.version>15</java.version>
<maven.compiler.source>15</maven.compiler.source>
<maven.compiler.target>15</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

<scm>
<connection>scm:git:git://github.com/MisakaTAT/Shiro.git</connection>
<developerConnection>scm:git:ssh://github.com/MisakaTAT/Shiro.git</developerConnection>
<url>https://github.com/MisakaTAT/Shiro/tree/main</url>
</scm>

<!-- snapshotRepository与repository中的id一定要与maven setting.xml中server的id保持一致! -->
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>

<developers>
<developer>
<name>MisakaTAT</name>
<email>[email protected]</email>
</developer>
</developers>

<licenses>
<license>
<name>GNU General Public License v3.0</name>
<url>https://github.com/MisakaTAT/Shiro/blob/main/LICENSE</url>
<distribution>repo</distribution>
</license>
</licenses>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- 配置gpg非交互式密码输入 -->
<gpgArguments>
<arg>--pinentry-mode</arg>
<arg>loopback</arg>
</gpgArguments>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>30.1.1-jre</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<version>2.5.4</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
<version>2.5.4</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.78</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>22.0.0</version>
</dependency>
</dependencies>

</project>
69 changes: 69 additions & 0 deletions src/main/java/com/mikuac/shiro/boot/Shiro.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.mikuac.shiro.boot;

import com.mikuac.shiro.core.BotContainer;
import com.mikuac.shiro.core.BotFactory;
import com.mikuac.shiro.handler.ActionHandler;
import com.mikuac.shiro.handler.EventHandler;
import com.mikuac.shiro.handler.WebSocketHandler;
import com.mikuac.shiro.properties.WebSocketProperties;
import com.mikuac.shiro.task.ShiroAsyncTask;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.server.standard.ServletServerContainerFactoryBean;

import javax.annotation.Resource;

/**
* Created on 2021/7/16.
*
* @author Zero
*/
@Component
public class Shiro {

@Resource
private WebSocketProperties webSocketProperties;

@Resource
private BotFactory botFactory;

@Resource
private EventHandler eventHandler;

@Resource
private ActionHandler actionHandler;

@Resource
private ShiroAsyncTask shiroAsyncTask;

@Resource
private BotContainer botContainer;

/**
* 创建ShiroWebSocketHandler
*
* @return ShiroWebSocketHandler
*/
@Bean
@ConditionalOnMissingBean
public WebSocketHandler createShiroWebSocketHandler() {
return new WebSocketHandler(eventHandler, botFactory, actionHandler, shiroAsyncTask, botContainer);
}

/**
* 设置ServletServerContainerFactoryBean
*
* @return ServletServerContainerFactoryBean
*/
@Bean
@ConditionalOnMissingBean
public ServletServerContainerFactoryBean createWebSocketContainer() {
ServletServerContainerFactoryBean container = new ServletServerContainerFactoryBean();
container.setMaxTextMessageBufferSize(webSocketProperties.getMaxTextMessageBufferSize());
container.setMaxBinaryMessageBufferSize(webSocketProperties.getMaxBinaryMessageBufferSize());
container.setMaxSessionIdleTimeout(webSocketProperties.getMaxSessionIdleTimeout());
return container;
}

}
Loading

0 comments on commit 14f1e23

Please sign in to comment.