Merge branch 'master' of github.com:whitechi73/OpenShamrock

This commit is contained in:
ikechan8370 2023-11-25 13:51:21 +08:00
commit 2d57dc021d
6 changed files with 50 additions and 32 deletions

View File

@ -6,7 +6,7 @@ labels: bug
--- ---
警告: 在进一步操作之前,请检查下列选项。如果您忽视此模板或者没有提供关键信息,您的 Issue 将直接被关闭 警告: 在进一步操作之前,请检查下列选项。如果您忽视此模板或者没有提供关键信息,您的 Issue 将直接被关闭
- 确保您使用的是 [最新开发版本](https://github.com/whitechi73/Shamrock/actions/workflows/build-apk.yml) 的 Shamrock. - 确保您使用的是 [最新开发版本](https://github.com/whitechi73/OpenShamrock/actions/workflows/build-apk.yml) 的 Shamrock.
- 确保您的问题尚未在 Issues 列表中提出. - 确保您的问题尚未在 Issues 列表中提出.
- 确保您的问题不是由于您的代码错误导致的. - 确保您的问题不是由于您的代码错误导致的.
@ -22,5 +22,6 @@ labels: bug
- Shamrock 版本: - Shamrock 版本:
- Android 版本: - Android 版本:
- LSPosed 框架版本:
- 设备的制造商和型号: - 设备的制造商和型号:
- 设备的 CPU 架构: - 设备的 CPU 架构:

View File

@ -7,7 +7,7 @@ labels: enhancement
警告: 在进一步操作之前,请检查下列选项。如果您忽视此模板或者没有提供关键信息,您的 Issue 将直接被关闭 警告: 在进一步操作之前,请检查下列选项。如果您忽视此模板或者没有提供关键信息,您的 Issue 将直接被关闭
- 确保您使用的是 [最新开发版本](https://github.com/whitechi73/Shamrock/actions/workflows/build-apk.yml) 的 Shamrock. - 确保您使用的是 [最新开发版本](https://github.com/whitechi73/OpenShamrock/actions/workflows/build-apk.yml) 的 Shamrock.
- 确保您的功能请求尚未在 Issues 列表中提出. - 确保您的功能请求尚未在 Issues 列表中提出.
- 确保您的功能请求是与 Shamrock 相关的,且可以实现. - 确保您的功能请求是与 Shamrock 相关的,且可以实现.

View File

@ -10,7 +10,7 @@
![][onebot-12] ![][onebot-12]
[![][license]](LICENSE) [![][license]](LICENSE)
[下载][download-link] | [部署][deploy-link] | [接口][api-link] | [文档][docs-link] | [加群][group-link] [下载][download-link] | [部署][deploy-link] | [接口][api-link] | [文档][docs-link]
</div> </div>
@ -29,8 +29,6 @@
- 一键移植:本项目基于 go-cqhttp 的文档进行开发实现。 - 一键移植:本项目基于 go-cqhttp 的文档进行开发实现。
- 平行部署:可多平台部署,未来将会支持 Docker 部署的教程。 - 平行部署:可多平台部署,未来将会支持 Docker 部署的教程。
> 若您追求小而轻便的Bot服务, [Chronocat](https://chronocat.vercel.app/)是您的不二之选。
## 权限声明 ## 权限声明
> 如出现未在此处声明的权限,请警惕 Shamrock 是否被修改/植入恶意代码 > 如出现未在此处声明的权限,请警惕 Shamrock 是否被修改/植入恶意代码
@ -45,7 +43,7 @@
## 贡献说明 ## 贡献说明
<img src="https://github.com/whitechi73/OpenShamrock/assets/98259561/f04d60bc-ec40-41fc-bc15-62c146f1a1f1" width="160px"> **我可爱吗?欢迎你的到来,这里是一个很大的地方,有着无限可能,主要是有你啦!** <img src="https://github.com/whitechi73/OpenShamrock/assets/98259561/f04d60bc-ec40-41fc-bc15-62c146f1a1f1" width="160px" alt="Shamrock"> **我可爱吗?欢迎你的到来,这里是一个很大的地方,有着无限可能,主要是有你啦!**
## 开源协议 ## 开源协议
@ -96,9 +94,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
[docs-link]: https://whitechi73.github.io/OpenShamrock/ [docs-link]: https://whitechi73.github.io/OpenShamrock/
[group-link]: https://whitechi73.github.io/OpenShamrock/group.html [hook-system]: https://github.com/whitechi73/OpenShamrock/blob/master/xposed/src/main/java/moe/fuqiuluo/shamrock/xposed/loader/FuckAMS.kt
[hook-system]: https://github.com/whitechi73/OpenShamrock/wiki/perm_hook_android
[voice-support]: https://whitechi73.github.io/OpenShamrock/advanced/voice.html [voice-support]: https://whitechi73.github.io/OpenShamrock/advanced/voice.html

View File

@ -13,6 +13,7 @@ import moe.fuqiuluo.shamrock.utils.FileUtils
import moe.fuqiuluo.shamrock.xposed.actions.toast import moe.fuqiuluo.shamrock.xposed.actions.toast
import moe.fuqiuluo.shamrock.xposed.helper.internal.DataRequester import moe.fuqiuluo.shamrock.xposed.helper.internal.DataRequester
import mqq.app.MobileQQ import mqq.app.MobileQQ
import java.io.File
import java.util.Date import java.util.Date
internal enum class Level( internal enum class Level(
@ -26,15 +27,28 @@ internal enum class Level(
@SuppressLint("SimpleDateFormat") @SuppressLint("SimpleDateFormat")
internal object LogCenter { internal object LogCenter {
private val logFileBaseName = MobileQQ.getMobileQQ().qqProcessName.replace(":", ".") + "_${
// 格式化时间
SimpleDateFormat("yyyy-MM-dd").format(Date())
}_"
private val LogFile = MobileQQ.getContext().getExternalFilesDir(null)!! private val LogFile = MobileQQ.getContext().getExternalFilesDir(null)!!
.parentFile!!.resolve("Tencent/Shamrock/log").also { .parentFile!!.resolve("Tencent/Shamrock/log").also {
if (it.exists()) it.delete() if (it.exists()) it.delete()
it.mkdirs() it.mkdirs()
}.let {
var i = 1
lateinit var result: File
while (true) {
result = it.resolve("$logFileBaseName$i.log")
if (result.exists()) {
i++
} else {
break
} }
.resolve(MobileQQ.getMobileQQ().qqProcessName.replace(":", ".") + "_${ }
// 格式化时间 return@let result
SimpleDateFormat("yyyy-MM-dd").format(Date()) }
}_" + ".log")
private val format = SimpleDateFormat("[HH:mm:ss] ") private val format = SimpleDateFormat("[HH:mm:ss] ")
fun log(string: String, level: Level = Level.INFO, toast: Boolean = false) = fun log(string: String, level: Level = Level.INFO, toast: Boolean = false) =

View File

@ -24,8 +24,8 @@ import java.net.URI
internal class WebSocketService( internal class WebSocketService(
host: String, host: String,
port: Int, port: Int,
val heartbeatInterval: Long, heartbeatInterval: Long,
): WebSocketTransmitServlet(host, port) { ): WebSocketTransmitServlet(host, port, heartbeatInterval) {
private val eventJobList = mutableSetOf<Job>() private val eventJobList = mutableSetOf<Job>()
override fun submitFlowJob(job: Job) { override fun submitFlowJob(job: Job) {
@ -85,7 +85,6 @@ internal class WebSocketService(
} }
private fun pushMetaLifecycle() { private fun pushMetaLifecycle() {
if (heartbeatInterval <= 0) return
GlobalScope.launch { GlobalScope.launch {
val runtime = AppRuntimeFetcher.appRuntime val runtime = AppRuntimeFetcher.appRuntime
pushTo(PushMetaEvent( pushTo(PushMetaEvent(

View File

@ -35,7 +35,8 @@ import kotlin.concurrent.timer
internal abstract class WebSocketTransmitServlet( internal abstract class WebSocketTransmitServlet(
host:String, host:String,
port: Int port: Int,
protected val heartbeatInterval: Long,
) : BaseTransmitServlet, WebSocketServer(InetSocketAddress(host, port)) { ) : BaseTransmitServlet, WebSocketServer(InetSocketAddress(host, port)) {
private val sendLock = Mutex() private val sendLock = Mutex()
protected val eventReceivers: MutableList<WebSocket> = Collections.synchronizedList(mutableListOf<WebSocket>()) protected val eventReceivers: MutableList<WebSocket> = Collections.synchronizedList(mutableListOf<WebSocket>())
@ -56,20 +57,27 @@ internal abstract class WebSocketTransmitServlet(
} }
init { init {
timer("heartbeat", true, 0, 1000L * 5) { if (heartbeatInterval > 0) {
timer("heartbeat", true, 0, heartbeatInterval) {
val runtime = AppRuntimeFetcher.appRuntime val runtime = AppRuntimeFetcher.appRuntime
val curUin = runtime.currentAccountUin val curUin = runtime.currentAccountUin
broadcastAnyEvent(PushMetaEvent( broadcastAnyEvent(
PushMetaEvent(
time = System.currentTimeMillis() / 1000, time = System.currentTimeMillis() / 1000,
selfId = app.longAccountUin, selfId = app.longAccountUin,
postType = PostType.Meta, postType = PostType.Meta,
type = MetaEventType.Heartbeat, type = MetaEventType.Heartbeat,
subType = MetaSubType.Connect, subType = MetaSubType.Connect,
status = BotStatus( status = BotStatus(
Self("qq", curUin.toLong()), runtime.isLogin, status = "正常", good = true Self("qq", curUin.toLong()),
runtime.isLogin,
status = "正常",
good = true
), ),
interval = 15000 interval = heartbeatInterval
)) )
)
}
} }
} }
@ -112,7 +120,7 @@ internal abstract class WebSocketTransmitServlet(
} }
override fun onStart() { override fun onStart() {
LogCenter.log("WSServer start running on ws://0.0.0.0:$port!") LogCenter.log("WSServer start running on ws://${getAddress()}!")
initTransmitter() initTransmitter()
} }