Skip to content

Commit

Permalink
Update Lolicon.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
cikiPAD authored Dec 5, 2023
1 parent b33de9a commit bfc126b
Showing 1 changed file with 88 additions and 158 deletions.
246 changes: 88 additions & 158 deletions src/main/kotlin/command/Lolicon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -493,176 +493,106 @@ object Lolicon : CompositeCommand(
}


@SubCommand("装填", "开始涩涩")
@Description("加载缓存池")
suspend fun CommandSenderOnMessage<MessageEvent>.reloadcache(reqNum: String = "") {
if (fromEvent !is GroupMessageEvent && fromEvent !is FriendMessageEvent)
return
if (fromEvent is GroupMessageEvent && !(fromEvent as GroupMessageEvent).sender.isOperator()) {
sendMessage(ReplyConfig.nonAdminPermissionDenied)
return
}
if (fromEvent is FriendMessageEvent && !this.hasPermission(trusted)) {
sendMessage(ReplyConfig.untrusted)
return
}
logger.info("开始装填")
val (r18, recall, cooldown) = ExecutionConfig(subject)
var num = 2
if (reqNum != null && !reqNum.isEmpty()) {
num = reqNum.toInt()
}
if (num > 5 || num <=0) {
num = 2
}
var str = "{\"num\":"+num+ "," + "\"size\":" +"[\"" +PluginConfig.size.name.lowercase()+ "\"]" +","+ "\"r18\":" + r18 +","+ "\"proxy\":" + "\""+ PluginConfig.proxy+"\"" +"}"
ImageCachedPool.instance.changeReq(str);
ImageCachedPool.instance.isActiveNow = true;
ImageCachedPool.instance.startRun();
// @SubCommand("装填", "开始涩涩")
// @Description("加载缓存池")
// suspend fun CommandSenderOnMessage<MessageEvent>.reloadcache(reqNum: String = "") {
// if (fromEvent !is GroupMessageEvent && fromEvent !is FriendMessageEvent)
// return
// if (fromEvent is GroupMessageEvent && !(fromEvent as GroupMessageEvent).sender.isOperator()) {
// sendMessage(ReplyConfig.nonAdminPermissionDenied)
// return
// }
// if (fromEvent is FriendMessageEvent && !this.hasPermission(trusted)) {
// sendMessage(ReplyConfig.untrusted)
// return
// }
// logger.info("开始装填")
// val (r18, recall, cooldown) = ExecutionConfig(subject)
// var num = 2
// if (reqNum != null && !reqNum.isEmpty()) {
// num = reqNum.toInt()
// }
// if (num > 5 || num <=0) {
// num = 2
// }
// var str = "{\"num\":"+num+ "," + "\"size\":" +"[\"" +PluginConfig.size.name.lowercase()+ "\"]" +","+ "\"r18\":" + r18 +","+ "\"proxy\":" + "\""+ PluginConfig.proxy+"\"" +"}"
// ImageCachedPool.instance.changeReq(str);
// ImageCachedPool.instance.isActiveNow = true;
// ImageCachedPool.instance.startRun();

sendMessage("开始加载缓存池,配置为" + str)
}
// sendMessage("开始加载缓存池,配置为" + str)
// }


@SubCommand("停止涩涩", "退膛")
@Description("停止缓存池")
suspend fun CommandSenderOnMessage<MessageEvent>.stopcache(reqNum: String = "") {
if (fromEvent !is GroupMessageEvent && fromEvent !is FriendMessageEvent)
return
if (fromEvent is GroupMessageEvent && !(fromEvent as GroupMessageEvent).sender.isOperator()) {
sendMessage(ReplyConfig.nonAdminPermissionDenied)
return
}
if (fromEvent is FriendMessageEvent && !this.hasPermission(trusted)) {
sendMessage(ReplyConfig.untrusted)
return
}
logger.info("停止装填")
// @SubCommand("停止涩涩", "退膛")
// @Description("停止缓存池")
// suspend fun CommandSenderOnMessage<MessageEvent>.stopcache(reqNum: String = "") {
// if (fromEvent !is GroupMessageEvent && fromEvent !is FriendMessageEvent)
// return
// if (fromEvent is GroupMessageEvent && !(fromEvent as GroupMessageEvent).sender.isOperator()) {
// sendMessage(ReplyConfig.nonAdminPermissionDenied)
// return
// }
// if (fromEvent is FriendMessageEvent && !this.hasPermission(trusted)) {
// sendMessage(ReplyConfig.untrusted)
// return
// }
// logger.info("停止装填")

ImageCachedPool.instance.isActiveNow = false;
// ImageCachedPool.instance.isActiveNow = false;


sendMessage("停止缓存池")
}
// sendMessage("停止缓存池")
// }

