mirror of
https://github.com/Eyre-S/Coeur-Morny-Cono.git
synced 2024-11-22 11:14:55 +08:00
添加 XXX还是XXX 的功能 通过斜线前缀触发 #2
This commit is contained in:
parent
5046a27266
commit
ce53e70dfa
@ -1,6 +1,6 @@
|
||||
## Core
|
||||
|
||||
VERSION = 0.7.0.1
|
||||
VERSION = 0.7.0.2
|
||||
|
||||
# dependencies
|
||||
|
||||
|
@ -4,6 +4,6 @@ package cc.sukazyo.cono.morny;
|
||||
* the final field that will be updated by gradle automatically.
|
||||
*/
|
||||
public class GradleProjectConfigures {
|
||||
public static final String VERSION = "0.7.0.1";
|
||||
public static final long COMPILE_TIMESTAMP = 1647424091182L;
|
||||
public static final String VERSION = "0.7.0.2";
|
||||
public static final long COMPILE_TIMESTAMP = 1647451512009L;
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ public class EventListeners {
|
||||
public static final OnCallMe CALL_ME = new OnCallMe();
|
||||
public static final OnEventHackHandle EVENT_HACK_HANDLE = new OnEventHackHandle();
|
||||
public static final OnKuohuanhuanNeedSleep KUOHUANHUAN_NEED_SLEEP = new OnKuohuanhuanNeedSleep();
|
||||
public static final OnUserRandoms USER_RANDOMS = new OnUserRandoms();
|
||||
|
||||
public static void registerAllListeners () {
|
||||
EventListenerManager.addListener(
|
||||
@ -19,6 +20,7 @@ public class EventListeners {
|
||||
UPDATE_TIMESTAMP_OFFSET_LOCK,
|
||||
KUOHUANHUAN_NEED_SLEEP,
|
||||
COMMANDS_LISTENER,
|
||||
USER_RANDOMS,
|
||||
USER_SLASH_ACTION,
|
||||
INLINE_QUERY,
|
||||
CALL_ME,
|
||||
|
@ -0,0 +1,48 @@
|
||||
package cc.sukazyo.cono.morny.bot.event;
|
||||
|
||||
import cc.sukazyo.cono.morny.MornyCoeur;
|
||||
import cc.sukazyo.cono.morny.bot.api.EventListener;
|
||||
import cc.sukazyo.untitled.util.command.CommonCommand;
|
||||
import com.pengrad.telegrambot.model.Update;
|
||||
import com.pengrad.telegrambot.request.SendMessage;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class OnUserRandoms extends EventListener {
|
||||
|
||||
private static final Pattern USER_OR_CN_QUERY = Pattern.compile("(.+)还是(.+)");
|
||||
private static final Pattern USER_OR_EN_QUERY = Pattern.compile("(.+)or(.+)");
|
||||
|
||||
@Override
|
||||
public boolean onMessage (@NotNull Update update) {
|
||||
|
||||
if (update.message().text() == null) return false;
|
||||
if (!update.message().text().startsWith("/")) return false;
|
||||
|
||||
final String[] preProcess = CommonCommand.format(update.message().text());
|
||||
if (preProcess.length > 1) return false;
|
||||
final String query = preProcess[0];
|
||||
|
||||
String result = null;
|
||||
final Matcher matcher;
|
||||
if (query.contains("还是")) {
|
||||
matcher = USER_OR_CN_QUERY.matcher(query);
|
||||
} else {
|
||||
matcher = USER_OR_EN_QUERY.matcher(query);
|
||||
}
|
||||
if (matcher.find()) {
|
||||
result = ThreadLocalRandom.current().nextBoolean() ? matcher.group(1) : matcher.group(2);
|
||||
}
|
||||
|
||||
if (result == null) return false;
|
||||
MornyCoeur.extra().exec(new SendMessage(
|
||||
update.message().chat().id(), result
|
||||
).replyToMessageId(update.message().messageId()));
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user