Skip to content

Commit

Permalink
Init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
yyuueexxiinngg committed May 22, 2020
1 parent 0ee66ff commit 4a91639
Show file tree
Hide file tree
Showing 31 changed files with 3,015 additions and 0 deletions.
106 changes: 106 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# CQHTTP Mirai

__CQHTTP runs on Mirai__

## 开始使用
0. 请首先运行[Mirai-console](https://github.com/mamoe/mirai-console)相关客户端生成plugins文件夹
1.`cqhttp-mirai`生成的`jar包文件`放入`plugins`文件夹中
2. 编辑`plugins/CQHTTPMirai/setting.yml`配置文件, 将以下给出配置复制并修改
3. 再次启动[Mirai-console](https://github.com/mamoe/mirai-console)相关客户端

## 配置相关

```yaml
# 要进行配置的QQ号 (Mirai支持多帐号登录, 故需要对每个帐号进行单独设置)
'1234567890':
# HTTP 相关配置
http:
# 可选,事件及数据上报URL, 默认为空, 即不上报
postUrl: "http://127.0.0.1:3000/"
# 可选,上报消息格式,string 为字符串格式,array 为数组格式, 默认为string
postMessageFormat: string
# 可选,上报数据签名密钥, 默认为空
secret: ""
# 可选,反向客户端服务
ws_reverse:
# 可选,是否启用反向客户端,默认不启用
enable: true
# 上报消息格式,string 为字符串格式,array 为数组格式, 默认为string
postMessageFormat: string
# 反向Websocket主机
reverseHost: 127.0.0.1
# 反向Websocket端口
reversePort: 8080
# 反向Websocket路径
reversePath: /ws
# 反向Websocket Api路径 尚未实现
# reverseApiPath: /ws/
# 反向Websocket Event路径 尚未实现
# reverseEventPath: /ws/
# 反向 WebSocket 客户端断线重连间隔,单位毫秒
reconnectInterval: 3000
```
## 计划
- [x] 反向Websocket客户端
- [x] HTTP上报服务
- [ ] HTTP API
- [ ] Websocket服务端
## 已经支持的CQHTTP API
#### 特别注意, 很多信息Mirai不支持获取, 如群成员的年龄、性别等, 为保证兼容性, 这些项已用`Unknown`, `0`之类的信息填充占位

<list>

- SendMessage (不包含讨论组消息)
- SendGroupMessage
- SendPrivateMessage
- DeleteMessage
- SetGroupKick
- SetGroupBan
- SetWholeGroupBan
- SetGroupCard
- SetGroupLeave
- SetFriendAddRequest
- GetLoginInfo
- GetFriendList
- GetGroupList
- GetGroupInfo (不支持获取群容量, 返回`0`)
- GetGroupMemberInfo
- GetGroupMemberList
- CanSendImage (恒为true)
- GetStatus (不完全支持, 仅返回`online`和`good`两项)
- GetVersionInfo

</list>

## 尚未支持的CQHTTP API

- GetImage
- SetRestartPlugin
- CleanDataDir
- CleanPluginLog
- GetCookies (Mirai不会支持)
- GetCSRFToken (Mirai不会支持)
- GetRecord
- GetCredentials
- GetStrangerInfo
- SendDiscussMessage
- SetGroupAnonymous
- SetGroupAdmin
- SetDiscussLeave
- SendLike (Mirai不会支持)
- SetAnonymousBan

## 开源协议

[AGPL-3.0](LICENSE) © yyuueexxiinngg

## 直接或间接引用到的其他开源项目

- [mirai-api-http](https://github.com/mamoe/mirai-api-http) - [LICENSE](https://github.com/mamoe/mirai-api-http/blob/master/LICENSE)
- [Mirai Native](https://github.com/iTXTech/mirai-native) - [LICENSE](https://github.com/iTXTech/mirai-native/blob/master/LICENSE)
- [CQHTTP](https://github.com/richardchien/coolq-http-api) - [LICENSE](https://github.com/richardchien/coolq-http-api/blob/master/LICENSE)
99 changes: 99 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
plugins {
kotlin("jvm") version "1.3.71"
kotlin("plugin.serialization") version "1.3.71"
java
id("com.github.johnrengelman.shadow") version "5.2.0"
}

group = "yyuueexxiinngg"
version = "0.1.0"

repositories {
maven(url = "https://mirrors.huaweicloud.com/repository/maven")
maven(url = "https://dl.bintray.com/kotlin/kotlin-eap")
jcenter()
mavenCentral()
}

val miraiCoreVersion: String by rootProject.ext
val miraiConsoleVersion: String by rootProject.ext
val ktorVersion: String by rootProject.ext
val kotlinVersion = "1.3.71"

fun ktor(id: String, version: String = this@Build_gradle.ktorVersion) = "io.ktor:ktor-$id:$version"

dependencies {
compileOnly(kotlin("stdlib-jdk8"))
compileOnly("net.mamoe:mirai-core:$miraiCoreVersion")
compileOnly("net.mamoe:mirai-console:$miraiConsoleVersion")
compileOnly(kotlin("serialization", kotlinVersion))

api(ktor("server-cio"))
api(ktor("client-cio"))
api(ktor("websockets"))
api(ktor("client-websockets"))

api(kotlin("reflect", kotlinVersion))

testImplementation(kotlin("stdlib-jdk8"))
testImplementation("net.mamoe:mirai-core:$miraiCoreVersion")
testImplementation("net.mamoe:mirai-core-qqandroid:$miraiCoreVersion")
testImplementation("net.mamoe:mirai-console:$miraiConsoleVersion")
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

tasks {
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}

val runMiraiConsole by creating(JavaExec::class.java) {
group = "mirai"
dependsOn(shadowJar)
dependsOn(testClasses)

val testConsoleDir = "test"

doFirst {
fun removeOldVersions() {
File("$testConsoleDir/plugins/").walk()
.filter { it.name.matches(Regex("""${project.name}-.*-all.jar""")) }
.forEach {
it.delete()
println("deleting old files: ${it.name}")
}
}

fun copyBuildOutput() {
File("build/libs/").walk()
.filter { it.name.contains("-all") }
.maxBy { it.lastModified() }
?.let {
println("Coping ${it.name}")
it.inputStream()
.transferTo(File("$testConsoleDir/plugins/${it.name}").apply { createNewFile() }
.outputStream())
println("Copied ${it.name}")
}
}

workingDir = File(testConsoleDir)
workingDir.mkdir()
File(workingDir, "plugins").mkdir()
removeOldVersions()
copyBuildOutput()

classpath = sourceSets["test"].runtimeClasspath
main = "mirai.RunMirai"
standardInput = System.`in`
args(miraiCoreVersion, miraiConsoleVersion)
}
}
}
6 changes: 6 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kotlin.code.style=official
# config
miraiCoreVersion=1.0-RC2-1
miraiConsoleVersion=0.5.1
# utility
ktorVersion=1.3.2
172 changes: 172 additions & 0 deletions gradlew
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
#!/usr/bin/env sh

##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################

# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null

APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

warn () {
echo "$*"
}

die () {
echo
echo "$*"
echo
exit 1
}

# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar

# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi

# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi

# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi

# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option

if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi

# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")

# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "$@"
Loading

0 comments on commit 4a91639

Please sign in to comment.