mirror of
https://github.com/Eyre-S/Coeur-Morny-Cono.git
synced 2024-11-22 11:14:55 +08:00
添加"用户发起动作响应"支持
- 支援动词后缀和名词前缀关闭选项
This commit is contained in:
parent
ed5d3e00bc
commit
4e89f67496
@ -6,7 +6,7 @@ plugins {
|
||||
}
|
||||
|
||||
group 'cc.sukazyo'
|
||||
version '0.3.2'
|
||||
version '0.3.3'
|
||||
project.ext.archiveBaseName = 'Coeur_Morny_Cono'
|
||||
project.ext.artifactId = 'morny-coeur'
|
||||
mainClassName = 'cc.sukazyo.cono.morny.MornyCoeur'
|
||||
|
@ -6,7 +6,7 @@ import java.net.URISyntaxException;
|
||||
|
||||
public class MornySystem {
|
||||
|
||||
public static final String VERSION = "@G_DEV_VERSION@";
|
||||
public static final String VERSION = "0.3.3";
|
||||
|
||||
public static String getJarMd5() {
|
||||
try {
|
||||
|
@ -6,11 +6,13 @@ public class EventListeners {
|
||||
|
||||
public static final OnCommandExecute COMMANDS_LISTENER = new OnCommandExecute();
|
||||
public static final OnActivityRecord ACTIVITY_RECORDER = new OnActivityRecord();
|
||||
public static final OnUserSlashAction USER_SLASH_ACTION = new OnUserSlashAction();
|
||||
|
||||
public static void registerAllListeners () {
|
||||
EventListenerManager.addListener(
|
||||
ACTIVITY_RECORDER,
|
||||
COMMANDS_LISTENER
|
||||
COMMANDS_LISTENER,
|
||||
USER_SLASH_ACTION
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,63 @@
|
||||
package cc.sukazyo.cono.morny.bot.event;
|
||||
|
||||
import cc.sukazyo.cono.morny.MornyCoeur;
|
||||
import cc.sukazyo.cono.morny.bot.api.EventListener;
|
||||
import cc.sukazyo.cono.morny.util.StringUtils;
|
||||
import com.pengrad.telegrambot.model.Update;
|
||||
import com.pengrad.telegrambot.model.User;
|
||||
import com.pengrad.telegrambot.model.request.ParseMode;
|
||||
import com.pengrad.telegrambot.request.SendMessage;
|
||||
|
||||
public class OnUserSlashAction extends EventListener {
|
||||
|
||||
@Override
|
||||
public boolean onMessage (Update event) {
|
||||
String text = event.message().text();
|
||||
if (text == null) return false;
|
||||
|
||||
if (text.startsWith("/")) {
|
||||
int prefixLength = 1;
|
||||
boolean useVerbSuffix = true;
|
||||
boolean useObjectPrefix = true;
|
||||
if (text.startsWith("//#") || text.startsWith("///")) {
|
||||
useVerbSuffix = false;
|
||||
useObjectPrefix = false;
|
||||
prefixLength = 3;
|
||||
} else if (text.startsWith("/#")) {
|
||||
useObjectPrefix = false;
|
||||
prefixLength = 2;
|
||||
} else if (text.startsWith("//")) {
|
||||
useVerbSuffix = false;
|
||||
prefixLength = 2;
|
||||
}
|
||||
|
||||
String[] action = StringUtils.formatCommand(text.substring(prefixLength));
|
||||
String verb = action[0];
|
||||
boolean hasObject = action.length != 1;
|
||||
String object = StringUtils.connectStringArray(action, " ", 1, action.length-1);
|
||||
User origin = event.message().from();
|
||||
User target = (event.message().replyToMessage() == null ? (
|
||||
origin
|
||||
): (
|
||||
event.message().replyToMessage().from()
|
||||
));
|
||||
|
||||
MornyCoeur.getAccount().execute(new SendMessage(
|
||||
event.message().chat().id(),
|
||||
String.format(
|
||||
"<a href='tg://user?id=%d'>%s</a> %s%s <a href='tg://user?id=%d'>%s</a>%s%s",
|
||||
origin.id(), origin.firstName(),
|
||||
verb, (useVerbSuffix?"了":""),
|
||||
target.id(), (origin==target ? "自己" : target.firstName()),
|
||||
(hasObject ? (useObjectPrefix ?" 的": " ") : ""),
|
||||
(hasObject ? object : "")
|
||||
)
|
||||
).parseMode(ParseMode.HTML));
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -49,4 +49,14 @@ public class StringUtils {
|
||||
|
||||
}
|
||||
|
||||
public static String connectStringArray (String[] array, String connector, int startIndex, int stopIndex) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = startIndex; i < stopIndex; i++) {
|
||||
builder.append(array[i]);
|
||||
builder.append(connector);
|
||||
}
|
||||
builder.append(array[stopIndex]);
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user