mirror of
https://github.com/Eyre-S/Coeur-Morny-Cono.git
synced 2024-11-22 19:24:53 +08:00
add function to randomly reply "?" message, added a CommonRandom tool, replace all jb.NotNull to javax.Nonnull
This commit is contained in:
parent
17c29036b3
commit
0e3a9d3f9b
@ -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.1
|
||||
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 -> "才不是";
|
||||
|
@ -17,6 +17,7 @@ public class EventListeners {
|
||||
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,
|
||||
|
@ -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;
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -4,19 +4,20 @@ 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 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_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;
|
||||
@ -25,9 +26,9 @@ public class OnUserRandoms extends EventListener {
|
||||
String result = null;
|
||||
Matcher matcher;
|
||||
if ((matcher = USER_OR_QUERY.matcher(query)).find()) {
|
||||
result = ThreadLocalRandom.current().nextBoolean() ? matcher.group(1) : matcher.group(2);
|
||||
result = iif() ? matcher.group(1) : matcher.group(2);
|
||||
} else if ((matcher = USER_IF_QUERY.matcher(query)).matches()) {
|
||||
result = (ThreadLocalRandom.current().nextBoolean()?"":"不") + matcher.group(1);
|
||||
result = (iif()?"":"不") + matcher.group(1);
|
||||
}
|
||||
|
||||
if (result == null) return false;
|
||||
|
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