Skip to content

Commit

Permalink
新模块
Browse files Browse the repository at this point in the history
  • Loading branch information
Kloping committed Nov 28, 2021
1 parent 06afe7e commit d62055e
Show file tree
Hide file tree
Showing 26 changed files with 471 additions and 32 deletions.
13 changes: 5 additions & 8 deletions Lsys-GetPic/src/main/java/cn/kloping/lsys/getPic/Loader.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@
import cn.kloping.lsys.entitys.Result;
import cn.kloping.lsys.entitys.User;
import cn.kloping.lsys.workers.Methods;
import cn.kloping.url.UrlUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import io.github.kloping.initialize.FileInitializeValue;
import io.github.kloping.url.UrlUtils;
import kotlin.jvm.functions.Function2;
import net.mamoe.mirai.contact.Contact;
import net.mamoe.mirai.message.data.ForwardMessageBuilder;
import net.mamoe.mirai.message.data.Image;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -45,7 +42,7 @@ public class Loader {
invokeGroup.getInvokes().put("堆糖搜图.*", "getDuitPics");
invokeGroup.getInvokesAfter().put("堆糖搜图.*", new String[]{"搜索到了$1个结果", "获取失败"});

conf = cn.kloping.initialize.FileInitializeValue.getValue(Resource.rootPath+"/conf/Lsys/lsys-getPic.json", conf, true);
conf = FileInitializeValue.getValue(Resource.rootPath + "/conf/Lsys/lsys-getPic.json", conf, true);
}

