Skip to content

Commit

Permalink
1. Fixed substring issue
Browse files Browse the repository at this point in the history
2. Add catch exceptions for delayreplay.
  • Loading branch information
hezhenwei committed Aug 10, 2021
1 parent 64179c8 commit 13e0174
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 41 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apply plugin: "java"

version '0.1.0'
version '0.1.1'

sourceCompatibility = 10

Expand Down Expand Up @@ -31,7 +31,7 @@ dependencies{
defaultTasks 'jar'

jar{
archiveFileName = "${project.archivesBaseName}-${project.version}.jar"
archiveFileName = "MykesTool_MTDChatBot-${project.version}.jar"
from{
configurations.runtimeClasspath.collect{it.isDirectory() ? it : zipTree(it)}
}
Expand Down
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"author": "Myke.H",
"main": "MykesTool.MTDChatBotPlugin",
"description": "Mindustry Chat Bot.",
"version": "0.1.0"
"version": "0.1.1"
}
79 changes: 41 additions & 38 deletions src/MykesTool/MTDChatBotPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,45 +151,48 @@ private String AskAndGetReplyContent(String strAsk)
private long m_nLastChatTime = 0;
private void DelayReply(Player player, String strMsg) {

int nBotNamePos = -1;
String strCallName = "@" + m_strBotName;
nBotNamePos = strMsg.indexOf(strCallName);

//Log.info(text);
//Log.info(nBotNamePos);
if (nBotNamePos == 0) {
String strAsk = strMsg.substring(strCallName.length());
String strFormattedReply = AskAndGetReplyContent(strAsk);
Call.sendMessage(m_strMsgPrefix + strFormattedReply); // say to all
Log.info(m_strMsgPrefix + strFormattedReply); // log this so we can trace back

m_nLastChatTime = System.currentTimeMillis( );
} // if has "@myke" prefix
else if( Groups.player.size()<= m_nLessPeopleActive)
{
String strAsk = strMsg;
String strFormattedReply = AskAndGetReplyContent(strAsk);
Call.sendMessage(m_strMsgPrefix + strFormattedReply); // say to all
Log.info(m_strMsgPrefix + strFormattedReply); // log this so we can trace back
m_nLastChatTime = System.currentTimeMillis( );

} else if(0 == strMsg.indexOf("无聊") || 0 == strMsg.indexOf("有点无聊") || 0 == strMsg.indexOf("好无聊")) {

String strAsk = strMsg;
String strFormattedReply = AskAndGetReplyContent(strAsk);
Call.sendMessage(m_strMsgPrefix + strFormattedReply); // say to all
Log.info(m_strMsgPrefix + strFormattedReply); // log this so we can trace back
m_nLastChatTime = System.currentTimeMillis( );
}
else {
// otherwise, only see what he will reply, but not show them.
String strAsk = strMsg.substring(strCallName.length());
String strFormattedReply = AskAndGetReplyContent(strAsk);
//Call.sendMessage(m_strMsgPrefix + strFormattedReply); // say to all
Log.info(m_strMsgPrefix + strFormattedReply); // log this so we can trace back

//m_nLastChatTime = System.currentTimeMillis( );
try {
int nBotNamePos = -1;
String strCallName = "@" + m_strBotName;
nBotNamePos = strMsg.indexOf(strCallName);

//Log.info(text);
//Log.info(nBotNamePos);
if (nBotNamePos == 0) {
String strAsk = strMsg.substring(strCallName.length());
String strFormattedReply = AskAndGetReplyContent(strAsk);
Call.sendMessage(m_strMsgPrefix + strFormattedReply); // say to all
Log.info(m_strMsgPrefix + strFormattedReply); // log this so we can trace back

m_nLastChatTime = System.currentTimeMillis();
} // if has "@myke" prefix
else if (Groups.player.size() <= m_nLessPeopleActive) {
String strAsk = strMsg;
String strFormattedReply = AskAndGetReplyContent(strAsk);
Call.sendMessage(m_strMsgPrefix + strFormattedReply); // say to all
Log.info(m_strMsgPrefix + strFormattedReply); // log this so we can trace back
m_nLastChatTime = System.currentTimeMillis();

} else if (0 == strMsg.indexOf("无聊") || 0 == strMsg.indexOf("有点无聊") || 0 == strMsg.indexOf("好无聊")) {

String strAsk = strMsg;
String strFormattedReply = AskAndGetReplyContent(strAsk);
Call.sendMessage(m_strMsgPrefix + strFormattedReply); // say to all
Log.info(m_strMsgPrefix + strFormattedReply); // log this so we can trace back
m_nLastChatTime = System.currentTimeMillis();
} else {
// otherwise, only see what he will reply, but not show them.
String strAsk = strMsg;
String strFormattedReply = AskAndGetReplyContent(strAsk);
//Call.sendMessage(m_strMsgPrefix + strFormattedReply); // say to all
Log.info(m_strMsgPrefix + strFormattedReply); // log this so we can trace back

//m_nLastChatTime = System.currentTimeMillis( );

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

Expand Down

0 comments on commit 13e0174

Please sign in to comment.