-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
471 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
36
Lsys-idiom/src/main/java/io/github/kloping/Idiom/CommandLine.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
96
Lsys-idiom/src/main/java/io/github/kloping/Idiom/Idiom.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
45
Lsys-idiom/src/main/java/io/github/kloping/Idiom/PluginMain.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
19
Lsys-idiom/src/main/java/io/github/kloping/Idiom/Utils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.