From 6f782054e047f2fd8e785976a4db1045fb383850 Mon Sep 17 00:00:00 2001 From: kloping <3474006766@qq.com> Date: Tue, 16 Nov 2021 12:22:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=AD=90=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/kloping/lsys/picParser/picParser.java | 22 -------- .../java/cn/kloping/lsys/sc1/Methods.java | 11 ++-- Lsys-Score2/pom.xml | 19 +++++++ Lsys-Score2/readme.md | 13 +++++ .../java/cn/kloping/lsys/sc2/Methods.java | 50 +++++++++++++++++++ .../java/cn/kloping/lsys/sc2/PluginMain.java | 41 +++++++++++++++ .../main/java/cn/kloping/lsys/sc2/Utils.java | 19 +++++++ .../main/java/cn/kloping/lsys/sc2/sc2.java | 42 ++++++++++++++++ ...t.mamoe.mirai.console.plugin.jvm.JvmPlugin | 1 + pom.xml | 1 + readme.md | 2 + src/main/java/cn/kloping/lsys/PluginMain.kt | 2 +- src/main/java/cn/kloping/lsys/Resource.kt | 2 +- src/main/java/cn/kloping/lsys/entitys/Conf.kt | 32 +----------- .../java/cn/kloping/lsys/entitys/Request.kt | 6 +++ src/main/java/cn/kloping/lsys/entitys/User.kt | 16 +++--- .../java/cn/kloping/lsys/workers/Methods.kt | 49 +++++++++++++----- 17 files changed, 248 insertions(+), 80 deletions(-) create mode 100644 Lsys-Score2/pom.xml create mode 100644 Lsys-Score2/readme.md create mode 100644 Lsys-Score2/src/main/java/cn/kloping/lsys/sc2/Methods.java create mode 100644 Lsys-Score2/src/main/java/cn/kloping/lsys/sc2/PluginMain.java create mode 100644 Lsys-Score2/src/main/java/cn/kloping/lsys/sc2/Utils.java create mode 100644 Lsys-Score2/src/main/java/cn/kloping/lsys/sc2/sc2.java create mode 100644 Lsys-Score2/src/main/resources/META-INF/services/net.mamoe.mirai.console.plugin.jvm.JvmPlugin diff --git a/Lsys-PicParser/src/main/java/cn/kloping/lsys/picParser/picParser.java b/Lsys-PicParser/src/main/java/cn/kloping/lsys/picParser/picParser.java index a7a6452..ca0e65c 100644 --- a/Lsys-PicParser/src/main/java/cn/kloping/lsys/picParser/picParser.java +++ b/Lsys-PicParser/src/main/java/cn/kloping/lsys/picParser/picParser.java @@ -147,26 +147,4 @@ public static String[] parseDyImgs(String url) { } return null; } - -// public static synchronized Image createImageInGroup(Contact group, String path) { -// try { -// if (path.startsWith("http")) { -// return Contact.uploadImage(group, new URL(path).openStream()); -// } else if (path.startsWith("{")) { -// return Image.fromId(path); -// } else { -// Image image = null; -// image = Contact.uploadImage(group, new File(path)); -// return image; -// } -// } catch (IOException e) { -// System.err.println(path + "加载重试"); -// try { -// return Contact.uploadImage(group, new URL(path).openStream()); -// } catch (IOException ioException) { -// ioException.printStackTrace(); -// return null; -// } -// } -// } } diff --git a/Lsys-Score1/src/main/java/cn/kloping/lsys/sc1/Methods.java b/Lsys-Score1/src/main/java/cn/kloping/lsys/sc1/Methods.java index a80d0f0..5bbab64 100644 --- a/Lsys-Score1/src/main/java/cn/kloping/lsys/sc1/Methods.java +++ b/Lsys-Score1/src/main/java/cn/kloping/lsys/sc1/Methods.java @@ -14,14 +14,9 @@ import java.io.*; import static cn.kloping.lsys.utils.MessageUtils.random; +import static cn.kloping.lsys.workers.Methods.*; public class Methods { - public static final Result state1 = new Result(new Object[]{}, 1); - public static final Result state2 = new Result(new Object[]{}, 2); - public static final Result state3 = new Result(new Object[]{}, 3); - public static final Result state4 = new Result(new Object[]{}, 4); - public static final Result state5 = new Result(new Object[]{}, 5); - public static final Function2 rob = (user, request) -> { long q2 = MessageUtils.getAtFromRequest(request); if (q2 == -1) return state1; @@ -87,11 +82,11 @@ public class Methods { switch (m1.Reff(m2)) { case 0: return new Result(new Object[]{m2.getValue()}, 2); - case 1: + case -1: user.addP(num); user.apply(); return new Result(new Object[]{m2.getValue(), num}, 1); - case -1: + case 1: user.addP(-num); user.apply(); return new Result(new Object[]{m2.getValue(), num}, 0); diff --git a/Lsys-Score2/pom.xml b/Lsys-Score2/pom.xml new file mode 100644 index 0000000..e9ef230 --- /dev/null +++ b/Lsys-Score2/pom.xml @@ -0,0 +1,19 @@ + + + + MiraiLSys + org.example + 1.0-SNAPSHOT + + 4.0.0 + + Lsys-Score2 + + + 8 + 8 + + + \ No newline at end of file diff --git a/Lsys-Score2/readme.md b/Lsys-Score2/readme.md new file mode 100644 index 0000000..a4b9556 --- /dev/null +++ b/Lsys-Score2/readme.md @@ -0,0 +1,13 @@ +### MiraiLsys 子插件 + +###积分相关的操作 +下载 + +- 积分相关的 [z5-Lsys-Score2 ](https://github.com/Kloping/MiraiLsys/releases) + - 同样若无极端情况请不要修改文件名 否则将无法正常工作 + +### 其命令 + + 1. 积分侦查@xx + 2. 积分转让@xx(xx) + 3. 打工@xx \ No newline at end of file diff --git a/Lsys-Score2/src/main/java/cn/kloping/lsys/sc2/Methods.java b/Lsys-Score2/src/main/java/cn/kloping/lsys/sc2/Methods.java new file mode 100644 index 0000000..5e47bde --- /dev/null +++ b/Lsys-Score2/src/main/java/cn/kloping/lsys/sc2/Methods.java @@ -0,0 +1,50 @@ +package cn.kloping.lsys.sc2; + +import cn.kloping.judge.Judge; +import cn.kloping.lsys.entitys.Request; +import cn.kloping.lsys.entitys.Result; +import cn.kloping.lsys.entitys.User; +import cn.kloping.lsys.utils.MessageUtils; +import cn.kloping.number.NumberUtils; +import kotlin.jvm.functions.Function2; + +import static cn.kloping.lsys.savers.PutGetter.get; +import static cn.kloping.lsys.workers.Methods.*; + +public class Methods { + + public static final Function2 transTo = (user, request) -> { + long q2 = MessageUtils.getAtFromRequest(request); + if (q2 == -1) return state3; + User u2 = get(q2); + if (u2 == null) return state2; + String nStr = NumberUtils.findNumberFromString(request.getStr()).replace(q2+"",""); + if (Judge.isEmpty(nStr)) return state4; + long n = Long.parseLong(nStr); + if (user.getP() < n) return state1; + u2.addP(n); + user.addP(-n); + return state0; + }; + public static final Function2 LongTimeWork = (user, request) -> { + long k1 = user.getK1(); + if (k1 >= System.currentTimeMillis()) { + String tips = (k1 - System.currentTimeMillis()) / 1000 / 60 + "分钟之后"; + return new Result(new Object[]{tips}, 0); + } + int r = MessageUtils.random.nextInt(20) + 40; + user.addP(r); + int rt = (MessageUtils.random.nextInt(5) + 6); + user.setK1(System.currentTimeMillis() + rt * 1000 * 60); + user.apply(); + return new Result(new Object[]{rt, r}, 1); + }; + public static final Function2 lookSc = (user, request) -> { + long q2 = MessageUtils.getAtFromRequest(request); + if (q2 == -1) return state2; + User u2 = get(q2); + if (u2 == null) return state1; + return new Result(new Object[]{u2.getP()}, 0); + }; + +} diff --git a/Lsys-Score2/src/main/java/cn/kloping/lsys/sc2/PluginMain.java b/Lsys-Score2/src/main/java/cn/kloping/lsys/sc2/PluginMain.java new file mode 100644 index 0000000..a4e2c15 --- /dev/null +++ b/Lsys-Score2/src/main/java/cn/kloping/lsys/sc2/PluginMain.java @@ -0,0 +1,41 @@ +package cn.kloping.lsys.sc2; + +import com.sun.istack.internal.NotNull; +import net.mamoe.mirai.console.extension.PluginComponentStorage; +import net.mamoe.mirai.console.plugin.PluginManager; +import net.mamoe.mirai.console.plugin.jvm.JavaPlugin; +import net.mamoe.mirai.console.plugin.jvm.JvmPluginDescriptionBuilder; + + +public class PluginMain extends JavaPlugin { + public static final PluginMain INSTANCE = new PluginMain(); + + private PluginMain() { + super(new JvmPluginDescriptionBuilder("cn.kloping.lsys.sco2.PluginMain", "0.1") + .name("插件_8 Author => HRS LSys sco2 Loaded") + .info("插件") + .author("HRS") + .build()); + } + + @Override + public void onLoad(@NotNull PluginComponentStorage $this$onLoad) { + if (!Utils.isExits()) { + getLogger().error("欲使用sco2插件 必须安装 Lsys 插件"); + getLogger().error("欲使用sco2插件 必须安装 Lsys 插件"); + getLogger().error("欲使用sco2插件 必须安装 Lsys 插件"); + PluginManager.INSTANCE.disablePlugin(INSTANCE); + return; + } + try { + sc2.start(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Override + public void onEnable() { + getLogger().info(""); + } +} \ No newline at end of file diff --git a/Lsys-Score2/src/main/java/cn/kloping/lsys/sc2/Utils.java b/Lsys-Score2/src/main/java/cn/kloping/lsys/sc2/Utils.java new file mode 100644 index 0000000..d7bfffe --- /dev/null +++ b/Lsys-Score2/src/main/java/cn/kloping/lsys/sc2/Utils.java @@ -0,0 +1,19 @@ +package cn.kloping.lsys.sc2; + +import net.mamoe.mirai.console.plugin.Plugin; +import net.mamoe.mirai.console.plugin.PluginManager; +import net.mamoe.mirai.console.plugin.description.PluginDescription; +import net.mamoe.mirai.console.plugin.loader.PluginLoader; + +public class Utils { + public static boolean isExits() { + for (Plugin plugin : PluginManager.INSTANCE.getPlugins()) { + PluginLoader loader = (PluginLoader) plugin.getLoader(); + String id = loader.getPluginDescription(plugin).getId(); + if (id.equals("cn.kloping.Lsys")) { + return true; + } + } + return false; + } +} diff --git a/Lsys-Score2/src/main/java/cn/kloping/lsys/sc2/sc2.java b/Lsys-Score2/src/main/java/cn/kloping/lsys/sc2/sc2.java new file mode 100644 index 0000000..1579f90 --- /dev/null +++ b/Lsys-Score2/src/main/java/cn/kloping/lsys/sc2/sc2.java @@ -0,0 +1,42 @@ +package cn.kloping.lsys.sc2; + +import cn.kloping.lsys.Resource; +import cn.kloping.lsys.entitys.InvokeGroup; +import cn.kloping.lsys.workers.Methods; + +import static cn.kloping.lsys.sc2.Methods.*; + +public class sc2 { + public static void start() { + InvokeGroup invokeGroup = new InvokeGroup("sco2"); + + invokeGroup.getInvokes().put("积分转让.*", "transTo"); + invokeGroup.getInvokesAfter().put("积分转让.*", new String[]{"\n积分转让成功" + , "\n积分不足" + , "\nta还没有注册呢" + , "\nta转给谁呢" + , "\n转多少呢" + }); + Methods.invokes.put("transTo", transTo); + //=打劫end + invokeGroup.getInvokes().put("积分侦查.*", "lookSc"); + invokeGroup.getInvokesAfter().put("积分侦查.*", new String[]{"\nta剩的积分:$1" + , "\nta还没有注册" + , "\n侦查谁" + }); + Methods.invokes.put("lookSc", lookSc); + //=签到end + invokeGroup.getInvokes().put("打工.*", "LongTimeWork"); + invokeGroup.getInvokesAfter().put("打工.*", new String[]{"\n冷却时间未到:$1" + , "\n您花费了$1分钟,打工赚了 $2 积分" + }); + Methods.invokes.put("LongTimeWork", LongTimeWork); + //=猜拳end + + Resource.loadConfAfter.add(() -> { + if (!Resource.conf.getInvokeGroups().containsKey(invokeGroup.getId())) + Resource.conf.getInvokeGroups().put(invokeGroup.getId(), invokeGroup); + }); + Resource.i1(); + } +} \ No newline at end of file diff --git a/Lsys-Score2/src/main/resources/META-INF/services/net.mamoe.mirai.console.plugin.jvm.JvmPlugin b/Lsys-Score2/src/main/resources/META-INF/services/net.mamoe.mirai.console.plugin.jvm.JvmPlugin new file mode 100644 index 0000000..e7d6051 --- /dev/null +++ b/Lsys-Score2/src/main/resources/META-INF/services/net.mamoe.mirai.console.plugin.jvm.JvmPlugin @@ -0,0 +1 @@ +cn.kloping.lsys.sc2.PluginMain \ No newline at end of file diff --git a/pom.xml b/pom.xml index bc3e188..8295ae4 100644 --- a/pom.xml +++ b/pom.xml @@ -14,6 +14,7 @@ Lsys-PartN Lsys-PicParser Lsys-Score1 + Lsys-Score2 diff --git a/readme.md b/readme.md index 9462784..2263792 100644 --- a/readme.md +++ b/readme.md @@ -108,6 +108,8 @@ - 发图的[z2-Lsys-GetPic ](https://github.com/Kloping/MiraiLsys/tree/master/Lsys-GetPic) - 解析图片[Lsys-PicParser](https://github.com/Kloping/MiraiLsys/tree/master/Lsys-PicParser) - 积分相关操作的1[Lsys-Score1](https://github.com/Kloping/MiraiLsys/tree/master/Lsys-Score1) +- 积分相关操作的2[Lsys-Score2](https://github.com/Kloping/MiraiLsys/tree/master/Lsys-Score2) +- - (后续将继续更新) #### 值得注意的是 若 未安装 主插件 diff --git a/src/main/java/cn/kloping/lsys/PluginMain.kt b/src/main/java/cn/kloping/lsys/PluginMain.kt index f35bcf4..bb6738d 100644 --- a/src/main/java/cn/kloping/lsys/PluginMain.kt +++ b/src/main/java/cn/kloping/lsys/PluginMain.kt @@ -21,7 +21,7 @@ import kotlin.coroutines.CoroutineContext class PluginMain : KotlinPlugin { constructor() : super( - JvmPluginDescriptionBuilder("cn.kloping.Lsys", "0.2.2") + JvmPluginDescriptionBuilder("cn.kloping.Lsys", "0.2.5") .name("插件_ Author => HRS LSys Loaded") .info("插件") .author("HRS") diff --git a/src/main/java/cn/kloping/lsys/Resource.kt b/src/main/java/cn/kloping/lsys/Resource.kt index a6c074b..13548a9 100644 --- a/src/main/java/cn/kloping/lsys/Resource.kt +++ b/src/main/java/cn/kloping/lsys/Resource.kt @@ -50,7 +50,7 @@ object Resource { val invokeGroupMap = ConcurrentHashMap().apply { put(invokeGroup.id, invokeGroup) } - conf = Conf("$rootPath/data/LSys", -1, arrayOf(-1), invokeGroupMap, false) + conf = Conf("$rootPath/data/LSys", -1, HashSet(), invokeGroupMap, false) } @OptIn(ConsoleFrontEndImplementation::class) diff --git a/src/main/java/cn/kloping/lsys/entitys/Conf.kt b/src/main/java/cn/kloping/lsys/entitys/Conf.kt index bb02aac..68a1331 100644 --- a/src/main/java/cn/kloping/lsys/entitys/Conf.kt +++ b/src/main/java/cn/kloping/lsys/entitys/Conf.kt @@ -10,12 +10,12 @@ import java.util.concurrent.ConcurrentHashMap data class Conf( val path: String, var qq: Number, - var opens: Array, + var opens: java.util.HashSet, val invokeGroups: ConcurrentHashMap, var prK: Boolean ) : Entity { - constructor() : this("", -1, arrayOf(-1), ConcurrentHashMap(), false); + constructor() : this("", -1, HashSet(), ConcurrentHashMap(), false); @JSONField(serialize = false) val invokes = ConcurrentHashMap(); @@ -33,32 +33,4 @@ data class Conf( override fun apply() { FileInitializeValue.putValues(File("$rootPath/", "conf/LSys/conf.json").absolutePath, Resource.conf, true) } - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (javaClass != other?.javaClass) return false - - other as Conf - - if (path != other.path) return false - if (qq != other.qq) return false - if (!opens.contentEquals(other.opens)) return false - if (invokeGroups != other.invokeGroups) return false - if (prK != other.prK) return false - if (invokes != other.invokes) return false - if (invokesAfter != other.invokesAfter) return false - - return true - } - - override fun hashCode(): Int { - var result = path.hashCode() - result = 31 * result + qq.hashCode() - result = 31 * result + opens.contentHashCode() - result = 31 * result + invokeGroups.hashCode() - result = 31 * result + prK.hashCode() - result = 31 * result + invokes.hashCode() - result = 31 * result + invokesAfter.hashCode() - return result - } } diff --git a/src/main/java/cn/kloping/lsys/entitys/Request.kt b/src/main/java/cn/kloping/lsys/entitys/Request.kt index e767341..26e80d8 100644 --- a/src/main/java/cn/kloping/lsys/entitys/Request.kt +++ b/src/main/java/cn/kloping/lsys/entitys/Request.kt @@ -2,6 +2,12 @@ package cn.kloping.lsys.entitys import net.mamoe.mirai.event.events.MessageEvent +/** + * str: 原话 + * oStr: 匹配到的语句 + * sendId: 发送人Id + * gId: 群Id 若存在 + */ data class Request( val str:String, val oStr:String, diff --git a/src/main/java/cn/kloping/lsys/entitys/User.kt b/src/main/java/cn/kloping/lsys/entitys/User.kt index c66027c..f601b9c 100644 --- a/src/main/java/cn/kloping/lsys/entitys/User.kt +++ b/src/main/java/cn/kloping/lsys/entitys/User.kt @@ -7,26 +7,30 @@ data class User( /** * qq */ - val qq: Number, + val qq: Number=-1, /** * 积分 */ - var p: Long, + var p: Long=1000, /** * 存的积分 */ - var p2: Long, + var p2: Long=200, /** * 犯罪指数 */ - var pf: Long, + var pf: Long=0, /** * 上次注册天 */ - var ur: Int + var ur: Int=0, + /** + * 打工冷却 + */ + var k1: Long =0, ) : Entity { - constructor() : this(-1, 0, 0, 0, 0) + constructor() : this(-1, 0, 0, 0, 0,0) fun getP2(n: Long): Boolean { if (n <= this.p2) { diff --git a/src/main/java/cn/kloping/lsys/workers/Methods.kt b/src/main/java/cn/kloping/lsys/workers/Methods.kt index 1050ca4..bcf3261 100644 --- a/src/main/java/cn/kloping/lsys/workers/Methods.kt +++ b/src/main/java/cn/kloping/lsys/workers/Methods.kt @@ -9,6 +9,29 @@ import cn.kloping.number.NumberUtils import java.util.concurrent.ConcurrentHashMap object Methods { + + @JvmField + val state0 = Result(arrayOf(), 0) + + @JvmField + val state1 = Result(arrayOf(), 1) + + @JvmField + val state2 = Result(arrayOf(), 2) + + @JvmField + val state3 = Result(arrayOf(), 3) + + @JvmField + val state4 = Result(arrayOf(), 4) + + @JvmField + val state5 = Result(arrayOf(), 5) + + @JvmField + val state6 = Result(arrayOf(), 6) + + @JvmField public val invokes = ConcurrentHashMap Result?>(); @@ -71,12 +94,11 @@ object Methods { val mOpen: (arg: User, args: Request?) -> Result? = { user: User, any: Request? -> val gq: Number = any?.gId!! if (user.qq == Resource.conf.qq) { - if (Resource.conf.opens.contains(gq)) { - Result(null, 1) - } else { - Resource.conf.opens = Resource.conf.opens.plusElement(gq) + if (conf.opens.add(gq)) { Resource.conf.apply() Result(null, 0) + } else { + Result(null, 1) } } else { null @@ -91,17 +113,20 @@ object Methods { val gq: Number = any?.gId!! if (user.qq == Resource.conf.qq) { if (Resource.conf.opens.contains(gq)) { - Resource.conf.opens = Resource.conf.opens.apply { - for ((i, gi) in this.withIndex()) { - when (gi) { - gq -> { - this.drop(i) - break + /* Resource.conf.opens = Resource.conf.opens.apply { + for ((i, gi) in this.withIndex()) { + when (gi) { + gq -> { + this.drop(i) + break + } } } } - } - Resource.conf.apply() + Resource.conf.apply() + */ + conf.opens.remove(gq); + conf.apply(); Result(null, 0) } else { Result(null, 1)