public static final Function2<User, Request, Result> fun2 = (user, request) -> {
Expand Down Expand Up @@ -174,11 +171,11 @@ private static void startCd() {
};

public static void loadConf() {
conf = cn.kloping.initialize.FileInitializeValue.getValue("./conf/Lsys/lsys-getPic.json", conf, true);
conf = FileInitializeValue.getValue(Resource.rootPath + "/conf/Lsys/lsys-getPic.json", conf, true);
}

public static void applyConf() {
cn.kloping.initialize.FileInitializeValue.putValues("./conf/Lsys/lsys-getPic.json", conf, true);
FileInitializeValue.putValues(Resource.rootPath+"/conf/Lsys/lsys-getPic.json", conf, true);
}

public static void load() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import cn.kloping.lsys.entitys.Result;
import cn.kloping.lsys.entitys.User;
import cn.kloping.lsys.workers.Methods;
import cn.kloping.url.UrlUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import io.github.kloping.url.UrlUtils;
import kotlin.jvm.functions.Function2;

import java.io.UnsupportedEncodingException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import java.util.regex.Pattern;

import static cn.kloping.lsys.utils.MessageUtils.createImageInGroup;
import static cn.kloping.url.UrlUtils.getStringFromHttpUrl;
import static io.github.kloping.url.UrlUtils.getStringFromHttpUrl;

public class picParser {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cn.kloping.lsys.sc1

import cn.kloping.initialize.FileInitializeValue
import cn.kloping.lsys.Resource
import io.github.kloping.initialize.FileInitializeValue
import net.mamoe.mirai.console.command.CommandSender
import net.mamoe.mirai.console.command.SimpleCommand
import java.lang.System.err
Expand Down
3 changes: 2 additions & 1 deletion Lsys-Score1/src/main/java/cn/kloping/lsys/sc1/Conf.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cn.kloping.lsys.sc1;

import cn.kloping.lsys.Resource;
import io.github.kloping.initialize.FileInitializeValue;

public class Conf {
private int win = 40;
Expand All @@ -23,6 +24,6 @@ public int getOb() {
}

public void apply() {
cn.kloping.initialize.FileInitializeValue.putValues(Resource.rootPath + "/conf/Lsys/sc1.json", this, true);
FileInitializeValue.putValues(Resource.rootPath + "/conf/Lsys/sc1.json", this, true);
}
}
6 changes: 3 additions & 3 deletions Lsys-Score1/src/main/java/cn/kloping/lsys/sc1/Methods.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package cn.kloping.lsys.sc1;

import cn.kloping.date.DateUtils;
import cn.kloping.file.FileUtils;
import cn.kloping.lsys.Resource;
import cn.kloping.lsys.entitys.Request;
import cn.kloping.lsys.entitys.Result;
import cn.kloping.lsys.entitys.User;
import cn.kloping.lsys.savers.PutGetter;
import cn.kloping.lsys.utils.MessageUtils;
import cn.kloping.number.NumberUtils;
import io.github.kloping.date.DateUtils;
import io.github.kloping.file.FileUtils;
import io.github.kloping.number.NumberUtils;
import kotlin.jvm.functions.Function2;

import java.io.*;
Expand Down
3 changes: 2 additions & 1 deletion Lsys-Score1/src/main/java/cn/kloping/lsys/sc1/sc1.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
import cn.kloping.lsys.Resource;
import cn.kloping.lsys.entitys.InvokeGroup;
import cn.kloping.lsys.workers.Methods;
import io.github.kloping.initialize.FileInitializeValue;

import static cn.kloping.lsys.sc1.Methods.*;

public class sc1 {
public static Conf conf = new Conf();
public static void start() {
conf = cn.kloping.initialize.FileInitializeValue.getValue(Resource.rootPath+"/conf/Lsys/sc1.json", conf, true);
conf = FileInitializeValue.getValue(Resource.rootPath+"/conf/Lsys/sc1.json", conf, true);

InvokeGroup invokeGroup = new InvokeGroup("sco1");

Expand Down
4 changes: 2 additions & 2 deletions Lsys-Score2/src/main/java/cn/kloping/lsys/sc2/Methods.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
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 io.github.kloping.judge.Judge;
import io.github.kloping.number.NumberUtils;
import kotlin.jvm.functions.Function2;

import static cn.kloping.lsys.savers.PutGetter.get;
Expand Down
19 changes: 19 additions & 0 deletions Lsys-idiom/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?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">
<parent>
<artifactId>MiraiLSys</artifactId>
<groupId>org.example</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>Lsys-idiom</artifactId>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>

</project>
12 changes: 12 additions & 0 deletions Lsys-idiom/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
### MiraiLsys 子插件

### 成语接龙小游戏


- 成语接龙 [z6-Lsys-GetSong.jar ](https://github.com/Kloping/MiraiLsys/releases/)
- 同样若无极端情况请不要修改文件名 否则将无法正常工作

### 其默认命令

开始成语接龙
我接 xxxx
36 changes: 36 additions & 0 deletions Lsys-idiom/src/main/java/io/github/kloping/Idiom/CommandLine.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.github.kloping.Idiom;

import io.github.kloping.Idiom.entity.Conf;
import net.mamoe.mirai.console.command.java.JSimpleCommand;

public class CommandLine extends JSimpleCommand {
public CommandLine() {
super(PluginMain.INSTANCE, "Lsys_idiom", "lsys-idiom");
setDescription("lsys的 idiom 成语接龙 插件指令");
}

public static final CommandLine INSTANCE = new CommandLine();

@Handler
public String m1(String arg) {
String[] ss = arg.split("=");
try {
Integer i1 = Integer.parseInt(ss[1].trim());
switch (ss[0]) {
case "setS1":
Conf.INSTANCE.setS1(i1);
Conf.INSTANCE.apply();
System.out.println("设置 积分值为: " + i1);
return "设置 积分值为: " + i1;
case "setMaxError":
Conf.INSTANCE.setMaxError(i1);
Conf.INSTANCE.apply();
System.out.println("设置 最大答错次数: " + i1);
return "设置 最大答错次数: " + i1;
}
} catch (Exception e) {
}
System.err.println("未知命令: \n\t已知: setS1=2\t#设置答对答错获得的积分\n\tsetMaxError=5\t#设置最大打错次数");
return "";
}
}
96 changes: 96 additions & 0 deletions Lsys-idiom/src/main/java/io/github/kloping/Idiom/Idiom.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package io.github.kloping.Idiom;

import com.alibaba.fastjson.JSON;
import io.github.kloping.Idiom.entity.Response;
import io.github.kloping.url.UrlUtils;

import java.net.URLEncoder;
import java.util.LinkedHashSet;
import java.util.Set;

public abstract class Idiom {

public Set<String> hist = new LinkedHashSet<>();

private String upWord;
private String upPinyin;

public Idiom() {
upWord = getRandom();
upPinyin = getEndPinyin(upWord);
hist.add(upWord);
}

public Idiom(int maxFailed) {
this.maxFailed = maxFailed;
}

private int maxFailed = 5;
private int failed = 0;

public int meet(String s) {
try {
failed++;
Response response = request(s);
if (s.trim().length() != 4) return -1;
if (hist.contains(s)) return -2;
if (response.getState().intValue() == -1)
return -3;
if (!upPinyin.equals(getStartPinyin(response)))
return -4;
upWord = s;
upPinyin = getEndPinyin(response);
hist.add(upWord);
failed = 0;
return 0;
} finally {
if (failed >= maxFailed)
fail(s);
}
}

public abstract void fail(String s);

public Set<String> getHist() {
return hist;
}

public String getUpWord() {
return upWord;
}

public String getUpPinyin() {
return upPinyin;
}

static Response request(String arg) {
String str = UrlUtils.getStringFromHttpUrl("http://49.232.209.180:20041/api/get/idiom?word=" + URLEncoder.encode(arg));
return JSON.parseObject(str).toJavaObject(Response.class);
}

static String getRandom() {
return UrlUtils.getStringFromHttpUrl("http://49.232.209.180:20041/api/get/idiom/random");
}

static String getStartPinyin(Response response) {
String s = response.getPinyin()[0];
return s.replaceAll("[0-9]", "");
} static String getStartPinyin(String arg) {
String str = UrlUtils.getStringFromHttpUrl("http://49.232.209.180:20041/api/get/idiom?word=" + URLEncoder.encode(arg));
Response response = JSON.parseObject(str).toJavaObject(Response.class);
String s = response.getPinyin()[0];
return s.replaceAll("[0-9]", "");
}

static String getEndPinyin(String arg) {
String str = UrlUtils.getStringFromHttpUrl("http://49.232.209.180:20041/api/get/idiom?word=" + URLEncoder.encode(arg));
Response response = JSON.parseObject(str).toJavaObject(Response.class);
String s = response.getPinyin()[3];
return s.replaceAll("[0-9]", "");
}

static String getEndPinyin(Response response) {
String s = response.getPinyin()[3];
return s.replaceAll("[0-9]", "");
}
}
45 changes: 45 additions & 0 deletions Lsys-idiom/src/main/java/io/github/kloping/Idiom/PluginMain.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.github.kloping.Idiom;

import com.sun.istack.internal.NotNull;
import net.mamoe.mirai.console.command.CommandManager;
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;

import static io.github.kloping.Idiom.Worker.start;

public class PluginMain extends JavaPlugin {
public static final PluginMain INSTANCE = new PluginMain();

private PluginMain() {
super(new JvmPluginDescriptionBuilder("cn.kloping.lsys.idiom.PluginMain", "0.1")
.name("插件_9 Author => HRS LSys idiom Loaded")
.info("插件")
.author("HRS")
.build());
}

@Override
public void onLoad(@NotNull PluginComponentStorage $this$onLoad) {
if (!Utils.isExits()) {
getLogger().error("欲使用idiom插件 必须安装 Lsys 插件");
getLogger().error("欲使用idiom插件 必须安装 Lsys 插件");
getLogger().error("欲使用idiom插件 必须安装 Lsys 插件");
PluginManager.INSTANCE.disablePlugin(INSTANCE);
return;
}
try {
start();

} catch (Exception e) {
e.printStackTrace();
}
}

@Override
public void onEnable() {
getLogger().info("");
CommandManager.INSTANCE.registerCommand(CommandLine.INSTANCE, false);
}
}
19 changes: 19 additions & 0 deletions Lsys-idiom/src/main/java/io/github/kloping/Idiom/Utils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.github.kloping.Idiom;

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<Plugin, PluginDescription> loader = (PluginLoader<Plugin, PluginDescription>) plugin.getLoader();
String id = loader.getPluginDescription(plugin).getId();
if (id.equals("cn.kloping.Lsys")) {
return true;
}
}
return false;
}
}
Loading

0 comments on commit d62055e

Please sign in to comment.