mirror of
https://github.com/Eyre-S/Coeur-Morny-Cono.git
synced 2024-11-27 05:26:51 +08:00
Compare commits
2 Commits
8e28bbbce1
...
0e3a9d3f9b
Author | SHA1 | Date | |
---|---|---|---|
0e3a9d3f9b | |||
17c29036b3 |
@ -5,7 +5,7 @@ MORNY_ARCHIVE_NAME = morny-coeur
|
||||
MORNY_CODE_STORE = https://github.com/Eyre-S/Coeur-Morny-Cono
|
||||
MORNY_COMMIT_PATH = https://github.com/Eyre-S/Coeur-Morny-Cono/commit/%s
|
||||
|
||||
VERSION = 1.0.0-RC3
|
||||
VERSION = 1.0.0-RC3.2
|
||||
|
||||
USE_DELTA = false
|
||||
VERSION_DELTA =
|
||||
|
@ -7,7 +7,6 @@ import cc.sukazyo.cono.morny.util.tgapi.InputCommand;
|
||||
import com.pengrad.telegrambot.model.Update;
|
||||
import com.pengrad.telegrambot.model.request.ParseMode;
|
||||
import com.pengrad.telegrambot.request.SendMessage;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@ -29,7 +28,7 @@ public class Ip186Query {
|
||||
@Nullable @Override public String[] getAliases () { return new String[0]; }
|
||||
@Nonnull @Override public String getParamRule () { return "[ip]"; }
|
||||
@Nonnull @Override public String getDescription () { return "通过 https://ip.186526.xyz 查询 ip 资料"; }
|
||||
@Override public void execute (@NotNull InputCommand command, @NotNull Update event) { exec(event, command); }
|
||||
@Override public void execute (@Nonnull InputCommand command, @Nonnull Update event) { exec(event, command); }
|
||||
}
|
||||
|
||||
public static class Whois implements ITelegramCommand {
|
||||
@ -37,7 +36,7 @@ public class Ip186Query {
|
||||
@Nullable @Override public String[] getAliases () { return new String[0]; }
|
||||
@Nonnull @Override public String getParamRule () { return "[domain]"; }
|
||||
@Nonnull @Override public String getDescription () { return "通过 https://ip.186526.xyz 查询域名资料"; }
|
||||
@Override public void execute (@NotNull InputCommand command, @NotNull Update event) { exec(event, command); }
|
||||
@Override public void execute (@Nonnull InputCommand command, @Nonnull Update event) { exec(event, command); }
|
||||
}
|
||||
|
||||
private static void exec (@Nonnull Update event, @Nonnull InputCommand command) {
|
||||
|
@ -14,7 +14,6 @@ import com.pengrad.telegrambot.model.request.ParseMode;
|
||||
import com.pengrad.telegrambot.request.SendMessage;
|
||||
import com.pengrad.telegrambot.request.SendSticker;
|
||||
import com.pengrad.telegrambot.request.SetMyCommands;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@ -201,7 +200,7 @@ public class MornyCommands {
|
||||
private static class ExitAlias implements ISimpleCommand {
|
||||
@Nonnull @Override public String getName () { return "quit"; }
|
||||
@Nullable @Override public String[] getAliases () { return new String[]{"stop"}; }
|
||||
@Override public void execute (@NotNull InputCommand command, @NotNull Update event) { onCommandExitExec(event); }
|
||||
@Override public void execute (@Nonnull InputCommand command, @Nonnull Update event) { onCommandExitExec(event); }
|
||||
}
|
||||
private static void onCommandExitExec (@Nonnull Update event) {
|
||||
if (MornyCoeur.trustedInstance().isTrusted(event.message().from().id())) {
|
||||
|
@ -7,7 +7,8 @@ import com.pengrad.telegrambot.request.SendMessage;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import static cc.sukazyo.cono.morny.util.CommonRandom.probabilityTrue;
|
||||
|
||||
@SuppressWarnings("NonAsciiCharacters")
|
||||
public class 私わね implements ISimpleCommand {
|
||||
@ -20,7 +21,7 @@ public class 私わね implements ISimpleCommand {
|
||||
|
||||
@Override
|
||||
public void execute (@Nonnull InputCommand command, @Nonnull Update event) {
|
||||
if (ThreadLocalRandom.current().nextInt(521) == 0) {
|
||||
if (probabilityTrue(521)) {
|
||||
// 可以接入未来的心情系统(如果有的话)
|
||||
// final String text = switch (ThreadLocalRandom.current().nextInt(11)) {
|
||||
// case 0,7,8,9,10 -> "才不是";
|
||||
|
@ -5,18 +5,19 @@ import cc.sukazyo.cono.morny.bot.api.EventListenerManager;
|
||||
public class EventListeners {
|
||||
|
||||
public static final OnTelegramCommand COMMANDS_LISTENER = new OnTelegramCommand();
|
||||
@SuppressWarnings("unused") public static final OnActivityRecord ACTIVITY_RECORDER = new OnActivityRecord();
|
||||
// public static final OnActivityRecord ACTIVITY_RECORDER = new OnActivityRecord();
|
||||
public static final OnUserSlashAction USER_SLASH_ACTION = new OnUserSlashAction();
|
||||
public static final OnUpdateTimestampOffsetLock UPDATE_TIMESTAMP_OFFSET_LOCK = new OnUpdateTimestampOffsetLock();
|
||||
public static final OnInlineQueries INLINE_QUERY = new OnInlineQueries();
|
||||
public static final OnCallMe CALL_ME = new OnCallMe();
|
||||
public static final OnEventHackHandle EVENT_HACK_HANDLE = new OnEventHackHandle();
|
||||
@SuppressWarnings("unused") static final OnKuohuanhuanNeedSleep KUOHUANHUAN_NEED_SLEEP = new OnKuohuanhuanNeedSleep();
|
||||
// static final OnKuohuanhuanNeedSleep KUOHUANHUAN_NEED_SLEEP = new OnKuohuanhuanNeedSleep();
|
||||
public static final OnUserRandoms USER_RANDOMS = new OnUserRandoms();
|
||||
public static final OnCallMsgSend CALL_MSG_SEND = new OnCallMsgSend();
|
||||
public static final OnMedicationNotifyApply MEDICATION_NOTIFY_APPLY = new OnMedicationNotifyApply();
|
||||
public static final OnRandomlyTriggered RANDOMLY_TRIGGERED = new OnRandomlyTriggered();
|
||||
public static final OnUniMeowTrigger UNI_MEOW_TRIGGER = new OnUniMeowTrigger();
|
||||
public static final OnQuestionMarkReply QUESTION_MARK_REPLY = new OnQuestionMarkReply();
|
||||
|
||||
public static void registerAllListeners () {
|
||||
EventListenerManager.addListener(
|
||||
@ -28,6 +29,7 @@ public class EventListeners {
|
||||
UNI_MEOW_TRIGGER,
|
||||
RANDOMLY_TRIGGERED,
|
||||
USER_RANDOMS,
|
||||
QUESTION_MARK_REPLY,
|
||||
USER_SLASH_ACTION,
|
||||
INLINE_QUERY,
|
||||
CALL_ME,
|
||||
|
@ -7,6 +7,7 @@ import com.pengrad.telegrambot.model.Update;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@Deprecated
|
||||
public class OnActivityRecord extends EventListener {
|
||||
|
||||
@Override
|
||||
|
@ -10,6 +10,7 @@ import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.Locale;
|
||||
|
||||
@Deprecated
|
||||
public class OnKuohuanhuanNeedSleep extends EventListener {
|
||||
|
||||
@Override
|
||||
|
@ -5,17 +5,18 @@ import cc.sukazyo.cono.morny.bot.api.EventListener;
|
||||
import cc.sukazyo.cono.morny.daemon.MornyDaemons;
|
||||
import com.pengrad.telegrambot.model.Message;
|
||||
import com.pengrad.telegrambot.model.Update;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class OnMedicationNotifyApply extends EventListener {
|
||||
|
||||
@Override
|
||||
public boolean onEditedChannelPost (@NotNull Update update) {
|
||||
public boolean onEditedChannelPost (@Nonnull Update update) {
|
||||
return editedMessageProcess(update.editedChannelPost());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onEditedMessage (@NotNull Update update) {
|
||||
public boolean onEditedMessage (@Nonnull Update update) {
|
||||
return editedMessageProcess(update.editedMessage());
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,33 @@
|
||||
package cc.sukazyo.cono.morny.bot.event;
|
||||
|
||||
import cc.sukazyo.cono.morny.MornyCoeur;
|
||||
import cc.sukazyo.cono.morny.bot.api.EventListener;
|
||||
import com.pengrad.telegrambot.model.Update;
|
||||
import com.pengrad.telegrambot.request.SendMessage;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Set;
|
||||
|
||||
import static cc.sukazyo.cono.morny.util.CommonRandom.probabilityTrue;
|
||||
|
||||
public class OnQuestionMarkReply extends EventListener {
|
||||
|
||||
public static final Set<String> QUESTION_MARKS = Set.of("?", "?", "¿", "⁈", "⁇", "‽", "❔", "❓");
|
||||
|
||||
@Override
|
||||
public boolean onMessage (@Nonnull Update update) {
|
||||
|
||||
if (update.message().text() == null) return false;
|
||||
|
||||
if (QUESTION_MARKS.contains(update.message().text()) && probabilityTrue(8)) {
|
||||
MornyCoeur.extra().exec(new SendMessage(
|
||||
update.message().chat().id(), update.message().text()
|
||||
).replyToMessageId(update.message().messageId()));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -2,44 +2,34 @@ 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.UniversalCommand;
|
||||
import com.pengrad.telegrambot.model.Update;
|
||||
import com.pengrad.telegrambot.request.SendMessage;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static cc.sukazyo.cono.morny.util.CommonRandom.iif;
|
||||
|
||||
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(.+)");
|
||||
private static final Pattern USER_OR_QUERY = Pattern.compile("(.+)(?:还是|or)(.+)");
|
||||
private static final Pattern USER_IF_QUERY = Pattern.compile("(.+)[吗?|?]+$");
|
||||
|
||||
@Override
|
||||
public boolean onMessage (@NotNull Update update) {
|
||||
public boolean onMessage (@Nonnull Update update) {
|
||||
|
||||
if (update.message().text() == null) return false;
|
||||
if (!update.message().text().startsWith("/")) return false;
|
||||
|
||||
final String[] preProcess = UniversalCommand.format(update.message().text());
|
||||
if (preProcess.length > 1) return false;
|
||||
final String query = preProcess[0];
|
||||
|
||||
// ----- START CODE BLOCK COMMENT -----
|
||||
// 这里实现思路和代码优化有至少一半是 copilot 和 IDEA 提供的
|
||||
// 实现思路都可以从人类手里抢一半贡献太恐怖了aba
|
||||
final String query = update.message().text().substring(1);
|
||||
String result = null;
|
||||
final Matcher matcher;
|
||||
if (query.contains("还是")) {
|
||||
matcher = USER_OR_CN_QUERY.matcher(query);
|
||||
} else {
|
||||
matcher = USER_OR_EN_QUERY.matcher(query);
|
||||
Matcher matcher;
|
||||
if ((matcher = USER_OR_QUERY.matcher(query)).find()) {
|
||||
result = iif() ? matcher.group(1) : matcher.group(2);
|
||||
} else if ((matcher = USER_IF_QUERY.matcher(query)).matches()) {
|
||||
result = (iif()?"":"不") + matcher.group(1);
|
||||
}
|
||||
if (matcher.find()) {
|
||||
result = ThreadLocalRandom.current().nextBoolean() ? matcher.group(1) : matcher.group(2);
|
||||
}
|
||||
// ----- STOP CODE BLOCK COMMENT -----
|
||||
|
||||
if (result == null) return false;
|
||||
MornyCoeur.extra().exec(new SendMessage(
|
||||
|
22
src/main/java/cc/sukazyo/cono/morny/util/CommonRandom.java
Normal file
22
src/main/java/cc/sukazyo/cono/morny/util/CommonRandom.java
Normal file
@ -0,0 +1,22 @@
|
||||
package cc.sukazyo.cono.morny.util;
|
||||
|
||||
import javax.annotation.Nonnegative;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class CommonRandom {
|
||||
|
||||
public static boolean probabilityTrue (@Nonnegative int probability, @Nonnegative int base) {
|
||||
if (probability < 1) throw new IllegalArgumentException("the probability must be a positive value!");
|
||||
if (base < 1) throw new IllegalArgumentException("the probability base must be a positive value!");
|
||||
return probability > ThreadLocalRandom.current().nextInt(base);
|
||||
}
|
||||
|
||||
public static boolean probabilityTrue (@Nonnegative int probabilityIn) {
|
||||
return (probabilityTrue(1, probabilityIn));
|
||||
}
|
||||
|
||||
public static boolean iif () {
|
||||
return ThreadLocalRandom.current().nextBoolean();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user