@SubCommand("搞快点", "gkd")
@Description("加载缓存")
suspend fun CommandSender.someimagescache(json: String = "") {
val mutex = getSubjectMutex(subject) ?: return
if (mutex.isLocked) {
logger.info("throttled")
return
}
mutex.withLock {
val (r18, recall, cooldown) = ExecutionConfig(subject)
// @SubCommand("搞快点", "gkd")
// @Description("加载缓存")
// suspend fun CommandSender.someimagescache(json: String = "") {
// val mutex = getSubjectMutex(subject) ?: return
// if (mutex.isLocked) {
// logger.info("throttled")
// return
// }
// mutex.withLock {
// val (r18, recall, cooldown) = ExecutionConfig(subject)

val notificationReceipt = getNotificationReceipt()
// val notificationReceipt = getNotificationReceipt()

if (subject != null && PluginConfig.messageType == PluginConfig.Type.Forward) {
val contact = subject as Contact
val imageMsgBuilder = ForwardMessageBuilder(contact)
imageMsgBuilder.displayStrategy = CustomDisplayStrategy
// if (subject != null && PluginConfig.messageType == PluginConfig.Type.Forward) {
// val contact = subject as Contact
// val imageMsgBuilder = ForwardMessageBuilder(contact)
// imageMsgBuilder.displayStrategy = CustomDisplayStrategy


//imageMsgBuilder.add(contact.bot, PlainText(imageData.toReadable(imageData.urls)))
// //imageMsgBuilder.add(contact.bot, PlainText(imageData.toReadable(imageData.urls)))

for (i in 0 until 5) {
runCatching {
val stream = ImageCachedPool.instance.getImage()
val image = contact.uploadImage(stream)
imageMsgBuilder.add(contact.bot, image)
stream
}.onFailure {
logger.error(it)
imageMsgBuilder.add(contact.bot, PlainText(ReplyConfig.networkError))
}.onSuccess {
runInterruptible(Dispatchers.IO) {
it.close()
}
}
}
// for (i in 0 until 5) {
// runCatching {
// val stream = ImageCachedPool.instance.getImage()
// val image = contact.uploadImage(stream)
// imageMsgBuilder.add(contact.bot, image)
// stream
// }.onFailure {
// logger.error(it)
// imageMsgBuilder.add(contact.bot, PlainText(ReplyConfig.networkError))
// }.onSuccess {
// runInterruptible(Dispatchers.IO) {
// it.close()
// }
// }
// }


val imgReceipt = sendMessage(imageMsgBuilder.build())
if (notificationReceipt != null)
recall(RecallType.NOTIFICATION, notificationReceipt, 0)
if (imgReceipt == null) {
return@withLock
} else if (recall > 0 && PluginConfig.recallImg)
recall(RecallType.IMAGE, imgReceipt, recall)
if (cooldown > 0)
cooldown(subject, cooldown)
}
//else {
// val imageInfoMsgBuilder = MessageChainBuilder()
// val imageMsgBuilder = MessageChainBuilder()
// for (imageData in response.data) {
// when {
// imageData.urls.size > 1 -> {
// for (url in imageData.urls.values) {
// runCatching {
// val stream = getImageInputStream(url)
// val image = subject?.uploadImage(stream)
// if (image != null)
// if (PluginConfig.messageType == PluginConfig.Type.Flash)
// imageMsgBuilder.add(FlashImage(image))
// else
// imageMsgBuilder.add(image)
// stream
// }.onFailure {
// logger.error(it)
// sendMessage(ReplyConfig.networkError)
// }.onSuccess {
// imageInfoMsgBuilder.add(imageData.toReadable(imageData.urls))
// imageInfoMsgBuilder.add("\n")
// runInterruptible(Dispatchers.IO) {
// it.close()
// }
// }
// }
// }

// imageData.urls.size == 1 -> runCatching {
// val stream = getImageInputStream(imageData.urls.values.first())
// val image = subject?.uploadImage(stream)
// if (image != null)
// if (PluginConfig.messageType == PluginConfig.Type.Flash)
// imageMsgBuilder.add(FlashImage(image))
// else
// imageMsgBuilder.add(image)
// stream
// }.onFailure {
// logger.error(it)
// sendMessage(ReplyConfig.networkError)
// }.onSuccess {
// imageInfoMsgBuilder.add(imageData.toReadable(imageData.urls))
// imageInfoMsgBuilder.add("\n")
// runInterruptible(Dispatchers.IO) {
// it.close()
// }
// }

// else -> {
// continue
// }
// }
// }
// val imgInfoReceipt =
// if (subject == null || PluginConfig.verbose)
// sendMessage(imageInfoMsgBuilder.asMessageChain())
// else null
// val imgReceipt = sendMessage(imageMsgBuilder.build())
// if (notificationReceipt != null)
// recall(RecallType.NOTIFICATION, notificationReceipt, 0)
// if (imgReceipt == null) {
// return@withLock
// } else if (recall > 0 && PluginConfig.recallImg)
// recall(RecallType.IMAGE, imgReceipt, recall)
// if (PluginConfig.verbose && imgInfoReceipt != null && recall > 0 && PluginConfig.recallImgInfo)
// recall(RecallType.IMAGE_INFO, imgInfoReceipt, recall)
// if (cooldown > 0)
// cooldown(subject, cooldown)
// }
}
}
// val imgReceipt = sendMessage(imageMsgBuilder.build())
// if (notificationReceipt != null)
// recall(RecallType.NOTIFICATION, notificationReceipt, 0)
// if (imgReceipt == null) {
// return@withLock
// } else if (recall > 0 && PluginConfig.recallImg)
// recall(RecallType.IMAGE, imgReceipt, recall)
// if (cooldown > 0)
// cooldown(subject, cooldown)
// }
// }
// }
}

0 comments on commit bfc126b

Please sign in to comment.