mirror of
https://github.com/Eyre-S/Coeur-Morny-Cono.git
synced 2024-11-22 19:24:53 +08:00
support QuestionMarkReply to reply more than 1 mark char message. add javadoc
This commit is contained in:
parent
0e3a9d3f9b
commit
031a799070
@ -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.2
|
||||
VERSION = 1.0.0-RC3.3
|
||||
|
||||
USE_DELTA = false
|
||||
VERSION_DELTA =
|
||||
|
@ -12,21 +12,26 @@ import static cc.sukazyo.cono.morny.util.CommonRandom.probabilityTrue;
|
||||
|
||||
public class OnQuestionMarkReply extends EventListener {
|
||||
|
||||
public static final Set<String> QUESTION_MARKS = Set.of("?", "?", "¿", "⁈", "⁇", "‽", "❔", "❓");
|
||||
/**
|
||||
* 一个 unicode 的问号字符列表. 不仅有半角全角问号,也包含了变体问号,和叹号结合的问好以及 uni-emoji 问号。
|
||||
* @since 1.0.0-RC3.2
|
||||
*/
|
||||
public static final Set<Character> 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;
|
||||
if (!probabilityTrue(8)) return false;
|
||||
for (char c : update.message().text().toCharArray()) {
|
||||
if (!QUESTION_MARKS.contains(c)) return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
MornyCoeur.extra().exec(new SendMessage(
|
||||
update.message().chat().id(), update.message().text()
|
||||
).replyToMessageId(update.message().messageId()));
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
@ -5,16 +5,38 @@ import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class CommonRandom {
|
||||
|
||||
/**
|
||||
* 通过 {@link ThreadLocalRandom} 以指定的一定几率返回 true.
|
||||
* @param probability 一个正整数,决定在样本空间中有多大的可能性为 true。
|
||||
* @param base 一个正整数,决定样本空间有多大。
|
||||
* @return 有 {@code base} 分之 {@code probability} 的几率,返回值为 {@link true}.
|
||||
* 如果 {@code probability} 大于 {@code base},也就是为 true 的可能性大于 100%,则会永远为 true。
|
||||
* @throws IllegalArgumentException
|
||||
* 当参数 base 或是 probability 不为正整数时
|
||||
* @since 1.0.0-RC3.2
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 以一定几率返回 true.
|
||||
* @return {@code probabilityIn} 分之 {@link 1} 的几率为 {@link true}.
|
||||
* @see #probabilityTrue(int, int)
|
||||
* @since 1.0.0-RC3.2
|
||||
*/
|
||||
public static boolean probabilityTrue (@Nonnegative int probabilityIn) {
|
||||
return (probabilityTrue(1, probabilityIn));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过 {@link ThreadLocalRandom} 实现的随机 boolean 取值.
|
||||
* @return 随机的 {@link true} 或 {@link false},各占(近似)一半可能性.
|
||||
* @see ThreadLocalRandom#nextBoolean()
|
||||
* @since 1.0.0-RC3.2
|
||||
*/
|
||||
public static boolean iif () {
|
||||
return ThreadLocalRandom.current().nextBoolean();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user